diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index 260b2552b5..a8a25d3ec6 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -350,6 +350,8 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key, switch_xml_t *root, switch_xml_t *domain, switch_xml_t *user, switch_xml_t *ingroup, switch_event_t *params); +SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(const char *user_name, switch_xml_t domain, switch_xml_t *user, switch_xml_t *ingroup); + ///\brief open a config in the core registry ///\param file_path the name of the config section e.g. modules.conf ///\param node a pointer to point to the node if it is found diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index 901270f0bb..4eb7ec4cd4 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -2261,7 +2261,9 @@ static switch_status_t deliver_vm(vm_profile_t *profile, } /*switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send mail is %d, var is %s\n", send_mail, var);*/ } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send mail is %d and that's my final answer\n", send_mail); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deliver VM to %s@%s\n", myid, domain_name); + if (!switch_strlen_zero(vm_storage_dir)) { dir_path = switch_mprintf("%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, myid); } else if (!switch_strlen_zero(profile->storage_dir)) { @@ -2507,7 +2509,7 @@ static switch_status_t voicemail_inject(const char *data) vm_profile_t *profile; char *dup = NULL, *user = NULL, *domain = NULL; switch_status_t status = SWITCH_STATUS_SUCCESS; - int istag = 0, isall = 0; + int isgroup = 0, isall = 0; int argc = 0; char *argv[4]; char *box, *path, *cid_num, *cid_name; @@ -2540,9 +2542,9 @@ static switch_status_t voicemail_inject(const char *data) domain = user; } - if (switch_stristr("tag=", user)) { - user += 4; - istag++; + if (switch_stristr("group=", user)) { + user += 6; + isgroup++; } else if (user == domain) { isall++; } @@ -2567,6 +2569,17 @@ static switch_status_t voicemail_inject(const char *data) switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS); switch_assert(my_params); + + if (isgroup) { + switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "group", user); + } else { + if (isall) { + switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "user", "_all_"); + } else { + switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "user", user); + } + } + switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain); switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "purpose", "publish-vm"); @@ -2581,24 +2594,66 @@ static switch_status_t voicemail_inject(const char *data) switch_core_new_memory_pool(&pool); - if (!isall && !istag) { - if ((ut = switch_xml_find_child(x_domain, "user", "id", user))) { + + if (isgroup) { + switch_xml_t group = NULL, groups = NULL, users = NULL; + if ((groups = switch_xml_child(x_domain, "groups"))) { + if ((group = switch_xml_find_child_multi(groups, "group", "name", user, NULL))) { + if ((users = switch_xml_child(group, "users"))) { + for (ut = switch_xml_child(users, "user"); ut; ut = ut->next) { + const char *type = switch_xml_attr_soft(ut, "type"); + + if (!strcasecmp(type, "pointer")) { + const char *uname = switch_xml_attr_soft(ut, "id"); + switch_xml_t ux; + + if (switch_xml_locate_user_in_domain(uname, x_domain, &ux, NULL) == SWITCH_STATUS_SUCCESS) { + switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS); + status = deliver_vm(profile, ux, domain, path, 0, "B", my_params, pool, cid_name, cid_num, SWITCH_TRUE); + switch_event_destroy(&my_params); + } + continue; + } + + switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS); + status = deliver_vm(profile, ut, domain, path, 0, "B", my_params, pool, cid_name, cid_num, SWITCH_TRUE); + switch_event_destroy(&my_params); + } + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot locate group %s\n", user); + } + } + } else if (isall) { + switch_xml_t group = NULL, groups = NULL, users = NULL; + if ((groups = switch_xml_child(x_domain, "groups"))) { + for (group = switch_xml_child(groups, "group"); group; group = group->next) { + if ((users = switch_xml_child(group, "users"))) { + for (ut = switch_xml_child(users, "user"); ut; ut = ut->next) { + const char *type = switch_xml_attr_soft(ut, "type"); + + if (!strcasecmp(type, "pointer")) { + continue; + } + + switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS); + status = deliver_vm(profile, ut, domain, path, 0, "B", my_params, pool, cid_name, cid_num, SWITCH_TRUE); + switch_event_destroy(&my_params); + } + } + } + } + + } else { + switch_xml_t x_group = NULL; + + if ((status = switch_xml_locate_user_in_domain(user, x_domain, &ut, &x_group)) == SWITCH_STATUS_SUCCESS) { switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS); status = deliver_vm(profile, ut, domain, path, 0, "B", my_params, pool, cid_name, cid_num, SWITCH_TRUE); switch_event_destroy(&my_params); } else { status = SWITCH_STATUS_FALSE; } - } else { - for (ut = switch_xml_child(x_domain, "user"); ut; ut = ut->next) { - const char *tag; - - if (isall || (istag && (tag=switch_xml_attr(ut, "vm-tag")) && !strcasecmp(tag, user))) { - switch_event_create(&my_params, SWITCH_EVENT_REQUEST_PARAMS); - status = deliver_vm(profile, ut, domain, path, 0, "B", my_params, pool, cid_name, cid_num, SWITCH_TRUE); - switch_event_destroy(&my_params); - } - } } switch_core_destroy_memory_pool(&pool); @@ -3562,7 +3617,7 @@ static void do_web(vm_profile_t *profile, char *user, char *domain, char *host, } } -#define VM_INJECT_USAGE "[tag=] [] []" +#define VM_INJECT_USAGE "[group=] [] []" SWITCH_STANDARD_API(voicemail_inject_api_function) { if (voicemail_inject(cmd) == SWITCH_STATUS_SUCCESS) { diff --git a/src/switch_xml.c b/src/switch_xml.c index 07bf355033..fdd6be8fea 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1634,7 +1634,6 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_group(const char *group_name, return status; } - static switch_status_t find_user_in_tag(switch_xml_t tag, const char *ip, const char *user_name, const char *key, switch_event_t *params, switch_xml_t *user) { const char *type = "!pointer"; @@ -1670,6 +1669,26 @@ static switch_status_t find_user_in_tag(switch_xml_t tag, const char *ip, const } +SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_in_domain(const char *user_name, switch_xml_t domain, switch_xml_t *user, switch_xml_t *ingroup) +{ + switch_xml_t group = NULL, groups = NULL, users = NULL; + switch_status_t status = SWITCH_STATUS_FALSE; + + if ((groups = switch_xml_child(domain, "groups"))) { + for (group = switch_xml_child(groups, "group"); group; group = group->next) { + if ((users = switch_xml_child(group, "users"))) { + if ((status = find_user_in_tag(users, NULL, user_name, "id", NULL, user)) == SWITCH_STATUS_SUCCESS) { + if (ingroup) { + *ingroup = group; + } + break; + } + } + } + } + + return status; +} SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key, const char *user_name,