|
1 | 1 | #include <stdint.h> |
2 | 2 |
|
| 3 | +#include "th_binary_encoder.h" |
| 4 | + |
3 | 5 | #include "../../parser/msg_parser.h" |
4 | 6 | #include "../../socket_info.h" |
5 | 7 |
|
|
52 | 54 | #define URI2_HAS_PORT 0x40 // Bit 6: URI2 has port |
53 | 55 | #define URI2_HAS_R2 0x80 // Bit 7: r2 flag for both URIs in dual encoding |
54 | 56 |
|
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"); |
70 | 61 |
|
71 | 62 | #define MAX_THINFO_BUFFER_SIZE 4096 |
72 | 63 |
|
73 | | -typedef struct { |
74 | | - uint16_t len; |
75 | | - unsigned char buf[MAX_THINFO_BUFFER_SIZE]; |
76 | | - int pos; |
77 | | -} encoded_uri_t; |
78 | | - |
79 | 64 | static const uint8_t SCHEMES[] = { |
80 | 65 | [ERROR_URI_T] = 0, |
81 | 66 | [SIP_URI_T] = SCHEME_SIP, |
@@ -170,9 +155,8 @@ static uint8_t encode_params(unsigned char *p, uint16_t *uri_properties, str *pa |
170 | 155 | for (int i = 0; i < param_count; i++) { |
171 | 156 | LM_DBG("Checking param [%.*s]\n", params_to_skip[i].len, params_to_skip[i].s); |
172 | 157 | 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)) { |
176 | 160 | *uri_properties |= HAS_LR; |
177 | 161 | } |
178 | 162 |
|
@@ -309,8 +293,8 @@ static int encode_uris(encoded_uri_t *encoding_uri, struct sip_uri *uri1, struct |
309 | 293 | extra_param_count = 0; |
310 | 294 | } |
311 | 295 |
|
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; |
314 | 298 |
|
315 | 299 | param_len_ptr = p++; |
316 | 300 | param_len = encode_params(p, &props, &uri1->params, extra_param_count, extra_params); |
|
0 commit comments