Index: pbx.c =================================================================== RCS file: /usr/cvsroot/asterisk/pbx.c,v retrieving revision 1.146 diff -u -r1.146 pbx.c --- pbx.c 21 Aug 2004 18:55:39 -0000 1.146 +++ pbx.c 24 Aug 2004 15:58:19 -0000 @@ -2394,13 +2394,15 @@ " Describes a particular application.\n"; static char show_applications_help[] = -"Usage: show applications\n" -" List applications which are currently available.\n"; +"Usage: show applications [{like|describing} ]\n" +" List applications which are currently available.\n" +" If 'like', will be a substring of the app name\n" +" If 'describing', will be a substring of the description\n"; static char show_dialplan_help[] = "Usage: show dialplan [exten@][context]\n" @@ -2553,6 +2555,7 @@ static int handle_show_applications(int fd, int argc, char *argv[]) { struct ast_app *a; + int like=0, describing=0; /* try to lock applications list ... */ if (ast_mutex_lock(&applock)) { @@ -2560,26 +2563,49 @@ return -1; } - /* ... go to first application ... */ - a = apps; - /* ... have we got at least one application (first)? no? */ - if (!a) { - ast_cli(fd, "There is no registered applications\n"); + if (!apps) { + ast_cli(fd, "There are no registered applications\n"); ast_mutex_unlock(&applock); return -1; } - /* ... we have applications ... */ - ast_cli(fd, "\n -= Registered Asterisk Applications =-\n"); + if ((argc == 4) && (!strcmp(argv[2], "like"))) { + like = 1; + } else if ((argc > 3) && (!strcmp(argv[2], "describing"))) { + describing = 1; + } + + if ((!like) && (!describing)) { + ast_cli(fd, " -= Registered Asterisk Applications =-\n"); + } else { + ast_cli(fd, " -= Matching Asterisk Applications =-\n"); + } /* ... go through all applications ... */ - while (a) { + for (a = apps; a; a = a->next) { /* ... show informations about applications ... */ - ast_cli(fd," %20s: %s\n", - a->name, - a->synopsis ? a->synopsis : ""); - a = a->next; + + if (like) { + if (ast_strcasestr(a->name, argv[3])) { + ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : ""); + } + } else if (describing) { + if (a->description) { + /* Match all words on command line */ + int found = 1, i; + for (i=3;idescription, argv[i])) { + found = 0; + } + } + if (found) { + ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : ""); + } + } + } else { + ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : ""); + } } /* ... unlock and return */ Index: utils.c =================================================================== RCS file: /usr/cvsroot/asterisk/utils.c,v retrieving revision 1.16 diff -u -r1.16 utils.c --- utils.c 8 Aug 2004 17:15:01 -0000 1.16 +++ utils.c 24 Aug 2004 15:58:19 -0000 @@ -20,6 +20,7 @@ #include #include #include +#include static char base64[64]; static char b2a[256]; @@ -363,3 +364,44 @@ return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */ } #endif /* ! LINUX */ + +static char *upper(const char *orig, char *buf, int bufsize) +{ + int i; + memset(buf, 0, bufsize); + for (i=0; i u1len) { + /* Needle bigger than haystack */ + return NULL; + } + offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len)); + if (offset) { + /* Return the offset into the original string */ + return ((char *)((unsigned int)haystack + (unsigned int)(offset - u1))); + } else { + return NULL; + } + } else { + ast_log(LOG_ERROR, "Out of memory\n"); + return NULL; + } +} + Index: include/asterisk/utils.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/utils.h,v retrieving revision 1.7 diff -u -r1.7 utils.h --- include/asterisk/utils.h 8 Aug 2004 17:15:02 -0000 1.7 +++ include/asterisk/utils.h 24 Aug 2004 15:58:19 -0000 @@ -49,4 +49,6 @@ extern int ast_pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data); #endif /* LINUX */ +extern char *ast_strcasestr(const char *, const char *); + #endif