>From 6aea6c27f78a7799b440a06be4c158f6f61bf601 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 20 Sep 2012 22:05:12 +0200 Subject: [PATCH] mod_voicemail: allow passing extra headers in event message to locate user directory - channel variable 'locate_event_extra_headers' can be set to the prefix of channel variable names that have to be added as extra headers to the event message fired to locate the user directory - the header name is variable name and the header body is variable value - here is an example of adding the value of SIP header X-Data as event message header X-Event-Data: - the headers are added for leave voice message and listen voice message events - the extra headers can be useful on building user directory dinamically, e.g., via a Lua script --- src/mod/applications/mod_voicemail/mod_voicemail.c | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index 51677c5..9509ea7 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -161,6 +161,31 @@ struct vm_profile { typedef struct vm_profile vm_profile_t; +static int voicemail_event_message_add_extra_headers(switch_channel_t *channel, switch_event_t *event, + const char *prefix) +{ + switch_event_header_t *hi = NULL; + int n; + + if(channel==NULL || event==NULL || prefix==NULL) + return 0; + + n = 0; + if ((hi = switch_channel_variable_first(channel))) { + for (; hi; hi = hi->next) { + const char *name = (char *) hi->name; + char *value = (char *) hi->value; + + if (!strncasecmp(name, prefix, strlen(prefix))) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, name, value); + } + } + switch_channel_variable_last(channel); + } + + return n; +} + switch_cache_db_handle_t *vm_get_db_handle(vm_profile_t *profile) { switch_cache_db_connection_options_t options = { {0} }; @@ -2326,6 +2351,8 @@ static void voicemail_check_main(switch_core_session_t *session, vm_profile_t *p switch_event_create(¶ms, SWITCH_EVENT_GENERAL); switch_assert(params); + voicemail_event_message_add_extra_headers(channel, params, + switch_channel_get_variable(channel, "locate_event_extra_headers")); switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "action", "voicemail-lookup"); switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "destination_number", caller_profile->destination_number); switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "caller_id_number", caller_id_number); @@ -3157,6 +3184,7 @@ static switch_status_t voicemail_inject(const char *data, switch_core_session_t return status; } + static switch_status_t voicemail_leave_main(switch_core_session_t *session, vm_profile_t *profile, const char *domain_name, const char *id) { switch_channel_t *channel = switch_core_session_get_channel(session); @@ -3220,6 +3248,8 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, vm_p switch_event_create(&locate_params, SWITCH_EVENT_REQUEST_PARAMS); switch_assert(locate_params); switch_event_add_header_string(locate_params, SWITCH_STACK_BOTTOM, "action", "voicemail-lookup"); + voicemail_event_message_add_extra_headers(channel, locate_params, + switch_channel_get_variable(channel, "locate_event_extra_headers")); if (switch_xml_locate_user_merged("id", id, domain_name, switch_channel_get_variable(channel, "network_addr"), &x_user, locate_params) == SWITCH_STATUS_SUCCESS) { -- 1.7.9.2