From 8f659a81cf183c0d2eb38b4df4dff0cffed4540b Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 18 Dec 2018 10:55:55 +0000 Subject: [PATCH 1/2] [FS-11608] [core] set prefix for caller profile soft variables --- src/include/switch_types.h | 6 ++++-- src/switch_caller.c | 10 +++++++++- src/switch_core.c | 7 +++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 926c8a6bea..afb3e4e7c6 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -377,7 +377,8 @@ typedef enum { SCF_DEBUG_SQL = (1 << 21), SCF_API_EXPANSION = (1 << 22), SCF_SESSION_THREAD_POOL = (1 << 23), - SCF_DIALPLAN_TIMESTAMPS = (1 << 24) + SCF_DIALPLAN_TIMESTAMPS = (1 << 24), + SCF_CPF_SOFT_PREFIX = (1 << 25) } switch_core_flag_enum_t; typedef uint32_t switch_core_flag_t; @@ -578,7 +579,8 @@ typedef enum { SWITCH_CPF_NONE = 0, SWITCH_CPF_SCREEN = (1 << 0), SWITCH_CPF_HIDE_NAME = (1 << 1), - SWITCH_CPF_HIDE_NUMBER = (1 << 2) + SWITCH_CPF_HIDE_NUMBER = (1 << 2), + SWITCH_CPF_SOFT_PREFIX = (1 << 3) } switch_caller_profile_flag_enum_t; typedef uint32_t switch_caller_profile_flag_t; diff --git a/src/switch_caller.c b/src/switch_caller.c index d3b835ec80..0667d65dd6 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -97,6 +97,9 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memor profile->callee_id_name = SWITCH_BLANK_STRING; profile->callee_id_number = SWITCH_BLANK_STRING; switch_set_flag(profile, SWITCH_CPF_SCREEN); + if (switch_core_test_flag(SCF_CPF_SOFT_PREFIX)) { + switch_set_flag(profile, SWITCH_CPF_SOFT_PREFIX); + } profile->pool = pool; return profile; } @@ -399,7 +402,12 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_ 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 (switch_test_flag(caller_profile, SWITCH_CPF_SOFT_PREFIX)) { + switch_snprintf(header_name, sizeof(header_name), "%s-%s", prefix, pn->var); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, header_name, pn->val); + } else { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, pn->var, pn->val); + } } } diff --git a/src/switch_core.c b/src/switch_core.c index ca87b5f8cd..443b8bc0b8 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -2340,6 +2340,13 @@ static void switch_load_core_config(const char *file) "rtp-retain-crypto-keys enabled. Could be used to decrypt secure media.\n"); } switch_core_set_variable("rtp_retain_crypto_keys", val); + } else if (!strcasecmp(var, "caller-profile-soft-variables-uses-prefix") && !zstr(val)) { + int v = switch_true(val); + if (v) { + switch_set_flag((&runtime), SCF_CPF_SOFT_PREFIX); + } else { + switch_clear_flag((&runtime), SCF_CPF_SOFT_PREFIX); + } } } } From 8ed52f4c266446e29fa040c49f55b79081054fcb Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 18 Feb 2019 14:03:24 +0000 Subject: [PATCH 2/2] [FS-11609] [core] lookup values in caller profile soft variables --- src/include/switch_types.h | 6 ++++-- src/switch_caller.c | 11 +++++++++++ src/switch_core.c | 7 +++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index afb3e4e7c6..aec3ae0bd1 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -378,7 +378,8 @@ typedef enum { SCF_API_EXPANSION = (1 << 22), SCF_SESSION_THREAD_POOL = (1 << 23), SCF_DIALPLAN_TIMESTAMPS = (1 << 24), - SCF_CPF_SOFT_PREFIX = (1 << 25) + SCF_CPF_SOFT_PREFIX = (1 << 25), + SCF_CPF_SOFT_LOOKUP = (1 << 26) } switch_core_flag_enum_t; typedef uint32_t switch_core_flag_t; @@ -580,7 +581,8 @@ typedef enum { SWITCH_CPF_SCREEN = (1 << 0), SWITCH_CPF_HIDE_NAME = (1 << 1), SWITCH_CPF_HIDE_NUMBER = (1 << 2), - SWITCH_CPF_SOFT_PREFIX = (1 << 3) + SWITCH_CPF_SOFT_PREFIX = (1 << 3), + SWITCH_CPF_SOFT_LOOKUP = (1 << 4) } switch_caller_profile_flag_enum_t; typedef uint32_t switch_caller_profile_flag_t; diff --git a/src/switch_caller.c b/src/switch_caller.c index 0667d65dd6..37a3683039 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -100,6 +100,9 @@ SWITCH_DECLARE(switch_caller_profile_t *) switch_caller_profile_new(switch_memor if (switch_core_test_flag(SCF_CPF_SOFT_PREFIX)) { switch_set_flag(profile, SWITCH_CPF_SOFT_PREFIX); } + if (switch_core_test_flag(SCF_CPF_SOFT_LOOKUP)) { + switch_set_flag(profile, SWITCH_CPF_SOFT_LOOKUP); + } profile->pool = pool; return profile; } @@ -304,6 +307,14 @@ SWITCH_DECLARE(const char *) switch_caller_get_field_by_name(switch_caller_profi return switch_core_sprintf(caller_profile->pool, "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred); } + if (caller_profile->soft && switch_test_flag(caller_profile, SWITCH_CPF_SOFT_LOOKUP)) { + profile_node_t *pn; + for (pn = caller_profile->soft; pn; pn = pn->next) { + if (!strcasecmp(name, pn->var)) { + return pn->val; + } + } + } return NULL; } diff --git a/src/switch_core.c b/src/switch_core.c index 443b8bc0b8..596ef2bbe4 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -2347,6 +2347,13 @@ static void switch_load_core_config(const char *file) } else { switch_clear_flag((&runtime), SCF_CPF_SOFT_PREFIX); } + } else if (!strcasecmp(var, "caller-profile-soft-lookup-values") && !zstr(val)) { + int v = switch_true(val); + if (v) { + switch_set_flag((&runtime), SCF_CPF_SOFT_LOOKUP); + } else { + switch_clear_flag((&runtime), SCF_CPF_SOFT_LOOKUP); + } } } }