Index: pbx/pbx_dundi.c =================================================================== --- pbx/pbx_dundi.c (revision 200142) +++ pbx/pbx_dundi.c (working copy) @@ -3802,40 +3802,55 @@ return dundi_query_eid_internal(dei, dcontext, &eid, &hmd, dundi_ttl, 0, avoid); } -static int dundifunc_read(struct ast_channel *chan, const char *cmd, char *num, char *buf, size_t len) +enum { + OPT_BYPASS_CACHE = (1 << 0), +}; + +AST_APP_OPTIONS(dundi_query_opts, BEGIN_OPTIONS + AST_APP_OPTION('b', OPT_BYPASS_CACHE), +END_OPTIONS ); + +static int dundifunc_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { - char *context; - char *opts; + struct ast_module_user *u; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(number); + AST_APP_ARG(context); + AST_APP_ARG(options); + ); + char *parse; + struct ast_flags opts = { 0, }; + struct dundi_result dr[MAX_RESULTS]; int results; int x; - int bypass = 0; - struct ast_module_user *u; - struct dundi_result dr[MAX_RESULTS]; buf[0] = '\0'; - if (ast_strlen_zero(num)) { + u = ast_module_user_add(chan); + + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "DUNDILOOKUP requires an argument (number)\n"); + ast_module_user_remove(u); return -1; } - u = ast_module_user_add(chan); - - context = strchr(num, '|'); - if (context) { - *context++ = '\0'; - opts = strchr(context, '|'); - if (opts) { - *opts++ = '\0'; - if (strchr(opts, 'b')) - bypass = 1; - } + if (!chan) { + ast_log(LOG_ERROR, "DUNDIQUERY can not be used without a channel!\n"); + ast_module_user_remove(u); + return -1; } - if (ast_strlen_zero(context)) - context = "e164"; + parse = ast_strdupa(data); + + AST_STANDARD_APP_ARGS(args, parse); - results = dundi_lookup(dr, MAX_RESULTS, NULL, context, num, bypass); + if (!ast_strlen_zero(args.options)) + ast_app_parse_options(dundi_query_opts, &opts, NULL, args.options); + + if (ast_strlen_zero(args.context)) + args.context = "e164"; + + results = dundi_lookup(dr, MAX_RESULTS, NULL, args.context, args.number, ast_test_flag(&opts, OPT_BYPASS_CACHE)); if (results > 0) { sort_results(dr, results); for (x = 0; x < results; x++) { @@ -3868,14 +3883,6 @@ .read = dundifunc_read, }; -enum { - OPT_BYPASS_CACHE = (1 << 0), -}; - -AST_APP_OPTIONS(dundi_query_opts, BEGIN_OPTIONS - AST_APP_OPTION('b', OPT_BYPASS_CACHE), -END_OPTIONS ); - unsigned int dundi_result_id; struct dundi_result_datastore {