[asterisk-commits] branch crichter/0.3.0 - r7670 in /team/crichter/0.3.0: ./ apps/ channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Dec 30 03:21:49 CST 2005


Author: crichter
Date: Fri Dec 30 03:21:41 2005
New Revision: 7670

URL: http://svn.digium.com/view/asterisk?rev=7670&view=rev
Log:
Merged revisions 7655-7662,7664,7666-7668 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r7655 | russell | 2005-12-27 18:24:54 +0100 (Di, 27 Dez 2005) | 3 lines

when doing tab completion, iterate the list of matches to count how many there
are instead of having the list of matches generated twice (issue #6066)

................
r7656 | tilghman | 2005-12-27 18:53:48 +0100 (Di, 27 Dez 2005) | 2 lines

Bug 5237 - Optional filename argument

................
r7657 | russell | 2005-12-27 19:18:41 +0100 (Di, 27 Dez 2005) | 3 lines

avoid repeated calls to strlen in command completion functions and normalize
some loops

................
r7658 | tilghman | 2005-12-27 20:13:13 +0100 (Di, 27 Dez 2005) | 2 lines

Bug 4880 - add priority label matching and dialplan function retrieval

................
r7659 | russell | 2005-12-27 20:48:44 +0100 (Di, 27 Dez 2005) | 2 lines

avoid unneeded calls to strlen in iax2 completion functions

................
r7660 | russell | 2005-12-27 20:59:09 +0100 (Di, 27 Dez 2005) | 3 lines

avoid duplicate strlen calls for the command completion functions for
'show application' and 'show applications'

................
r7661 | russell | 2005-12-27 21:03:07 +0100 (Di, 27 Dez 2005) | 2 lines

minor cleanups for another cli completion function ...

................
r7662 | russell | 2005-12-27 22:03:18 +0100 (Di, 27 Dez 2005) | 2 lines

fix permissions of created recordings (issue #6067)

................
r7664 | russell | 2005-12-28 18:31:12 +0100 (Mi, 28 Dez 2005) | 2 lines

restore alphabetical order for builtin cli commands (issue #6073)

................
r7666 | russell | 2005-12-28 18:37:35 +0100 (Mi, 28 Dez 2005) | 10 lines

Merged revisions 7665 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r7665 | russell | 2005-12-28 12:35:56 -0500 (Wed, 28 Dec 2005) | 2 lines

fix memory leak in build_rpid (issue #6070)

........

................
r7667 | russell | 2005-12-29 09:15:48 +0100 (Do, 29 Dez 2005) | 2 lines

avoid multiple strlen calls in complete_queue

................
r7668 | russell | 2005-12-29 09:25:06 +0100 (Do, 29 Dez 2005) | 2 lines

normalize a loop and avoid multiple strlen calls when completing voicemail users

................

Modified:
    team/crichter/0.3.0/   (props changed)
    team/crichter/0.3.0/apps/app_chanspy.c
    team/crichter/0.3.0/apps/app_dictate.c
    team/crichter/0.3.0/apps/app_queue.c
    team/crichter/0.3.0/apps/app_voicemail.c
    team/crichter/0.3.0/asterisk.c
    team/crichter/0.3.0/channels/chan_iax2.c
    team/crichter/0.3.0/channels/chan_sip.c
    team/crichter/0.3.0/channels/iax2-provision.c
    team/crichter/0.3.0/cli.c
    team/crichter/0.3.0/manager.c
    team/crichter/0.3.0/pbx.c

Propchange: team/crichter/0.3.0/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Dec 30 03:21:41 2005
@@ -1,1 +1,1 @@
-/trunk:1-7650
+/trunk:1-7669

Modified: team/crichter/0.3.0/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/apps/app_chanspy.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/apps/app_chanspy.c (original)
+++ team/crichter/0.3.0/apps/app_chanspy.c Fri Dec 30 03:21:41 2005
@@ -440,7 +440,7 @@
 	if (recbase) {
 		char filename[512];
 		snprintf(filename,sizeof(filename),"%s/%s.%d.raw",ast_config_AST_MONITOR_DIR, recbase, (int)time(NULL));
-		if ((fd = open(filename, O_CREAT | O_WRONLY, O_TRUNC)) <= 0) {
+		if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644)) <= 0) {
 			ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename);
 			fd = 0;
 		}

Modified: team/crichter/0.3.0/apps/app_dictate.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/apps/app_dictate.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/apps/app_dictate.c (original)
+++ team/crichter/0.3.0/apps/app_dictate.c Fri Dec 30 03:21:41 2005
@@ -47,7 +47,7 @@
 static char *tdesc = "Virtual Dictation Machine";
 static char *app = "Dictate";
 static char *synopsis = "Virtual Dictation Machine";
-static char *desc = "  Dictate([<base_dir>])\n"
+static char *desc = "  Dictate([<base_dir>[|<filename>]])\n"
 "Start dictation machine using optional base dir for files.\n";
 
 
@@ -80,7 +80,7 @@
 
 static int dictate_exec(struct ast_channel *chan, void *data)
 {
-	char *mydata, *argv[2], *path = NULL, filein[256];
+	char *mydata, *argv[3], *path = NULL, filein[256], *filename = "";
 	char dftbase[256];
 	char *base;
 	struct ast_flags flags = {0};
@@ -112,7 +112,9 @@
 	} else {
 		base = dftbase;
 	}
-
+	if (argc && argv[1]) {
+		filename = argv[1];
+	} 
 	oldr = chan->readformat;
 	if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
@@ -122,13 +124,17 @@
 
 	ast_answer(chan);
 	ast_safe_sleep(chan, 200);
-	for(res = 0; !res;) {
-		if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0) || 
-			ast_strlen_zero(filein)) {
-			res = -1;
-			break;
+	for (res = 0; !res;) {
+		if (ast_strlen_zero(filename)) {
+			if (ast_app_getdata(chan, "dictate/enter_filename", filein, sizeof(filein), 0) || 
+				ast_strlen_zero(filein)) {
+				res = -1;
+				break;
+			}
+		} else {
+			ast_copy_string(filein, filename, sizeof(filein));
+			filename = "";
 		}
-		
 		mkdir(base, 0755);
 		len = strlen(base) + strlen(filein) + 2;
 		if (!path || len > maxlen) {

Modified: team/crichter/0.3.0/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/apps/app_queue.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/apps/app_queue.c (original)
+++ team/crichter/0.3.0/apps/app_queue.c Fri Dec 30 03:21:41 2005
@@ -3360,17 +3360,22 @@
 static char *complete_queue(char *line, char *word, int pos, int state)
 {
 	struct ast_call_queue *q;
-	int which=0;
+	char *ret = NULL;
+	int which = 0;
+	int wordlen = strlen(word);
 	
 	ast_mutex_lock(&qlock);
 	for (q = queues; q; q = q->next) {
-		if (!strncasecmp(word, q->name, strlen(word))) {
-			if (++which > state)
+		if (!strncasecmp(word, q->name, wordlen)) {
+			if (++which > state) {
+				ret = strdup(q->name);	
 				break;
+			}
 		}
 	}
 	ast_mutex_unlock(&qlock);
-	return q ? strdup(q->name) : NULL;
+
+	return ret;
 }
 
 /*!\brief callback to display queues status in manager 

Modified: team/crichter/0.3.0/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/apps/app_voicemail.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/apps/app_voicemail.c (original)
+++ team/crichter/0.3.0/apps/app_voicemail.c Fri Dec 30 03:21:41 2005
@@ -5741,7 +5741,8 @@
 static char *complete_show_voicemail_users(char *line, char *word, int pos, int state)
 {
 	int which = 0;
-	struct ast_vm_user *vmu = users;
+	int wordlen;
+	struct ast_vm_user *vmu;
 	char *context = "";
 
 	/* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - <context> */
@@ -5753,8 +5754,9 @@
 		else
 			return NULL;
 	}
-	while (vmu) {
-		if (!strncasecmp(word, vmu->context, strlen(word))) {
+	wordlen = strlen(word);
+	for (vmu = users; vmu; vmu = vmu->next) {
+		if (!strncasecmp(word, vmu->context, wordlen)) {
 			if (context && strcmp(context, vmu->context)) {
 				if (++which > state) {
 					return strdup(vmu->context);
@@ -5762,7 +5764,6 @@
 				context = vmu->context;
 			}
 		}
-		vmu = vmu->next;
 	}
 	return NULL;
 }

Modified: team/crichter/0.3.0/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/asterisk.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/asterisk.c (original)
+++ team/crichter/0.3.0/asterisk.c Fri Dec 30 03:21:41 2005
@@ -1602,12 +1602,13 @@
 			free(mbuf);
 		} else
 			matches = (char **) NULL;
-
-
 	} else {
-
-		nummatches = ast_cli_generatornummatches((char *)lf->buffer,ptr);
+		char **p;
+		int count = 0;
 		matches = ast_cli_completion_matches((char *)lf->buffer,ptr);
+		for (p = matches; p && *p; p++)
+			count++;
+		nummatches = count - 1; /* XXX apparently there is one dup ? */
 	}
 
 	if (matches) {
@@ -1641,7 +1642,7 @@
 				retval = CC_REFRESH;
 			}
 		}
-	free(matches);
+		free(matches);
 	}
 
 	return (char *)(long)retval;

Modified: team/crichter/0.3.0/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/chan_iax2.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_iax2.c (original)
+++ team/crichter/0.3.0/channels/chan_iax2.c Fri Dec 30 03:21:41 2005
@@ -1975,13 +1975,14 @@
 	int which = 0;
 	struct iax2_peer *p;
 	char *res = NULL;
+	int wordlen = strlen(word);
 
 	/* 0 - iax2; 1 - show; 2 - peer; 3 - <peername> */
-	if(pos == 3) {
+	if (pos == 3) {
 		ast_mutex_lock(&peerl.lock);
-		for(p = peerl.peers ; p ; p = p->next) {
-			if(!strncasecmp(p->name, word, strlen(word))) {
-				if(++which > state) {
+		for (p = peerl.peers ; p ; p = p->next) {
+			if (!strncasecmp(p->name, word, wordlen)) {
+				if (++which > state) {
 					res = strdup(p->name);
 					break;
 				}

Modified: team/crichter/0.3.0/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/chan_sip.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_sip.c (original)
+++ team/crichter/0.3.0/channels/chan_sip.c Fri Dec 30 03:21:41 2005
@@ -4628,13 +4628,10 @@
 	if (p->rpid || p->rpid_from)
 		return;
 
-	if (p->owner && p->owner->cid.cid_num) {
-		clid = strdup(p->owner->cid.cid_num);
-	} 
-
-	if (p->owner && p->owner->cid.cid_name) {
-		clin = strdup(p->owner->cid.cid_name);
-	}
+	if (p->owner && p->owner->cid.cid_num)
+		clid = p->owner->cid.cid_num;
+	if (p->owner && p->owner->cid.cid_name)
+		clin = p->owner->cid.cid_name;
 	if (ast_strlen_zero(clin))
 		clin = clid;
 
@@ -8294,17 +8291,16 @@
 	int which=0;
 	struct sip_pvt *cur;
 	char *c = NULL;
+	int wordlen = strlen(word);
 
 	ast_mutex_lock(&iflock);
-	cur = iflist;
-	while(cur) {
-		if (!strncasecmp(word, cur->callid, strlen(word))) {
+	for (cur = iflist; cur; cur = cur->next) {
+		if (!strncasecmp(word, cur->callid, wordlen)) {
 			if (++which > state) {
 				c = strdup(cur->callid);
 				break;
 			}
 		}
-		cur = cur->next;
 	}
 	ast_mutex_unlock(&iflock);
 	return c;
@@ -8384,22 +8380,21 @@
 
 	if (pos == 2) {
 		int which = 0;
-		char *cat;
+		char *cat = NULL;
+		int wordlen = strlen(word);
 
 		/* do completion for notify type */
 
 		if (!notify_types)
 			return NULL;
 		
-		cat = ast_category_browse(notify_types, NULL);
-		while(cat) {
-			if (!strncasecmp(word, cat, strlen(word))) {
+		while ( (cat = ast_category_browse(notify_types, cat)) ) {
+			if (!strncasecmp(word, cat, wordlen)) {
 				if (++which > state) {
 					c = strdup(cat);
 					break;
 				}
 			}
-			cat = ast_category_browse(notify_types, cat);
 		}
 		return c;
 	}
@@ -8439,9 +8434,8 @@
 		return RESULT_SHOWUSAGE;
 	len = strlen(argv[3]);
 	ast_mutex_lock(&iflock);
-	cur = iflist;
-	while(cur) {
-		if (!strncasecmp(cur->callid, argv[3],len)) {
+	for (cur = iflist; cur; cur = cur->next) {
+		if (!strncasecmp(cur->callid, argv[3], len)) {
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
 				ast_cli(fd, "  * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
@@ -8486,7 +8480,6 @@
 			ast_cli(fd, "\n\n");
 			found++;
 		}
-		cur = cur->next;
 	}
 	ast_mutex_unlock(&iflock);
 	if (!found) 
@@ -8509,8 +8502,7 @@
 		ast_cli(fd, "\n***Note: History recording is currently DISABLED.  Use 'sip history' to ENABLE.\n");
 	len = strlen(argv[3]);
 	ast_mutex_lock(&iflock);
-	cur = iflist;
-	while(cur) {
+	for (cur = iflist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
@@ -8528,7 +8520,6 @@
 				ast_cli(fd, "Call '%s' has no history\n", cur->callid);
 			found++;
 		}
-		cur = cur->next;
 	}
 	ast_mutex_unlock(&iflock);
 	if (!found) 
@@ -8552,11 +8543,9 @@
 	else
 		ast_log(LOG_DEBUG, "  * SIP Call\n");
 	x = 0;
-	hist = dialog->history;
-	while(hist) {
+	for (hist = dialog->history; hist; hist = hist->next) {
 		x++;
 		ast_log(LOG_DEBUG, "  %d. %s\n", x, hist->event);
-		hist = hist->next;
 	}
 	if (!x)
 		ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid);
@@ -11207,8 +11196,7 @@
 		ast_mutex_lock(&iflock);
 restartsearch:		
 		time(&t);
-		sip = iflist;
-		while(sip) {
+		for (sip = iflist; sip; sip = sip->next) {
 			ast_mutex_lock(&sip->lock);
 			if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && !sip->redirip.sin_addr.s_addr) {
 				if (sip->lastrtptx && sip->rtpkeepalive && t > sip->lastrtptx + sip->rtpkeepalive) {
@@ -11246,7 +11234,6 @@
 				goto restartsearch;
 			}
 			ast_mutex_unlock(&sip->lock);
-			sip = sip->next;
 		}
 		ast_mutex_unlock(&iflock);
 		/* Don't let anybody kill us right away.  Nobody should lock the interface list
@@ -11828,13 +11815,11 @@
 /*! \brief  find_realm_authentication: Find authentication for a specific realm ---*/
 static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm)
 {
-	struct sip_auth *a = authlist; 	/* First entry in auth list */
-
-	while (a) {
-		if (!strcasecmp(a->realm, realm)){
+	struct sip_auth *a;
+
+	for (a = authlist; a; a = a->next) {
+		if (!strcasecmp(a->realm, realm))
 			break;
-		}
-		a = a->next;
 	}
 	
 	return a;

Modified: team/crichter/0.3.0/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/iax2-provision.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/iax2-provision.c (original)
+++ team/crichter/0.3.0/channels/iax2-provision.c Fri Dec 30 03:21:41 2005
@@ -156,21 +156,20 @@
 {
 	struct iax_template *c;
 	int which=0;
-	char *ret;
+	char *ret = NULL;
+	int wordlen = strlen(word);
+
 	ast_mutex_lock(&provlock);
-	c = templates;
-	while(c) {
-		if (!strncasecmp(word, c->name, strlen(word))) {
-			if (++which > state)
+	for (c = templates; c; c = c->next) {
+		if (!strncasecmp(word, c->name, wordlen)) {
+			if (++which > state) {
+				ret = strdup(c->name);
 				break;
-		}
-		c = c->next;
-	}
-	if (c) {
-		ret = strdup(c->name);
-	} else
-		ret = NULL;
+			}
+		}
+	}
 	ast_mutex_unlock(&provlock);
+	
 	return ret;
 }
 

Modified: team/crichter/0.3.0/cli.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/cli.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/cli.c (original)
+++ team/crichter/0.3.0/cli.c Fri Dec 30 03:21:41 2005
@@ -953,6 +953,7 @@
 	{ { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help },
 	{ { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch_3 },
 	{ { "debug", "level", NULL }, handle_debuglevel, "Set global debug level", debuglevel_help },
+	{ { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", group_show_channels_help},
 	{ { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help },
 	{ { "load", NULL }, handle_load, "Load a dynamic module by name", load_help, complete_fn },
 	{ { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch_4 },
@@ -967,7 +968,6 @@
 	{ { "show", "version", NULL }, handle_version, "Display version info", version_help },
 	{ { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch_3 },
 	{ { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
-	{ { "group", "show", "channels", NULL }, group_show_channels, "Show active channels with group(s)", group_show_channels_help},
 	{ { NULL }, NULL, NULL, NULL }
 };
 

Modified: team/crichter/0.3.0/manager.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/manager.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/manager.c (original)
+++ team/crichter/0.3.0/manager.c Fri Dec 30 03:21:41 2005
@@ -722,35 +722,32 @@
 
 static int action_getvar(struct mansession *s, struct message *m)
 {
-        struct ast_channel *c = NULL;
-        char *name = astman_get_header(m, "Channel");
-        char *varname = astman_get_header(m, "Variable");
+	struct ast_channel *c = NULL;
+	char *name = astman_get_header(m, "Channel");
+	char *varname = astman_get_header(m, "Variable");
 	char *id = astman_get_header(m,"ActionID");
-	const char *varval;
-	char *varval2=NULL;
-
-	if (!strlen(varname)) {
+	char *varval;
+	char workspace[1024];
+
+	if (ast_strlen_zero(varname)) {
 		astman_send_error(s, m, "No variable specified");
 		return 0;
 	}
 
-	if (strlen(name)) {
+	if (!ast_strlen_zero(name)) {
 		c = ast_get_channel_by_name_locked(name);
 		if (!c) {
 			astman_send_error(s, m, "No such channel");
 			return 0;
 		}
 	}
-	
-	varval=pbx_builtin_getvar_helper(c,varname);
-	if (varval)
-		varval2 = ast_strdupa(varval);
-	if (!varval2)
-		varval2 = "";
+
+	pbx_retrieve_variable(c, varname, &varval, workspace, sizeof(workspace), NULL);
+
 	if (c)
 		ast_mutex_unlock(&c->lock);
 	ast_cli(s->fd, "Response: Success\r\n"
-		"Variable: %s\r\nValue: %s\r\n" ,varname,varval2);
+		"Variable: %s\r\nValue: %s\r\n", varname, varval);
 	if (!ast_strlen_zero(id))
 		ast_cli(s->fd, "ActionID: %s\r\n",id);
 	ast_cli(s->fd, "\r\n");
@@ -874,8 +871,10 @@
 		return 0;
 	}
 	if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
-		astman_send_error(s, m, "Invalid priority\n");
-		return 0;
+		if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
+			astman_send_error(s, m, "Invalid priority\n");
+			return 0;
+		}
 	}
 	chan = ast_get_channel_by_name_locked(name);
 	if (!chan) {
@@ -1020,8 +1019,10 @@
 		return 0;
 	}
 	if (!ast_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
-		astman_send_error(s, m, "Invalid priority\n");
-		return 0;
+		if ((pi = ast_findlabel_extension(NULL, context, exten, priority, NULL)) < 1) {
+			astman_send_error(s, m, "Invalid priority\n");
+			return 0;
+		}
 	}
 	if (!ast_strlen_zero(timeout) && (sscanf(timeout, "%d", &to) != 1)) {
 		astman_send_error(s, m, "Invalid timeout\n");

Modified: team/crichter/0.3.0/pbx.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/pbx.c?rev=7670&r1=7669&r2=7670&view=diff
==============================================================================
--- team/crichter/0.3.0/pbx.c (original)
+++ team/crichter/0.3.0/pbx.c Fri Dec 30 03:21:41 2005
@@ -1196,10 +1196,9 @@
 static char *complete_show_function(char *line, char *word, int pos, int state)
 {
 	struct ast_custom_function *acf;
+	char *ret = NULL;
 	int which = 0;
-	int wordlen;
-
-	wordlen = strlen(word);
+	int wordlen = strlen(word);
 
 	/* try to lock functions list ... */
 	if (ast_mutex_lock(&acflock)) {
@@ -1210,15 +1209,15 @@
 	for (acf = acf_root; acf; acf = acf->next) {
 		if (!strncasecmp(word, acf->name, wordlen)) {
 			if (++which > state) {
-				char *ret = strdup(acf->name);
-				ast_mutex_unlock(&acflock);
-				return ret;
+				ret = strdup(acf->name);
+				break;
 			}
 		}
 	}
 
 	ast_mutex_unlock(&acflock);
-	return NULL; 
+
+	return ret; 
 }
 
 struct ast_custom_function* ast_custom_function_find(const char *name) 
@@ -2957,11 +2956,12 @@
  * application at one time. You can type 'show application Dial Echo' and
  * you will see informations about these two applications ...
  */
-static char *complete_show_application(char *line, char *word,
-	int pos, int state)
+static char *complete_show_application(char *line, char *word, int pos, int state)
 {
 	struct ast_app *a;
+	char *ret = NULL;
 	int which = 0;
+	int wordlen = strlen(word);
 
 	/* try to lock applications list ... */
 	if (ast_mutex_lock(&applock)) {
@@ -2972,19 +2972,18 @@
 	/* ... walk all applications ... */
 	for (a = apps; a; a = a->next) {
 		/* ... check if word matches this application ... */
-		if (!strncasecmp(word, a->name, strlen(word))) {
+		if (!strncasecmp(word, a->name, wordlen)) {
 			/* ... if this is right app serve it ... */
 			if (++which > state) {
-				char *ret = strdup(a->name);
-				ast_mutex_unlock(&applock);
-				return ret;
+				ret = strdup(a->name);
+				break;
 			}
 		}
 	}
 
-	/* no application match */
 	ast_mutex_unlock(&applock);
-	return NULL; 
+
+	return ret; 
 }
 
 static int handle_show_application(int fd, int argc, char *argv[])
@@ -3198,6 +3197,8 @@
 
 static char *complete_show_applications(char *line, char *word, int pos, int state)
 {
+	int wordlen = strlen(word);
+
 	if (pos == 2) {
 		if (ast_strlen_zero(word)) {
 			switch (state) {
@@ -3208,13 +3209,13 @@
 			default:
 				return NULL;
 			}
-		} else if (! strncasecmp(word, "like", strlen(word))) {
+		} else if (! strncasecmp(word, "like", wordlen)) {
 			if (state == 0) {
 				return strdup("like");
 			} else {
 				return NULL;
 			}
-		} else if (! strncasecmp(word, "describing", strlen(word))) {
+		} else if (! strncasecmp(word, "describing", wordlen)) {
 			if (state == 0) {
 				return strdup("describing");
 			} else {



More information about the asterisk-commits mailing list