Skip to content

Commit

Permalink
siprec: add from_uri and to_uri settings to $siprec
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jan 29, 2024
1 parent 247ae6f commit b9ebc83
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 16 deletions.
18 changes: 16 additions & 2 deletions modules/siprec/doc/siprec_admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
<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.
of the initial dialog 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.
of the initial dialog is used to build the value.
</para></listitem>
<listitem><para>
<emphasis>media</emphasis> - the IP that
Expand All @@ -433,6 +433,20 @@ 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>from_uri</emphasis> - the URI to appear in the
<emphasis>From</emphasis> header of the dialog. Default value is the
request URI. Note that this does not influence the
<emphasis>caller</emphasis> information in the XML block,
which is taken from the initial dialog.
</para></listitem>
<listitem><para>
<emphasis>to_uri</emphasis> - the URI to appear in the
<emphasis>To</emphasis> header of the dialog. Default value is the
request URI. Note that this does not influence the
<emphasis>callee</emphasis> information in the XML block,
which is taken from the initial dialog.
</para></listitem>
<listitem><para>
<emphasis>group_custom_extension</emphasis> - an optional XML block
containing custom information to be added under the
Expand Down
12 changes: 9 additions & 3 deletions modules/siprec/siprec_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,15 @@ static int srs_send_invite(struct src_sess *sess)
ci.method.len = INVITE_LEN;
/* try the first srs_uri */
ci.req_uri = SIPREC_SRS(sess);
/* TODO: fix uris */
ci.to_uri = ci.req_uri;
ci.from_uri = ci.to_uri;

if (sess->from_uri.len)
ci.from_uri = sess->from_uri;
else
ci.from_uri = ci.req_uri;
if (sess->to_uri.len)
ci.to_uri = sess->to_uri;
else
ci.to_uri = ci.req_uri;
if (sess->headers.s) {
hdrs.s = pkg_malloc(extra_headers.len + sess->headers.len);
if (!hdrs.s) {
Expand Down
44 changes: 34 additions & 10 deletions modules/siprec/siprec_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ 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,
const struct socket_info *si, int version, time_t ts, str *hdrs, siprec_uuid *uuid,
const struct socket_info *si, int version, time_t ts, str *hdrs,
str *from_uri, str *to_uri, siprec_uuid *uuid,
str* group_custom_extension, str* session_custom_extension)
{
char *p;
struct src_sess *ss = shm_malloc(sizeof *ss + (m_ip ? m_ip->len : 0) +
(grp ? grp->len : 0) + (hdrs ? hdrs->len : 0) +
(from_uri ? from_uri->len : 0) + (to_uri ? to_uri->len : 0) +
(group_custom_extension ? group_custom_extension->len : 0) +
(session_custom_extension ? session_custom_extension->len : 0));
if (!ss) {
Expand All @@ -49,42 +52,60 @@ static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp,
ss->socket = si;
ss->rtp = rtp;

p = (char *)(ss + 1);
if (m_ip) {
ss->media.s = (char *)(ss + 1);
ss->media.s = p;
memcpy(ss->media.s, m_ip->s, m_ip->len);
ss->media.len = m_ip->len;
p += m_ip->len;
} else {
ss->media.s = NULL;
ss->media.len = 0;
}

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

if (hdrs && hdrs->len) {
ss->headers.s = (char *)(ss + 1) + ss->media.len +
ss->group.len;
ss->headers.s = p;
memcpy(ss->headers.s, hdrs->s, hdrs->len);
ss->headers.len = hdrs->len;
p += 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;
ss->group_custom_extension.s = p;
memcpy(ss->group_custom_extension.s, group_custom_extension->s, group_custom_extension->len);
ss->group_custom_extension.len = group_custom_extension->len;
p += 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;
ss->session_custom_extension.s = p;
memcpy(ss->session_custom_extension.s, session_custom_extension->s, session_custom_extension->len);
ss->session_custom_extension.len = session_custom_extension->len;
p += session_custom_extension->len;
}

if (from_uri && from_uri->len) {
ss->from_uri.s = p;
memcpy(ss->from_uri.s, from_uri->s, from_uri->len);
ss->from_uri.len = from_uri->len;
p += from_uri->len;
}

if (to_uri && to_uri->len) {
ss->to_uri.s = p;
memcpy(ss->to_uri.s, to_uri->s, to_uri->len);
ss->to_uri.len = to_uri->len;
p += to_uri->len;
}


memcpy(ss->uuid, uuid, sizeof(*uuid));
ss->participants_no = 0;
ss->ts = ts;
Expand Down Expand Up @@ -116,6 +137,8 @@ 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,
(var && var->from_uri.len)?&var->from_uri:NULL,
(var && var->to_uri.len)?&var->to_uri:NULL,
&uuid,
(var && var->group_custom_extension.len)?&var->group_custom_extension:NULL,
(var && var->session_custom_extension.len)?&var->session_custom_extension:NULL);
Expand Down Expand Up @@ -341,7 +364,8 @@ static int srec_pop_sess(struct dlg_cell *dlg, bin_packet_t *packet)

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 */,
NULL, NULL /* we already know from and to */, &uuid,
(group_custom_extension.len ? &group_custom_extension : NULL),
(session_custom_extension.len ? &session_custom_extension : NULL));
if (!sess) {
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 @@ -87,6 +87,8 @@ struct src_sess {
int streams_no;
str media;
str headers;
str from_uri;
str to_uri;
rtp_ctx rtp;
str initial_sdp;

Expand Down
20 changes: 20 additions & 0 deletions modules/siprec/siprec_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#define SIPREC_VAR_SOCKET_ID (1 << 5)
#define SIPREC_GROUP_CUSTOM_EXTENSION_ID (1 << 6)
#define SIPREC_SESSION_CUSTOM_EXTENSION_ID (1 << 7)
#define SIPREC_VAR_FROM_URI_ID (1 << 8)
#define SIPREC_VAR_TO_URI_ID (1 << 9)

struct {
const char *name;
Expand All @@ -45,6 +47,8 @@ struct {
{"socket", SIPREC_VAR_SOCKET_ID},
{"group_custom_extension", SIPREC_GROUP_CUSTOM_EXTENSION_ID},
{"session_custom_extension", SIPREC_SESSION_CUSTOM_EXTENSION_ID},
{"from_uri", SIPREC_VAR_FROM_URI_ID},
{"to_uri", SIPREC_VAR_TO_URI_ID},
};

static int srec_msg_idx;
Expand Down Expand Up @@ -90,6 +94,10 @@ static void free_srec_var(void *v)
pkg_free(sv->group_custom_extension.s);
if (sv->session_custom_extension.s)
pkg_free(sv->session_custom_extension.s);
if (sv->from_uri.s)
pkg_free(sv->from_uri.s);
if (sv->to_uri.s)
pkg_free(sv->to_uri.s);
pkg_free(sv);
}

Expand Down Expand Up @@ -198,6 +206,12 @@ int pv_get_siprec(struct sip_msg *msg, pv_param_t *param,
case SIPREC_SESSION_CUSTOM_EXTENSION_ID:
field = &sv->session_custom_extension;
break;
case SIPREC_VAR_FROM_URI_ID:
field = &sv->from_uri;
break;
case SIPREC_VAR_TO_URI_ID:
field = &sv->to_uri;
break;
default:
LM_BUG("unknown field!\n");
case SIPREC_VAR_INVAID_ID:
Expand Down Expand Up @@ -260,6 +274,12 @@ int pv_set_siprec(struct sip_msg* msg, pv_param_t *param,
case SIPREC_SESSION_CUSTOM_EXTENSION_ID:
field = &sv->session_custom_extension;
break;
case SIPREC_VAR_FROM_URI_ID:
field = &sv->from_uri;
break;
case SIPREC_VAR_TO_URI_ID:
field = &sv->to_uri;
break;
default:
LM_BUG("unknown field %d!\n", pv_parse_siprec_get_name(msg, param));
case SIPREC_VAR_INVAID_ID:
Expand Down
10 changes: 9 additions & 1 deletion modules/siprec/siprec_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
#include "../../socket_info.h"

struct srec_var {
str group, caller, callee, media, headers, group_custom_extension, session_custom_extension;
str group;
str caller;
str callee;
str media;
str headers;
str from_uri;
str to_uri;
str group_custom_extension;
str session_custom_extension;
const struct socket_info *si;
};

Expand Down

0 comments on commit b9ebc83

Please sign in to comment.