Skip to content

Commit

Permalink
siprec: add $siprec variable
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Nov 22, 2021
1 parent c4a674f commit bbe3ec0
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 43 deletions.
81 changes: 53 additions & 28 deletions modules/siprec/doc/siprec_admin.xml
Expand Up @@ -273,8 +273,7 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
<title>Exported Functions</title>
<section id="func_siprec_start_recording" xreflabel="siprec_start_recording()">
<title>
<function moreinfo="none">siprec_start_recording(srs, [group], [caller],
[callee], [rtpproxy_sock], [media_ip], [headers])</function>
<function moreinfo="none">siprec_start_recording(srs[, rtpproxy_sock])</function>
</title>
<para>
Calling this function on an initial
Expand All @@ -299,39 +298,13 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
<xref linkend="siprec_srs_failover"/> for more
information.
</para></listitem>
<listitem><para>
<emphasis>group</emphasis> (string, optional) - an opaque values
used by the SIPREC protocol to group calls in certain
profiles.
</para></listitem>
<listitem><para>
<emphasis>caller</emphasis> (string, optional) - an XML block
containing information about the caller. If absent, the
<emphasis>From</emphasis> header is used to build the value from.
</para></listitem>
<listitem><para>
<emphasis>callee</emphasis> (string, optional) - an XML block
containing information about the callee. If absent, the
<emphasis>To</emphasis> header is used to build the value from.
</para></listitem>
<listitem><para>
<emphasis>rtpproxy_sock</emphasis> (string, optional) - the
RTPProxy socket used for this call. If absent, the rtpproxy
module will try to detect the proxy used for the initial call,
based on the default set provisioned in the
<emphasis>rtpproxy</emphasis> module.
</para></listitem>
<listitem><para>
<emphasis>media_ip</emphasis> (string, optional) - the IP that
RTPProxy will be streaming media from. If absent
<emphasis>127.0.0.1</emphasis> will be used.
</para></listitem>
<listitem><para>
<emphasis>headers</emphasis> (string, optional) - extra headers
that are to be added in the initial request towards the SRS.
<emphasis>NOTE:</emphasis> headers must be separated by
<emphasis>\r\n</emphasis> and must end with <emphasis>\r\n</emphasis>.
</para></listitem>
</itemizedlist>
</para>
<para>
Expand Down Expand Up @@ -437,5 +410,57 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
</section>
</section>

<section id="exported_pseudo_variables">
<title>Exported Pseudo-Variables</title>
<section id="pv_siprec" xreflabel="$siprec">
<title><varname>$siprec</varname></title>
<para>
Used to modify/describe different siprec sessions
parameters that should be taken into account by the
<xref linkend="func_siprec_start_recording"/> function.
</para>
<para>
The context of this variable is only limited to the current
message processed - it is not available at the transaction
or dialog level.
</para>
<para>
Any of this setting is optional.
</para>
<para>
Settings that can be provisioned:
</para>
<itemizedlist>
<listitem><para>
<emphasis>group</emphasis> - an apaque value that will be inserted
in the SIPREC body and represents the name of the group that can be
used to clasify calls in certain profiles. If missing, no group is added.
</para></listitem>
<listitem><para>
<emphasis>caller</emphasis> - an XML block containing information
about the caller. If absent, the <emphasis>From</emphasis> header
is used to build the value.
</para></listitem>
<listitem><para>
<emphasis>callee</emphasis> - an XML block containing information
about the callee. If absent, the <emphasis>To</emphasis> header
is used to build the value.
</para></listitem>
<listitem><para>
<emphasis>media_ip</emphasis> - the IP that
RTPProxy will be streaming media from. If absent
<emphasis>127.0.0.1</emphasis> will be used.
</para></listitem>
<listitem><para>
<emphasis>headers</emphasis> - extra headers
that are to be added in the initial request towards the SRS.
<emphasis>NOTE:</emphasis> headers must be separated by
<emphasis>\r\n</emphasis> and must end with <emphasis>\r\n</emphasis>.
</para></listitem>
</itemizedlist>
</section>

</section>

</chapter>

43 changes: 28 additions & 15 deletions modules/siprec/siprec.c
Expand Up @@ -31,14 +31,14 @@

#include "siprec_sess.h"
#include "siprec_logic.h"
#include "siprec_var.h"

static int mod_preinit(void);
static int mod_init(void);
static int child_init(int);
static void mod_destroy(void);

static int siprec_start_rec(struct sip_msg *msg, str *srs, str *group,
str *_cA, str *_cB, str *rtp, str *m_ip, str *_hdrs);
static int siprec_start_rec(struct sip_msg *msg, str *srs, str *rtp);
static int siprec_pause_rec(struct sip_msg *msg);
static int siprec_resume_rec(struct sip_msg *msg);

Expand All @@ -61,11 +61,6 @@ static dep_export_t deps = {
static cmd_export_t cmds[] = {
{"siprec_start_recording",(cmd_function)siprec_start_rec, {
{CMD_PARAM_STR,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0},
{CMD_PARAM_STR|CMD_PARAM_OPT,0,0}, {0,0,0}},
REQUEST_ROUTE|ONREPLY_ROUTE},
{"siprec_pause_recording",(cmd_function)siprec_pause_rec,
Expand All @@ -83,6 +78,13 @@ static param_export_t params[] = {
{0, 0, 0}
};

static pv_export_t vars[] = {
{ {"siprec", sizeof("siprec")-1}, 1000,
pv_get_siprec, pv_set_siprec, pv_parse_siprec,
0, 0, 0 },
};


/* module exports */
struct module_exports exports = {
"siprec", /* module name */
Expand All @@ -96,7 +98,7 @@ struct module_exports exports = {
params, /* exported parameters */
0, /* exported statistics */
0, /* exported MI functions */
0, /* exported pseudo-variables */
vars, /* exported pseudo-variables */
0, /* extra processes */
0, /* extra transformations */
mod_preinit, /* module pre-initialization function */
Expand Down Expand Up @@ -134,6 +136,11 @@ static int mod_preinit(void)

srec_dlg_idx = srec_dlg.dlg_ctx_register_ptr(NULL);

if (init_srec_var() < 0) {
LM_ERR("cannot initialize siprec variable!\n");
return -1;
}

return 0;
}

Expand Down Expand Up @@ -188,13 +195,13 @@ static void tm_src_unref_session(void *p)
/*
* function that simply prints the parameters passed
*/
static int siprec_start_rec(struct sip_msg *msg, str *srs, str *group,
str *_cA, str *_cB, str *rtp, str *m_ip, str *_hdrs)
static int siprec_start_rec(struct sip_msg *msg, str *srs, str *rtp)
{
int ret;
str *aor, *display, *xml_val;
struct src_sess *ss;
struct dlg_cell *dlg;
struct srec_var *var;

/* create the dialog, if does not exist yet */
dlg = srec_dlg.get_dlg();
Expand All @@ -206,11 +213,17 @@ static int siprec_start_rec(struct sip_msg *msg, str *srs, str *group,
dlg = srec_dlg.get_dlg();
}

var = get_srec_var();

/* XXX: if there is a forced send socket in the message, use it
* this is the only way to provide a different socket for SRS, but
* we might need to take a different approach */
/* check if the current dialog has a siprec session ongoing */
if (!(ss = src_new_session(srs, rtp, m_ip, group, _hdrs, msg->force_send_socket))) {
if (!(ss = src_new_session(srs, rtp,
(var && var->media.len?&var->media:NULL),
(var && var->group.len?&var->group:NULL),
(var && var->headers.len?&var->headers:NULL),
msg->force_send_socket))) {
LM_ERR("cannot create siprec session!\n");
return -2;
}
Expand All @@ -224,8 +237,8 @@ static int siprec_start_rec(struct sip_msg *msg, str *srs, str *group,
ret = -2;

/* caller info */
if (_cA) {
xml_val = _cA;
if (var && var->caller.len) {
xml_val = &var->caller;
display = aor = NULL;
} else {
if (parse_from_header(msg) < 0) {
Expand All @@ -246,8 +259,8 @@ static int siprec_start_rec(struct sip_msg *msg, str *srs, str *group,
goto session_cleanup;
}
/* caller info */
if (_cB) {
xml_val = _cB;
if (var && var->callee.len) {
xml_val = &var->callee;
} else {
if ((!msg->to && parse_headers(msg, HDR_TO_F, 0) < 0) || !msg->to) {
LM_ERR("inexisting or invalid to header!\n");
Expand Down

0 comments on commit bbe3ec0

Please sign in to comment.