From ffa220792607afaa85726348162b5174bfb3b0b6 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 31 Oct 2022 17:49:17 +0300 Subject: [PATCH] [Core] SWITCH_STACK_NODUP flag is deprecated and will be soon removed. Introduce switch_event_add_header_string_nodup() API. --- src/include/switch_event.h | 1 + .../event_handlers/mod_erlang_event/handle_msg.c | 4 ++-- src/mod/event_handlers/mod_kazoo/kazoo_cdr.c | 14 +++++++------- src/mod/event_handlers/mod_kazoo/kazoo_node.c | 2 +- src/switch_core.c | 2 +- src/switch_event.c | 8 ++++++++ 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/include/switch_event.h b/src/include/switch_event.h index f2ac381ee8..10841f469c 100644 --- a/src/include/switch_event.h +++ b/src/include/switch_event.h @@ -206,6 +206,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_subclass_name(switch_event_t *e \return SWITCH_STATUS_SUCCESS if the header was added */ SWITCH_DECLARE(switch_status_t) switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data); +SWITCH_DECLARE(switch_status_t) switch_event_add_header_string_nodup(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data); SWITCH_DECLARE(switch_status_t) switch_event_del_header_val(switch_event_t *event, const char *header_name, const char *val); #define switch_event_del_header(_e, _h) switch_event_del_header_val(_e, _h, NULL) diff --git a/src/mod/event_handlers/mod_erlang_event/handle_msg.c b/src/mod/event_handlers/mod_erlang_event/handle_msg.c index 292134d716..aad45a4986 100644 --- a/src/mod/event_handlers/mod_erlang_event/handle_msg.c +++ b/src/mod/event_handlers/mod_erlang_event/handle_msg.c @@ -836,7 +836,7 @@ static switch_status_t handle_msg_sendevent(listener_t *listener, int arity, ei_ switch_safe_free(event->body); event->body = value; } else if (!fail) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); + switch_event_add_header_string_nodup(event, SWITCH_STACK_BOTTOM, key, value); } /* Do not free malloc here! The above commands utilize the raw allocated memory and skip any copying/duplication. Faster. */ @@ -901,7 +901,7 @@ static switch_status_t handle_msg_sendmsg(listener_t *listener, int arity, ei_x_ } if (!fail) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); + switch_event_add_header_string_nodup(event, SWITCH_STACK_BOTTOM, key, value); } } diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c b/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c index f7b0d53df6..fef66f8be3 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_cdr.c @@ -196,7 +196,7 @@ static switch_status_t kz_report_channel_flaws(switch_core_session_t *session, s kz_switch_ivr_set_json_call_flaws(callStats, session, SWITCH_MEDIA_TYPE_AUDIO); kz_switch_ivr_set_json_call_flaws(callStats, session, SWITCH_MEDIA_TYPE_VIDEO); - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, "_json_channel_media_errors", cJSON_PrintUnformatted(callStats)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_channel_media_errors", cJSON_PrintUnformatted(callStats)); cJSON_Delete(callStats); @@ -210,7 +210,7 @@ static switch_status_t kz_report_channel_stats(switch_core_session_t *session, s kz_switch_ivr_set_json_call_stats(callStats, session, SWITCH_MEDIA_TYPE_AUDIO); kz_switch_ivr_set_json_call_stats(callStats, session, SWITCH_MEDIA_TYPE_VIDEO); - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, "_json_channel_stats", cJSON_PrintUnformatted(callStats)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_channel_stats", cJSON_PrintUnformatted(callStats)); cJSON_Delete(callStats); @@ -237,7 +237,7 @@ static switch_status_t kz_report_app_log(switch_core_session_t *session, switch_ cJSON_AddItemToArray(j_apps, j_application); } - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, "_json_application_log", cJSON_PrintUnformatted(j_apps)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_application_log", cJSON_PrintUnformatted(j_apps)); cJSON_Delete(j_apps); @@ -381,7 +381,7 @@ static switch_status_t kz_report_callflow(switch_core_session_t *session, switch caller_profile = caller_profile->next; } - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, "_json_callflow", cJSON_PrintUnformatted(j_callflow)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_callflow", cJSON_PrintUnformatted(j_callflow)); cJSON_Delete(j_callflow); @@ -435,7 +435,7 @@ static switch_status_t kz_report_originated_legs(switch_core_session_t *session, idx++; } - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, "_json_originated_legs", cJSON_PrintUnformatted(j_originated)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, "_json_originated_legs", cJSON_PrintUnformatted(j_originated)); cJSON_Delete(j_originated); @@ -526,10 +526,10 @@ static switch_status_t kz_report_transfer_history(switch_core_session_t *session for(n=0; n < argc; n++) { kz_report_transfer_history_item(argv[n], j_transfer); } - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, event_header, cJSON_PrintUnformatted(j_transfer)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, event_header, cJSON_PrintUnformatted(j_transfer)); } else if (strchr(history, HST_ITEM_DELIM)) { kz_report_transfer_history_item(history, j_transfer); - switch_event_add_header_string(cdr_event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, event_header, cJSON_PrintUnformatted(j_transfer)); + switch_event_add_header_string_nodup(cdr_event, SWITCH_STACK_BOTTOM, event_header, cJSON_PrintUnformatted(j_transfer)); } cJSON_Delete(j_transfer); switch_safe_free(tmp_history); diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_node.c b/src/mod/event_handlers/mod_kazoo/kazoo_node.c index fae09bee2f..feb8970a86 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_node.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_node.c @@ -512,7 +512,7 @@ static switch_status_t build_event(switch_event_t *event, ei_x_buff * buf) { } } } - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, key, value); + switch_event_add_header_string_nodup(event, SWITCH_STACK_BOTTOM, key, value); } n++; } diff --git a/src/switch_core.c b/src/switch_core.c index b9b92f40c7..83db2fc0d9 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -482,7 +482,7 @@ SWITCH_DECLARE(switch_bool_t) switch_core_set_var_conditional(const char *varnam if (value) { char *v = strdup(value); switch_string_var_check(v, SWITCH_TRUE); - switch_event_add_header_string(runtime.global_vars, SWITCH_STACK_BOTTOM | SWITCH_STACK_NODUP, varname, v); + switch_event_add_header_string_nodup(runtime.global_vars, SWITCH_STACK_BOTTOM, varname, v); } else { switch_event_del_header(runtime.global_vars, varname); } diff --git a/src/switch_event.c b/src/switch_event.c index 4cc60fa60c..a8ba532d19 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1235,6 +1235,14 @@ SWITCH_DECLARE(switch_status_t) switch_event_set_subclass_name(switch_event_t *e return SWITCH_STATUS_SUCCESS; } +SWITCH_DECLARE(switch_status_t) switch_event_add_header_string_nodup(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data) +{ + if (data) { + return switch_event_base_add_header(event, stack, header_name, (char *)data); + } + return SWITCH_STATUS_GENERR; +} + SWITCH_DECLARE(switch_status_t) switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data) { if (data) {