Index: main/devicestate.c =================================================================== --- main/devicestate.c (revision 174361) +++ main/devicestate.c (working copy) @@ -308,14 +308,14 @@ char *buf; char *number; const struct ast_channel_tech *chan_tech; - enum ast_device_state res; + enum ast_device_state res = AST_DEVICE_UNKNOWN; /*! \brief Channel driver that provides device state */ char *tech; /*! \brief Another provider of device state */ char *provider = NULL; /* If the last known state is cached, just return that */ - if (check_cache) { + if (check_cache && !strcasestr(device,"Custom:")) { res = devstate_cached(device); if (res != AST_DEVICE_UNKNOWN) { return res; @@ -325,8 +325,9 @@ buf = ast_strdupa(device); tech = strsep(&buf, "/"); if (!(number = buf)) { - if (!(provider = strsep(&tech, ":"))) + if (!(provider = strsep(&tech, ":"))) { return AST_DEVICE_INVALID; + } /* We have a provider */ number = tech; tech = NULL; @@ -334,27 +335,32 @@ if (provider) { ast_debug(3, "Checking if I can find provider for \"%s\" - number: %s\n", provider, number); - return getproviderstate(provider, number); + res = getproviderstate(provider, number); + return res; } ast_debug(4, "No provider found, checking channel drivers for %s - %s\n", tech, number); - if (!(chan_tech = ast_get_channel_tech(tech))) + if (!(chan_tech = ast_get_channel_tech(tech))){ return AST_DEVICE_INVALID; + } - if (!(chan_tech->devicestate)) /* Does the channel driver support device state notification? */ + if (!(chan_tech->devicestate)) { /* Does the channel driver support device state notification? */ return ast_parse_device_state(device); /* No, try the generic function */ + } res = chan_tech->devicestate(number); - if (res != AST_DEVICE_UNKNOWN) + if (res != AST_DEVICE_UNKNOWN) { return res; + } res = ast_parse_device_state(device); - if (res == AST_DEVICE_UNKNOWN) + if (res == AST_DEVICE_UNKNOWN) { return AST_DEVICE_NOT_INUSE; - + } + return res; } @@ -431,13 +437,14 @@ ast_debug(3, "device '%s' state '%d'\n", device, state); - if (!(event = ast_event_new(AST_EVENT_DEVICE_STATE_CHANGE, - AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device, - AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, state, - AST_EVENT_IE_END))) { - return; - } + event = ast_event_new(AST_EVENT_DEVICE_STATE_CHANGE, + AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device, + AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, state, + AST_EVENT_IE_END); + if (!event) + return; + /* Cache this event, replacing an event in the cache with the same * device name if it exists. */ ast_event_queue_and_cache(event, @@ -451,7 +458,7 @@ static void do_state_change(const char *device) { enum ast_device_state state; - + state = _ast_device_state(device, 0); ast_debug(3, "Changing state for %s - state %d (%s)\n", device, state, ast_devstate2str(state));