Index: main/devicestate.c =================================================================== --- main/devicestate.c (revision 129801) +++ main/devicestate.c (working copy) @@ -294,17 +294,24 @@ ast_hint_state_changed(device); } -static int __ast_device_state_changed_literal(char *buf, int norecurse) +static int __ast_device_state_changed_literal(char *buf) { char *device; struct state_change *change; char *tmp = NULL; + struct ast_channel *tmpchan; if (option_debug > 2) ast_log(LOG_DEBUG, "Notification of state change to be queued on device/channel %s\n", buf); device = buf; - + + /* If found, then the unique identifier is appended; remove it and proceed */ + if ((tmp = strrchr(device, '-')) && (tmpchan = ast_get_channel_by_name_locked(device))) { + ast_channel_unlock(tmpchan); + *tmp = '\0'; + } + if (change_thread == AST_PTHREADT_NULL || !(change = ast_calloc(1, sizeof(*change) + strlen(device)))) { /* we could not allocate a change struct, or */ /* there is no background thread, so process the change now */ @@ -320,18 +327,6 @@ AST_LIST_UNLOCK(&state_changes); } - /* The problem with this API is that a device may be called with the unique - * identifier appended or not, but it's separated from the channel name - * with a '-', which is also a legitimate character in a channel name. So, - * we have to force both names to get their names checked for state changes - * to ensure that the right one gets notified. Not a huge performance hit, - * but it might could be fixed by an enterprising programmer in trunk. - */ - if (!norecurse && (tmp = strrchr(device, '-'))) { - *tmp = '\0'; - __ast_device_state_changed_literal(device, 1); - } - return 1; } @@ -339,7 +334,7 @@ { char *buf; buf = ast_strdupa(dev); - return __ast_device_state_changed_literal(buf, 0); + return __ast_device_state_changed_literal(buf); } /*! \brief Accept change notification, add it to change queue */ @@ -351,7 +346,7 @@ va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); - return __ast_device_state_changed_literal(buf, 0); + return __ast_device_state_changed_literal(buf); } /*! \brief Go through the dev state change queue and update changes in the dev state thread */