[Asterisk-cvs] asterisk/channels chan_agent.c,1.130,1.131

markster at lists.digium.com markster at lists.digium.com
Fri Apr 15 00:59:59 CDT 2005


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv20657/channels

Modified Files:
	chan_agent.c 
Log Message:
Fix "show agents" when name is not present (bug #4030)


Index: chan_agent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -d -r1.130 -r1.131
--- chan_agent.c	6 Apr 2005 16:06:05 -0000	1.130
+++ chan_agent.c	15 Apr 2005 05:51:30 -0000	1.131
@@ -245,25 +245,34 @@
 
 static struct agent_pvt *add_agent(char *agent, int pending)
 {
-	char tmp[AST_MAX_BUF] = "";
-	char *password=NULL, *name=NULL;
+	int argc;
+	char *argv[3];
+	char *args;
+	char *password = NULL;
+	char *name = NULL;
+	char *agt = NULL;
 	struct agent_pvt *p, *prev;
-	
-	strncpy(tmp, agent, sizeof(tmp) - 1);
-	if ((password = strchr(tmp, ','))) {
-		*password = '\0';
-		password++;
-		while (*password < 33) password++;
-	}
-	if (password && (name = strchr(password, ','))) {
-		*name = '\0';
-		name++;
-		while (*name < 33) name++; 
+
+	args = ast_strdupa(agent);
+
+	if ((argc = ast_separate_app_args(args, ',', argv, sizeof(argv) / sizeof(argv[0])))) {
+		agt = argv[0];
+		if (argc > 1) {
+			password = argv[1];
+			while (*password && *password < 33) password++;
+		} 
+		if (argc > 2) {
+			name = argv[2];
+			while (*name && *name < 33) name++;
+		}
+	} else {
+		ast_log(LOG_WARNING, "A blank agent line!\n");
 	}
+	
 	prev=NULL;
 	p = agents;
 	while(p) {
-		if (!pending && !strcmp(p->agent, tmp))
+		if (!pending && !strcmp(p->agent, agt))
 			break;
 		prev = p;
 		p = p->next;
@@ -272,7 +281,7 @@
 		p = malloc(sizeof(struct agent_pvt));
 		if (p) {
 			memset(p, 0, sizeof(struct agent_pvt));
-			strncpy(p->agent, tmp, sizeof(p->agent) -1);
+			strncpy(p->agent, agt, sizeof(p->agent) -1);
 			ast_mutex_init(&p->lock);
 			ast_mutex_init(&p->app_lock);
 			p->owning_app = (pthread_t) -1;
@@ -285,12 +294,13 @@
 			else
 				agents = p;
 			
+		} else {
+			return NULL;
 		}
 	}
-	if (!p)
-		return NULL;
+	
 	strncpy(p->password, password ? password : "", sizeof(p->password) - 1);
-	strncpy(p->name, name ? name : "", sizeof(p->name) - 1);
+	strncpy(p->name, !ast_strlen_zero(name) ? name : "---", sizeof(p->name) - 1);
 	strncpy(p->moh, moh, sizeof(p->moh) - 1);
 	p->ackcall = ackcall;
 	p->autologoff = autologoff;




More information about the svn-commits mailing list