clean update devicestate function, ensure that it can return AST_DEVICE_UNKNOWN when call limits are not turned on (issue #5281)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6654 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Kevin P. Fleming 21 years ago
parent 5599da9581
commit 051ddb97f3

@ -10904,60 +10904,49 @@ static int sip_poke_peer(struct sip_peer *peer)
/*--- sip_devicestate: Part of PBX channel interface ---*/ /*--- sip_devicestate: Part of PBX channel interface ---*/
static int sip_devicestate(void *data) static int sip_devicestate(void *data)
{ {
char *ext, *host; char *host;
char tmp[256]; char *tmp;
char *dest = data;
struct hostent *hp; struct hostent *hp;
struct ast_hostent ahp; struct ast_hostent ahp;
struct sip_peer *p; struct sip_peer *p;
int found = 0;
int res = AST_DEVICE_INVALID; int res = AST_DEVICE_INVALID;
ast_copy_string(tmp, dest, sizeof(tmp)); host = ast_strdupa(data);
host = strchr(tmp, '@'); if ((tmp = strchr(host, '@')))
if (host) { host = tmp + 1;
*host = '\0';
host++;
ext = tmp;
} else {
host = tmp;
ext = NULL;
}
p = find_peer(host, NULL, 1);
if (p) {
found++;
res = AST_DEVICE_UNAVAILABLE;
if (option_debug > 2) if (option_debug > 2)
ast_log(LOG_DEBUG, "Checking device state for peer %s\n", dest); ast_log(LOG_DEBUG, "Checking device state for DNS host %s\n", host);
if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) &&
(!p->maxms || ((p->lastms > -1) && (p->lastms <= p->maxms)))) { if ((p = find_peer(host, NULL, 1))) {
/* Peer is registred, or has default IP address and a valid registration */ if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) {
/* Now check if we know anything about the state. The only way is by implementing /* we have an address for the peer */
* call control with incominglimit=X in sip.conf where X > 0 /* if qualify is turned on, check the status */
* Check if the device has incominglimit, and if qualify=on, if the device if (p->maxms && (p->lastms > p->maxms)) {
* is reachable */ res = AST_DEVICE_UNAVAILABLE;
if (p->call_limit && (p->lastms == 0 || p->lastms <= p->maxms)) { /* Free for a call */ } else {
res = AST_DEVICE_NOT_INUSE; /* qualify is not on, or the peer is responding properly */
if (p->inUse) /* On a call */ /* check call limit */
if (p->call_limit && (p->inUse >= p->call_limit))
res = AST_DEVICE_BUSY; res = AST_DEVICE_BUSY;
} else { /* peer found and valid, state unknown */ else if (p->call_limit)
res = AST_DEVICE_NOT_INUSE;
else
res = AST_DEVICE_UNKNOWN; res = AST_DEVICE_UNKNOWN;
} }
} else {
/* there is no address, it's unavailable */
res = AST_DEVICE_UNAVAILABLE;
} }
} ASTOBJ_UNREF(p,sip_destroy_peer);
if (!p && !found) { } else {
if (option_debug > 2)
ast_log(LOG_DEBUG, "Checking device state for DNS host %s\n", dest);
hp = ast_gethostbyname(host, &ahp); hp = ast_gethostbyname(host, &ahp);
if (hp) if (hp)
res = AST_DEVICE_UNKNOWN; res = AST_DEVICE_UNKNOWN;
} }
if (p)
ASTOBJ_UNREF(p,sip_destroy_peer);
return res; return res;
} }

Loading…
Cancel
Save