Skip to content

Commit

Permalink
Merge pull request #1856 from signalwire/nodupremovewithflag
Browse files Browse the repository at this point in the history
[Core] SWITCH_STACK_NODUP flag is deprecated and will be soon removed. Introduce switch_event_add_header_string_nodup() API.
  • Loading branch information
andywolk authored Nov 7, 2022
2 parents eb6c233 + ffa2207 commit 9675ef6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/include/switch_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/mod/event_handlers/mod_erlang_event/handle_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/mod/event_handlers/mod_kazoo/kazoo_cdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/mod/event_handlers/mod_kazoo/kazoo_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/switch_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/switch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9675ef6

Please sign in to comment.