From: Terry Wilson Date: Tue, 13 Mar 2012 19:51:23 +0000 (+0000) Subject: Make hints for invalid SIP devices return Unavail, not idle X-Git-Tag: 1.8.10.1~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7622a34c89f27d293ca6d19de4d7742f711e9957;p=thirdparty%2Fasterisk.git Make hints for invalid SIP devices return Unavail, not idle This patch drastically simplifies the device state aggegation code. The old method was not only overly complex, but also made it impossible to return AST_DEVICE_INVALID from the aggregation code. The unit test update is as a result of fixing that bug. The SIP change stems from a bug introduced by removing a DNS lookup for hostname-based SIP channels. (closes issue ASTERISK-16702) Review: https://reviewboard.asterisk.org/r/1808/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@358943 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 6c9c6dddde..999c5a9e13 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -26396,8 +26396,6 @@ static int sip_devicestate(void *data) res = AST_DEVICE_UNAVAILABLE; } unref_peer(p, "unref_peer, from sip_devicestate, release ref from find_peer"); - } else { - res = AST_DEVICE_UNKNOWN; } return res; diff --git a/include/asterisk/devicestate.h b/include/asterisk/devicestate.h index 2a53ebb46a..66ca2bd1a3 100644 --- a/include/asterisk/devicestate.h +++ b/include/asterisk/devicestate.h @@ -254,14 +254,9 @@ enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregat * This struct is only here so that it can be easily declared on the stack. */ struct ast_devstate_aggregate { - unsigned int all_unknown:1; - unsigned int all_unavail:1; - unsigned int all_busy:1; - unsigned int all_free:1; - unsigned int on_hold:1; - unsigned int busy:1; - unsigned int in_use:1; - unsigned int ring:1; + unsigned int ringing:1; + unsigned int inuse:1; + enum ast_device_state state; }; /*! diff --git a/main/devicestate.c b/main/devicestate.c index ab5225bea3..cccf159f39 100644 --- a/main/devicestate.c +++ b/main/devicestate.c @@ -732,91 +732,39 @@ int ast_device_state_engine_init(void) void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg) { memset(agg, 0, sizeof(*agg)); - - agg->all_unknown = 1; - agg->all_unavail = 1; - agg->all_busy = 1; - agg->all_free = 1; + agg->state = AST_DEVICE_INVALID; } void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state) { - switch (state) { - case AST_DEVICE_NOT_INUSE: - agg->all_unknown = 0; - agg->all_unavail = 0; - agg->all_busy = 0; - break; - case AST_DEVICE_INUSE: - agg->in_use = 1; - agg->all_unavail = 0; - agg->all_free = 0; - agg->all_unknown = 0; - break; - case AST_DEVICE_RINGING: - agg->ring = 1; - agg->all_unavail = 0; - agg->all_free = 0; - agg->all_unknown = 0; - break; - case AST_DEVICE_RINGINUSE: - agg->in_use = 1; - agg->ring = 1; - agg->all_unavail = 0; - agg->all_free = 0; - agg->all_unknown = 0; - break; - case AST_DEVICE_ONHOLD: - agg->all_unknown = 0; - agg->all_unavail = 0; - agg->all_free = 0; - agg->on_hold = 1; - break; - case AST_DEVICE_BUSY: - agg->all_unknown = 0; - agg->all_unavail = 0; - agg->all_free = 0; - agg->busy = 1; - agg->in_use = 1; - break; - case AST_DEVICE_UNAVAILABLE: - agg->all_unknown = 0; - case AST_DEVICE_INVALID: - agg->all_busy = 0; - agg->all_free = 0; - break; - case AST_DEVICE_UNKNOWN: - agg->all_busy = 0; - agg->all_free = 0; - break; - case AST_DEVICE_TOTAL: /* not a device state, included for completeness. */ - break; + static enum ast_device_state state_order[] = { + 1, /* AST_DEVICE_UNKNOWN */ + 3, /* AST_DEVICE_NOT_INUSE */ + 6, /* AST_DEVICE_INUSE */ + 7, /* AST_DEVICE_BUSY */ + 0, /* AST_DEVICE_INVALID */ + 2, /* AST_DEVICE_UNAVAILABLE */ + 5, /* AST_DEVICE_RINGING */ + 8, /* AST_DEVICE_RINGINUSE */ + 4, /* AST_DEVICE_ONHOLD */ + }; + + if (state == AST_DEVICE_RINGING) { + agg->ringing = 1; + } else if (state == AST_DEVICE_INUSE || state == AST_DEVICE_ONHOLD || state == AST_DEVICE_BUSY) { + agg->inuse = 1; } -} + if (agg->ringing && agg->inuse) { + agg->state = AST_DEVICE_RINGINUSE; + } else if (state_order[state] > state_order[agg->state]) { + agg->state = state; + } +} enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg) { - if (agg->all_free) - return AST_DEVICE_NOT_INUSE; - if ((agg->in_use || agg->on_hold) && agg->ring) - return AST_DEVICE_RINGINUSE; - if (agg->ring) - return AST_DEVICE_RINGING; - if (agg->busy) - return AST_DEVICE_BUSY; - if (agg->in_use) - return AST_DEVICE_INUSE; - if (agg->on_hold) - return AST_DEVICE_ONHOLD; - if (agg->all_busy) - return AST_DEVICE_BUSY; - if (agg->all_unknown) - return AST_DEVICE_UNKNOWN; - if (agg->all_unavail) - return AST_DEVICE_UNAVAILABLE; - - return AST_DEVICE_NOT_INUSE; + return agg->state; } int ast_enable_distributed_devstate(void) diff --git a/tests/test_devicestate.c b/tests/test_devicestate.c index ede2b23447..f5f209b9e4 100644 --- a/tests/test_devicestate.c +++ b/tests/test_devicestate.c @@ -83,7 +83,7 @@ static int combined_results[] = { AST_DEVICE_NOT_INUSE, AST_DEVICE_INUSE, AST_DEVICE_BUSY, - AST_DEVICE_UNKNOWN, + AST_DEVICE_INVALID, AST_DEVICE_UNAVAILABLE, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, @@ -167,7 +167,7 @@ static int exten_results[] = { AST_EXTENSION_NOT_INUSE, AST_EXTENSION_INUSE, AST_EXTENSION_BUSY, - AST_EXTENSION_NOT_INUSE, + AST_EXTENSION_UNAVAILABLE, AST_EXTENSION_UNAVAILABLE, AST_EXTENSION_RINGING, AST_EXTENSION_INUSE | AST_EXTENSION_RINGING,