Skip to content

Commit ca3410f

Browse files
committed
b2b: add custom_contact_header_params support
1 parent f4da97b commit ca3410f

10 files changed

Lines changed: 235 additions & 12 deletions

File tree

modules/b2b_entities/b2be_load.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef struct client_info
7373
str* body;
7474
str* from_tag;
7575
str local_contact;
76+
str *contact_hdr_params;
7677
unsigned int cseq;
7778
unsigned int maxfwd;
7879
const struct socket_info* send_sock;
@@ -98,6 +99,7 @@ typedef struct b2b_req_data
9899
b2b_dlginfo_t* dlginfo;
99100
unsigned int maxfwd;
100101
unsigned int no_cb;
102+
str *contact_hdr_params;
101103
}b2b_req_data_t;
102104

103105
typedef struct b2b_rpl_data
@@ -109,6 +111,7 @@ typedef struct b2b_rpl_data
109111
str* text;
110112
str* body;
111113
str* extra_headers;
114+
str* contact_hdr_params;
112115
str* contact;
113116
b2b_dlginfo_t* dlginfo;
114117
}b2b_rpl_data_t;

modules/b2b_entities/client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ str* _client_new(client_info_t* ci,b2b_notify_t b2b_cback,
170170
}
171171

172172
if(b2breq_complete_ehdr(ci->extra_headers, ci->client_headers,
173-
&ehdr, ci->body, &ci->local_contact)< 0)
173+
&ehdr, ci->body, &ci->local_contact, ci->contact_hdr_params)< 0)
174174
{
175175
LM_ERR("Failed to complete extra headers\n");
176176
goto error;

modules/b2b_entities/dlg.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,8 @@ int _b2b_send_reply(b2b_dlg_t* dlg, b2b_rpl_data_t* rpl_data)
19411941
bin_free_packet(&storage);
19421942

19431943
if((extra_headers?extra_headers->len:0) + 14 + local_contact.len
1944-
+ 20 + CRLF_LEN > BUF_LEN)
1944+
+ 20 + CRLF_LEN > BUF_LEN +
1945+
(rpl_data->contact_hdr_params?rpl_data->contact_hdr_params->len:0))
19451946
{
19461947
LM_ERR("Buffer overflow!\n");
19471948
goto error;
@@ -1953,7 +1954,9 @@ int _b2b_send_reply(b2b_dlg_t* dlg, b2b_rpl_data_t* rpl_data)
19531954
memcpy(p, extra_headers->s, extra_headers->len);
19541955
p += extra_headers->len;
19551956
}
1956-
len = sprintf(p,"Contact: <%.*s>", local_contact.len, local_contact.s);
1957+
len = sprintf(p,"Contact: <%.*s>%.*s", local_contact.len, local_contact.s,
1958+
(rpl_data->contact_hdr_params?rpl_data->contact_hdr_params->len: 0),
1959+
(rpl_data->contact_hdr_params?rpl_data->contact_hdr_params->s: ""));
19571960
p += len;
19581961
memcpy(p, CRLF, CRLF_LEN);
19591962
p += CRLF_LEN;
@@ -2482,7 +2485,8 @@ int _b2b_send_request(b2b_dlg_t* dlg, b2b_req_data_t* req_data)
24822485

24832486
if(b2breq_complete_ehdr(req_data->extra_headers, req_data->client_headers,
24842487
&ehdr, req_data->body,
2485-
((et==B2B_SERVER)?&dlg->contact[CALLEE_LEG]:&dlg->contact[CALLER_LEG]))< 0)
2488+
((et==B2B_SERVER)?&dlg->contact[CALLEE_LEG]:&dlg->contact[CALLER_LEG]),
2489+
req_data->contact_hdr_params)< 0)
24862490
{
24872491
LM_ERR("Failed to complete extra headers\n");
24882492
goto error;
@@ -3912,11 +3916,12 @@ static inline int is_CT_present(struct hdr_field* headers)
39123916
}
39133917

39143918
int b2breq_complete_ehdr(str* extra_headers, str *client_headers,
3915-
str* ehdr_out, str* body, str* local_contact)
3919+
str* ehdr_out, str* body, str* local_contact, str *ct_hdr_params)
39163920
{
39173921
str ehdr= {NULL,0};
39183922
static char buf[BUF_LEN];
39193923
static struct sip_msg foo_msg;
3924+
str str_empty = str_init("");
39203925

39213926
if(((extra_headers?extra_headers->len:0) + 14 + local_contact->len +
39223927
(client_headers?client_headers->len:0))> BUF_LEN)
@@ -3931,13 +3936,17 @@ int b2breq_complete_ehdr(str* extra_headers, str *client_headers,
39313936
memcpy(ehdr.s, extra_headers->s, extra_headers->len);
39323937
ehdr.len = extra_headers->len;
39333938
}
3939+
if (!ct_hdr_params)
3940+
ct_hdr_params = &str_empty;
39343941
if (local_contact->s[0] == '<') {
39353942
/* already enclosed */
3936-
ehdr.len += sprintf(ehdr.s+ ehdr.len, "Contact: %.*s\r\n",
3937-
local_contact->len, local_contact->s);
3943+
ehdr.len += sprintf(ehdr.s+ ehdr.len, "Contact: %.*s%.*s\r\n",
3944+
local_contact->len, local_contact->s,
3945+
ct_hdr_params->len, ct_hdr_params->s);
39383946
} else {
3939-
ehdr.len += sprintf(ehdr.s+ ehdr.len, "Contact: <%.*s>\r\n",
3940-
local_contact->len, local_contact->s);
3947+
ehdr.len += sprintf(ehdr.s+ ehdr.len, "Contact: <%.*s>%.*s\r\n",
3948+
local_contact->len, local_contact->s,
3949+
ct_hdr_params->len, ct_hdr_params->s);
39413950
}
39423951
if (client_headers && client_headers->len && client_headers->s)
39433952
{

modules/b2b_entities/dlg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ void b2b_tm_cback(struct cell* t, b2b_table htable, struct tmcb_params *ps);
191191
void print_b2b_entities(void);
192192

193193
int b2breq_complete_ehdr(str* extra_headers, str *client_headers,
194-
str* ehdr_out, str* body, str* contact);
194+
str* ehdr_out, str* body, str* contact, str *ct_hdr_params);
195195

196196
b2b_dlg_t* b2b_search_htable_dlg(b2b_table table, unsigned int hash_index,
197197
unsigned int local_index, str* to_tag, str* from_tag, str* callid);

modules/b2b_logic/b2b_logic.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ struct script_route_ref *global_reply_rt_ref = NULL;
130130
unsigned int b2b_clean_period = 100;
131131
unsigned int b2b_update_period = 100;
132132
str custom_headers = {0, 0};
133+
static str custom_ct_hdrs_params = {0, 0};
133134
str custom_headers_lst[HDR_LST_LEN];
134135
int custom_headers_lst_len =0;
135136
str custom_headers_regexp = {0, 0};
137+
csv_record *custom_ct_hdrs_params_list;
136138
regex_t* custom_headers_re;
137139
/* The list of the headers that are passed on the other side by default */
138140
static str default_headers[HDR_DEFAULT_LEN]=
@@ -285,6 +287,7 @@ static const param_export_t params[]=
285287
{"script_reply_route", STR_PARAM, &script_reply_route },
286288
{"custom_headers", STR_PARAM, &custom_headers.s },
287289
{"custom_headers_regexp", STR_PARAM, &custom_headers_regexp.s },
290+
{"custom_contact_header_params", STR_PARAM, &custom_ct_hdrs_params.s },
288291
{"contact_user", INT_PARAM, &contact_user },
289292
{"db_url", STR_PARAM, &db_url.s },
290293
{"cachedb_url", STR_PARAM, &cdb_url.s },
@@ -572,6 +575,16 @@ static int mod_init(void)
572575
if(custom_headers.s)
573576
custom_headers.len = strlen(custom_headers.s);
574577

578+
if(custom_ct_hdrs_params.s) {
579+
custom_ct_hdrs_params.len = strlen(custom_ct_hdrs_params.s);
580+
custom_ct_hdrs_params_list = __parse_csv_record(&custom_ct_hdrs_params, 0, ';');
581+
if (!custom_ct_hdrs_params_list) {
582+
LM_ERR("cannot parse contact headers parameters param [%s]\n",
583+
custom_ct_hdrs_params.s);
584+
return -1;
585+
}
586+
}
587+
575588
memset(custom_headers_lst, 0, HDR_LST_LEN*sizeof(str));
576589
custom_headers_lst[i].s = custom_headers.s;
577590
if(custom_headers.s)

modules/b2b_logic/b2b_logic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "../../cachedb/cachedb.h"
3333
#include "../../timer.h"
3434
#include "../b2b_entities/b2be_load.h"
35+
#include "../../lib/csv.h"
3536

3637
enum b2b_tuple_state {
3738
/* initial bridge state */
@@ -131,6 +132,7 @@ enum pv_entity_field {
131132
};
132133

133134
extern str custom_headers_lst[HDR_LST_LEN];
135+
extern csv_record *custom_ct_hdrs_params_list;
134136
extern regex_t* custom_headers_re;
135137
extern int custom_headers_lst_len;
136138
extern int contact_user;

modules/b2b_logic/bridging.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
506506
b2bl_entity_id_t* bentity0, *bentity1;
507507
int entity_no;
508508
b2b_req_data_t req_data;
509+
str *ct_hdrs = NULL;
509510

510511
bentity0 = tuple->bridge_entities[0];
511512
bentity1 = tuple->bridge_entities[1];
@@ -526,6 +527,9 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
526527
LM_DBG("entity_no = %d, entity=%p, be[0]= %p\n",
527528
entity_no, entity, tuple->bridge_entities[0]);
528529

530+
if ((ct_hdrs = b2b_extract_msg_contact_hdrs(msg)) != NULL)
531+
b2b_store_msg_contact_hdrs(tuple, &entity->key, ct_hdrs);
532+
529533
switch (tuple->state) {
530534
case B2B_BRIDGING_HOLD_STATE:
531535
if (entity_no != 0) {
@@ -654,6 +658,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
654658
req_data.method =&method_ack;
655659
req_data.extra_headers =extra_headers;
656660
req_data.body = body;
661+
req_data.contact_hdr_params = ct_hdrs;
657662
req_data.dlginfo =bentity1->dlginfo;
658663
if(b2b_api.send_request(&req_data) < 0)
659664
{
@@ -732,6 +737,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
732737
req_data.client_headers=&bentity1->hdrs;;
733738
req_data.extra_headers =extra_headers;
734739
req_data.body = body;
740+
req_data.contact_hdr_params = ct_hdrs;
735741
req_data.dlginfo =bentity1->dlginfo;
736742
if(b2b_api.send_request(&req_data) < 0)
737743
{
@@ -753,6 +759,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
753759
req_data.client_headers=&bentity1->hdrs;;
754760
req_data.extra_headers =extra_headers;
755761
req_data.body =body;
762+
req_data.contact_hdr_params = ct_hdrs;
756763
req_data.dlginfo =bentity1->dlginfo;
757764
if(b2b_api.send_request(&req_data) < 0)
758765
{
@@ -795,6 +802,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
795802
req_data.method =&method_invite;
796803
req_data.extra_headers = NULL;
797804
req_data.client_headers = &bentity0->hdrs;
805+
req_data.contact_hdr_params = ct_hdrs;
798806
req_data.body = body;
799807
b2b_api.send_request(&req_data);
800808
bentity0->state = B2BL_ENT_NEW;
@@ -905,6 +913,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers,
905913
req_data.client_headers=&bentity0->hdrs;
906914
req_data.extra_headers =extra_headers;
907915
req_data.body =body;
916+
req_data.contact_hdr_params = ct_hdrs;
908917
req_data.dlginfo =bentity0->dlginfo;
909918
if(b2b_api.send_request(&req_data) < 0)
910919
{
@@ -1382,6 +1391,7 @@ static int bridging_start_old_ent(b2bl_tuple_t* tuple, b2bl_entity_id_t *old_ent
13821391
req_data.extra_headers = NULL;
13831392
req_data.client_headers = &old_entity->hdrs;
13841393
req_data.body = body;
1394+
req_data.contact_hdr_params = b2b_get_msg_contact_hdrs(tuple, &old_entity->key);
13851395
b2b_api.send_request(&req_data);
13861396
old_entity->state = B2BL_ENT_NEW;
13871397
if (body) {
@@ -2163,7 +2173,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no,
21632173
str to_uri={NULL,0}, from_uri, from_dname;
21642174
b2b_req_data_t req_data;
21652175
int ret;
2166-
str local_contact;
2176+
str local_contact, *ct_hdrs;
21672177
int maxfwd;
21682178

21692179
if(!msg || !key)
@@ -2242,6 +2252,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no,
22422252
}
22432253
bridging_entity = tuple->bridge_entities[entity_no];
22442254
old_entity = tuple->bridge_entities[(entity_no?0:1)];
2255+
ct_hdrs = b2b_get_msg_contact_hdrs(tuple, &old_entity->key);
22452256

22462257
if(!old_entity || old_entity->next || old_entity->prev)
22472258
{

modules/b2b_logic/doc/b2b_logic_admin.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,30 @@ modparam("b2b_logic", "custom_headers_regexp", "/^x-/i")
237237
<programlisting format="linespecific">
238238
...
239239
modparam("b2b_logic", "custom_headers", "User-Agent;Date")
240+
...
241+
</programlisting>
242+
</example>
243+
</section>
244+
<section id="param_custom_contact_header_param" xreflabel="custom_contact_header_params">
245+
<title><varname>custom_contact_header_params</varname> (str)</title>
246+
<para>
247+
A list of Contact header parameters, delimited by ';', that should
248+
be passed from the dialog of one side to the other side.
249+
</para>
250+
<para>
251+
Throughout a dialog, the value of each parameter is being
252+
attached to the entity - this means that when an entity is being bridged,
253+
the corresponding entity's headers params are being sent towards the new
254+
entity.
255+
</para>
256+
<para>
257+
<emphasis>Default value is <quote></quote> (no parameter).</emphasis>
258+
</para>
259+
<example>
260+
<title>Set <varname>custom_contact_header_params</varname> parameter</title>
261+
<programlisting format="linespecific">
262+
...
263+
modparam("b2b_logic", "custom_contact_header_params", "audio;video")
240264
...
241265
</programlisting>
242266
</example>

0 commit comments

Comments
 (0)