static void del_bridge_call(const char *key);
-switch_status_t fifo_queue_create(fifo_queue_t **queue, int size, switch_memory_pool_t *pool)
+switch_status_t fifo_queue_create(fifo_queue_t **queue, int size, switch_memory_pool_t *pool)
{
fifo_queue_t *q;
q->nelm = size - 1;
q->data = switch_core_alloc(pool, size * sizeof(switch_event_t *));
switch_mutex_init(&q->mutex, SWITCH_MUTEX_NESTED, pool);
-
+
*queue = q;
-
+
return SWITCH_STATUS_SUCCESS;
}
if (!(session = switch_core_session_locate(uuid))) {
return;
}
-
+
channel = switch_core_session_get_channel(session);
-
+
switch_snprintf(tmp, sizeof(tmp), "%d", pos);
switch_channel_set_variable(channel, "fifo_position", tmp);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fifo_position", tmp);
-
+
switch_core_session_rwunlock(session);
switch_mutex_unlock(queue->mutex);
return SWITCH_STATUS_FALSE;
}
-
+
if (remove) {
for (i = j+1; i < queue->idx; i++) {
queue->data[i-1] = queue->data[i];
queue->data[i] = NULL;
change_pos(queue->data[i-1], i);
}
-
+
queue->idx--;
}
-
+
switch_mutex_unlock(queue->mutex);
return SWITCH_STATUS_SUCCESS;
switch_mutex_unlock(queue->mutex);
return SWITCH_STATUS_FALSE;
}
-
+
if (remove) {
for (i = j+1; i < queue->idx; i++) {
queue->data[i-1] = queue->data[i];
queue->data[i] = NULL;
change_pos(queue->data[i-1], i);
}
-
+
queue->idx--;
}
-
+
switch_mutex_unlock(queue->mutex);
return SWITCH_STATUS_SUCCESS;
queue->data[i] = NULL;
change_pos(queue->data[i-1], i);
}
-
+
queue->idx--;
-
+
switch_mutex_unlock(queue->mutex);
return SWITCH_STATUS_SUCCESS;
default:
break;
}
-
+
return "invalid";
}
cd->do_orbit = 1;
return SWITCH_STATUS_BREAK;
}
-
+
return SWITCH_STATUS_SUCCESS;
}
cd->next = switch_epoch_time_now(NULL) + cd->freq;
cd->index++;
}
- }
+ }
return chime_read_frame_callback(session, frame, user_data);
}
if (!key) return;
switch_mutex_lock(globals.caller_orig_mutex);
- if ((cancel_cause = (switch_call_cause_t *) switch_core_hash_find(globals.caller_orig_hash, key))) {
+ if ((cancel_cause = (switch_call_cause_t *) switch_core_hash_find(globals.caller_orig_hash, key))) {
*cancel_cause = cause;
}
- switch_mutex_unlock(globals.caller_orig_mutex);
+ switch_mutex_unlock(globals.caller_orig_mutex);
fifo_caller_del(key);
if (!key) return;
switch_mutex_lock(globals.consumer_orig_mutex);
- if ((cancel_cause = (switch_call_cause_t *) switch_core_hash_find(globals.consumer_orig_hash, key))) {
+ if ((cancel_cause = (switch_call_cause_t *) switch_core_hash_find(globals.consumer_orig_hash, key))) {
*cancel_cause = cause;
}
- switch_mutex_unlock(globals.consumer_orig_mutex);
+ switch_mutex_unlock(globals.consumer_orig_mutex);
}
}
if (globals.debug > 1) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "sql: %s\n", sql);
-
+
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
{
switch_channel_t *consumer_channel = switch_core_session_get_channel(consumer_session);
switch_channel_t *caller_channel = NULL;
-
+
if (caller_session) {
caller_channel = switch_core_session_get_channel(caller_session);
}
const char *epoch_start_a = NULL;
char *sql;
switch_event_t *event;
-
+
switch_channel_clear_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG);
switch_channel_set_variable(consumer_channel, "fifo_bridged", NULL);
-
+
ts = switch_micro_time_now();
switch_time_exp_lt(&tm, ts);
switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
-
+
sql = switch_mprintf("delete from fifo_bridge where consumer_uuid='%q'", switch_core_session_get_uuid(consumer_session));
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
-
+
+
switch_channel_set_variable(consumer_channel, "fifo_status", "WAITING");
switch_channel_set_variable(consumer_channel, "fifo_timestamp", date);
-
+
if (caller_channel) {
switch_channel_set_variable(caller_channel, "fifo_status", "DONE");
switch_channel_set_variable(caller_channel, "fifo_timestamp", date);
if ((epoch_start_a = switch_channel_get_variable(consumer_channel, "fifo_epoch_start_bridge"))) {
epoch_start = atol(epoch_start_a);
}
-
+
epoch_end = (long)switch_epoch_time_now(NULL);
switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end);
switch_channel_set_variable_printf(consumer_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start);
-
+
if (caller_channel) {
switch_channel_set_variable_printf(caller_channel, "fifo_epoch_stop_bridge", "%ld", epoch_end);
switch_channel_set_variable_printf(caller_channel, "fifo_bridge_seconds", "%d", epoch_end - epoch_start);
if (!outbound_id) return SWITCH_STATUS_SUCCESS;
switch (msg->message_id) {
- case SWITCH_MESSAGE_INDICATE_BRIDGE:
- case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
+ case SWITCH_MESSAGE_INDICATE_BRIDGE:
+ case SWITCH_MESSAGE_INDICATE_UNBRIDGE:
if (msg->numeric_arg == 42) {
goto end;
}
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
goto end;
- default:
+ default:
goto end;
- }
+ }
+
-
switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_BRIDGE:
{
switch_time_exp_t tm;
switch_size_t retsize;
const char *ced_name, *ced_number, *cid_name, *cid_number;
-
+
if (switch_channel_test_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG)) {
goto end;
}
switch_channel_set_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG);
-
+
switch_channel_set_variable(consumer_channel, "fifo_bridged", "true");
switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true");
switch_channel_set_variable(consumer_channel, "fifo_role", "consumer");
if (caller_channel) {
switch_channel_set_variable(caller_channel, "fifo_role", "caller");
- switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import",
+ switch_process_import(consumer_session, caller_channel, "fifo_caller_consumer_import",
switch_channel_get_variable(consumer_channel, "fifo_import_prefix"));
switch_process_import(caller_session, consumer_channel, "fifo_consumer_caller_import",
switch_channel_get_variable(caller_channel, "fifo_import_prefix"));
if (zstr(ced_name) || !strcmp(ced_name, cid_name)) {
ced_name = ced_number;
}
-
+
if (zstr(ced_number) || !strcmp(ced_number, cid_number)) {
ced_name = switch_channel_get_variable(consumer_channel, "destination_number");
ced_number = ced_name;
ced_name = cid_name;
ced_number = cid_number;
}
-
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(consumer_channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", ced_number);
switch_event_fire(&event);
}
-
+
if (caller_channel) {
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(caller_channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start");
switch_event_fire(&event);
}
-
+
sql = switch_mprintf("insert into fifo_bridge "
"(fifo_name,caller_uuid,caller_caller_id_name,caller_caller_id_number,consumer_uuid,consumer_outgoing_uuid,bridge_start) "
"values ('%q','%q','%q','%q','%q','%q',%ld)",
(long) switch_epoch_time_now(NULL)
);
}
-
+
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
epoch_start = (long)switch_epoch_time_now(NULL);
ts = switch_micro_time_now();
switch_channel_set_variable(consumer_channel, "fifo_timestamp", date);
switch_channel_set_variable_printf(consumer_channel, "fifo_epoch_start_bridge", "%ld", epoch_start);
switch_channel_set_variable(consumer_channel, "fifo_role", "consumer");
-
+
if (caller_channel) {
switch_channel_set_variable(caller_channel, "fifo_status", "TALKING");
switch_channel_set_variable(caller_channel, "fifo_timestamp", date);
int x = 0;
switch_event_t *event;
switch_uuid_t uuid;
- char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+ char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
switch_call_cause_t cancel_cause = 0;
char *uuid_list = NULL;
int total = 0;
switch_mutex_lock(globals.mutex);
globals.threads++;
switch_mutex_unlock(globals.mutex);
-
+
if (!globals.running) goto dpool;
- switch_uuid_get(&uuid);
- switch_uuid_format(uuid_str, &uuid);
+ switch_uuid_get(&uuid);
+ switch_uuid_format(uuid_str, &uuid);
if (!cbh->rowcount) {
goto end;
for (i = 0; i < cbh->rowcount; i++) {
struct call_helper *h = cbh->rows[i];
-
+
if (check_consumer_outbound_call(h->uuid) || check_bridge_call(h->uuid)) {
continue;
}
}
cbh->rowcount = rowcount;
-
+
cbh->ready = 1;
-
+
if (!total) {
goto end;
}
switch_event_create(&ovars, SWITCH_EVENT_REQUEST_PARAMS);
switch_assert(ovars);
-
+
for (i = 0; i < cbh->rowcount; i++) {
struct call_helper *h = cbh->rows[i];
char *parsed = NULL;
switch_event_create_brackets(h->originate_string, '{', '}', ',', &ovars, &parsed, SWITCH_TRUE);
switch_event_del_header(ovars, "fifo_outbound_uuid");
-
+
if (!h->timeout) h->timeout = node->ring_timeout;
if (timeout < h->timeout) timeout = h->timeout;
-
+
stream.write_function(&stream, "[leg_timeout=%d,fifo_outbound_uuid=%s,fifo_name=%s]%s,",
h->timeout, h->uuid, node->name, parsed ? parsed : h->originate_string);
stream2.write_function(&stream2, "%s,", h->uuid);
switch_safe_free(parsed);
-
+
}
-
+
originate_string = (char *) stream.data;
if (originate_string) {
end_of(originate_string) = '\0';
}
-
+
uuid_list = (char *) stream2.data;
-
+
if (uuid_list) {
end_of(uuid_list) = '\0';
}
if (!timeout) timeout = 60;
-
+
pop = pop_dup = NULL;
for (x = 0; x < MAX_PRI; x++) {
if (!pop) {
goto end;
}
-
+
if (!switch_event_get_header(ovars, "origination_caller_id_name")) {
if ((caller_id_name = switch_event_get_header(pop, "caller-caller-id-name"))) {
if (!zstr(node->outbound_name)) {
}
}
}
-
+
if (!switch_event_get_header(ovars, "origination_caller_id_number")) {
if ((cid_num = switch_event_get_header(pop, "caller-caller-id-number"))) {
switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "origination_caller_id_number", cid_num);
}
}
-
+
if ((id = switch_event_get_header(pop, "unique-id"))) {
switch_event_add_header_string(ovars, SWITCH_STACK_BOTTOM, "fifo_bridge_uuid", id);
}
switch_channel_event_set_data(channel, event);
switch_core_session_rwunlock(session);
}
-
+
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "pre-dial");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "outbound-strategy", "ringall");
for (i = 0; i < cbh->rowcount; i++) {
struct call_helper *h = cbh->rows[i];
char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count+1 where uuid='%s'", h->uuid);
-
+
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
}
if (!total) goto end;
const char *rate = switch_event_get_header(pop, "variable_sip_use_codec_rate");
const char *ptime = switch_event_get_header(pop, "variable_sip_use_codec_ptime");
char nstr[256] = "";
-
+
if (strcasecmp(codec, "PCMU") && strcasecmp(codec, "PCMA")) {
switch_snprintf(nstr, sizeof(nstr), "%s@%si@%sh,PCMU@%si,PCMA@%si", codec, ptime, rate, ptime, ptime);
} else {
del_caller_outbound_call(id);
-
+
if (status != SWITCH_STATUS_SUCCESS || cause != SWITCH_CAUSE_SUCCESS) {
const char *acceptable = "false";
-
+
switch (cause) {
case SWITCH_CAUSE_ORIGINATOR_CANCEL:
case SWITCH_CAUSE_PICKED_OFF:
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
}
-
+
}
break;
default:
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Outbound-UUID-List", uuid_list);
switch_event_fire(&event);
}
-
+
goto end;
}
-
+
for (i = 0; i < cbh->rowcount; i++) {
struct call_helper *h = cbh->rows[i];
char *sql = switch_mprintf("update fifo_outbound set ring_count=ring_count-1 where uuid='%q' and ring_count > 0", h->uuid);
if (pop_dup) {
switch_event_destroy(&pop_dup);
}
-
+
dpool:
pool = cbh->pool;
switch_event_t *event = NULL;
char *sql = NULL;
- if (!globals.running) return NULL;
+ if (!globals.running) return NULL;
switch_mutex_lock(globals.mutex);
globals.threads++;
"origination_caller_id_name=Queue,origination_caller_id_number='Queue: %q'}%s",
node->name, node->name, node->name, h->originate_string);
}
-
+
}
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_event_fire(&event);
}
-
+
sql = switch_mprintf("update fifo_outbound set ring_count=ring_count+1 where uuid='%s'", h->uuid);
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
(long) switch_epoch_time_now(NULL), h->uuid);
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", node->name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "post-dial");
h->node_name = switch_core_strdup(h->pool, argv[1]);
h->originate_string = switch_core_strdup(h->pool, argv[2]);
h->timeout = atoi(argv[5]);
-
+
cbh->rows[cbh->rowcount++] = h;
if (cbh->rowcount == MAX_ROWS) return -1;
}
return 0;
-
+
}
static int place_call_enterprise_callback(void *pArg, int argc, char **argv, char **columnNames)
"order by next_avail, outbound_fail_count, outbound_call_count",
node->name, (long) switch_epoch_time_now(NULL)
);
-
-
+
+
switch(node->outbound_strategy) {
case NODE_STRATEGY_ENTERPRISE:
cbh = switch_core_alloc(pool, sizeof(*cbh));
cbh->pool = pool;
cbh->need = 1;
-
+
if (node->outbound_per_cycle != cbh->need) {
cbh->need = node->outbound_per_cycle;
}
void *val;
const void *var;
int ppl_waiting, consumer_total, idle_consumers, found = 0;
-
+
switch_mutex_lock(globals.mutex);
if (globals.debug) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Trying priority: %d\n", cur_priority);
-
+
restart:
switch_event_destroy(&pop);
}
}
-
+
node->ready = 0;
switch_core_hash_destroy(&node->consumer_hash);
switch_mutex_unlock(node->mutex);
goto restart;
}
}
-
+
if (node->outbound_priority == 0) node->outbound_priority = 5;
if (node->has_outbound && node->ready && !node->busy && node->outbound_priority == cur_priority) {
idle_consumers = node_idle_consumers(node);
if (globals.debug) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "%s waiting %d consumer_total %d idle_consumers %d ring_consumers %d pri %d\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "%s waiting %d consumer_total %d idle_consumers %d ring_consumers %d pri %d\n",
node->name, ppl_waiting, consumer_total, idle_consumers, node->ring_consumer_count, node->outbound_priority);
}
-
+
if ((ppl_waiting - node->ring_consumer_count > 0) && (!consumer_total || !idle_consumers)) {
found++;
find_consumers(node);
if (++cur_priority > 10) {
cur_priority = 1;
}
-
+
switch_mutex_unlock(globals.mutex);
-
+
if (cur_priority == 1) {
switch_yield(1000000);
}
static void check_cancel(fifo_node_t *node)
{
- int ppl_waiting;
+ int ppl_waiting;
if (node->outbound_strategy != NODE_STRATEGY_ENTERPRISE) {
return;
ppl_waiting = node_caller_count(node);
- if (node->ring_consumer_count > 0 && ppl_waiting < 1) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Outbound call count (%d) exceeds required value for queue %s (%d), "
- "Ending extraneous calls\n", node->ring_consumer_count, node->name, ppl_waiting);
+ if (node->ring_consumer_count > 0 && ppl_waiting < 1) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Outbound call count (%d) exceeds required value for queue %s (%d), "
+ "Ending extraneous calls\n", node->ring_consumer_count, node->name, ppl_waiting);
- switch_core_session_hupall_matching_var("fifo_hangup_check", node->name, SWITCH_CAUSE_ORIGINATOR_CANCEL);
- }
+ switch_core_session_hupall_matching_var("fifo_hangup_check", node->name, SWITCH_CAUSE_ORIGINATOR_CANCEL);
+ }
}
static void send_presence(fifo_node_t *node)
switch_event_create(&call_event, SWITCH_EVENT_CHANNEL_DATA);
switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "dial-url", url);
-
+
fifo_queue_push(node->fifo_list[priority], call_event);
call_event = NULL;
switch_safe_free(sql);
del_bridge_call(outbound_id);
- sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, stop_time=%ld, next_avail=%ld + lag + 1 where use_count > 0 and uuid='%q'",
+ sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, stop_time=%ld, next_avail=%ld + lag + 1 where use_count > 0 and uuid='%q'",
now, now, outbound_id);
-
+
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
}
static switch_status_t hanguphook(switch_core_session_t *session)
{
- switch_channel_t *channel = switch_core_session_get_channel(session);
- switch_channel_state_t state = switch_channel_get_state(channel);
-
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ switch_channel_state_t state = switch_channel_get_state(channel);
+
if (state >= CS_HANGUP && !switch_channel_test_app_flag_key(FIFO_APP_KEY, channel, FIFO_APP_DID_HOOK)) {
dec_use_count(session, SWITCH_TRUE);
switch_core_event_hook_remove_state_change(session, hanguphook);
char *sql;
const char *col1 = NULL, *col2 = NULL, *cid_name, *cid_number;
switch_event_t *event;
-
+
if (zstr(data)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid!\n");
return;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s tracking call on uuid %s!\n", switch_channel_get_name(channel), data);
-
+
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
col1 = "manual_calls_in_count";
col2 = "manual_calls_in_total_count";
col2 = "manual_calls_out_total_count";
}
- sql = switch_mprintf("update fifo_outbound set stop_time=0,start_time=%ld,outbound_fail_count=0,use_count=use_count+1,%s=%s+1,%s=%s+1 where uuid='%q'",
+ sql = switch_mprintf("update fifo_outbound set stop_time=0,start_time=%ld,outbound_fail_count=0,use_count=use_count+1,%s=%s+1,%s=%s+1 where uuid='%q'",
(long) switch_epoch_time_now(NULL), col1, col1, col2, col2, data);
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) {
cid_name = switch_channel_get_variable(channel, "destination_number");
cid_number = cid_name;
cid_name = switch_channel_get_variable(channel, "caller_id_name");
cid_number = switch_channel_get_variable(channel, "caller_id_number");
}
-
+
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME);
static void fifo_caller_del(const char *uuid)
{
char *sql;
-
+
if (uuid) {
sql = switch_mprintf("delete from fifo_callers where uuid='%q'", uuid);
} else {
sql = switch_mprintf("delete from fifo_callers", uuid);
}
-
+
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
}
switch_event_create(&call_event, SWITCH_EVENT_CHANNEL_DATA);
switch_channel_event_set_data(channel, call_event);
-
+
fifo_queue_push(node->fifo_list[p], call_event);
fifo_caller_add(node, session);
int x = 0, winner = -1;
switch_time_t longest = (0xFFFFFFFFFFFFFFFFULL / 2);
uint32_t importance = 0, waiting = 0, most_waiting = 0;
-
+
pop = NULL;
if (moh && do_wait) {
const char *varval, *check = NULL;
check = switch_channel_get_variable(channel, "fifo_bridge_uuid_required");
-
+
if ((varval = switch_channel_get_variable(channel, "fifo_bridge_uuid"))) {
if (check_bridge_call(varval) && switch_true(check)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Call has already been answered\n",
if (!pop && switch_true(check)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "%s Call has already been answered\n",
switch_channel_get_name(channel));
-
+
goto done;
}
}
if (!pop && (varval = switch_channel_get_variable(channel, "fifo_target_skill"))) {
for (x = 0; x < MAX_PRI; x++) {
- if (fifo_queue_pop_nameval(node->fifo_list[pop_array[x]], "variable_fifo_skill",
+ if (fifo_queue_pop_nameval(node->fifo_list[pop_array[x]], "variable_fifo_skill",
varval, &pop, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && pop) {
break;
}
if (!pop) {
for (x = 0; x < MAX_PRI; x++) {
- if (fifo_queue_pop_nameval(node->fifo_list[pop_array[x]], "variable_fifo_vip", "true",
+ if (fifo_queue_pop_nameval(node->fifo_list[pop_array[x]], "variable_fifo_vip", "true",
&pop, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS && pop) {
break;
}
url = switch_event_get_header(pop, "dial-url");
caller_uuid = switch_core_session_strdup(session, switch_event_get_header(pop, "unique-id"));
switch_event_destroy(&pop);
-
+
if (url) {
switch_call_cause_t cause = SWITCH_CAUSE_NONE;
const char *o_announce = NULL;
-
+
if ((o_announce = switch_channel_get_variable(channel, "fifo_outbound_announce"))) {
switch_ivr_play_file(session, NULL, o_announce, NULL);
}
switch_channel_set_flag(other_channel, CF_BREAK);
- while (switch_channel_ready(channel) && switch_channel_ready(other_channel) &&
+ while (switch_channel_ready(channel) && switch_channel_ready(other_channel) &&
switch_channel_test_app_flag_key(FIFO_APP_KEY, other_channel, FIFO_APP_BRIDGE_TAG)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
switch_core_session_rwunlock(other_session);
break;
}
-
+
switch_channel_answer(channel);
cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
switch_assert(cloned_profile);
cancel_consumer_outbound_call(outbound_id, SWITCH_CAUSE_ORIGINATOR_CANCEL);
add_bridge_call(outbound_id);
- sql = switch_mprintf("update fifo_outbound set stop_time=0,start_time=%ld,use_count=use_count+1,outbound_fail_count=0 where uuid='%s'",
+ sql = switch_mprintf("update fifo_outbound set stop_time=0,start_time=%ld,use_count=use_count+1,outbound_fail_count=0 where uuid='%s'",
switch_epoch_time_now(NULL), outbound_id);
switch_str_nil(outbound_id),
(long) switch_epoch_time_now(NULL)
);
-
-
+
+
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);
if (outbound_id) {
long now = (long) switch_epoch_time_now(NULL);
-
+
sql = switch_mprintf("update fifo_outbound set stop_time=%ld, use_count=use_count-1, "
"outbound_call_total_count=outbound_call_total_count+1, "
- "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag + 1 where uuid='%s' and use_count > 0",
+ "outbound_call_count=outbound_call_count+1, next_avail=%ld + lag + 1 where uuid='%s' and use_count > 0",
now, now, outbound_id);
fifo_execute_sql(sql, globals.sql_mutex);
fifo_execute_sql(sql, globals.sql_mutex);
switch_safe_free(sql);
-
+
switch_core_media_bug_pause(session);
switch_core_media_bug_pause(other_session);
switch_xml_set_attr_d(x_out, "outbound-call-total-count", argv[15]);
switch_xml_set_attr_d(x_out, "outbound-fail-total-count", argv[16]);
-
+
if (arg == 17) {
switch_xml_set_attr_d(x_out, "logged-on-since", tb);
} else {
switch_xml_set_attr_d(x_out, "manual-calls-in-count", argv[20]);
switch_xml_set_attr_d(x_out, "manual-calls-out-total-count", argv[21]);
switch_xml_set_attr_d(x_out, "manual-calls-in-total-count", argv[22]);
-
+
if (argc > 23) {
switch_xml_set_attr_d(x_out, "ring-count", argv[23]);
if ((etime = atol(argv[6]))) {
switch_size_t retsize;
-
+
switch_time_exp_lt(&tm, switch_time_from_sec(etime));
switch_strftime_nocheck(exp_buf, &retsize, sizeof(exp_buf), "%Y-%m-%d %T", &tm);
} else {
switch_xml_set_attr_d(x_bridge, "bridge_start_epoch", argv[6]);
x_caller = switch_xml_add_child_d(x_bridge, "caller", tag_off++);
-
+
switch_xml_set_attr_d(x_caller, "uuid", argv[1]);
-
+
encoded = switch_url_encode(argv[2], url_buf, sizeof(url_buf));
switch_xml_set_attr_d(x_caller, "caller_id_name", encoded);
switch_ivr_generate_xml_cdr(session, &x_cdr);
switch_core_session_rwunlock(session);
}
- }
+ }
off = 0;
switch_channel_t *channel;
void *val;
const void *var;
-
+
x_tmp = switch_xml_add_child_d(xml, container, cc_off++);
switch_assert(x_tmp);
if ((status = switch_channel_get_variable(channel, "fifo_status"))) {
switch_xml_set_attr_d(x_caller, "status", status);
}
-
+
if ((status = switch_channel_get_variable(channel, "caller_id_name"))) {
encoded = switch_url_encode(status, url_buf, sizeof(url_buf));
switch_xml_set_attr_d(x_caller, "caller_id_name", encoded);
switch_mutex_lock(q->mutex);
for (i = 0; i < q->idx; i++) {
-
+
int c_off = 0, d_off = 0;
const char *status;
const char *ts;
char sl[30] = "";
char url_buf[512] = "";
char *encoded;
-
+
if (!uuid) {
continue;
}
encoded = switch_url_encode(status, url_buf, sizeof(url_buf));
switch_xml_set_attr_d(x_caller, "caller_id_name", encoded);
}
-
+
if ((status = switch_channel_get_variable(channel, "caller_id_number"))) {
encoded = switch_url_encode(status, url_buf, sizeof(url_buf));
switch_xml_set_attr_d(x_caller, "caller_id_number", encoded);
if (!(x_cp = switch_xml_add_child_d(x_caller, "cdr", d_off++))) {
abort();
}
-
+
switch_ivr_generate_xml_cdr(session, &x_cp);
}
" busy: %d\n"
" ready: %d\n"
" waiting: %d\n"
- ,
+ ,
node->name, node->outbound_name, node->outbound_per_cycle,
node->outbound_priority, strat_parse(node->outbound_strategy),
node->has_outbound,
node->busy,
node->ready,
node_caller_count(node)
-
+
);
}
}
dump_hash(globals.consumer_orig_hash, stream);
stream->write_function(stream, " bridge:\n");
dump_hash(globals.bridge_hash, stream);
-
+
switch_mutex_unlock(globals.mutex);
-
-
+
+
}
if (!strcasecmp(argv[0], "status")) {
node_dump(stream);
- goto done;
+ goto done;
}
if (!strcasecmp(argv[0], "debug")) {
}
}
stream->write_function(stream, "debug %d\n", globals.debug);
- goto done;
+ goto done;
}
verbose = !strcasecmp(argv[0], "list_verbose");
switch_event_t *ovars;
char *parsed = NULL;
const char *fifo_outbound_uuid;
-
+
switch_event_create(&ovars, SWITCH_EVENT_REQUEST_PARAMS);
-
+
switch_event_create_brackets(string, '{', '}', ',', &ovars, &parsed, SWITCH_TRUE);
-
+
if ((fifo_outbound_uuid = switch_event_get_header(ovars, "fifo_outbound_uuid"))) {
switch_snprintf(uuid, len, "%s", fifo_outbound_uuid);
}
}
if (!reload) {
- switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or stop_time < 0",
+ switch_cache_db_test_reactive(dbh, "delete from fifo_outbound where static = 1 or taking_calls < 0 or stop_time < 0",
"drop table fifo_outbound", outbound_sql);
switch_cache_db_test_reactive(dbh, "delete from fifo_bridge", "drop table fifo_bridge", bridge_sql);
switch_cache_db_test_reactive(dbh, "delete from fifo_callers", "drop table fifo_callers", callers_sql);
switch_assert(node);
switch_mutex_lock(node->mutex);
-
+
outbound_strategy = switch_xml_attr(fifo, "outbound_strategy");
-
+
if ((val = switch_xml_attr(fifo, "outbound_per_cycle"))) {
if ((outbound_per_cycle = atoi(val)) < 0) {
}
node->has_outbound = 1;
}
-
+
if ((val = switch_xml_attr(fifo, "outbound_ring_timeout"))) {
int tmp = atoi(val);
if (tmp > 10) {
node->outbound_per_cycle = outbound_per_cycle;
node->outbound_priority = outbound_priority;
node->default_lag = default_lag;
-
+
if (outbound_strategy) {
node->outbound_strategy = parse_strat(outbound_strategy);
node->has_outbound = 1;
} else {
switch_md5_string(digest, (void *) member->txt, strlen(member->txt));
}
-
+
if (simo) {
simo_i = atoi(simo);
}
"values ('%q','%q','%q',%d,%d,%d,%d,0,0,1,0,0,'%q',%d,%ld,0)",
digest, node->name, member->txt, simo_i, 0, timeout_i, lag_i, globals.hostname, taking_calls_i,
(long) switch_epoch_time_now(NULL));
-
+
switch_assert(sql);
fifo_execute_sql(sql, globals.sql_mutex);
free(sql);
if (switch_stristr("fifo_outbound_uuid=", originate_string)) {
extract_fifo_outbound_uuid(originate_string, digest, sizeof(digest));
} else {
- switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
+ switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
}
sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q'", fifo_name, digest);
if (switch_stristr("fifo_outbound_uuid=", originate_string)) {
extract_fifo_outbound_uuid(originate_string, digest, sizeof(digest));
} else {
- switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
+ switch_md5_string(digest, (void *) originate_string, strlen(originate_string));
}
sql = switch_mprintf("delete from fifo_outbound where fifo_name='%q' and uuid = '%q' and hostname='%q'", fifo_name, digest, globals.hostname);
sql = switch_mprintf("select count(*) from fifo_outbound where fifo_name = '%q'", node->name);
fifo_execute_sql_callback(globals.sql_mutex, sql, sql2str_callback, &cbt);
if (atoi(outbound_count) > 0) {
- node->has_outbound = 1;
+ node->has_outbound = 1;
} else {
- node->has_outbound = 0;
+ node->has_outbound = 0;
}
- switch_safe_free(sql);
+ switch_safe_free(sql);
}
#define FIFO_MEMBER_API_SYNTAX "[add <fifo_name> <originate_string> [<simo_count>] [<timeout>] [<lag>] [<expires>] [<taking_calls>] | del <fifo_name> <originate_string>]"
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
SWITCH_ADD_APP(app_interface, "fifo", "Park with FIFO", FIFO_DESC, fifo_function, FIFO_USAGE, SAF_NONE);
- SWITCH_ADD_APP(app_interface, "fifo_track_call", "Count a call as a fifo call in the manual_calls queue",
+ SWITCH_ADD_APP(app_interface, "fifo_track_call", "Count a call as a fifo call in the manual_calls queue",
"", fifo_track_call_function, "<fifo_outbound_uuid>", SAF_SUPPORT_NOMEDIA);
SWITCH_ADD_API(commands_api_interface, "fifo", "Return data about a fifo", fifo_api_function, FIFO_API_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "fifo_member", "Add members to a fifo", fifo_member_api_function, FIFO_MEMBER_API_SYNTAX);
}
/*
- Called when the system shuts down
+ Called when the system shuts down
*/
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fifo_shutdown)
{
/* Cleanup */
stop_node_thread();
-
+
while(globals.threads) {
switch_cond_next();
}
switch_core_hash_destroy(&globals.fifo_hash);
memset(&globals, 0, sizeof(globals));
switch_mutex_unlock(mutex);
-
+
return SWITCH_STATUS_SUCCESS;
}