[asterisk-commits] trunk r15859 - /trunk/manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 28 16:52:23 MST 2006


Author: rizzo
Date: Tue Mar 28 17:52:21 2006
New Revision: 15859

URL: http://svn.digium.com/view/asterisk?rev=15859&view=rev
Log:
more command completion normalization.
also change some explicit constant with sizeof()


Modified:
    trunk/manager.c

Modified: trunk/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/manager.c?rev=15859&r1=15858&r2=15859&view=diff
==============================================================================
--- trunk/manager.c (original)
+++ trunk/manager.c Tue Mar 28 17:52:21 2006
@@ -197,22 +197,19 @@
 
 static char *complete_show_mancmd(const char *line, const char *word, int pos, int state)
 {
-	struct manager_action *cur = first_action;
+	struct manager_action *cur;
 	int which = 0;
+	char *ret = NULL;
 
 	ast_mutex_lock(&actionlock);
-	while (cur) { /* Walk the list of actions */
-		if (!strncasecmp(word, cur->action, strlen(word))) {
-			if (++which > state) {
-				char *ret = strdup(cur->action);
-				ast_mutex_unlock(&actionlock);
-				return ret;
-			}
-		}
-		cur = cur->next;
+	for (cur = first_action; cur; cur = cur->next) { /* Walk the list of actions */
+		if (!strncasecmp(word, cur->action, strlen(word)) && ++which > state) {
+			ret = ast_strdup(cur->action);
+			break;	/* make sure we exit even if ast_strdup() returns NULL */
+		}
 	}
 	ast_mutex_unlock(&actionlock);
-	return NULL;
+	return ret;
 }
 
 void astman_append(struct mansession *s, const char *fmt, ...)
@@ -659,7 +656,7 @@
 	char *id = astman_get_header(m,"ActionID");
 
 	if (!ast_strlen_zero(id))
-		snprintf(idText,256,"ActionID: %s\r\n",id);
+		snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
 	astman_append(s, "Response: Success\r\n%s", idText);
 	ast_mutex_lock(&actionlock);
 	while (cur) { /* Walk the list of actions */
@@ -833,7 +830,7 @@
 
 	astman_send_ack(s, m, "Channel status will follow");
         if (!ast_strlen_zero(id))
-                snprintf(idText,256,"ActionID: %s\r\n",id);
+                snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
 	if (all)
 		c = ast_channel_walk_locked(NULL);
 	else {
@@ -938,6 +935,7 @@
 			return 0;
 		}
 	}
+	/* XXX watch out, possible deadlock!!! */
 	chan = ast_get_channel_by_name_locked(name);
 	if (!chan) {
 		char buf[BUFSIZ];
@@ -1094,8 +1092,7 @@
 		astman_send_error(s, m, "Invalid channel\n");
 		return 0;
 	}
-	*data = '\0';
-	data++;
+	*data++ = '\0';
 	ast_copy_string(tmp2, callerid, sizeof(tmp2));
 	ast_callerid_parse(tmp2, &n, &l);
 	if (n) {
@@ -1178,7 +1175,7 @@
 		return 0;
 	}
         if (!ast_strlen_zero(id))
-                snprintf(idText,256,"ActionID: %s\r\n",id);
+                snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
 	ret = ast_app_has_voicemail(mailbox, NULL);
 	astman_append(s, "Response: Success\r\n"
 				   "%s"
@@ -1211,7 +1208,7 @@
 	}
 	ast_app_messagecount(mailbox, &newmsgs, &oldmsgs);
 	if (!ast_strlen_zero(id)) {
-		snprintf(idText,256,"ActionID: %s\r\n",id);
+		snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
 	}
 	astman_append(s, "Response: Success\r\n"
 				   "%s"
@@ -1252,7 +1249,7 @@
 	status = ast_extension_state(NULL, context, exten);
 	ast_get_hint(hint, sizeof(hint) - 1, NULL, 0, NULL, context, exten);
         if (!ast_strlen_zero(id)) {
-                snprintf(idText,256,"ActionID: %s\r\n",id);
+                snprintf(idText, sizeof(idText), "ActionID: %s\r\n", id);
         }
 	astman_append(s, "Response: Success\r\n"
 			           "%s"
@@ -1311,9 +1308,9 @@
 		astman_send_error(s, m, "Missing action in request");
 		return 0;
 	}
-	if (!ast_strlen_zero(id)) {
-		snprintf(idText,256,"ActionID: %s\r\n",id);
-	}
+        if (!ast_strlen_zero(id)) {
+                snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
+        }
 	if (!s->authenticated) {
 		if (!strcasecmp(action, "Challenge")) {
 			char *authtype;



More information about the asterisk-commits mailing list