mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 16:50:14 +00:00
use existing dial string parser for strings supplied to iax2_devicestate, because they can be complete dial strings, not just device names
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.2@34159 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -9330,51 +9330,39 @@ struct ast_custom_function iaxpeer_function = {
|
|||||||
/*--- iax2_devicestate: Part of the device state notification system ---*/
|
/*--- iax2_devicestate: Part of the device state notification system ---*/
|
||||||
static int iax2_devicestate(void *data)
|
static int iax2_devicestate(void *data)
|
||||||
{
|
{
|
||||||
char *dest = (char *) data;
|
struct parsed_dial_string pds;
|
||||||
|
char *tmp = ast_strdupa(data);
|
||||||
struct iax2_peer *p;
|
struct iax2_peer *p;
|
||||||
int found = 0;
|
|
||||||
char *ext, *host;
|
|
||||||
char tmp[256];
|
|
||||||
int res = AST_DEVICE_INVALID;
|
int res = AST_DEVICE_INVALID;
|
||||||
|
|
||||||
ast_copy_string(tmp, dest, sizeof(tmp));
|
parse_dial_string(tmp, &pds);
|
||||||
host = strchr(tmp, '@');
|
if (!pds.peer || ast_strlen_zero(pds.peer))
|
||||||
if (host) {
|
return res;
|
||||||
*host = '\0';
|
|
||||||
host++;
|
|
||||||
ext = tmp;
|
|
||||||
} else {
|
|
||||||
host = tmp;
|
|
||||||
ext = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (option_debug > 2)
|
if (option_debug > 2)
|
||||||
ast_log(LOG_DEBUG, "Checking device state for device %s\n", dest);
|
ast_log(LOG_DEBUG, "Checking device state for device %s\n", pds.peer);
|
||||||
|
|
||||||
/* SLD: FIXME: second call to find_peer during registration */
|
/* SLD: FIXME: second call to find_peer during registration */
|
||||||
p = find_peer(host, 1);
|
if (!(p = find_peer(pds.peer, 1)))
|
||||||
if (p) {
|
return res;
|
||||||
found++;
|
|
||||||
res = AST_DEVICE_UNAVAILABLE;
|
|
||||||
if (option_debug > 2)
|
|
||||||
ast_log(LOG_DEBUG, "iax2_devicestate(%s): Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n",
|
|
||||||
host, dest, p->addr.sin_addr.s_addr, p->defaddr.sin_addr.s_addr, p->maxms, p->lastms);
|
|
||||||
|
|
||||||
if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
|
res = AST_DEVICE_UNAVAILABLE;
|
||||||
(!p->maxms || ((p->lastms > -1) && (p->historicms <= p->maxms)))) {
|
if (option_debug > 2)
|
||||||
/* Peer is registered, or have default IP address
|
ast_log(LOG_DEBUG, "iax2_devicestate: Found peer. What's device state of %s? addr=%d, defaddr=%d maxms=%d, lastms=%d\n",
|
||||||
and a valid registration */
|
pds.peer, p->addr.sin_addr.s_addr, p->defaddr.sin_addr.s_addr, p->maxms, p->lastms);
|
||||||
if (p->historicms == 0 || p->historicms <= p->maxms)
|
|
||||||
/* let the core figure out whether it is in use or not */
|
|
||||||
res = AST_DEVICE_UNKNOWN;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (option_debug > 2)
|
|
||||||
ast_log(LOG_DEBUG, "Devicestate: Can't find peer %s.\n", host);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p && ast_test_flag(p, IAX_TEMPONLY))
|
if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
|
||||||
|
(!p->maxms || ((p->lastms > -1) && (p->historicms <= p->maxms)))) {
|
||||||
|
/* Peer is registered, or have default IP address
|
||||||
|
and a valid registration */
|
||||||
|
if (p->historicms == 0 || p->historicms <= p->maxms)
|
||||||
|
/* let the core figure out whether it is in use or not */
|
||||||
|
res = AST_DEVICE_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_test_flag(p, IAX_TEMPONLY))
|
||||||
destroy_peer(p);
|
destroy_peer(p);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user