[asterisk-commits] murf: branch murf/bug7109 r47820 - in
/team/murf/bug7109: ./ apps/ configs/ m...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Nov 17 16:06:03 MST 2006
Author: murf
Date: Fri Nov 17 17:06:02 2006
New Revision: 47820
URL: http://svn.digium.com/view/asterisk?view=rev&rev=47820
Log:
Merged revisions 47813-47815,47817-47818 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
........
r47813 | rizzo | 2006-11-17 14:50:55 -0700 (Fri, 17 Nov 2006) | 9 lines
describe a bit the patterns that you can have in the commands,
and add support for wildcard (spelled as '%').
On passing fix a bug in the expansion code which was hidden and
appeared when implementing the wildcard
The fix is just the line 'src != argindex', in case someone wants
to test this on 1.4 - but i would just keep this in trunk.
........
r47814 | qwell | 2006-11-17 14:51:42 -0700 (Fri, 17 Nov 2006) | 6 lines
Add ability to notify an external application/script that the voicemail password was,
while also still changing the password "internally".
Issue 7371, initial patch by pdunkel, with rewrite/config comments by me.
Additional modifications (yay bitmask) by pdunkel.
........
r47815 | rizzo | 2006-11-17 15:02:15 -0700 (Fri, 17 Nov 2006) | 3 lines
standardize "module show [like]"
........
r47817 | rizzo | 2006-11-17 15:53:57 -0700 (Fri, 17 Nov 2006) | 5 lines
convert "help" to new style,
fix completion of arguments past the first one
that i broke earlier today.
........
r47818 | rizzo | 2006-11-17 15:56:58 -0700 (Fri, 17 Nov 2006) | 3 lines
remove a debugging message
........
Modified:
team/murf/bug7109/ (props changed)
team/murf/bug7109/apps/app_voicemail.c
team/murf/bug7109/configs/voicemail.conf.sample
team/murf/bug7109/main/cli.c
Propchange: team/murf/bug7109/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Nov 17 17:06:02 2006
@@ -1,1 +1,1 @@
-/trunk:1-47810
+/trunk:1-47819
Modified: team/murf/bug7109/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug7109/apps/app_voicemail.c?view=diff&rev=47820&r1=47819&r2=47820
==============================================================================
--- team/murf/bug7109/apps/app_voicemail.c (original)
+++ team/murf/bug7109/apps/app_voicemail.c Fri Nov 17 17:06:02 2006
@@ -401,6 +401,10 @@
static char VM_SPOOL_DIR[PATH_MAX];
static char ext_pass_cmd[128];
+
+#define PWDCHANGE_INTERNAL (1 << 1)
+#define PWDCHANGE_EXTERNAL (1 << 2)
+static int pwdchange = PWDCHANGE_INTERNAL;
#if ODBC_STORAGE
#define tdesc "Comedian Mail (Voicemail System) with ODBC Storage"
@@ -5741,10 +5745,11 @@
if (++tries == 3)
return -1;
}
- if (ast_strlen_zero(ext_pass_cmd))
- vm_change_password(vmu,newpassword);
- else
- vm_change_password_shell(vmu,newpassword);
+ if (pwdchange & PWDCHANGE_INTERNAL)
+ vm_change_password(vmu, newpassword);
+ if ((pwdchange & PWDCHANGE_EXTERNAL) && !ast_strlen_zero(ext_pass_cmd))
+ vm_change_password_shell(vmu, newpassword);
+
if (option_debug)
ast_log(LOG_DEBUG,"User %s set password to %s of length %d\n",vms->username,newpassword,(int)strlen(newpassword));
cmd = ast_play_and_wait(chan, vm_passchanged);
@@ -5844,10 +5849,11 @@
cmd = ast_play_and_wait(chan, vm_mismatch);
break;
}
- if (ast_strlen_zero(ext_pass_cmd))
- vm_change_password(vmu,newpassword);
- else
- vm_change_password_shell(vmu,newpassword);
+ if (pwdchange & PWDCHANGE_INTERNAL)
+ vm_change_password(vmu, newpassword);
+ if ((pwdchange & PWDCHANGE_EXTERNAL) && !ast_strlen_zero(ext_pass_cmd))
+ vm_change_password_shell(vmu, newpassword);
+
if (option_debug)
ast_log(LOG_DEBUG,"User %s set password to %s of length %d\n",vms->username,newpassword,(int)strlen(newpassword));
cmd = ast_play_and_wait(chan, vm_passchanged);
@@ -7176,7 +7182,12 @@
/* External password changing command */
if ((extpc = ast_variable_retrieve(cfg, "general", "externpass"))) {
ast_copy_string(ext_pass_cmd,extpc,sizeof(ext_pass_cmd));
- }
+ pwdchange = PWDCHANGE_EXTERNAL;
+ } else if ((extpc = ast_variable_retrieve(cfg, "general", "externpassnotify"))) {
+ ast_copy_string(ext_pass_cmd,extpc,sizeof(ext_pass_cmd));
+ pwdchange = PWDCHANGE_EXTERNAL | PWDCHANGE_INTERNAL;
+ }
+
#ifdef IMAP_STORAGE
/* IMAP server address */
if ((imap_server = ast_variable_retrieve(cfg, "general", "imapserver"))) {
Modified: team/murf/bug7109/configs/voicemail.conf.sample
URL: http://svn.digium.com/view/asterisk/team/murf/bug7109/configs/voicemail.conf.sample?view=diff&rev=47820&r1=47819&r2=47820
==============================================================================
--- team/murf/bug7109/configs/voicemail.conf.sample (original)
+++ team/murf/bug7109/configs/voicemail.conf.sample Fri Nov 17 17:06:02 2006
@@ -66,7 +66,11 @@
; If you need to have an external program, i.e. /usr/bin/myapp
; called when a voicemail password is changed, uncomment this:
+; Note: If this is set, the password will NOT be changed in voicemail.conf
+; If you would like to also change the password in voicemail.conf, use
+; the externpassnotify option below instead.
;externpass=/usr/bin/myapp
+;externpassnotify=/usr/bin/myapp
; For the directory, you can override the intro file if you want
;directoryintro=dir-intro
; The character set for voicemail messages can be specified here
Modified: team/murf/bug7109/main/cli.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug7109/main/cli.c?view=diff&rev=47820&r1=47819&r2=47820
==============================================================================
--- team/murf/bug7109/main/cli.c (original)
+++ team/murf/bug7109/main/cli.c Fri Nov 17 17:06:02 2006
@@ -75,12 +75,6 @@
static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
-static char help_help[] =
-"Usage: help [topic]\n"
-" When called with a topic as an argument, displays usage\n"
-" information on the given command. If called without a\n"
-" topic, it provides a list of commands.\n";
-
static char logger_mute_help[] =
"Usage: logger mute\n"
" Disables logging output to the current console, making it possible to\n"
@@ -425,7 +419,7 @@
switch (cmd) {
case CLI_INIT:
- e->command = "module show";
+ e->command = "module show [like]";
e->usage =
"Usage: module show [like keyword]\n"
" Shows Asterisk modules currently in use, and usage statistics.\n";
@@ -433,8 +427,6 @@
case CLI_GENERATE:
if (a->pos == e->args)
- return a->n == 0 ? strdup("like") : NULL;
- else if (a->pos == e->args+1 && strcasestr(a->line," like "))
return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0);
else
return NULL;
@@ -442,10 +434,10 @@
/* all the above return, so we proceed with the handler.
* we are guaranteed to have argc >= e->args
*/
- if (a->argc == e->args)
+ if (a->argc == e->args - 1)
like = "";
- else if (a->argc == e->args + 2 && !strcmp(a->argv[e->args],"like"))
- like = a->argv[e->args + 1];
+ else if (a->argc == e->args + 1 && !strcasecmp(a->argv[e->args-1], "like") )
+ like = a->argv[e->args];
else
return CLI_SHOWUSAGE;
@@ -951,20 +943,6 @@
#undef FORMAT_STRING
}
-static int handle_help(int fd, int argc, char *argv[]);
-
-static char * complete_help(const char *text, const char *word, int pos, int state)
-{
- /* skip first 4 or 5 chars, "help "*/
- int l = strlen(text);
-
- if (l > 5)
- l = 5;
- text += l;
- /* XXX watch out, should stop to the non-generator parts */
- return __ast_cli_generator(text, word, state, 0);
-}
-
/* XXX Nothing in this array can currently be deprecated...
You have to change the way find_cli works in order to remove this array
I recommend doing this eventually...
@@ -991,6 +969,8 @@
static struct ast_cli_entry cli_module_reload_deprecated = NEW_CLI(handle_reload_deprecated, "reload modules by name");
static struct ast_cli_entry cli_module_unload_deprecated = NEW_CLI(handle_unload_deprecated, "unload modules by name");
+static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+
static struct ast_cli_entry cli_cli[] = {
/* Deprecated, but preferred command is now consolidated (and already has a deprecated command for it). */
NEW_CLI(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),
@@ -1010,9 +990,7 @@
group_show_channels, "Display active channels with group(s)",
group_show_channels_help },
- { { "help", NULL },
- handle_help, "Display help list, or specific help on a command",
- help_help, complete_help },
+ NEW_CLI(handle_help, "Display help list, or specific help on a command"),
{ { "logger", "mute", NULL },
handle_logger_mute, "Toggle logging output to a console",
@@ -1036,7 +1014,7 @@
/*!
* Some regexp characters in cli arguments are reserved and used as separators.
*/
-static const char cli_rsvd[] = "[]{}|*";
+static const char cli_rsvd[] = "[]{}|*%";
/*!
* initialize the _full_cmd string and related parameters,
@@ -1111,6 +1089,12 @@
* match a word in the CLI entry.
* returns -1 on mismatch, 0 on match of an optional word,
* 1 on match of a full word.
+ *
+ * The pattern can be
+ * any_word match for equal
+ * [foo|bar|baz] optionally, one of these words
+ * {foo|bar|baz} exactly, one of these words
+ * % any word
*/
static int word_match(const char *cmd, const char *cli_word)
{
@@ -1123,6 +1107,10 @@
return (strcasecmp(cmd, cli_word) == 0) ? 1 : -1;
/* regexp match, takes [foo|bar] or {foo|bar} */
l = strlen(cmd);
+ /* wildcard match - will extend in the future */
+ if (l > 0 && cli_word[0] == '%') {
+ return 1; /* wildcard */
+ }
pos = strcasestr(cli_word, cmd);
if (pos == NULL) /* not found, say ok if optional */
return cli_word[0] == '[' ? 0 : -1;
@@ -1158,8 +1146,13 @@
return (pos != 0) ? NULL : strdup(token);
}
/* now handle regexp match */
+
+ /* Wildcard always matches, so we never do is_prefix on them */
+
t1 = ast_strdupa(token + 1); /* copy, skipping first char */
while (pos >= 0 && (s = strsep(&t1, cli_rsvd)) && *s) {
+ if (*s == '%') /* wildcard */
+ continue;
if (strncasecmp(s, word, lw)) /* no match */
continue;
(*actual)++;
@@ -1375,12 +1368,12 @@
}
-/*! \brief helper for help_workhorse and final part of
- * handle_help. if locked = 0 it's just help_workhorse,
+/*! \brief helper for final part of
+ * handle_help. if locked = 0 it's just "help_workhorse",
* otherwise assume the list is already locked and print
* an error message if not found.
*/
-static int help1(int fd, char *match[], int locked)
+static char *help1(int fd, char *match[], int locked)
{
char matchstr[80] = "";
struct ast_cli_entry *e;
@@ -1406,36 +1399,48 @@
ast_cli(fd, "%30.30s %s\n", e->_full_cmd, S_OR(e->summary, "<no description available>"));
found++;
}
- AST_LIST_UNLOCK(&helpers);
+ if (!locked)
+ AST_LIST_UNLOCK(&helpers);
if (!locked && !found && matchstr[0])
ast_cli(fd, "No such command '%s'.\n", matchstr);
- return 0;
-}
-
-static int help_workhorse(int fd, char *match[])
-{
- return help1(fd, match, 0 /* do not print errors */);
-}
-
-static int handle_help(int fd, int argc, char *argv[])
+ return CLI_SUCCESS;
+}
+
+static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char fullcmd[80];
- struct ast_cli_entry *e;
-
- if (argc < 1)
- return RESULT_SHOWUSAGE;
- if (argc == 1)
- return help_workhorse(fd, NULL);
+ struct ast_cli_entry *my_e;
+
+ if (cmd == CLI_INIT) {
+ e->command = "help";
+ e->usage =
+ "Usage: help [topic]\n"
+ " When called with a topic as an argument, displays usage\n"
+ " information on the given command. If called without a\n"
+ " topic, it provides a list of commands.\n";
+ return NULL;
+
+ } else if (cmd == CLI_GENERATE) {
+ /* skip first 4 or 5 chars, "help " */
+ int l = strlen(a->line);
+
+ if (l > 5)
+ l = 5;
+ /* XXX watch out, should stop to the non-generator parts */
+ return __ast_cli_generator(a->line + l, a->word, a->n, 0);
+ }
+ if (a->argc == 1)
+ return help1(a->fd, NULL, 0);
AST_LIST_LOCK(&helpers);
- e = find_cli(argv + 1, 1); /* try exact match first */
- if (!e)
- return help1(fd, argv + 1, 1 /* locked */);
- if (e->usage)
- ast_cli(fd, "%s", e->usage);
+ my_e = find_cli(a->argv + 1, 1); /* try exact match first */
+ if (!my_e)
+ return help1(a->fd, a->argv + 1, 1 /* locked */);
+ if (my_e->usage)
+ ast_cli(a->fd, "%s", my_e->usage);
else {
- ast_join(fullcmd, sizeof(fullcmd), argv+1);
- ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
+ ast_join(fullcmd, sizeof(fullcmd), a->argv+1);
+ ast_cli(a->fd, "No help text available for '%s'.\n", fullcmd);
}
AST_LIST_UNLOCK(&helpers);
return RESULT_SUCCESS;
@@ -1571,6 +1576,17 @@
return match_list;
}
+/*! \brief returns true if there are more words to match */
+static int more_words (char * const *dst)
+{
+ int i;
+ for (i = 0; dst[i]; i++) {
+ if (dst[i][0] != '[')
+ return -1;
+ }
+ return 0;
+}
+
/*
* generate the entry at position 'state'
*/
@@ -1608,7 +1624,7 @@
break;
}
- if (src < argindex) /* not a match */
+ if (src != argindex && more_words(e->cmda + dst)) /* not a match */
continue;
ret = is_prefix(argv[src], e->cmda[dst], state - matchnum, &n);
matchnum += n; /* this many matches here */
More information about the asterisk-commits
mailing list