[svn-commits] tilghman: branch 1.4 r133649 - in /branches/1.4: channels/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jul 25 12:19:40 CDT 2008


Author: tilghman
Date: Fri Jul 25 12:19:39 2008
New Revision: 133649

URL: http://svn.digium.com/view/asterisk?view=rev&rev=133649
Log:
Fix some errant device states by making the devicestate API more strict in
terms of the device argument (only without the unique identifier appended).
(closes issue #12771)
 Reported by: davidw
 Patches: 
       20080717__bug12771.diff.txt uploaded by Corydon76 (license 14)
 Tested by: davidw, jvandal, murf

Modified:
    branches/1.4/channels/chan_agent.c
    branches/1.4/main/channel.c
    branches/1.4/main/devicestate.c

Modified: branches/1.4/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_agent.c?view=diff&rev=133649&r1=133648&r2=133649
==============================================================================
--- branches/1.4/channels/chan_agent.c (original)
+++ branches/1.4/channels/chan_agent.c Fri Jul 25 12:19:39 2008
@@ -288,6 +288,11 @@
 	int res, i;
 	struct agent_pvt *p;
 	char basename[AST_CHANNEL_NAME], *tmp;
+
+	/* Skip Agent status */
+	if (!strncasecmp(dev, "Agent/", 6)) {
+		return 0;
+	}
 
 	/* Try to be safe, but don't deadlock */
 	for (i = 0; i < 10; i++) {
@@ -522,6 +527,7 @@
 			}
 			p->chan = NULL;
 			p->inherited_devicestate = -1;
+			ast_device_state_changed("Agent/%s", p->agent);
 			p->acknowledged = 0;
 		}
  	} else {
@@ -744,6 +750,7 @@
 		/* Agent hung-up */
 		p->chan = NULL;
 		p->inherited_devicestate = -1;
+		ast_device_state_changed("Agent/%s", p->agent);
 	}
 
 	if (!res) {
@@ -867,6 +874,7 @@
 				ast_hangup(p->chan);
 				p->chan = NULL;
 				p->inherited_devicestate = -1;
+				ast_device_state_changed("Agent/%s", p->agent);
 			}
 			ast_log(LOG_DEBUG, "Hungup, howlong is %d, autologoff is %d\n", howlong, p->autologoff);
 			if ((p->deferlogoff) || (howlong && p->autologoff && (howlong > p->autologoff))) {

Modified: branches/1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/channel.c?view=diff&rev=133649&r1=133648&r2=133649
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Fri Jul 25 12:19:39 2008
@@ -1201,7 +1201,7 @@
 	struct ast_frame *f;
 	struct varshead *headp;
 	struct ast_datastore *datastore = NULL;
-	char name[AST_CHANNEL_NAME];
+	char name[AST_CHANNEL_NAME], *dashptr;
 	
 	headp=&chan->varshead;
 	
@@ -1234,6 +1234,9 @@
 		sched_context_destroy(chan->sched);
 
 	ast_copy_string(name, chan->name, sizeof(name));
+	if ((dashptr = strrchr(name, '-'))) {
+		*dashptr = '\0';
+	}
 
 	/* Stop monitoring */
 	if (chan->monitor)
@@ -3669,13 +3672,19 @@
 
 int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)
 {
+	char name[AST_CHANNEL_NAME], *dashptr;
 	int oldstate = chan->_state;
 
 	if (oldstate == state)
 		return 0;
 
+	ast_copy_string(name, chan->name, sizeof(name));
+	if ((dashptr = strrchr(name, '-'))) {
+		*dashptr = '\0';
+	}
+
 	chan->_state = state;
-	ast_device_state_changed_literal(chan->name);
+	ast_device_state_changed_literal(name);
 	/* setstate used to conditionally report Newchannel; this is no more */
 	manager_event(EVENT_FLAG_CALL,
 		      "Newstate",

Modified: branches/1.4/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/devicestate.c?view=diff&rev=133649&r1=133648&r2=133649
==============================================================================
--- branches/1.4/main/devicestate.c (original)
+++ branches/1.4/main/devicestate.c Fri Jul 25 12:19:39 2008
@@ -294,17 +294,13 @@
 	ast_hint_state_changed(device);
 }
 
-static int __ast_device_state_changed_literal(char *buf, int norecurse)
-{
-	char *device;
+int ast_device_state_changed_literal(const char *device)
+{
 	struct state_change *change;
-	char *tmp = NULL;
 
 	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "Notification of state change to be queued on device/channel %s\n", buf);
-
-	device = buf;
-	
+		ast_log(LOG_DEBUG, "Notification of state change to be queued on device/channel %s\n", device);
+
 	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,26 +316,7 @@
 		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;
-}
-
-int ast_device_state_changed_literal(const char *dev)
-{
-	char *buf;
-	buf = ast_strdupa(dev);
-	return __ast_device_state_changed_literal(buf, 0);
 }
 
 /*! \brief Accept change notification, add it to change queue */
@@ -351,7 +328,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 */




More information about the svn-commits mailing list