From c576631b899ded661bbfede48fa92fd03dbc7e88 Mon Sep 17 00:00:00 2001 From: Robert Boisvert Date: Mon, 22 Mar 2021 10:43:12 -0400 Subject: [PATCH] mohqueue: use ptime - version 1.7 - match ptime of incoming call; otherwise, default to 20ms - update copyright dates --- src/modules/mohqueue/README | 2 +- src/modules/mohqueue/doc/mohqueue.xml | 2 +- src/modules/mohqueue/doc/mohqueue_admin.xml | 11 +- src/modules/mohqueue/mohq_common.h | 2 +- src/modules/mohqueue/mohq_db.c | 2 +- src/modules/mohqueue/mohq_db.h | 2 +- src/modules/mohqueue/mohq_funcs.c | 112 +++++++++++++------- src/modules/mohqueue/mohq_funcs.h | 2 +- src/modules/mohqueue/mohq_locks.c | 2 +- src/modules/mohqueue/mohq_locks.h | 2 +- src/modules/mohqueue/mohqueue_mod.c | 4 +- src/modules/mohqueue/mohqueue_mod.h | 2 +- 12 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/modules/mohqueue/README b/src/modules/mohqueue/README index fa845da0f8e..a0f30357ae1 100644 --- a/src/modules/mohqueue/README +++ b/src/modules/mohqueue/README @@ -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 diff --git a/src/modules/mohqueue/doc/mohqueue.xml b/src/modules/mohqueue/doc/mohqueue.xml index e4c1563c662..5498c1b57b3 100644 --- a/src/modules/mohqueue/doc/mohqueue.xml +++ b/src/modules/mohqueue/doc/mohqueue.xml @@ -21,7 +21,7 @@ - 2013-2019 + 2013-2021 Robert Boisvert, rdbprog@gmail.com diff --git a/src/modules/mohqueue/doc/mohqueue_admin.xml b/src/modules/mohqueue/doc/mohqueue_admin.xml index 112b1f4fa4f..37cc02e1a0d 100644 --- a/src/modules/mohqueue/doc/mohqueue_admin.xml +++ b/src/modules/mohqueue/doc/mohqueue_admin.xml @@ -387,10 +387,13 @@ Duplicate names are not allowed. uri (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 (). mohdir (100-character string, optional): path to diff --git a/src/modules/mohqueue/mohq_common.h b/src/modules/mohqueue/mohq_common.h index 88fed7fc516..228587cc989 100644 --- a/src/modules/mohqueue/mohq_common.h +++ b/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. * diff --git a/src/modules/mohqueue/mohq_db.c b/src/modules/mohqueue/mohq_db.c index 3f70b0bf118..7c62ee6d4cb 100644 --- a/src/modules/mohqueue/mohq_db.c +++ b/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. * diff --git a/src/modules/mohqueue/mohq_db.h b/src/modules/mohqueue/mohq_db.h index 41b0a3f24c4..565f0ae141a 100644 --- a/src/modules/mohqueue/mohq_db.h +++ b/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. * diff --git a/src/modules/mohqueue/mohq_funcs.c b/src/modules/mohqueue/mohq_funcs.c index 54ee87486ce..c9c8d6704e7 100644 --- a/src/modules/mohqueue/mohq_funcs.c +++ b/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. * @@ -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 @@ -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 @@ -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) { /********** @@ -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) @@ -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", @@ -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)) @@ -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)) @@ -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); @@ -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 @@ -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); @@ -2961,4 +2999,4 @@ if (pmod_data->ptm->t_relay (pmsg, 0, 0) < 0) return -1; } return 1; -} +} \ No newline at end of file diff --git a/src/modules/mohqueue/mohq_funcs.h b/src/modules/mohqueue/mohq_funcs.h index cc991853062..35d55edaa05 100644 --- a/src/modules/mohqueue/mohq_funcs.h +++ b/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. * diff --git a/src/modules/mohqueue/mohq_locks.c b/src/modules/mohqueue/mohq_locks.c index 080dd394869..b31e052cb8a 100644 --- a/src/modules/mohqueue/mohq_locks.c +++ b/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. * diff --git a/src/modules/mohqueue/mohq_locks.h b/src/modules/mohqueue/mohq_locks.h index 2ae41b7192b..20deed8b029 100644 --- a/src/modules/mohqueue/mohq_locks.h +++ b/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. * diff --git a/src/modules/mohqueue/mohqueue_mod.c b/src/modules/mohqueue/mohqueue_mod.c index a9ec1550971..8a17dfc45e7 100644 --- a/src/modules/mohqueue/mohqueue_mod.c +++ b/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. * @@ -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) diff --git a/src/modules/mohqueue/mohqueue_mod.h b/src/modules/mohqueue/mohqueue_mod.h index b783b03f40f..61d2f98c9cc 100644 --- a/src/modules/mohqueue/mohqueue_mod.h +++ b/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. *