[Core] SWITCH_STACK_NODUP flag is deprecated and will be soon removed. Introduce switch_event_add_header_string_nodup() API.

This commit is contained in:
Andrey Volk 2022-10-31 17:49:17 +03:00
parent eb6c2333dd
commit ffa2207926
6 changed files with 20 additions and 11 deletions

View File

@ -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)

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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++;
}

View File

@ -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);
}

View File

@ -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) {