Skip to content

Commit

Permalink
mohqueue: prevent calls sticking in queue
Browse files Browse the repository at this point in the history
- query RTP to see if the link is active
- update user-agent version
- fixed edge case where REFER response arrives after call closed
(cherry picked from commit a051bd9)
  • Loading branch information
rdboisvert authored and miconda committed Sep 8, 2016
1 parent 3b4f399 commit 4236d74
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
28 changes: 27 additions & 1 deletion modules/mohqueue/mohq.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-15 Robert Boisvert
* Copyright (C) 2013-16 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down Expand Up @@ -42,6 +42,7 @@ static int mod_init (void);
**********/

mod_data *pmod_data;
pv_spec_t *prtp_pv;

/**********
* module exports
Expand Down Expand Up @@ -97,6 +98,12 @@ struct module_exports exports = {
mod_child_init, /* per-child initialization function */
};

/**********
* local constants
**********/

str prtpstat [1] = {STR_STATIC_INIT ("$rtpstat")};

/**********
* local functions
**********/
Expand Down Expand Up @@ -349,6 +356,8 @@ return;
int mod_init (void)

{
int rtplen;

/**********
* o allocate shared mem and init
* o init configuration data
Expand Down Expand Up @@ -430,6 +439,23 @@ if (!pmod_data->fn_rtp_destroy)
goto initerr;
}

/**********
* get RTPSTAT pv spec
**********/

rtplen = pv_locate_name (prtpstat);
if(rtplen != prtpstat->len)
{
LM_ERR ("Unable to find RTPSTAT pv!\n");
goto initerr;
}
prtp_pv = pv_cache_get (&prtpstat);
if(!prtp_pv)
{
LM_ERR ("Unable to find pv spec for RTPSTAT!\n");
goto initerr;
}

/**********
* init MOH and call queue locks
**********/
Expand Down
1 change: 1 addition & 0 deletions modules/mohqueue/mohq.h
Expand Up @@ -131,6 +131,7 @@ typedef struct
**********/

extern mod_data *pmod_data;
extern pv_spec_t *prtp_pv;
extern rtpmap prtpmap [];

#endif /* MOHQ_H */
57 changes: 52 additions & 5 deletions modules/mohqueue/mohq_funcs.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-15 Robert Boisvert
* Copyright (C) 2013-16 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down Expand Up @@ -32,7 +32,7 @@
#define ALLOWHDR "Allow: INVITE, ACK, BYE, CANCEL, NOTIFY, PRACK"
#define CLENHDR "Content-Length"
#define SIPEOL "\r\n"
#define USRAGNT "Kamailio MOH Queue v1.2"
#define USRAGNT "Kamailio MOH Queue v1.3"

/**********
* local constants
Expand Down Expand Up @@ -403,6 +403,26 @@ else
return;
}

/**********
* Check if RTP Still Active
*
* INPUT:
* Arg (1) = SIP message pointer
* OUTPUT: =0 if inactive
**********/

int chk_rtpstat (sip_msg_t *pmsg)

{
pv_value_t pval [1];
memset (pval, 0, sizeof (pv_value_t));
if (pv_get_spec_value (pmsg, prtp_pv, pval))
{ return 0; }
if (pval->flags & PV_VAL_NULL)
{ return 0; }
return 1;
}

/**********
* Close the Call
*
Expand Down Expand Up @@ -1664,10 +1684,23 @@ return nret;

static void refer_cb
(struct cell *ptrans, int ntype, struct tmcb_params *pcbp)

{
char *pfncname = "refer_cb: ";
call_lst *pcall = (call_lst *)*pcbp->param;
if (pcall->call_state != CLSTA_REFER)
{
if (!pcall->call_state)
{
LM_ERR
("%sREFER response ignored because call not in queue!\n", pfncname);
}
else
{
LM_ERR ("%sCall (%s) ignored because not in REFER state!\n", pfncname,
pcall->call_from);
}
return;
}
if ((ntype == TMCB_ON_FAILURE) || (pcbp->req == FAKED_REPLY))
{
LM_ERR ("%sCall (%s) did not respond to REFER!\n", pfncname,
Expand All @@ -1676,6 +1709,11 @@ if ((ntype == TMCB_ON_FAILURE) || (pcbp->req == FAKED_REPLY))
delete_call (pcall);
return;
}

/**********
* check reply
**********/

int nreply = pcbp->code;
if ((nreply / 100) == 2)
{
Expand All @@ -1692,8 +1730,17 @@ else
{ delete_call (pcall); }
else
{
pcall->call_state = CLSTA_INQUEUE;
update_call_rec (pcall);
if (!chk_rtpstat (pcbp->req))
{
LM_ERR ("%sRTP for call (%s) no longer active!\n",
pfncname, pcall->call_from);
delete_call (pcall);
}
else
{
pcall->call_state = CLSTA_INQUEUE;
update_call_rec (pcall);
}
}
}
return;
Expand Down

0 comments on commit 4236d74

Please sign in to comment.