15年基于freewitch做的自动群呼系统,主要由监听模块,任务外呼模块,及FIFO实现。
1、mod_cctask.c#include
#include
#define zstr(x) _zstr(x)
SWITCH_MODULE_LOAD_FUNCTION(mod_cctask_load);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_cctask_runtime);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cctask_shutdown);
SWITCH_MODULE_DEFINITION(mod_cctask, mod_cctask_load, mod_cctask_shutdown, mod_cctask_runtime);
switch_api_interface_t *api_interface;
static struct {
switch_hash_t *caller_orig_hash;
switch_hash_t *consumer_orig_hash;
switch_hash_t *bridge_hash;
switch_hash_t *use_hash;
switch_mutex_t *use_mutex;
switch_mutex_t *caller_orig_mutex;
switch_mutex_t *consumer_orig_mutex;
switch_mutex_t *bridge_mutex;
switch_hash_t *fifo_hash;
switch_mutex_t *mutex;
switch_mutex_t *sql_mutex;
switch_memory_pool_t *pool;
int running;
switch_event_node_t *node;
char hostname[256];
char *dbname;
char odbc_dsn[1024];
int node_thread_running;
switch_odbc_handle_t *master_odbc;
int threads;
switch_thread_t *node_thread;
int debug;
struct fifo_node *nodes;
char *pre_trans_execute;
char *post_trans_execute;
char *inner_pre_trans_execute;
char *inner_post_trans_execute;
switch_sql_queue_manager_t *qm;
int allow_transcoding;
switch_bool_t delete_all_members_on_startup;
} globals;
struct callback {
char *buf;
size_t len;
int matches;
};
typedef struct callback callback_t;
struct cc_cctask_call_obj {
char task_id[32];
char gateway[64]; //网关
char exten[64];//分机
char context[64];//context区分
char cid_name[64];//主叫
char cid_num[64];//主叫号码
char fifo_name[64];
};
typedef struct cc_cctask_call_obj cctask_call_obj;
switch_cache_db_handle_t *cctask_get_db_handle(void)
{
switch_cache_db_handle_t *dbh = NULL;
char *dsn;
if (!zstr(globals.odbc_dsn)) {
dsn = globals.odbc_dsn;
} else {
dsn = globals.dbname;
}
if (switch_cache_db_get_db_handle_dsn(&dbh, dsn) != SWITCH_STATUS_SUCCESS) {
dbh = NULL;
}
return dbh;
}
static switch_bool_t cctask_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
{
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = cctask_get_db_handle())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
if (globals.debug > 1) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "sql: %s\n", sql);
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
}
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mut