Skip to content

Commit

Permalink
mohqueue: use ptime
Browse files Browse the repository at this point in the history
- version 1.7
- match ptime of incoming call; otherwise, default to 20ms
- update copyright dates
  • Loading branch information
Robert Boisvert authored and Robert Boisvert committed Mar 22, 2021
1 parent 1d45652 commit c576631
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/modules/mohqueue/README
Expand Up @@ -2,7 +2,7 @@ mohqueue Module

Robert Boisvert

Copyright © 2013-2019 Robert Boisvert, rdbprog@gmail.com
Copyright © 2013-2021 Robert Boisvert, rdbprog@gmail.com
__________________________________________________________________

Table of Contents
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/doc/mohqueue.xml
Expand Up @@ -21,7 +21,7 @@
</author>
</authorgroup>
<copyright>
<year>2013-2019</year>
<year>2013-2021</year>
<holder>Robert Boisvert, rdbprog@gmail.com</holder>
</copyright>
</bookinfo>
Expand Down
11 changes: 7 additions & 4 deletions src/modules/mohqueue/doc/mohqueue_admin.xml
Expand Up @@ -387,10 +387,13 @@ Duplicate names are not allowed.
</listitem>
<listitem>
<emphasis>uri</emphasis> (100-character string, required): the URI of
the queue. It should not include any parameters or headers (e.g.
"sip:user@host;maddr=239.255.255.1" or "sip:user@host?subject=project")
although it will match any RURI that contains this URI even if the
RURI has parameters or headers. Duplicates are not allowed.
the queue. Duplicates are not allowed. It should not include any parameters
or headers (e.g. "sip:user@host;maddr=239.255.255.1" or
"sip:user@host?subject=project") although it will match any RURI that
contains this URI even if the RURI has parameters or headers. The server
name of the URI must uniquely identify the server. If the RURI server name
does not uniquely identify the server then it should be rewritten to one
the does before calling mohq_send ().
</listitem>
<listitem>
<emphasis>mohdir</emphasis> (100-character string, optional): path to
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohq_common.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohq_db.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohq_db.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down
112 changes: 75 additions & 37 deletions src/modules/mohqueue/mohq_funcs.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 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.6"
#define USRAGNT "Kamailio MOH Queue v1.7"

/**********
* local constants
Expand Down Expand Up @@ -122,17 +122,6 @@ char prefermsg [] =
"Referred-By: <%s>" SIPEOL
};

char preinvitemsg [] =
{
"%s"
"Max-Forwards: 70" SIPEOL
"Contact: <%s>" SIPEOL
ALLOWHDR SIPEOL
"Supported: 100rel" SIPEOL
"Accept-Language: en" SIPEOL
"Content-Type: application/sdp" SIPEOL
};

char prtpsdp [] =
{
"v=0" SIPEOL
Expand Down Expand Up @@ -185,7 +174,6 @@ void ack_msg (sip_msg_t *pmsg, call_lst *pcall)
char *pfncname = "ack_msg: ";
struct cell *ptrans;
tm_api_t *ptm = pmod_data->ptm;
tm_cell_t *t = 0;
if (pcall->call_state != CLSTA_INVITED)
{
/**********
Expand All @@ -203,9 +191,7 @@ if (pcall->call_state != CLSTA_INVITED)
}

/**********
* o release INVITE transaction
* o save SDP address info
* o put in queue
* release INVITE transaction
**********/

if (ptm->t_lookup_ident (&ptrans, pcall->call_hash, pcall->call_label) < 0)
Expand All @@ -216,28 +202,39 @@ if (ptm->t_lookup_ident (&ptrans, pcall->call_hash, pcall->call_label) < 0)
}
else
{
t = ptm->t_gett();
if (t==NULL || t==T_UNDEFINED)
/**********
* create new transaction if current missing
**********/

tm_cell_t *ptcell;
ptcell = ptm->t_gett ();
if ((ptcell == NULL) || (ptcell == T_UNDEFINED))
{
if (ptm->t_newtran(pmsg)<0)
{
LM_ERR("cannot create the transaction\n");
return;
}
t = ptm->t_gett();
if (t==NULL || t==T_UNDEFINED)
{
LM_ERR("cannot lookup the transaction\n");
return;
}
if (ptm->t_newtran (pmsg) < 0)
{
LM_ERR ("%sUnable to create temporary transaction!\n", pfncname);
return;
}
ptcell = ptm->t_gett ();
if ((ptcell == NULL) || (ptcell == T_UNDEFINED))
{
LM_ERR ("%sUnable to find temporary transaction!\n", pfncname);
return;
}
}
if (ptm->t_release_transaction(t) < 0)
if (ptm->t_release (ptcell) < 0)
{
LM_ERR ("%sRelease transaction failed for call (%s)!\n",
pfncname, pcall->call_from);
return;
}
}

/**********
* o save SDP address info
* o put in queue
**********/

pcall->call_hash = pcall->call_label = 0;
sprintf (pcall->call_addr, "%s %s",
pmsg->rcv.dst_ip.af == AF_INET ? "IP4" : "IP6",
Expand Down Expand Up @@ -538,14 +535,19 @@ int
create_call (sip_msg_t *pmsg, call_lst *pcall, int ncall_idx, int mohq_idx)

{
char *pfncname = "create_call: ";
char *pbuf;
str *pstr;

/**********
* add values to new entry
* o call ID
* o from
**********/

char *pfncname = "create_call: ";
pcall->pmohq = &pmod_data->pmohq_lst [mohq_idx];
str *pstr = &pmsg->callid->body;
char *pbuf = pcall->call_buffer;
pstr = &pmsg->callid->body;
pbuf = pcall->call_buffer;
pcall->call_buflen = sizeof (pcall->call_buffer);
pcall->call_id = pbuf;
if (!addstrbfr (pstr->s, pstr->len, &pbuf, &pcall->call_buflen, 1))
Expand Down Expand Up @@ -1036,7 +1038,6 @@ char *pfncname = "first_invite_msg: ";
/**********
* o SDP exists?
* o accepts REFER?
* o send RTP offer
**********/

if (!(pmsg->msg_flags & FL_SDP_BODY))
Expand Down Expand Up @@ -1069,6 +1070,11 @@ if (pmsg->allow)
return;
}
}

/**********
* send RTP offer
**********/

mohq_debug (pcall->pmohq,
"%sMaking offer for RTP link for call (%s) from queue (%s)",
pfncname, pcall->call_from, pcall->pmohq->mohq_name);
Expand Down Expand Up @@ -2146,6 +2152,38 @@ struct sip_msg pnmsg [1];
build_sip_msg_from_buf (pnmsg, pbuf->s, pbuf->len, 0);
memcpy (&pnmsg->rcv, &pmsg->rcv, sizeof (struct receive_info));

/**********
* ptime set?
**********/

int nsession;
sdp_session_cell_t *psession;
char pflagbuf [5];
strcpy (pflagbuf, "z20");
fparam_t pzflag [1] = {0, FPARAM_STRING, {pflagbuf}, 0};
for (nsession = 0; (psession = get_sdp_session (pmsg, nsession)); nsession++)
{
int nstream;
sdp_stream_cell_t *pstream;
for (nstream = 0; (pstream = get_sdp_stream (pmsg, nsession, nstream));
nstream++)
{
/**********
* ptime set?
**********/

if ((pstream->ptime.len < 1) || (pstream->ptime.len > 3))
{ continue; }
strncpy (&pzflag->v.asciiz [1], pstream->ptime.s, pstream->ptime.len);
pzflag->v.asciiz [pstream->ptime.len + 1] = 0;
mohq_debug (pcall->pmohq,
"%sSet ptime (%s) for RTP link for call (%s) from queue (%s)",
pfncname,
&pzflag->v.asciiz [1], pcall->call_from, pcall->pmohq->mohq_name);
break;
}
}

/**********
* o send RTP answer
* o form stream file
Expand All @@ -2154,7 +2192,7 @@ memcpy (&pnmsg->rcv, &pmsg->rcv, sizeof (struct receive_info));

mohq_debug (pcall->pmohq, "%sAnswering RTP link for call (%s)",
pfncname, pcall->call_from);
if (pmod_data->fn_rtp_answer (pnmsg, 0, 0) != 1)
if (pmod_data->fn_rtp_answer (pnmsg, (char *) pzflag, 0) != 1)
{
LM_ERR ("%srtpproxy_answer refused for call (%s)!\n",
pfncname, pcall->call_from);
Expand Down Expand Up @@ -2961,4 +2999,4 @@ if (pmod_data->ptm->t_relay (pmsg, 0, 0) < 0)
return -1;
}
return 1;
}
}
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohq_funcs.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohq_locks.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohq_locks.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down
4 changes: 2 additions & 2 deletions src/modules/mohqueue/mohqueue_mod.c
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down Expand Up @@ -313,7 +313,7 @@ int mod_child_init (int rank)

{
/**********
* o make sure DB initialized
* make sure DB initialized
**********/

if (rank == PROC_INIT || rank == PROC_TCP_MAIN || rank == PROC_MAIN)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mohqueue/mohqueue_mod.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-19 Robert Boisvert
* Copyright (C) 2013-21 Robert Boisvert
*
* This file is part of the mohqueue module for Kamailio, a free SIP server.
*
Expand Down

0 comments on commit c576631

Please sign in to comment.