Skip to content

Commit

Permalink
* support Route in REFER/BYE
Browse files Browse the repository at this point in the history
* added stop_stream ()
* updated copyright
* added trailing linefeed to LM_* () messages
* add create call strings into buffer
* drop calls that to respond to REFER
* changed Referred-By to mohqueue
* added TRYING status
* only INVITE can come in w/o to tag
* use TM for first reply on INVITE
* changed the way messages are entered into the queue
* 180 Ringing not sent if not required
  • Loading branch information
rdboisvert committed Jun 5, 2015
1 parent f8f4004 commit 9d87603
Show file tree
Hide file tree
Showing 9 changed files with 757 additions and 515 deletions.
173 changes: 94 additions & 79 deletions modules/mohqueue/mohq.c
@@ -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.
*
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**********
Expand All @@ -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 ();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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;
}

Expand All @@ -438,4 +453,4 @@ if (pmod_data->pcall_lock->plock)
shm_free (pmod_data);
pmod_data = NULL;
return -1;
}
}
28 changes: 17 additions & 11 deletions modules/mohqueue/mohq.h
@@ -1,5 +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.
*
Expand Down Expand Up @@ -61,31 +61,35 @@ typedef struct

/* call_state values */
#define CLSTA_ENTER 100
#define CLSTA_PRACKSTRT 101
#define CLSTA_PRACKRPLY 102
#define CLSTA_RINGING 103
#define CLSTA_TRYING 101
#define CLSTA_PRACKSTRT 102
#define CLSTA_PRACKRPLY 103
#define CLSTA_INVITED 104
#define CLSTA_CANCEL 105
#define CLSTA_INQUEUE 200
#define CLSTA_REFER 301
#define CLSTA_RFRWAIT 302
#define CLSTA_BYEOK 304
#define CLSTA_BYE 305

typedef struct
{
int call_active;
char call_id [101];
char call_from [URI_LEN + 1];
char call_buffer [1024];
size_t call_bufpos;
char *call_id;
char *call_from;
char call_referto [URI_LEN + 1];
char call_contact [URI_LEN + 1];
char call_tag [101];
char call_via [1024];
char *call_contact;
char *call_tag;
char *call_via;
char *call_route;
char call_addr [IP_ADDR_MAX_STR_SIZE + 4];
int call_state;
int call_cseq;
int call_aport;
mohq_lst *pmohq;
time_t call_time;
time_t refer_time;
unsigned int call_hash;
unsigned int call_label;
sip_msg_t *call_pmsg;
Expand Down Expand Up @@ -118,6 +122,8 @@ typedef struct
cmd_function fn_rtp_offer;
cmd_function fn_rtp_stream_c;
cmd_function fn_rtp_stream_s;
cmd_function fn_rtp_stop_c;
cmd_function fn_rtp_stop_s;
} mod_data;

/**********
Expand All @@ -127,4 +133,4 @@ typedef struct
extern mod_data *pmod_data;
extern rtpmap prtpmap [];

#endif /* MOHQ_H */
#endif /* MOHQ_H */

0 comments on commit 9d87603

Please sign in to comment.