From 8764a046c626dff6615673e3850c662c2228cbdf Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 13 May 2011 15:29:40 -0500 Subject: [PATCH] allow creation of arbitrary profile vars --- src/include/switch_caller.h | 10 ++++++++++ src/switch_caller.c | 10 ++++++++++ src/switch_channel.c | 15 ++++++++++++++- src/switch_ivr.c | 15 +++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/include/switch_caller.h b/src/include/switch_caller.h index bd53a04f68..fde3372105 100644 --- a/src/include/switch_caller.h +++ b/src/include/switch_caller.h @@ -56,6 +56,15 @@ #include SWITCH_BEGIN_EXTERN_C + +typedef struct profile_node_s { + char *var; + char *val; + struct profile_node_s *next; +} profile_node_t; + + + /*! \brief Call Specific Data */ struct switch_caller_profile { @@ -110,6 +119,7 @@ SWITCH_BEGIN_EXTERN_C switch_memory_pool_t *pool; struct switch_caller_profile *next; switch_call_direction_t direction; + profile_node_t *soft; }; /*! \brief An Abstract Representation of a dialplan Application */ diff --git a/src/switch_caller.c b/src/switch_caller.c index d0d242fe90..5e3070548e 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -324,6 +324,16 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_ switch_snprintf(header_name, sizeof(header_name), "%s-Profile-Index", prefix); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, caller_profile->profile_index); } + + if (caller_profile->soft) { + profile_node_t *pn; + + for (pn = caller_profile->soft; pn; pn = pn->next) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, pn->var, pn->val); + } + + } + if (caller_profile->times) { switch_snprintf(header_name, sizeof(header_name), "%s-Profile-Created-Time", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created); diff --git a/src/switch_channel.c b/src/switch_channel.c index d0c478a170..76538bdaa6 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -877,7 +877,20 @@ SWITCH_DECLARE(switch_status_t) switch_channel_set_profile_var(switch_channel_t } else if (!strcasecmp(name, "chan_name")) { channel->caller_profile->chan_name = v; } else { - status = SWITCH_STATUS_FALSE; + profile_node_t *pn, *n = switch_core_alloc(channel->caller_profile->pool, sizeof(*n)); + + n->var = switch_core_strdup(channel->caller_profile->pool, name); + n->val = v; + + if (!channel->caller_profile->soft) { + channel->caller_profile->soft = n; + } else { + for(pn = channel->caller_profile->soft; pn && pn->next; pn = pn->next); + + if (pn) { + pn->next = n; + } + } } switch_mutex_unlock(channel->profile_mutex); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index ee7fe868b1..2f0066f415 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1964,6 +1964,21 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_profile_data(switch_xml_t xml, switch_cal } switch_xml_set_txt_d(param, caller_profile->chan_name); + + if (caller_profile->soft) { + profile_node_t *pn; + + for (pn = caller_profile->soft; pn; pn = pn->next) { + + if (!(param = switch_xml_add_child_d(xml, pn->var, off++))) { + return -1; + } + switch_xml_set_txt_d(param, pn->val); + } + + } + + return off; }