From b9ebc83fe1d94f553f04fe38ea3fdfe28677d990 Mon Sep 17 00:00:00 2001 From: Razvan Crainea Date: Mon, 29 Jan 2024 12:34:16 +0200 Subject: [PATCH] siprec: add from_uri and to_uri settings to $siprec --- modules/siprec/doc/siprec_admin.xml | 18 ++++++++++-- modules/siprec/siprec_logic.c | 12 ++++++-- modules/siprec/siprec_sess.c | 44 ++++++++++++++++++++++------- modules/siprec/siprec_sess.h | 2 ++ modules/siprec/siprec_var.c | 20 +++++++++++++ modules/siprec/siprec_var.h | 10 ++++++- 6 files changed, 90 insertions(+), 16 deletions(-) diff --git a/modules/siprec/doc/siprec_admin.xml b/modules/siprec/doc/siprec_admin.xml index 59e8b7baaf6..012729cd282 100644 --- a/modules/siprec/doc/siprec_admin.xml +++ b/modules/siprec/doc/siprec_admin.xml @@ -409,12 +409,12 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]") caller - an XML block containing information about the caller. If absent, the From header - is used to build the value. + of the initial dialog is used to build the value. callee - an XML block containing information about the callee. If absent, the To header - is used to build the value. + of the initial dialog is used to build the value. media - the IP that @@ -433,6 +433,20 @@ modparam("siprec", "skip_failover_codes", "[34][0-9][0-9]") socket - listening socket that the outgoing request towards SRS should be used. + + from_uri - the URI to appear in the + From header of the dialog. Default value is the + request URI. Note that this does not influence the + caller information in the XML block, + which is taken from the initial dialog. + + + to_uri - the URI to appear in the + To header of the dialog. Default value is the + request URI. Note that this does not influence the + callee information in the XML block, + which is taken from the initial dialog. + group_custom_extension - an optional XML block containing custom information to be added under the diff --git a/modules/siprec/siprec_logic.c b/modules/siprec/siprec_logic.c index 93cdbc5e77c..d0656b83d25 100644 --- a/modules/siprec/siprec_logic.c +++ b/modules/siprec/siprec_logic.c @@ -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) { diff --git a/modules/siprec/siprec_sess.c b/modules/siprec/siprec_sess.c index c95d507c4ca..69ba4363a20 100644 --- a/modules/siprec/siprec_sess.c +++ b/modules/siprec/siprec_sess.c @@ -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) { @@ -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; @@ -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); @@ -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) { diff --git a/modules/siprec/siprec_sess.h b/modules/siprec/siprec_sess.h index d6fca9acd7b..f6a83891819 100644 --- a/modules/siprec/siprec_sess.h +++ b/modules/siprec/siprec_sess.h @@ -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; diff --git a/modules/siprec/siprec_var.c b/modules/siprec/siprec_var.c index 6089367b7a8..a4800366e39 100644 --- a/modules/siprec/siprec_var.c +++ b/modules/siprec/siprec_var.c @@ -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; @@ -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; @@ -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); } @@ -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: @@ -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: diff --git a/modules/siprec/siprec_var.h b/modules/siprec/siprec_var.h index 2dd392da4a5..1827b20524a 100644 --- a/modules/siprec/siprec_var.h +++ b/modules/siprec/siprec_var.h @@ -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; };