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