Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 47419) +++ channels/chan_sip.c (working copy) @@ -1308,7 +1308,6 @@ /*--- Device monitoring and Device/extension state handling */ static int cb_extensionstate(char *context, char* exten, int state, void *data); -static int sip_devicestate(void *data); static int sip_poke_noanswer(void *data); static int sip_poke_peer(struct sip_peer *peer); static void sip_poke_all_peers(void); @@ -8019,9 +8018,9 @@ /* If they put someone on hold, increment the value... otherwise decrement it */ if (hold) peer->onHold++; - else if (hold > 0) + else peer->onHold--; - + ast_log(LOG_NOTICE, "onHold now: %d; hold arg was: %d\n", peer->onHold, hold); /* Request device state update */ ast_device_state_changed("SIP/%s", peer->name); @@ -14880,33 +14879,51 @@ /* if qualify is turned on, check the status */ if (p->maxms && (p->lastms > p->maxms)) { res = AST_DEVICE_UNAVAILABLE; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); } else { /* qualify is not on, or the peer is responding properly */ /* check call limit */ - if (p->call_limit && (p->inUse == p->call_limit)) + if (p->call_limit && (p->inUse == p->call_limit)) { res = AST_DEVICE_BUSY; - else if (p->call_limit && p->inUse) + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); + } else if (p->onHold) { + res = AST_DEVICE_ONHOLD; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); + } else if (p->inRinging && p->inRinging == p->inUse) { + res = AST_DEVICE_RINGING; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); + } else if (p->inRinging) { + res = AST_DEVICE_RINGINUSE; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); + } else if (p->inUse) { res = AST_DEVICE_INUSE; - else + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); + } else { res = AST_DEVICE_NOT_INUSE; - if (p->onHold) - res = AST_DEVICE_ONHOLD; - else if (p->inRinging) { - if (p->inRinging == p->inUse) - res = AST_DEVICE_RINGING; - else - res = AST_DEVICE_RINGINUSE; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); } } } else { /* there is no address, it's unavailable */ res = AST_DEVICE_UNAVAILABLE; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s call-lim=%d, inuse=%d, onHold=%d, inRinging=%d, maxms=%d, lastms=%d\n", + host, devstate2str(res), p->call_limit, p->inUse, p->onHold, p->inRinging, p->maxms, p->lastms); } ASTOBJ_UNREF(p,sip_destroy_peer); } else { hp = ast_gethostbyname(host, &ahp); - if (hp) + if (hp) { res = AST_DEVICE_UNKNOWN; + ast_log(LOG_NOTICE, "sip_devicestate(%s) returning %s\n", + host, devstate2str(res)); + } } return res; Index: main/devicestate.c =================================================================== --- main/devicestate.c (revision 47419) +++ main/devicestate.c (working copy) @@ -117,11 +117,22 @@ if (!chan) return AST_DEVICE_UNKNOWN; + + switch (chan->_state) { - if (chan->_state == AST_STATE_RINGING) + case AST_STATE_RINGING: res = AST_DEVICE_RINGING; - else + break; + case AST_STATE_BUSY: + res = AST_DEVICE_BUSY; + break; + case AST_STATE_DOWN: + res = AST_DEVICE_NOT_INUSE; + break; + default: res = AST_DEVICE_INUSE; + break; + } ast_channel_unlock(chan);