Merge pull request #1048 in FS/freeswitch from ~ARON45/freeswitch:feature/FS-9716-expand-variables-for-mod_amqp-command to master
* commit 'f4321a28267c9e5c089df24b22aa0a71619bd9cf': FS-9716: [mod_amqp] Command profile expand params
This commit is contained in:
commit
0c17af6321
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue