[mod_kazoo] recurse context runtime vars

This commit is contained in:
lazedo 2019-11-11 18:09:26 +00:00
parent 647ed310e5
commit 3c6d47c293
3 changed files with 29 additions and 11 deletions

View File

@ -340,17 +340,7 @@ static switch_call_cause_t kz_endpoint_outgoing_channel(switch_core_session_t *s
// add runtime vars to event for expand
if (ctx) {
cJSON *item = NULL;
char *response = NULL;
cJSON_ArrayForEach(item, ctx) {
if (item->type == cJSON_String) {
response = strdup(item->valuestring);
} else {
response = cJSON_PrintUnformatted(item);
}
kz_switch_event_add_variable_name_printf(event, SWITCH_STACK_BOTTOM, response, "kz_ctx_%s", item->string);
switch_safe_free(response);
}
kz_expand_json_to_event(ctx, event, "kz_ctx");
}
d_dest = kz_event_expand_headers(event, dest);

View File

@ -516,6 +516,32 @@ SWITCH_DECLARE(switch_status_t) kz_switch_event_add_variable_name_printf(switch_
return status;
}
SWITCH_DECLARE(switch_status_t) kz_expand_json_to_event(cJSON *json, switch_event_t *event, char * prefix)
{
char * fmt = switch_mprintf("%s%s%%s", prefix ? prefix : "", prefix ? "_" : "");
if (event) {
cJSON *item = NULL;
char *response = NULL;
cJSON_ArrayForEach(item, json) {
if (item->type == cJSON_String) {
response = strdup(item->valuestring);
} else if (item->type == cJSON_Object) {
char * fmt1 = switch_mprintf(fmt, item->string);
kz_expand_json_to_event(item, event, fmt1);
switch_safe_free(fmt1);
continue;
} else {
response = cJSON_PrintUnformatted(item);
}
kz_switch_event_add_variable_name_printf(event, SWITCH_STACK_BOTTOM, response, fmt, item->string);
switch_safe_free(response);
}
}
switch_safe_free(fmt);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_xml_t) kz_xml_child(switch_xml_t xml, const char *name)
{
xml = (xml) ? xml->child : NULL;

View File

@ -48,4 +48,6 @@ void kz_expand_headers_self(switch_event_t *event);
char * kz_expand_vars_pool(char *xml_str, switch_memory_pool_t *pool);
switch_status_t kz_json_api(const char * command, cJSON *args, cJSON **res);
SWITCH_DECLARE(switch_status_t) kz_expand_json_to_event(cJSON *json, switch_event_t *event, char * prefix);
KZ_END_EXTERN_C