From 402f2391dc15152f96619c9bfb21809b13ccc46d Mon Sep 17 00:00:00 2001 From: Marc Olivier Chouinard Date: Thu, 9 Sep 2010 20:03:36 -0400 Subject: [PATCH] mod_commands: Fix user_data returning the first value found instead of the last. Also add support to get variable from the group. --- .../applications/mod_commands/mod_commands.c | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index e1eb2a6b6a..e308a0004f 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -605,11 +605,12 @@ SWITCH_STANDARD_API(in_group_function) SWITCH_STANDARD_API(user_data_function) { - switch_xml_t x_domain, xml = NULL, x_user = NULL, x_param, x_params; + switch_xml_t x_domain, xml = NULL, x_user = NULL, x_group = NULL, x_param, x_params; int argc; char *mydata = NULL, *argv[3], *key = NULL, *type = NULL, *user, *domain; char delim = ' '; const char *container = "params", *elem = "param"; + const char *result = NULL; switch_event_t *params = NULL; if (zstr(cmd) || !(mydata = strdup(cmd))) { @@ -637,10 +638,10 @@ SWITCH_STANDARD_API(user_data_function) switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain); switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "type", type); - if (key && type && switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, NULL, params) == SWITCH_STATUS_SUCCESS) { + if (key && type && switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, &x_group, params) == SWITCH_STATUS_SUCCESS) { if (!strcmp(type, "attr")) { const char *attr = switch_xml_attr_soft(x_user, key); - stream->write_function(stream, "%s", attr); + result = attr; goto end; } @@ -649,33 +650,45 @@ SWITCH_STANDARD_API(user_data_function) elem = "variable"; } - if ((x_params = switch_xml_child(x_user, container))) { - for (x_param = switch_xml_child(x_params, elem); x_param; x_param = x_param->next) { - const char *var = switch_xml_attr(x_param, "name"); - const char *val = switch_xml_attr(x_param, "value"); - - if (var && val && !strcasecmp(var, key)) { - stream->write_function(stream, "%s", val); - goto end; - } - - } - } - if ((x_params = switch_xml_child(x_domain, container))) { for (x_param = switch_xml_child(x_params, elem); x_param; x_param = x_param->next) { const char *var = switch_xml_attr(x_param, "name"); const char *val = switch_xml_attr(x_param, "value"); if (var && val && !strcasecmp(var, key)) { - stream->write_function(stream, "%s", val); - goto end; + result = val; + } + + } + } + + if (x_group && (x_params = switch_xml_child(x_group, container))) { + for (x_param = switch_xml_child(x_params, elem); x_param; x_param = x_param->next) { + const char *var = switch_xml_attr(x_param, "name"); + const char *val = switch_xml_attr(x_param, "value"); + + if (var && val && !strcasecmp(var, key)) { + result = val; + } + } + } + + if ((x_params = switch_xml_child(x_user, container))) { + for (x_param = switch_xml_child(x_params, elem); x_param; x_param = x_param->next) { + const char *var = switch_xml_attr(x_param, "name"); + const char *val = switch_xml_attr(x_param, "value"); + + if (var && val && !strcasecmp(var, key)) { + result = val; } } } } end: + if (result) { + stream->write_function(stream, "%s", result); + } switch_xml_free(xml); switch_safe_free(mydata); switch_event_destroy(¶ms);