]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9716: [mod_amqp] Command profile expand params
authorAron Podrigal <aronp@guaranteedplus.com>
Mon, 7 Nov 2016 18:56:23 +0000 (18:56 +0000)
committerAron Podrigal <aronp@guaranteedplus.com>
Sun, 13 Nov 2016 20:38:15 +0000 (20:38 +0000)
Expand command profile params "exchange-name, queue-name, binding_key"
This allows dynamic binding based on fs core-uuid (ie, ${core-uuid} ).

src/mod/event_handlers/mod_amqp/mod_amqp_command.c

index 29760d427129b5127e636f19a01b9d0df49f0d2e..1c4676cc22266c4cd9f5d99e9134ce8fa8c15af3 100644 (file)
@@ -80,12 +80,30 @@ switch_status_t mod_amqp_command_destroy(mod_amqp_command_profile_t **prof)
        return SWITCH_STATUS_SUCCESS;
 }
 
+
+static char *mod_amqp_expand_header(switch_memory_pool_t *pool, switch_event_t *event, char *val)
+{
+        char *expanded;
+        char *dup = NULL;
+
+        expanded = switch_event_expand_headers(event, val);
+        dup = switch_core_strdup(pool, expanded);
+
+        if (expanded != val) {
+                free(expanded);
+        }
+
+        return dup;
+}
+
+
 switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg)
 {
        mod_amqp_command_profile_t *profile = NULL;
        switch_xml_t params, param, connections, connection;
        switch_threadattr_t *thd_attr = NULL;
        switch_memory_pool_t *pool;
+       switch_event_t *event;
        char *exchange = NULL, *binding_key = NULL, *queue = NULL;
 
        if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
@@ -99,6 +117,10 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg)
        profile->running = 1;
        profile->reconnect_interval_ms = 1000;
 
+        if (switch_event_create(&event, SWITCH_EVENT_GENERAL) != SWITCH_STATUS_SUCCESS) {
+                goto err;
+       }
+
        if ((params = switch_xml_child(cfg, "params")) != NULL) {
                for (param = switch_xml_child(params, "param"); param; param = param->next) {
                        char *var = (char *) switch_xml_attr_soft(param, "name");
@@ -120,15 +142,17 @@ switch_status_t mod_amqp_command_create(char *name, switch_xml_t cfg)
                                        profile->reconnect_interval_ms = interval;
                                }
                        } else if (!strncmp(var, "exchange-name", 13)) {
-                               exchange = switch_core_strdup(profile->pool, val);
+                               exchange = mod_amqp_expand_header(profile->pool, event, val);
                        } else if (!strncmp(var, "queue-name", 10)) {
-                               queue = switch_core_strdup(profile->pool, val);
+                               queue = mod_amqp_expand_header(profile->pool, event, val);
                        } else if (!strncmp(var, "binding_key", 11)) {
-                               binding_key = switch_core_strdup(profile->pool, val);
+                               binding_key = mod_amqp_expand_header(profile->pool, event, val);
                        }
                }
        }
 
+        switch_event_destroy(&event);
+
        /* Handle defaults of string types */
        profile->exchange = exchange ? exchange : switch_core_strdup(profile->pool, "TAP.Commands");
        profile->queue = queue ? queue : NULL;