Skip to content

Commit 8f26e72

Browse files
First working version of one way topology hiding with binary encoding and auto route
1 parent 462fe92 commit 8f26e72

21 files changed

+3854
-1572
lines changed

modules/compression/gz_helpers.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ int gzip_compress(unsigned char* in, unsigned long ilen, str* out, unsigned long
109109
return -1;
110110
}
111111

112+
static inline int is_gzip_compressed(unsigned char *data, int len)
113+
{
114+
if (len < 3)
115+
return 0;
116+
117+
return (data[0] == 0x1f && data[1] == 0x8b && data[2] == 0x08);
118+
}
119+
112120
/*
113121
*
114122
*/
@@ -122,6 +130,11 @@ int gzip_uncompress(unsigned char* in, unsigned long ilen, str* out, unsigned lo
122130
return -1;
123131
}
124132

133+
if (is_gzip_compressed(in, ilen) != 1) {
134+
LM_ERR("Not gzip decompressable\n");
135+
return -1;
136+
}
137+
125138
/* Gzip holds the length of the original message
126139
in the last 4 bytes */
127140
*olen = ((unsigned long)in[ilen-1] << 24) +

modules/rr/api.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "rr_cb.h"
3838

3939
extern int append_fromtag;
40+
extern int enable_double_rr;
4041

4142
int load_rr( struct rr_binds *rrb )
4243
{
@@ -50,6 +51,7 @@ int load_rr( struct rr_binds *rrb )
5051
rrb->loose_route = loose_route;
5152
rrb->record_route = record_route;
5253
rrb->append_fromtag = append_fromtag;
54+
rrb->enable_double_rr = enable_double_rr;
5355

5456
return 1;
5557
}

modules/rr/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct rr_binds {
6363
loose_route_t loose_route;
6464
record_route_t record_route;
6565
int append_fromtag;
66+
int enable_double_rr;
6667
};
6768

6869
typedef int (*load_rr_f)( struct rr_binds* );

modules/rr/loose.c

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -137,89 +137,6 @@ static inline int find_first_route(struct sip_msg* _m)
137137
}
138138
}
139139

140-
141-
/*
142-
* Find out if a URI contains r2 parameter which indicates
143-
* that we put 2 record routes
144-
*/
145-
static inline int is_2rr(str* _params)
146-
{
147-
str s;
148-
int i, state = 0;
149-
150-
if (_params->len == 0) return 0;
151-
s = *_params;
152-
153-
for(i = 0; i < s.len; i++) {
154-
switch(state) {
155-
case 0:
156-
switch(s.s[i]) {
157-
case ' ':
158-
case '\r':
159-
case '\n':
160-
case '\t': break;
161-
case 'r':
162-
case 'R': state = 1; break;
163-
default: state = 4; break;
164-
}
165-
break;
166-
167-
case 1:
168-
switch(s.s[i]) {
169-
case '2': state = 2; break;
170-
default: state = 4; break;
171-
}
172-
break;
173-
174-
case 2:
175-
switch(s.s[i]) {
176-
case ';': return 1;
177-
case '=': return 1;
178-
case ' ':
179-
case '\r':
180-
case '\n':
181-
case '\t': state = 3; break;
182-
default: state = 4; break;
183-
}
184-
break;
185-
186-
case 3:
187-
switch(s.s[i]) {
188-
case ';': return 1;
189-
case '=': return 1;
190-
case ' ':
191-
case '\r':
192-
case '\n':
193-
case '\t': break;
194-
default: state = 4; break;
195-
}
196-
break;
197-
198-
case 4:
199-
switch(s.s[i]) {
200-
case '\"': state = 5; break;
201-
case ';': state = 0; break;
202-
default: break;
203-
}
204-
break;
205-
206-
case 5:
207-
switch(s.s[i]) {
208-
case '\\': state = 6; break;
209-
case '\"': state = 4; break;
210-
default: break;
211-
}
212-
break;
213-
214-
case 6: state = 5; break;
215-
}
216-
}
217-
218-
if ((state == 2) || (state == 3)) return 1;
219-
else return 0;
220-
}
221-
222-
223140
/*
224141
* Check if URI is myself
225142
*/

modules/rr/loose.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,87 @@ static inline int is_strict(str* _params)
159159
else return 1;
160160
}
161161

162+
/*
163+
* Find out if a URI contains r2 parameter which indicates
164+
* that we put 2 record routes
165+
*/
166+
static inline int is_2rr(str* _params)
167+
{
168+
str s;
169+
int i, state = 0;
170+
171+
if (_params->len == 0) return 0;
172+
s = *_params;
173+
174+
for(i = 0; i < s.len; i++) {
175+
switch(state) {
176+
case 0:
177+
switch(s.s[i]) {
178+
case ' ':
179+
case '\r':
180+
case '\n':
181+
case '\t': break;
182+
case 'r':
183+
case 'R': state = 1; break;
184+
default: state = 4; break;
185+
}
186+
break;
187+
188+
case 1:
189+
switch(s.s[i]) {
190+
case '2': state = 2; break;
191+
default: state = 4; break;
192+
}
193+
break;
194+
195+
case 2:
196+
switch(s.s[i]) {
197+
case ';': return 1;
198+
case '=': return 1;
199+
case ' ':
200+
case '\r':
201+
case '\n':
202+
case '\t': state = 3; break;
203+
default: state = 4; break;
204+
}
205+
break;
206+
207+
case 3:
208+
switch(s.s[i]) {
209+
case ';': return 1;
210+
case '=': return 1;
211+
case ' ':
212+
case '\r':
213+
case '\n':
214+
case '\t': break;
215+
default: state = 4; break;
216+
}
217+
break;
218+
219+
case 4:
220+
switch(s.s[i]) {
221+
case '\"': state = 5; break;
222+
case ';': state = 0; break;
223+
default: break;
224+
}
225+
break;
226+
227+
case 5:
228+
switch(s.s[i]) {
229+
case '\\': state = 6; break;
230+
case '\"': state = 4; break;
231+
default: break;
232+
}
233+
break;
234+
235+
case 6: state = 5; break;
236+
}
237+
}
238+
239+
if ((state == 2) || (state == 3)) return 1;
240+
else return 0;
241+
}
242+
243+
162244

163245
#endif /* LOOSE_H */

modules/rr/record.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ int record_route(struct sip_msg* _m, str *params)
245245
str user = STR_NULL;
246246
struct to_body* from;
247247
str* tag;
248+
char *anchor_pos;
248249

249250
from = 0; /* Makes gcc happy */
250251
lp = lp2 = NULL;
@@ -267,8 +268,11 @@ int record_route(struct sip_msg* _m, str *params)
267268
tag = 0;
268269
}
269270

270-
l = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
271-
l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
271+
/* Get the anchor position relative to other Record-Routes if existing */
272+
anchor_pos = _m->record_route != NULL ? _m->record_route->name.s : _m->headers->name.s;
273+
274+
l = anchor_lump(_m, anchor_pos - _m->buf, HDR_RECORDROUTE_T);
275+
l2 = anchor_lump(_m, anchor_pos - _m->buf, HDR_RECORDROUTE_T);
272276
if (!l || !l2) {
273277
LM_ERR("failed to create an anchor\n");
274278
return -3;
@@ -299,8 +303,8 @@ int record_route(struct sip_msg* _m, str *params)
299303
}
300304

301305
if (enable_double_rr) {
302-
l = anchor_lump(_m, _m->headers->name.s - _m->buf,HDR_RECORDROUTE_T);
303-
l2 = anchor_lump(_m, _m->headers->name.s - _m->buf, HDR_RECORDROUTE_T);
306+
l = anchor_lump(_m, anchor_pos - _m->buf,HDR_RECORDROUTE_T);
307+
l2 = anchor_lump(_m, anchor_pos - _m->buf, HDR_RECORDROUTE_T);
304308
if (!l || !l2) {
305309
LM_ERR("failed to create an anchor\n");
306310
return -5;

modules/tm/t_hooks.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ void destroy_tmcb_lists(void)
8888
}
8989
}
9090

91+
static unsigned int tmcb_flags = 0;
92+
void set_tmcb_flags(unsigned int flags) {
93+
tmcb_flags |= flags;
94+
}
9195

9296
int insert_tmcb(struct tmcb_head_list *cb_list, int types,
9397
transaction_cb f, void *param, release_tmcb_param release_func )
@@ -109,6 +113,7 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
109113
cbp->param = param;
110114
cbp->release = release_func;
111115
cbp->types = types;
116+
cbp->flags = tmcb_flags;
112117
if (cbp->next)
113118
cbp->id = cbp->next->id+1;
114119
else
@@ -211,6 +216,7 @@ static void run_any_trans_callbacks(struct tmcb_head_list *list, unsigned int ty
211216
LM_DBG("trans=%p, callback type %d, id %d entered\n",
212217
trans, type, cbp->id );
213218
params.param = &(cbp->param);
219+
params.flags = cbp->flags;
214220
cbp->callback( trans, type, &params );
215221
if ((cbp->types)&(TMCB_REQUEST_IN|TMCB_LOCAL_TRANS_NEW)) {
216222
if (req && req->dst_uri.len==-1) {
@@ -224,6 +230,7 @@ static void run_any_trans_callbacks(struct tmcb_head_list *list, unsigned int ty
224230
/* env cleanup */
225231
set_avp_list( backup );
226232
tmcb_extra1 = tmcb_extra2 = 0;
233+
tmcb_flags = 0;
227234
set_t(trans_backup);
228235
}
229236

modules/tm/t_hooks.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct tmcb_params {
204204
struct sip_msg* req;
205205
struct sip_msg* rpl;
206206
int code;
207+
unsigned int flags;
207208
void **param;
208209
void *extra1;
209210
void *extra2;
@@ -216,14 +217,15 @@ typedef void (release_tmcb_param) (void *param);
216217
/* register callback function prototype */
217218
typedef int (*register_tmcb_f)(struct sip_msg* p_msg, struct cell *t,
218219
int cb_types, transaction_cb f, void *param, release_tmcb_param func);
219-
220+
typedef void (*set_tmcb_flags_f)(unsigned int flags);
220221

221222
struct tm_callback {
222223
int id; /* id of this callback - useless */
223224
int types; /* types of events that trigger the callback*/
224225
transaction_cb* callback; /* callback function */
225226
void *param; /* param to be passed to callback function */
226227
release_tmcb_param *release; /* function to release the callback param when the callback is deleted */
228+
unsigned int flags; /* flags to be passed into the callback*/
227229
struct tm_callback* next;
228230
};
229231

@@ -264,6 +266,9 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
264266
/* set extra params for callbacks */
265267
void set_extra_tmcb_params(void *extra1, void *extra2);
266268

269+
/* set extra params for callbacks */
270+
void set_tmcb_flags(unsigned int flags);
271+
267272
/* run all transaction callbacks for an event type */
268273
void run_trans_callbacks( int type , struct cell *trans,
269274
struct sip_msg *req, struct sip_msg *rpl, int code );

modules/tm/tm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ static int fixup_inject_flags(void **param)
767767
int load_tm( struct tm_binds *tmb)
768768
{
769769
tmb->register_tmcb = register_tmcb;
770+
tmb->set_tmcb_flags = set_tmcb_flags;
770771

771772
/* relay function */
772773
tmb->t_relay = w_t_relay;

modules/tm/tm_load.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
struct tm_binds {
4949
register_tmcb_f register_tmcb;
50+
set_tmcb_flags_f set_tmcb_flags;
51+
5052
trelay_f t_relay;
5153
tcheck_trans_f t_check_trans;
5254

0 commit comments

Comments
 (0)