]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_kazoo] recurse context runtime vars 117/head
authorlazedo <luis.azedo@factorlusitano.com>
Mon, 11 Nov 2019 18:09:26 +0000 (18:09 +0000)
committerlazedo <luis.azedo@factorlusitano.com>
Mon, 11 Nov 2019 18:09:26 +0000 (18:09 +0000)
src/mod/event_handlers/mod_kazoo/kazoo_endpoints.c
src/mod/event_handlers/mod_kazoo/kazoo_utils.c
src/mod/event_handlers/mod_kazoo/kazoo_utils.h

index cf253760ed652eb95b1acc4079602200d3a42643..bec5b5e1ea3a46419be8690273bdbd0ba5f8e283 100644 (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);
index afc685434fb48870a2949ec7976089978195eb78..34b33c8ae1e93157b9a8b7fcdfb94f2e85dfce81 100644 (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;
index 397d94a36141d9ab33c5562100fbea8a8c9c21ed..c5ddc3e037f03f21e46481cea09d82dae80cdb17 100644 (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