[Asterisk-cvs] asterisk ChangeLog, 1.14, 1.15 app.c, 1.81,
1.82 pbx.c, 1.294, 1.295
kpfleming
kpfleming
Thu Nov 3 16:27:26 CST 2005
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv1836
Modified Files:
ChangeLog app.c pbx.c
Log Message:
major update to arg/option parsing APIs and documentation
Index: ChangeLog
===================================================================
RCS file: /usr/cvsroot/asterisk/ChangeLog,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ChangeLog 2 Nov 2005 21:46:52 -0000 1.14
+++ ChangeLog 3 Nov 2005 21:19:10 -0000 1.15
@@ -1,3 +1,8 @@
+2005-11-03 Kevin P. Fleming <kpfleming at digium.com>
+
+ * include/asterisk/app.h: re-work application arg/option parsing APIs for consistent naming, add doxygen docs for option API
+ * many files: update to new APIs
+
2005-11-02 Kevin P. Fleming <kpfleming at digium.com>
* apps/app_dial.c (dial_exec_full): convert to use API calls for argument/option parsing
Index: app.c
===================================================================
RCS file: /usr/cvsroot/asterisk/app.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- app.c 1 Nov 2005 17:22:25 -0000 1.81
+++ app.c 3 Nov 2005 21:19:10 -0000 1.82
@@ -1105,7 +1105,7 @@
return count;
}
-int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
+unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
{
int argc;
char *scan;
@@ -1523,41 +1523,40 @@
return output;
}
-int ast_parseoptions(const struct ast_option *options, struct ast_flags *flags, char **args, char *optstr)
+int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
{
char *s;
int curarg;
- int argloc;
+ unsigned int argloc;
char *arg;
int res = 0;
- flags->flags = 0;
+ ast_clear_flag(flags, AST_FLAGS_ALL);
if (!optstr)
return 0;
s = optstr;
while (*s) {
- curarg = *s & 0x7f;
- flags->flags |= options[curarg].flag;
+ curarg = *s++ & 0x7f;
+ ast_set_flag(flags, options[curarg].flag);
argloc = options[curarg].arg_index;
- s++;
if (*s == '(') {
/* Has argument */
- s++;
arg = s;
- while (*s && (*s != ')')) s++;
+ while (*++s && (*s != ')'));
if (*s) {
if (argloc)
args[argloc - 1] = arg;
- *s = '\0';
- s++;
+ *s++ = '\0';
} else {
ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
res = -1;
}
- } else if (argloc)
+ } else if (argloc) {
args[argloc - 1] = NULL;
+ }
}
+
return res;
}
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.294
retrieving revision 1.295
diff -u -d -r1.294 -r1.295
--- pbx.c 31 Oct 2005 15:34:11 -0000 1.294
+++ pbx.c 3 Nov 2005 21:19:10 -0000 1.295
@@ -86,17 +86,17 @@
#define BACKGROUND_MATCHEXTEN (1 << 2)
#define BACKGROUND_PLAYBACK (1 << 3)
-AST_DECLARE_OPTIONS(background_opts,{
- ['s'] = { BACKGROUND_SKIP },
- ['n'] = { BACKGROUND_NOANSWER },
- ['m'] = { BACKGROUND_MATCHEXTEN },
- ['p'] = { BACKGROUND_PLAYBACK },
+AST_APP_OPTIONS(background_opts, {
+ AST_APP_OPTION('s', BACKGROUND_SKIP),
+ AST_APP_OPTION('n', BACKGROUND_NOANSWER),
+ AST_APP_OPTION('m', BACKGROUND_MATCHEXTEN),
+ AST_APP_OPTION('p', BACKGROUND_PLAYBACK),
});
#define WAITEXTEN_MOH (1 << 0)
-AST_DECLARE_OPTIONS(waitexten_opts,{
- ['m'] = { WAITEXTEN_MOH, 1 },
+AST_APP_OPTIONS(waitexten_opts, {
+ AST_APP_OPTION_ARG('m', WAITEXTEN_MOH, 1),
});
struct ast_context;
@@ -5616,13 +5616,13 @@
char *args;
char *argv[2];
char *options = NULL;
- char *mohclass = NULL;
char *timeout = NULL;
struct ast_flags flags = {0};
+ char *opts[1] = { NULL };
args = ast_strdupa(data);
- if ((argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
+ if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
if (argc > 0) {
timeout = argv[0];
if (argc > 1)
@@ -5630,16 +5630,11 @@
}
}
- if (options) {
- char *opts[1];
- ast_parseoptions(waitexten_opts, &flags, opts, options);
- if (ast_test_flag(&flags, WAITEXTEN_MOH)) {
- mohclass = opts[0];
- }
- }
+ if (options)
+ ast_app_parse_options(waitexten_opts, &flags, opts, options);
if (ast_test_flag(&flags, WAITEXTEN_MOH))
- ast_moh_start(chan, mohclass);
+ ast_moh_start(chan, opts[0]);
/* Wait for "n" seconds */
if (timeout && atof((char *)timeout))
@@ -5685,7 +5680,7 @@
parse = ast_strdupa(data);
- if ((argc = ast_separate_app_args(parse, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
+ if ((argc = ast_app_separate_args(parse, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
switch (argc) {
case 4:
context = argv[3];
@@ -5714,7 +5709,7 @@
else if (!strcasecmp(options, "noanswer"))
flags.flags = BACKGROUND_NOANSWER;
else
- ast_parseoptions(background_opts, &flags, NULL, options);
+ ast_app_parse_options(background_opts, &flags, NULL, options);
}
/* Answer if need be */
@@ -5948,7 +5943,7 @@
}
mydata = ast_strdupa(data);
- argc = ast_separate_app_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
+ argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
/* check for a trailing flags argument */
if ((argc > 1) && !strchr(argv[argc-1], '=')) {
More information about the svn-commits
mailing list