Skip to content

Commit a63b15a

Browse files
Changing how we rebuild Record-Route headers when adding the auto route
1 parent 76e1a95 commit a63b15a

File tree

5 files changed

+203
-104
lines changed

5 files changed

+203
-104
lines changed

modules/rr/record.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ int record_route_preset(struct sip_msg* _m, str* _data)
335335
struct to_body* from;
336336
struct lump* l, *lp, *ap;
337337
struct lump* l2;
338-
char *hdr, *suffix, *p, *term;
338+
char *hdr, *suffix, *p, *term, *anchor_pos;
339339
int hdr_len, suffix_len;
340340

341341
from = 0;
@@ -406,8 +406,11 @@ int record_route_preset(struct sip_msg* _m, str* _data)
406406

407407
memcpy(term, RR_TERM, RR_TERM_LEN);
408408

409-
l = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
410-
l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
409+
/* Get the anchor position relative to other Record-Routes if existing */
410+
anchor_pos = _m->record_route != NULL ? _m->record_route->name.s : _m->headers->name.s;
411+
412+
l = anchor_lump(_m, anchor_pos - _m->buf, HDR_RECORDROUTE_T);
413+
l2 = anchor_lump(_m, anchor_pos - _m->buf, HDR_RECORDROUTE_T);
411414
if (!l || !l2) {
412415
LM_ERR("failed to create lump anchor\n");
413416
goto error;

modules/topology_hiding/th_binary_encoder.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <stdint.h>
22

3+
#include "th_binary_encoder.h"
4+
35
#include "../../parser/msg_parser.h"
46
#include "../../socket_info.h"
57

@@ -52,30 +54,13 @@
5254
#define URI2_HAS_PORT 0x40 // Bit 6: URI2 has port
5355
#define URI2_HAS_R2 0x80 // Bit 7: r2 flag for both URIs in dual encoding
5456

55-
static str r2_on = str_init("r2=on");
56-
static str lr = str_init("lr");
57-
static str lr_on = str_init("lr=on");
58-
59-
#define MAX_ENCODED_URI_SIZE ( \
60-
sizeof(uint16_t) + /* uri properties */ \
61-
sizeof(uint8_t) + UINT8_MAX + /* username */ \
62-
sizeof(uint8_t) + UINT8_MAX + /* password */ \
63-
sizeof(uint8_t) + UINT8_MAX + /* domain */ \
64-
sizeof(uint16_t) + /* port */ \
65-
sizeof(uint8_t) + UINT8_MAX + /* params */ \
66-
sizeof(uint8_t) + UINT8_MAX + /* headers */ \
67-
sizeof(uint8_t) + /* second associated uri flags */ \
68-
sizeof(uint16_t) /* second associated uri port */ \
69-
)
57+
static str r2_on_uri_param = str_init("r2=on");
58+
static str lr_uri_param = str_init("lr");
59+
static str lr_on_uri_param = str_init("lr=on");
60+
static str transport_uri_param = str_init("transport");
7061

7162
#define MAX_THINFO_BUFFER_SIZE 4096
7263

73-
typedef struct {
74-
uint16_t len;
75-
unsigned char buf[MAX_THINFO_BUFFER_SIZE];
76-
int pos;
77-
} encoded_uri_t;
78-
7964
static const uint8_t SCHEMES[] = {
8065
[ERROR_URI_T] = 0,
8166
[SIP_URI_T] = SCHEME_SIP,
@@ -170,9 +155,8 @@ static uint8_t encode_params(unsigned char *p, uint16_t *uri_properties, str *pa
170155
for (int i = 0; i < param_count; i++) {
171156
LM_DBG("Checking param [%.*s]\n", params_to_skip[i].len, params_to_skip[i].s);
172157
if (param_len_current >= params_to_skip[i].len && strncmp(src, params_to_skip[i].s, params_to_skip[i].len) == 0) {
173-
/* Setting some flags in case of lr or r2 params which will be encoded into the uri properties */
174-
if ((param_len_current == lr.len && memcmp(src, lr.s, lr.len) == 0) ||
175-
(param_len_current == lr_on.len && memcmp(src, lr_on.s, lr_on.len) == 0)) {
158+
if ((param_len_current == lr_uri_param.len && memcmp(src, lr_uri_param.s, lr_uri_param.len) == 0) ||
159+
(param_len_current == lr_on_uri_param.len && memcmp(src, lr_on_uri_param.s, lr_on_uri_param.len) == 0)) {
176160
*uri_properties |= HAS_LR;
177161
}
178162

@@ -309,8 +293,8 @@ static int encode_uris(encoded_uri_t *encoding_uri, struct sip_uri *uri1, struct
309293
extra_param_count = 0;
310294
}
311295

312-
extra_params[extra_param_count++] = str_init("transport");
313-
extra_params[extra_param_count++] = str_init("lr");
296+
extra_params[extra_param_count++] = transport_uri_param;
297+
extra_params[extra_param_count++] = lr_uri_param;
314298

315299
param_len_ptr = p++;
316300
param_len = encode_params(p, &props, &uri1->params, extra_param_count, extra_params);

0 commit comments

Comments
 (0)