Skip to content

Commit

Permalink
Merge pull request #3252 from BSVN/Feature/1-siprec-add-xml-custom-ex…
Browse files Browse the repository at this point in the history
…tension

Add xml group and session custom extensions in metadata for siprec module.
  • Loading branch information
razvancrainea committed Nov 22, 2023
2 parents 2a70e61 + 490575c commit b26490e
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 30 deletions.
34 changes: 27 additions & 7 deletions modules/siprec/README
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ SIPREC Module
values for participants

1.5. Use siprec_start_recording() function with custom headers
1.6. Use siprec_pause_recording()
1.7. Use siprec_resume_recording()
1.6. Use siprec_start_recording() function with custom group
and session extensions

1.7. Use siprec_pause_recording()
1.8. Use siprec_resume_recording()

Chapter 1. Admin Guide

Expand Down Expand Up @@ -148,7 +151,7 @@ Chapter 1. Admin Guide
for us to postpone the media between the caller and callee
to play a Recording Indicator message.
* Cannot handle Recording Sessions initiated by SRS - we do
not support the scenario when an SRS suddently decides to
not support the scenario when an SRS suddenly decides to
record a call in the middle of the dialog.
* OpenSIPS cannot be “queried” for ongoing recording sessions
- this is scheduled to be implemented in further releases.
Expand Down Expand Up @@ -259,14 +262,25 @@ for $ci in inbound group\n");
siprec_start_recording($var(srs));
...

Example 1.6. Use siprec_start_recording() function with custom
group and session extensions
...
$var(temp) = "<callcenterID> 17</callcenterID>";
$siprec(group_custom_extension) = $var(temp);
$siprec(session_custom_extension) = "<callcenterCode>dfgh3q45gsd
fty5</callcenterCode>";

siprec_start_recording($var(srs));
...

1.8.2. siprec_pause_recording()

Pauses the recording for the ongoing call. Should be called
after the dialog has matched.

This function can be used from any route.

Example 1.6. Use siprec_pause_recording()
Example 1.7. Use siprec_pause_recording()
...
if (has_totag() && is_method("INVITE")) {
if (is_audio_on_hold())
Expand All @@ -281,7 +295,7 @@ for $ci in inbound group\n");

This function can be used from any route.

Example 1.7. Use siprec_resume_recording()
Example 1.8. Use siprec_resume_recording()
...
if (has_totag() && is_method("INVITE")) {
if (!is_audio_on_hold())
Expand All @@ -304,9 +318,9 @@ for $ci in inbound group\n");
Any of this setting is optional.

Settings that can be provisioned:
* group - an apaque value that will be inserted in the SIPREC
* group - an opaque 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
to classify calls in certain profiles. If missing, no group
is added.
* caller - an XML block containing information about the
caller. If absent, the From header is used to build the
Expand All @@ -322,6 +336,12 @@ for $ci in inbound group\n");
\r\n and must end with \r\n.
* socket - listening socket that the outgoing request towards
SRS should be used.
* group_custom_extension - an optional XML block containing
custom information to be added under the group tag. NOTE:
if the group is absent this value will be ignored and not
used anywhere.
* session_custom_extension - an optional XML block containing
custom information to be added under the session tag.

Chapter 2. Contributors

Expand Down
31 changes: 28 additions & 3 deletions modules/siprec/doc/siprec_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<para>
<emphasis>Cannot handle Recording Sessions initiated by
SRS</emphasis> - we do not support the scenario when an SRS
suddently decides to record a call in the middle of the dialog.
suddenly decides to record a call in the middle of the dialog.
</para>
</listitem>
<listitem>
Expand Down Expand Up @@ -314,6 +314,19 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
<programlisting format="linespecific">
...
$siprec(headers) = "X-MY-CUSTOM_HDR: 1\r\n";
siprec_start_recording($var(srs));
...
</programlisting>
</example>

<example>
<title>Use <function>siprec_start_recording()</function> function with custom group and session extensions</title>
<programlisting format="linespecific">
...
$var(temp) = "<callcenterID> 17</callcenterID>";
$siprec(group_custom_extension) = $var(temp);
$siprec(session_custom_extension) = "<callcenterCode>dfgh3q45gsdfty5</callcenterCode>";

siprec_start_recording($var(srs));
...
</programlisting>
Expand Down Expand Up @@ -389,9 +402,9 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
</para>
<itemizedlist>
<listitem><para>
<emphasis>group</emphasis> - an apaque value that will be inserted
<emphasis>group</emphasis> - an opaque 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.
used to classify calls in certain profiles. If missing, no group is added.
</para></listitem>
<listitem><para>
<emphasis>caller</emphasis> - an XML block containing information
Expand Down Expand Up @@ -420,6 +433,18 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
<emphasis>socket</emphasis> - listening socket that the outgoing
request towards SRS should be used.
</para></listitem>
<listitem><para>
<emphasis>group_custom_extension</emphasis> - an optional XML block
containing custom information to be added under the
<emphasis>group</emphasis> tag.
<emphasis>NOTE:</emphasis> if the <emphasis>group</emphasis> is absent this
value will be ignored and not used anywhere.
</para></listitem>
<listitem><para>
<emphasis>session_custom_extension</emphasis> - an optional XML block
containing custom information to be added under the
<emphasis>session</emphasis> tag.
</para></listitem>
</itemizedlist>
</section>

Expand Down
2 changes: 0 additions & 2 deletions modules/siprec/siprec.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static const pv_export_t vars[] = {
{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
};


/* module exports */
struct module_exports exports = {
"siprec", /* module name */
Expand Down Expand Up @@ -143,7 +142,6 @@ static int mod_preinit(void)
return 0;
}


/**
* init module function
*/
Expand Down
26 changes: 23 additions & 3 deletions modules/siprec/siprec_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,23 @@ static int srs_build_xml(struct src_sess *sess, struct srec_buffer *buf)
if (sess->group.s) {
SIPREC_COPY("\r\n\t<group group_id=\"", buf);
SIPREC_COPY_STR(sess->group, buf);
SIPREC_COPY("\"/>", buf);
SIPREC_COPY("\">", buf);

if (sess->group_custom_extension.s) {
LM_DBG("group_custom_extension: %.*s\n", sess->group_custom_extension.len, sess->group_custom_extension.s);
LM_DBG("group_custom_extension.len: %d\n", sess->group_custom_extension.len);

// add group custom extensions
SIPREC_COPY("\r\n\t\t", buf);
SIPREC_COPY_STR(sess->group_custom_extension, buf);
}

SIPREC_COPY("\r\n\t</group>", buf);
}

SIPREC_COPY("\r\n\t<session session_id=\"", buf);
SIPREC_COPY_UUID(sess->uuid, buf);
if (!sess->group.s && !sess->dlg)
if (!sess->group.s && !sess->dlg && !sess->session_custom_extension.s)
SIPREC_COPY("\"/>\r\n", buf);
else {
SIPREC_COPY("\">", buf);
Expand All @@ -216,8 +228,16 @@ static int srs_build_xml(struct src_sess *sess, struct srec_buffer *buf)
SIPREC_COPY_STR(sess->group, buf);
SIPREC_COPY_CLOSE_TAG("group-ref", buf);
}

if (sess->session_custom_extension.s) {
// add session custom extensions
SIPREC_COPY("\r\n\t\t", buf);
SIPREC_COPY_STR(sess->session_custom_extension, buf);
}

SIPREC_COPY("\r\n\t</session>\r\n", buf);
}

for (p = 0; p < sess->participants_no; p++) {
if (!sess->participants[p].aor.s && !sess->participants[p].xml_val.s)
continue;
Expand Down Expand Up @@ -359,7 +379,7 @@ int srs_build_body(struct src_sess *sess, str *sdp, str *body)
SIPREC_COPY_STR(siprec_content_type, &buf);
SIPREC_COPY_STR(siprec_content_disposition, &buf);
SIPREC_COPY(CRLF, &buf);

if (srs_build_xml(sess, &buf) < 0)
return -1;

Expand Down
57 changes: 51 additions & 6 deletions modules/siprec/siprec_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ struct dlg_binds srec_dlg;
static str srec_dlg_name = str_init("siprecX_ctx");

static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp,
struct socket_info *si, int version, time_t ts, str *hdrs, siprec_uuid *uuid)
struct socket_info *si, int version, time_t ts, str *hdrs, siprec_uuid *uuid,
str* group_custom_extension, str* session_custom_extension)
{
struct src_sess *ss = shm_malloc(sizeof *ss + (m_ip ? m_ip->len : 0) +
(grp ? grp->len : 0) + (hdrs ? hdrs->len : 0));
(grp ? grp->len : 0) + (hdrs ? hdrs->len : 0) +
(group_custom_extension ? group_custom_extension->len : 0) +
(session_custom_extension ? session_custom_extension->len : 0));
if (!ss) {
LM_ERR("not enough memory for creating siprec session!\n");
return NULL;
Expand All @@ -55,7 +58,7 @@ static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp,
ss->media.len = 0;
}

if (grp) {
if (grp && grp->len) {
ss->group.s = (char *)(ss + 1) + ss->media.len;
memcpy(ss->group.s, grp->s, grp->len);
ss->group.len = grp->len;
Expand All @@ -67,6 +70,21 @@ static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp,
memcpy(ss->headers.s, hdrs->s, hdrs->len);
ss->headers.len = hdrs->len;
}

if (grp && grp->len && group_custom_extension && group_custom_extension->len) {
ss->group_custom_extension.s = (char *)(ss + 1) + ss->media.len +
ss->group.len + ss->headers.len;
memcpy(ss->group_custom_extension.s, group_custom_extension->s, group_custom_extension->len);
ss->group_custom_extension.len = group_custom_extension->len;
}

if (session_custom_extension && session_custom_extension->len) {
ss->session_custom_extension.s = (char *)(ss + 1) + ss->media.len +
ss->group.len + ss->headers.len + ss->group_custom_extension.len;
memcpy(ss->session_custom_extension.s, session_custom_extension->s, session_custom_extension->len);
ss->session_custom_extension.len = session_custom_extension->len;
}

memcpy(ss->uuid, uuid, sizeof(*uuid));
ss->participants_no = 0;
ss->ts = ts;
Expand Down Expand Up @@ -98,12 +116,16 @@ struct src_sess *src_new_session(str *srs, rtp_ctx rtp,
(var && var->group.len)?&var->group:NULL,
(var?var->si:NULL), 0, time(NULL),
(var && var->headers.len)?&var->headers:NULL,
&uuid);
&uuid,
(var && var->group_custom_extension.len)?&var->group_custom_extension:NULL,
(var && var->session_custom_extension.len)?&var->session_custom_extension:NULL);

if (!sess)
return NULL;

/* parse the srs here */
end = srs->s + srs->len;

do {
p = end - 1;
while (p > srs->s && *p != ',')
Expand All @@ -116,7 +138,9 @@ struct src_sess *src_new_session(str *srs, rtp_ctx rtp,
end = p;

trim(&s);

node = shm_malloc(sizeof(*node) + s.len);

if (!node) {
LM_ERR("cannot add srs node information!\n");
src_free_session(sess);
Expand All @@ -132,7 +156,6 @@ struct src_sess *src_new_session(str *srs, rtp_ctx rtp,
return sess;
}


void src_free_participant(struct src_part *part)
{
struct srs_sdp_stream *stream;
Expand Down Expand Up @@ -256,6 +279,7 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type,
int version;
time_t ts;
str tmp, media_ip, srs_uri, group;
str group_custom_extension, session_custom_extension;
str aor, name, xml_val, *xml;
siprec_uuid uuid;
struct socket_info *si;
Expand Down Expand Up @@ -302,6 +326,15 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type,
SIPREC_BIN_POP(str, &media_ip);
SIPREC_BIN_POP(str, &srs_uri);
SIPREC_BIN_POP(str, &group);

SIPREC_BIN_POP(str, &group_custom_extension);
if (group_custom_extension.s)
LM_DBG("group custom extension: <%.*s>\n", group_custom_extension.len, group_custom_extension.s);

SIPREC_BIN_POP(str, &session_custom_extension);
if (group_custom_extension.s)
LM_DBG("session custom extension: <%.*s>\n", session_custom_extension.len, session_custom_extension.s);

SIPREC_BIN_POP(str, &tmp);

if (tmp.len) {
Expand All @@ -321,7 +354,9 @@ void srec_loaded_callback(struct dlg_cell *dlg, int type,

sess = src_create_session(rtp,
(media_ip.len ? &media_ip : NULL), (group.len ? &group : NULL),
si, version, ts, NULL /* we do not replicate headers */, &uuid);
si, version, ts, NULL /* we do not replicate headers */, &uuid,
(group_custom_extension.len ? &group_custom_extension : NULL),
(session_custom_extension.len ? &session_custom_extension : NULL));
if (!sess) {
LM_ERR("cannot create a new siprec session!\n");
return;
Expand Down Expand Up @@ -482,6 +517,16 @@ void srec_dlg_write_callback(struct dlg_cell *dlg, int type,
/* push only the first SRS - this is the one chosen */
SIPREC_BIN_PUSH(str, &SIPREC_SRS(ss));
SIPREC_BIN_PUSH(str, &ss->group);

if (ss->group_custom_extension.s && ss->group_custom_extension.len)
SIPREC_BIN_PUSH(str, &ss->group_custom_extension);
else
SIPREC_BIN_PUSH(str, &empty);
if (ss->session_custom_extension.s && ss->session_custom_extension.len)
SIPREC_BIN_PUSH(str, &ss->session_custom_extension);
else
SIPREC_BIN_PUSH(str, &empty);

if (ss->socket)
SIPREC_BIN_PUSH(str, &ss->socket->sock_str);
else
Expand Down
2 changes: 2 additions & 0 deletions modules/siprec/siprec_sess.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ struct src_sess {
struct list_head srs;
str group;
struct socket_info *socket; /* socket used towards SRS */
str group_custom_extension;
str session_custom_extension;

/* siprec */
siprec_uuid uuid;
Expand Down

0 comments on commit b26490e

Please sign in to comment.