mod_fifo: Refactor load_config()
Reduce number of local variables where possible; consolidate lines.
This commit is contained in:
parent
353c3b19fa
commit
6105e9783c
|
@ -4484,15 +4484,9 @@ static switch_status_t load_config(int reload, int del_all)
|
||||||
|
|
||||||
if ((fifos = switch_xml_child(cfg, "fifos"))) {
|
if ((fifos = switch_xml_child(cfg, "fifos"))) {
|
||||||
for (fifo = switch_xml_child(fifos, "fifo"); fifo; fifo = fifo->next) {
|
for (fifo = switch_xml_child(fifos, "fifo"); fifo; fifo = fifo->next) {
|
||||||
const char *name, *outbound_strategy;
|
const char *name, *sp;
|
||||||
const char *val;
|
const char *val;
|
||||||
int imp = 0, outbound_per_cycle = 1, outbound_priority = 5;
|
int i, importance = 0;
|
||||||
int simo_i = 1;
|
|
||||||
int taking_calls_i = 1;
|
|
||||||
int timeout_i = 60;
|
|
||||||
int lag_i = 10;
|
|
||||||
int ring_timeout = 60;
|
|
||||||
int default_lag = 30;
|
|
||||||
|
|
||||||
if (!(name = switch_xml_attr(fifo, "name"))) {
|
if (!(name = switch_xml_attr(fifo, "name"))) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "fifo has no name!\n");
|
||||||
|
@ -4504,15 +4498,13 @@ static switch_status_t load_config(int reload, int del_all)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((val = switch_xml_attr(fifo, "importance"))) {
|
if ((val = switch_xml_attr(fifo, "importance")) && !(i = atoi(val)) < 0) {
|
||||||
if ((imp = atoi(val)) < 0) {
|
importance = i;
|
||||||
imp = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_mutex_lock(globals.mutex);
|
switch_mutex_lock(globals.mutex);
|
||||||
if (!(node = switch_core_hash_find(globals.fifo_hash, name))) {
|
if (!(node = switch_core_hash_find(globals.fifo_hash, name))) {
|
||||||
node = create_node(name, imp, globals.sql_mutex);
|
node = create_node(name, importance, globals.sql_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((val = switch_xml_attr(fifo, "outbound_name"))) {
|
if ((val = switch_xml_attr(fifo, "outbound_name"))) {
|
||||||
|
@ -4523,64 +4515,54 @@ static switch_status_t load_config(int reload, int del_all)
|
||||||
switch_assert(node);
|
switch_assert(node);
|
||||||
switch_mutex_lock(node->mutex);
|
switch_mutex_lock(node->mutex);
|
||||||
|
|
||||||
outbound_strategy = switch_xml_attr(fifo, "outbound_strategy");
|
if ((sp = switch_xml_attr(fifo, "outbound_strategy"))) {
|
||||||
|
node->outbound_strategy = parse_strategy(sp);
|
||||||
|
node->has_outbound = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
node->outbound_per_cycle = 1;
|
||||||
if ((val = switch_xml_attr(fifo, "outbound_per_cycle"))) {
|
if ((val = switch_xml_attr(fifo, "outbound_per_cycle"))) {
|
||||||
if ((outbound_per_cycle = atoi(val)) < 0) {
|
if (!(i = atoi(val)) < 0) {
|
||||||
outbound_per_cycle = 1;
|
node->outbound_per_cycle = i;
|
||||||
}
|
}
|
||||||
node->has_outbound = 1;
|
node->has_outbound = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((val = switch_xml_attr(fifo, "retry_delay"))) {
|
if ((val = switch_xml_attr(fifo, "retry_delay"))) {
|
||||||
int tmp;
|
if ((i = atoi(val)) < 0) i = 0;
|
||||||
if ((tmp = atoi(val)) < 0) {
|
node->retry_delay = i;
|
||||||
tmp = 0;
|
|
||||||
}
|
|
||||||
node->retry_delay = tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node->outbound_priority = 5;
|
||||||
if ((val = switch_xml_attr(fifo, "outbound_priority"))) {
|
if ((val = switch_xml_attr(fifo, "outbound_priority"))) {
|
||||||
outbound_priority = atoi(val);
|
i = atoi(val);
|
||||||
if (outbound_priority < 1 || outbound_priority > 10) {
|
if (!(i < 1 || i > 10)) {
|
||||||
outbound_priority = 5;
|
node->outbound_priority = i;
|
||||||
}
|
}
|
||||||
node->has_outbound = 1;
|
node->has_outbound = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node->ring_timeout = 60;
|
||||||
if ((val = switch_xml_attr(fifo, "outbound_ring_timeout"))) {
|
if ((val = switch_xml_attr(fifo, "outbound_ring_timeout"))) {
|
||||||
int tmp = atoi(val);
|
if ((i = atoi(val)) > 10) {
|
||||||
if (tmp > 10) {
|
node->ring_timeout = i;
|
||||||
ring_timeout = tmp;
|
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid ring_timeout: must be > 10 for queue %s\n", node->name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid ring_timeout: must be > 10 for queue %s\n", node->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node->default_lag = 30;
|
||||||
if ((val = switch_xml_attr(fifo, "outbound_default_lag"))) {
|
if ((val = switch_xml_attr(fifo, "outbound_default_lag"))) {
|
||||||
int tmp = atoi(val);
|
if ((i = atoi(val)) > 10) {
|
||||||
if (tmp > 10) {
|
node->default_lag = i;
|
||||||
default_lag = tmp;
|
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid default_lag: must be > 10 for queue %s\n", node->name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Invalid default_lag: must be > 10 for queue %s\n", node->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node->ring_timeout = ring_timeout;
|
|
||||||
node->outbound_per_cycle = outbound_per_cycle;
|
|
||||||
node->outbound_priority = outbound_priority;
|
|
||||||
node->default_lag = default_lag;
|
|
||||||
|
|
||||||
if (outbound_strategy) {
|
|
||||||
node->outbound_strategy = parse_strategy(outbound_strategy);
|
|
||||||
node->has_outbound = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (member = switch_xml_child(fifo, "member"); member; member = member->next) {
|
for (member = switch_xml_child(fifo, "member"); member; member = member->next) {
|
||||||
const char *simo = switch_xml_attr_soft(member, "simo");
|
const char *simo, *taking_calls, *timeout, *lag;
|
||||||
const char *lag = switch_xml_attr_soft(member, "lag");
|
int simo_i = 1, taking_calls_i = 1, timeout_i = 60, lag_i = 10;
|
||||||
const char *timeout = switch_xml_attr_soft(member, "timeout");
|
|
||||||
const char *taking_calls = switch_xml_attr_soft(member, "taking_calls");
|
|
||||||
char *name_dup, *p;
|
char *name_dup, *p;
|
||||||
char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
|
char digest[SWITCH_MD5_DIGEST_STRING_SIZE] = { 0 };
|
||||||
|
|
||||||
|
@ -4590,27 +4572,23 @@ static switch_status_t load_config(int reload, int del_all)
|
||||||
switch_md5_string(digest, (void *) member->txt, strlen(member->txt));
|
switch_md5_string(digest, (void *) member->txt, strlen(member->txt));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (simo) {
|
if ((simo = switch_xml_attr_soft(member, "simo"))) {
|
||||||
simo_i = atoi(simo);
|
simo_i = atoi(simo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taking_calls) {
|
if ((taking_calls = switch_xml_attr_soft(member, "taking_calls"))
|
||||||
if ((taking_calls_i = atoi(taking_calls)) < 1) {
|
&& (taking_calls_i = atoi(taking_calls)) < 1) {
|
||||||
taking_calls_i = 1;
|
taking_calls_i = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeout) {
|
if ((timeout = switch_xml_attr_soft(member, "timeout"))
|
||||||
if ((timeout_i = atoi(timeout)) < 10) {
|
&& (timeout_i = atoi(timeout)) < 10) {
|
||||||
timeout_i = ring_timeout;
|
timeout_i = node->ring_timeout;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lag) {
|
if ((lag = switch_xml_attr_soft(member, "lag"))
|
||||||
if ((lag_i = atoi(lag)) < 0) {
|
&& (lag_i = atoi(lag)) < 0) {
|
||||||
lag_i = default_lag;
|
lag_i = node->default_lag;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
name_dup = strdup(node->name);
|
name_dup = strdup(node->name);
|
||||||
|
@ -4634,7 +4612,6 @@ static switch_status_t load_config(int reload, int del_all)
|
||||||
node->ready = 1;
|
node->ready = 1;
|
||||||
node->is_static = 1;
|
node->is_static = 1;
|
||||||
switch_mutex_unlock(node->mutex);
|
switch_mutex_unlock(node->mutex);
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s configured\n", node->name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s configured\n", node->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue