Skip to content

Commit b9ebc83

Browse files
committed
siprec: add from_uri and to_uri settings to $siprec
1 parent 247ae6f commit b9ebc83

File tree

6 files changed

+90
-16
lines changed

6 files changed

+90
-16
lines changed

modules/siprec/doc/siprec_admin.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
409409
<listitem><para>
410410
<emphasis>caller</emphasis> - an XML block containing information
411411
about the caller. If absent, the <emphasis>From</emphasis> header
412-
is used to build the value.
412+
of the initial dialog is used to build the value.
413413
</para></listitem>
414414
<listitem><para>
415415
<emphasis>callee</emphasis> - an XML block containing information
416416
about the callee. If absent, the <emphasis>To</emphasis> header
417-
is used to build the value.
417+
of the initial dialog is used to build the value.
418418
</para></listitem>
419419
<listitem><para>
420420
<emphasis>media</emphasis> - the IP that
@@ -433,6 +433,20 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]")
433433
<emphasis>socket</emphasis> - listening socket that the outgoing
434434
request towards SRS should be used.
435435
</para></listitem>
436+
<listitem><para>
437+
<emphasis>from_uri</emphasis> - the URI to appear in the
438+
<emphasis>From</emphasis> header of the dialog. Default value is the
439+
request URI. Note that this does not influence the
440+
<emphasis>caller</emphasis> information in the XML block,
441+
which is taken from the initial dialog.
442+
</para></listitem>
443+
<listitem><para>
444+
<emphasis>to_uri</emphasis> - the URI to appear in the
445+
<emphasis>To</emphasis> header of the dialog. Default value is the
446+
request URI. Note that this does not influence the
447+
<emphasis>callee</emphasis> information in the XML block,
448+
which is taken from the initial dialog.
449+
</para></listitem>
436450
<listitem><para>
437451
<emphasis>group_custom_extension</emphasis> - an optional XML block
438452
containing custom information to be added under the

modules/siprec/siprec_logic.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,15 @@ static int srs_send_invite(struct src_sess *sess)
446446
ci.method.len = INVITE_LEN;
447447
/* try the first srs_uri */
448448
ci.req_uri = SIPREC_SRS(sess);
449-
/* TODO: fix uris */
450-
ci.to_uri = ci.req_uri;
451-
ci.from_uri = ci.to_uri;
449+
450+
if (sess->from_uri.len)
451+
ci.from_uri = sess->from_uri;
452+
else
453+
ci.from_uri = ci.req_uri;
454+
if (sess->to_uri.len)
455+
ci.to_uri = sess->to_uri;
456+
else
457+
ci.to_uri = ci.req_uri;
452458
if (sess->headers.s) {
453459
hdrs.s = pkg_malloc(extra_headers.len + sess->headers.len);
454460
if (!hdrs.s) {

modules/siprec/siprec_sess.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ struct dlg_binds srec_dlg;
3434
static str srec_dlg_name = str_init("siprecX_ctx");
3535

3636
static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp,
37-
const struct socket_info *si, int version, time_t ts, str *hdrs, siprec_uuid *uuid,
37+
const struct socket_info *si, int version, time_t ts, str *hdrs,
38+
str *from_uri, str *to_uri, siprec_uuid *uuid,
3839
str* group_custom_extension, str* session_custom_extension)
3940
{
41+
char *p;
4042
struct src_sess *ss = shm_malloc(sizeof *ss + (m_ip ? m_ip->len : 0) +
4143
(grp ? grp->len : 0) + (hdrs ? hdrs->len : 0) +
44+
(from_uri ? from_uri->len : 0) + (to_uri ? to_uri->len : 0) +
4245
(group_custom_extension ? group_custom_extension->len : 0) +
4346
(session_custom_extension ? session_custom_extension->len : 0));
4447
if (!ss) {
@@ -49,42 +52,60 @@ static struct src_sess *src_create_session(rtp_ctx rtp, str *m_ip, str *grp,
4952
ss->socket = si;
5053
ss->rtp = rtp;
5154

55+
p = (char *)(ss + 1);
5256
if (m_ip) {
53-
ss->media.s = (char *)(ss + 1);
57+
ss->media.s = p;
5458
memcpy(ss->media.s, m_ip->s, m_ip->len);
5559
ss->media.len = m_ip->len;
60+
p += m_ip->len;
5661
} else {
5762
ss->media.s = NULL;
5863
ss->media.len = 0;
5964
}
6065

6166
if (grp && grp->len) {
62-
ss->group.s = (char *)(ss + 1) + ss->media.len;
67+
ss->group.s = p;
6368
memcpy(ss->group.s, grp->s, grp->len);
6469
ss->group.len = grp->len;
70+
p += grp->len;
6571
}
6672

6773
if (hdrs && hdrs->len) {
68-
ss->headers.s = (char *)(ss + 1) + ss->media.len +
69-
ss->group.len;
74+
ss->headers.s = p;
7075
memcpy(ss->headers.s, hdrs->s, hdrs->len);
7176
ss->headers.len = hdrs->len;
77+
p += hdrs->len;
7278
}
7379

7480
if (grp && grp->len && group_custom_extension && group_custom_extension->len) {
75-
ss->group_custom_extension.s = (char *)(ss + 1) + ss->media.len +
76-
ss->group.len + ss->headers.len;
81+
ss->group_custom_extension.s = p;
7782
memcpy(ss->group_custom_extension.s, group_custom_extension->s, group_custom_extension->len);
7883
ss->group_custom_extension.len = group_custom_extension->len;
84+
p += group_custom_extension->len;
7985
}
8086

8187
if (session_custom_extension && session_custom_extension->len) {
82-
ss->session_custom_extension.s = (char *)(ss + 1) + ss->media.len +
83-
ss->group.len + ss->headers.len + ss->group_custom_extension.len;
88+
ss->session_custom_extension.s = p;
8489
memcpy(ss->session_custom_extension.s, session_custom_extension->s, session_custom_extension->len);
8590
ss->session_custom_extension.len = session_custom_extension->len;
91+
p += session_custom_extension->len;
8692
}
8793

94+
if (from_uri && from_uri->len) {
95+
ss->from_uri.s = p;
96+
memcpy(ss->from_uri.s, from_uri->s, from_uri->len);
97+
ss->from_uri.len = from_uri->len;
98+
p += from_uri->len;
99+
}
100+
101+
if (to_uri && to_uri->len) {
102+
ss->to_uri.s = p;
103+
memcpy(ss->to_uri.s, to_uri->s, to_uri->len);
104+
ss->to_uri.len = to_uri->len;
105+
p += to_uri->len;
106+
}
107+
108+
88109
memcpy(ss->uuid, uuid, sizeof(*uuid));
89110
ss->participants_no = 0;
90111
ss->ts = ts;
@@ -116,6 +137,8 @@ struct src_sess *src_new_session(str *srs, rtp_ctx rtp,
116137
(var && var->group.len)?&var->group:NULL,
117138
(var?var->si:NULL), 0, time(NULL),
118139
(var && var->headers.len)?&var->headers:NULL,
140+
(var && var->from_uri.len)?&var->from_uri:NULL,
141+
(var && var->to_uri.len)?&var->to_uri:NULL,
119142
&uuid,
120143
(var && var->group_custom_extension.len)?&var->group_custom_extension:NULL,
121144
(var && var->session_custom_extension.len)?&var->session_custom_extension:NULL);
@@ -341,7 +364,8 @@ static int srec_pop_sess(struct dlg_cell *dlg, bin_packet_t *packet)
341364

342365
sess = src_create_session(rtp,
343366
(media_ip.len ? &media_ip : NULL), (group.len ? &group : NULL),
344-
si, version, ts, NULL /* we do not replicate headers */, &uuid,
367+
si, version, ts, NULL /* we do not replicate headers */,
368+
NULL, NULL /* we already know from and to */, &uuid,
345369
(group_custom_extension.len ? &group_custom_extension : NULL),
346370
(session_custom_extension.len ? &session_custom_extension : NULL));
347371
if (!sess) {

modules/siprec/siprec_sess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ struct src_sess {
8787
int streams_no;
8888
str media;
8989
str headers;
90+
str from_uri;
91+
str to_uri;
9092
rtp_ctx rtp;
9193
str initial_sdp;
9294

modules/siprec/siprec_var.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#define SIPREC_VAR_SOCKET_ID (1 << 5)
3232
#define SIPREC_GROUP_CUSTOM_EXTENSION_ID (1 << 6)
3333
#define SIPREC_SESSION_CUSTOM_EXTENSION_ID (1 << 7)
34+
#define SIPREC_VAR_FROM_URI_ID (1 << 8)
35+
#define SIPREC_VAR_TO_URI_ID (1 << 9)
3436

3537
struct {
3638
const char *name;
@@ -45,6 +47,8 @@ struct {
4547
{"socket", SIPREC_VAR_SOCKET_ID},
4648
{"group_custom_extension", SIPREC_GROUP_CUSTOM_EXTENSION_ID},
4749
{"session_custom_extension", SIPREC_SESSION_CUSTOM_EXTENSION_ID},
50+
{"from_uri", SIPREC_VAR_FROM_URI_ID},
51+
{"to_uri", SIPREC_VAR_TO_URI_ID},
4852
};
4953

5054
static int srec_msg_idx;
@@ -90,6 +94,10 @@ static void free_srec_var(void *v)
9094
pkg_free(sv->group_custom_extension.s);
9195
if (sv->session_custom_extension.s)
9296
pkg_free(sv->session_custom_extension.s);
97+
if (sv->from_uri.s)
98+
pkg_free(sv->from_uri.s);
99+
if (sv->to_uri.s)
100+
pkg_free(sv->to_uri.s);
93101
pkg_free(sv);
94102
}
95103

@@ -198,6 +206,12 @@ int pv_get_siprec(struct sip_msg *msg, pv_param_t *param,
198206
case SIPREC_SESSION_CUSTOM_EXTENSION_ID:
199207
field = &sv->session_custom_extension;
200208
break;
209+
case SIPREC_VAR_FROM_URI_ID:
210+
field = &sv->from_uri;
211+
break;
212+
case SIPREC_VAR_TO_URI_ID:
213+
field = &sv->to_uri;
214+
break;
201215
default:
202216
LM_BUG("unknown field!\n");
203217
case SIPREC_VAR_INVAID_ID:
@@ -260,6 +274,12 @@ int pv_set_siprec(struct sip_msg* msg, pv_param_t *param,
260274
case SIPREC_SESSION_CUSTOM_EXTENSION_ID:
261275
field = &sv->session_custom_extension;
262276
break;
277+
case SIPREC_VAR_FROM_URI_ID:
278+
field = &sv->from_uri;
279+
break;
280+
case SIPREC_VAR_TO_URI_ID:
281+
field = &sv->to_uri;
282+
break;
263283
default:
264284
LM_BUG("unknown field %d!\n", pv_parse_siprec_get_name(msg, param));
265285
case SIPREC_VAR_INVAID_ID:

modules/siprec/siprec_var.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626
#include "../../socket_info.h"
2727

2828
struct srec_var {
29-
str group, caller, callee, media, headers, group_custom_extension, session_custom_extension;
29+
str group;
30+
str caller;
31+
str callee;
32+
str media;
33+
str headers;
34+
str from_uri;
35+
str to_uri;
36+
str group_custom_extension;
37+
str session_custom_extension;
3038
const struct socket_info *si;
3139
};
3240

0 commit comments

Comments
 (0)