|
@@ -1,6 +1,5 @@
|
|
|
/*
|
|
|
- *
|
|
|
- * Copyright (C) 2013 Robert Boisvert
|
|
|
+ * Copyright (C) 2013-15 Robert Boisvert
|
|
|
*
|
|
|
* This file is part of the mohqueue module for Kamailio, a free SIP server.
|
|
|
*
|
|
@@ -60,9 +59,9 @@ static cmd_export_t mod_cmds [] = {
|
|
|
};
|
|
|
|
|
|
/* PARAMETERS */
|
|
|
-str db_url = str_init(DEFAULT_DB_URL);
|
|
|
-str db_ctable = str_init("mohqcalls");
|
|
|
-str db_qtable = str_init("mohqueues");
|
|
|
+str db_url = str_init (DEFAULT_DB_URL);
|
|
|
+str db_ctable = str_init ("mohqcalls");
|
|
|
+str db_qtable = str_init ("mohqueues");
|
|
|
char *mohdir = "";
|
|
|
int moh_maxcalls = 50;
|
|
|
|
|
@@ -133,83 +132,87 @@ return 0;
|
|
|
static int init_cfg (void)
|
|
|
|
|
|
{
|
|
|
- int error = 0;
|
|
|
- int bfnd = 0;
|
|
|
- struct stat psb [1];
|
|
|
-
|
|
|
- /**********
|
|
|
- * db_url, db_ctable, db_qtable exist?
|
|
|
- **********/
|
|
|
-
|
|
|
- if (!db_url.s || db_url.len<=0)
|
|
|
+int bfnd = 0;
|
|
|
+int berror = 0;
|
|
|
+struct stat psb [1];
|
|
|
+
|
|
|
+/**********
|
|
|
+* db_url, db_ctable, db_qtable exist?
|
|
|
+**********/
|
|
|
+
|
|
|
+if (!db_url.s || db_url.len <= 0)
|
|
|
{
|
|
|
- LM_ERR ("db_url parameter not set!\n");
|
|
|
- error = 1;
|
|
|
+ LM_ERR ("db_url parameter not set!\n");
|
|
|
+ berror = 1;
|
|
|
}
|
|
|
-
|
|
|
- if (!db_ctable.s || db_ctable.len<=0)
|
|
|
+if (!db_ctable.s || db_ctable.len <= 0)
|
|
|
{
|
|
|
- LM_ERR ("db_ctable parameter not set!\n");
|
|
|
- error = 1;
|
|
|
+ LM_ERR ("db_ctable parameter not set!\n");
|
|
|
+ berror = 1;
|
|
|
}
|
|
|
-
|
|
|
- if (!db_qtable.s || db_qtable.len<=0)
|
|
|
+if (!db_qtable.s || db_qtable.len <= 0)
|
|
|
{
|
|
|
- LM_ERR ("db_qtable parameter not set!\n");
|
|
|
- error = 1;
|
|
|
- }
|
|
|
-
|
|
|
- /**********
|
|
|
- * mohdir
|
|
|
- * o exists?
|
|
|
- * o directory?
|
|
|
- **********/
|
|
|
-
|
|
|
- if (!*mohdir) {
|
|
|
- LM_ERR ("mohdir parameter not set!\n");
|
|
|
- error = 1;
|
|
|
- } else if (strlen(mohdir) > MOHDIRLEN) {
|
|
|
- LM_ERR ("mohdir too long!");
|
|
|
- error = 1;
|
|
|
+ LM_ERR ("db_qtable parameter not set!\n");
|
|
|
+ berror = 1;
|
|
|
}
|
|
|
- if (moh_maxcalls < 1 || moh_maxcalls > 5000)
|
|
|
+
|
|
|
+/**********
|
|
|
+* mohdir
|
|
|
+* o exists?
|
|
|
+* o directory?
|
|
|
+**********/
|
|
|
+
|
|
|
+if (!*mohdir)
|
|
|
{
|
|
|
- LM_ERR ("moh_maxcalls not in range of 1-5000!");
|
|
|
- error = 1;
|
|
|
+ LM_ERR ("mohdir parameter not set!\n");
|
|
|
+ berror = 1;
|
|
|
}
|
|
|
- if (error == 1) {
|
|
|
- return 0;
|
|
|
+else if (strlen (mohdir) > MOHDIRLEN)
|
|
|
+ {
|
|
|
+ LM_ERR ("mohdir too long!\n");
|
|
|
+ berror = 1;
|
|
|
}
|
|
|
- pmod_data->pcfg->db_qtable = db_qtable;
|
|
|
- pmod_data->pcfg->db_ctable = db_ctable;
|
|
|
- pmod_data->pcfg->db_url = db_url;
|
|
|
- pmod_data->pcfg->mohdir = mohdir;
|
|
|
-
|
|
|
- if (!lstat (mohdir, psb))
|
|
|
+else
|
|
|
{
|
|
|
+ if (!lstat (mohdir, psb))
|
|
|
+ {
|
|
|
if ((psb->st_mode & S_IFMT) == S_IFDIR)
|
|
|
{ bfnd = 1; }
|
|
|
- }
|
|
|
+ }
|
|
|
if (!bfnd)
|
|
|
- {
|
|
|
+ {
|
|
|
LM_ERR ("mohdir is not a directory!\n");
|
|
|
- return 0;
|
|
|
+ berror = 1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**********
|
|
|
- * max calls
|
|
|
- * o valid count?
|
|
|
- * o alloc memory
|
|
|
- **********/
|
|
|
+/**********
|
|
|
+* o max calls valid?
|
|
|
+* o alloc memory
|
|
|
+* o save data
|
|
|
+**********/
|
|
|
|
|
|
- pmod_data->pcall_lst = (call_lst *) shm_malloc (sizeof (call_lst) * moh_maxcalls);
|
|
|
- if (!pmod_data->pcall_lst) {
|
|
|
- LM_ERR ("Unable to allocate shared memory");
|
|
|
- return -1;
|
|
|
+if (moh_maxcalls < 1 || moh_maxcalls > 5000)
|
|
|
+ {
|
|
|
+ LM_ERR ("moh_maxcalls not in range of 1-5000!\n");
|
|
|
+ berror = 1;
|
|
|
}
|
|
|
- memset (pmod_data->pcall_lst, 0, sizeof (call_lst) * moh_maxcalls);
|
|
|
- pmod_data->call_cnt = moh_maxcalls;
|
|
|
- return -1;
|
|
|
+if (berror)
|
|
|
+ { return 0; }
|
|
|
+pmod_data->pcall_lst =
|
|
|
+ (call_lst *) shm_malloc (sizeof (call_lst) * moh_maxcalls);
|
|
|
+if (!pmod_data->pcall_lst)
|
|
|
+ {
|
|
|
+ LM_ERR ("Unable to allocate shared memory!\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+pmod_data->pcfg->db_url = db_url;
|
|
|
+pmod_data->pcfg->db_ctable = db_ctable;
|
|
|
+pmod_data->pcfg->db_qtable = db_qtable;
|
|
|
+pmod_data->pcfg->mohdir = mohdir;
|
|
|
+memset (pmod_data->pcall_lst, 0, sizeof (call_lst) * moh_maxcalls);
|
|
|
+pmod_data->call_cnt = moh_maxcalls;
|
|
|
+return -1;
|
|
|
}
|
|
|
|
|
|
/**********
|
|
@@ -232,13 +235,13 @@ static int init_db (void)
|
|
|
str *pdb_url = &pmod_data->pcfg->db_url;
|
|
|
if (db_bind_mod (pdb_url, pmod_data->pdb))
|
|
|
{
|
|
|
- LM_ERR ("Unable to bind DB API using %s", pdb_url->s);
|
|
|
+ LM_ERR ("Unable to bind DB API using %s!\n", pdb_url->s);
|
|
|
return 0;
|
|
|
}
|
|
|
db_func_t *pdb = pmod_data->pdb;
|
|
|
if (!DB_CAPABILITY ((*pdb), DB_CAP_ALL))
|
|
|
{
|
|
|
- LM_ERR ("Selected database %s lacks required capabilities", pdb_url->s);
|
|
|
+ LM_ERR ("Selected database %s lacks required capabilities!\n", pdb_url->s);
|
|
|
return 0;
|
|
|
}
|
|
|
db1_con_t *pconn = mohq_dbconnect ();
|
|
@@ -254,14 +257,14 @@ if (!pconn)
|
|
|
if (db_check_table_version (pdb, pconn,
|
|
|
&pmod_data->pcfg->db_ctable, MOHQ_CTABLE_VERSION) < 0)
|
|
|
{
|
|
|
- LM_ERR ("%s table in DB %s not at version %d",
|
|
|
+ LM_ERR ("%s table in DB %s not at version %d!\n",
|
|
|
pmod_data->pcfg->db_ctable.s, pdb_url->s, MOHQ_CTABLE_VERSION);
|
|
|
goto dberr;
|
|
|
}
|
|
|
if (db_check_table_version (pdb, pconn,
|
|
|
&pmod_data->pcfg->db_qtable, MOHQ_QTABLE_VERSION) < 0)
|
|
|
{
|
|
|
- LM_ERR ("%s table in DB %s not at version %d",
|
|
|
+ LM_ERR ("%s table in DB %s not at version %d!\n",
|
|
|
pmod_data->pcfg->db_qtable.s, pdb_url->s, MOHQ_QTABLE_VERSION);
|
|
|
goto dberr;
|
|
|
}
|
|
@@ -301,7 +304,7 @@ if (rank == PROC_INIT || rank == PROC_TCP_MAIN || rank == PROC_MAIN)
|
|
|
{ return 0; }
|
|
|
if (!pmod_data->pdb->init)
|
|
|
{
|
|
|
- LM_CRIT ("DB API not loaded!");
|
|
|
+ LM_CRIT ("DB API not loaded!\n");
|
|
|
return -1;
|
|
|
}
|
|
|
return 0;
|
|
@@ -355,7 +358,7 @@ int mod_init (void)
|
|
|
pmod_data = (mod_data *) shm_malloc (sizeof (mod_data));
|
|
|
if (!pmod_data)
|
|
|
{
|
|
|
- LM_ERR ("Unable to allocate shared memory");
|
|
|
+ LM_ERR ("Unable to allocate shared memory!\n");
|
|
|
return -1;
|
|
|
}
|
|
|
memset (pmod_data, 0, sizeof (mod_data));
|
|
@@ -371,47 +374,59 @@ if (!init_db ())
|
|
|
|
|
|
if (sl_load_api (pmod_data->psl))
|
|
|
{
|
|
|
- LM_ERR ("Unable to load SL module\n");
|
|
|
+ LM_ERR ("Unable to load SL module!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
if (load_tm_api (pmod_data->ptm))
|
|
|
{
|
|
|
- LM_ERR ("Unable to load TM module\n");
|
|
|
+ LM_ERR ("Unable to load TM module!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
if (load_rr_api (pmod_data->prr))
|
|
|
{
|
|
|
- LM_ERR ("Unable to load RR module\n");
|
|
|
+ LM_ERR ("Unable to load RR module!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
pmod_data->fn_rtp_answer = find_export ("rtpproxy_answer", 0, 0);
|
|
|
if (!pmod_data->fn_rtp_answer)
|
|
|
{
|
|
|
- LM_ERR ("Unable to load rtpproxy_answer\n");
|
|
|
+ LM_ERR ("Unable to load rtpproxy_answer!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
pmod_data->fn_rtp_offer = find_export ("rtpproxy_offer", 0, 0);
|
|
|
if (!pmod_data->fn_rtp_offer)
|
|
|
{
|
|
|
- LM_ERR ("Unable to load rtpproxy_offer\n");
|
|
|
+ LM_ERR ("Unable to load rtpproxy_offer!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
pmod_data->fn_rtp_stream_c = find_export ("rtpproxy_stream2uac", 2, 0);
|
|
|
if (!pmod_data->fn_rtp_stream_c)
|
|
|
{
|
|
|
- LM_ERR ("Unable to load rtpproxy_stream2uac\n");
|
|
|
+ LM_ERR ("Unable to load rtpproxy_stream2uac!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
pmod_data->fn_rtp_stream_s = find_export ("rtpproxy_stream2uas", 2, 0);
|
|
|
if (!pmod_data->fn_rtp_stream_s)
|
|
|
{
|
|
|
- LM_ERR ("Unable to load rtpproxy_stream2uas\n");
|
|
|
+ LM_ERR ("Unable to load rtpproxy_stream2uas!\n");
|
|
|
+ goto initerr;
|
|
|
+ }
|
|
|
+pmod_data->fn_rtp_stop_c = find_export ("rtpproxy_stop_stream2uac", 0, 0);
|
|
|
+if (!pmod_data->fn_rtp_stop_c)
|
|
|
+ {
|
|
|
+ LM_ERR ("Unable to load rtpproxy_stop_stream2uac!\n");
|
|
|
+ goto initerr;
|
|
|
+ }
|
|
|
+pmod_data->fn_rtp_stop_s = find_export ("rtpproxy_stop_stream2uas", 0, 0);
|
|
|
+if (!pmod_data->fn_rtp_stop_s)
|
|
|
+ {
|
|
|
+ LM_ERR ("Unable to load rtpproxy_stop_stream2uas!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
pmod_data->fn_rtp_destroy = find_export ("rtpproxy_destroy", 0, 0);
|
|
|
if (!pmod_data->fn_rtp_destroy)
|
|
|
{
|
|
|
- LM_ERR ("Unable to load rtpproxy_destroy\n");
|
|
|
+ LM_ERR ("Unable to load rtpproxy_destroy!\n");
|
|
|
goto initerr;
|
|
|
}
|
|
|
|
|
@@ -438,4 +453,4 @@ if (pmod_data->pcall_lock->plock)
|
|
|
shm_free (pmod_data);
|
|
|
pmod_data = NULL;
|
|
|
return -1;
|
|
|
-}
|
|
|
+}
|