aboutsummaryrefslogtreecommitdiffstats
path: root/main/devicestate.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-04 23:03:40 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-04 23:03:40 +0000
commit12285cdca5962b1d2ff4657d9162151214acdf2d (patch)
tree97db696d02088336f3d4ed7d4cab789b0067bfe4 /main/devicestate.c
parent64c13aeb0d4d07c2b3d77c26bc2155473c49bfee (diff)
Fix the problem of notification of a device state change to a device with a '-'
in the name. Could probably do with a better fix in trunk, but this bug has been open way too long without a better solution. Reported by: stevedavies Patch by: tilghman (Closes issue #9668) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@96575 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/devicestate.c')
-rw-r--r--main/devicestate.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/main/devicestate.c b/main/devicestate.c
index 1b9d49d87..7e0c28f68 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -294,7 +294,7 @@ static void do_state_change(const char *device)
ast_hint_state_changed(device);
}
-static int __ast_device_state_changed_literal(char *buf)
+static int __ast_device_state_changed_literal(char *buf, int norecurse)
{
char *device;
struct state_change *change;
@@ -305,10 +305,6 @@ static int __ast_device_state_changed_literal(char *buf)
device = buf;
- tmp = strrchr(device, '-');
- if (tmp)
- *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 */
@@ -324,6 +320,18 @@ static int __ast_device_state_changed_literal(char *buf)
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(tmp, 1);
+ }
+
return 1;
}
@@ -331,7 +339,7 @@ int ast_device_state_changed_literal(const char *dev)
{
char *buf;
buf = ast_strdupa(dev);
- return __ast_device_state_changed_literal(buf);
+ return __ast_device_state_changed_literal(buf, 0);
}
/*! \brief Accept change notification, add it to change queue */
@@ -343,7 +351,7 @@ int ast_device_state_changed(const char *fmt, ...)
va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
- return __ast_device_state_changed_literal(buf);
+ return __ast_device_state_changed_literal(buf, 0);
}
/*! \brief Go through the dev state change queue and update changes in the dev state thread */