aboutsummaryrefslogtreecommitdiffstats
path: root/pbx.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-27 19:59:09 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-12-27 19:59:09 +0000
commit64632fcfa82afe74d9420b60872fa58841d35004 (patch)
treefa344a62701efdc1c0bf52535c71c128b295b18a /pbx.c
parent07d8efab6e28543087233f8a1c62862e0ebefa82 (diff)
avoid duplicate strlen calls for the command completion functions for
'show application' and 'show applications' git-svn-id: http://svn.digium.com/svn/asterisk/trunk@7660 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'pbx.c')
-rw-r--r--pbx.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/pbx.c b/pbx.c
index 6d6cb2441..20754475f 100644
--- a/pbx.c
+++ b/pbx.c
@@ -2957,11 +2957,12 @@ static char show_hints_help[] =
* 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 +2973,18 @@ static char *complete_show_application(char *line, char *word,
/* ... 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 +3198,8 @@ static int handle_show_applications(int fd, int argc, char *argv[])
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 +3210,13 @@ static char *complete_show_applications(char *line, char *word, int pos, int sta
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 {