Skip to content

Commit a914df6

Browse files
committed
[tm] added $tm.branch.xxxx family of variables
Also the t_get_branch_idx_by_attr() script function
1 parent 4496379 commit a914df6

4 files changed

Lines changed: 608 additions & 31 deletions

File tree

modules/tm/h_table.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ typedef struct ua_client
143143
timer may fire and interfere with whoever tries to
144144
rewrite it */
145145
struct retr_buf local_cancel;
146+
/* UAC specific flags */
147+
short flags;
148+
/* the onreply_route to be processed only for this branch */
149+
struct script_route_ref *on_reply;
150+
/* if we store a reply (branch picking), this is where it is */
151+
struct sip_msg *reply;
152+
/* if we don't store, we at least want to know the status */
153+
short last_received;
154+
/* number of RR headers that were locally added for this branch */
155+
unsigned int added_rr;
156+
146157
/* pointer to retransmission buffer where uri is printed;
147158
good for generating ACK/CANCEL */
148159
str uri;
@@ -154,19 +165,13 @@ typedef struct ua_client
154165
str adv_address;
155166
/* the advertised port used for this branch */
156167
str adv_port;
157-
/* number of RR headers that were locally added for this branch */
158-
unsigned int added_rr;
159-
/* if we store a reply (branch picking), this is where it is */
160-
struct sip_msg *reply;
161-
/* if we don't store, we at least want to know the status */
162-
short last_received;
163-
/* UAC specific flags */
164-
short flags;
165168
/* script flags, specific to this branch */
166169
int br_flags;
167-
/* the onreply_route to be processed only for this branch */
168-
struct script_route_ref *on_reply;
169-
/* head list for avps */
170+
/* q value of this branch */
171+
int q;
172+
/* head list for branch attrs */
173+
struct usr_avp *battrs;
174+
/* head list for script bavps */
170175
struct usr_avp *user_avps;
171176
}ua_client_type;
172177

modules/tm/t_funcs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ static inline void force_retr(struct retr_buf *rb)
170170
free_f((br).duri.s); \
171171
if ((br).user_avps) \
172172
avp_destr_f(&(br).user_avps); \
173+
if ((br).battrs) \
174+
avp_destr_f(&(br).battrs); \
173175
} while (0)
174176

175177
#define clean_branch(br) \

modules/tm/t_fwd.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ static inline unsigned int count_local_rr(struct sip_msg *req)
396396
may break the function logic!
397397
*/
398398
static int add_uac( struct cell *t, struct sip_msg *request, const str *uri,
399-
str* next_hop, unsigned int bflags, str* path, struct proxy_l *proxy)
399+
str* next_hop, unsigned int bflags, str* path,
400+
int q, struct usr_avp **attrs, struct proxy_l *proxy)
400401
{
401402
unsigned short branch;
402403
struct sip_msg_body *body_clone=NO_BODY_CLONE_MARKER;
@@ -424,6 +425,16 @@ static int add_uac( struct cell *t, struct sip_msg *request, const str *uri,
424425
request->path_vec=*path;
425426
request->ruri_bflags=bflags;
426427

428+
/* we attach the attrs here as we need to see them in branch route
429+
* (inside pre_print_uac_request())
430+
* They will remain attached here if the UAC is successfully created;
431+
* if we exit with return the attrs will be freed by clean_branch().
432+
* Bottom line, we take over the attr list handling, so we NULL the
433+
* received holder (so the upper level will havve nothing to care furhter)
434+
*/
435+
t->uac[branch].battrs = *attrs;
436+
*attrs = NULL;
437+
427438
if ( pre_print_uac_request( t, branch, request, &body_clone)!= 0 ) {
428439
ret = -1;
429440
goto error01;
@@ -471,6 +482,7 @@ static int add_uac( struct cell *t, struct sip_msg *request, const str *uri,
471482
t->uac[branch].uri.len=request->new_uri.len;
472483
t->uac[branch].br_flags = request->ruri_bflags;
473484
t->uac[branch].added_rr = count_local_rr( request );
485+
t->uac[branch].q = q;
474486
t->nr_of_outgoings++;
475487

476488
/* done! */
@@ -766,7 +778,8 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
766778

767779
/* as first branch, use current R-URI, bflags, etc. */
768780
branch_ret = add_uac( t, p_msg, &current_uri, &backup_dst,
769-
getb0flags(p_msg), &p_msg->path_vec, proxy);
781+
getb0flags(p_msg), &p_msg->path_vec, p_msg->ruri_q,
782+
ruri_branch_attrs_head() , proxy);
770783
if (branch_ret>=0)
771784
added_branches |= 1<<branch_ret;
772785
else
@@ -776,7 +789,7 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
776789
for( idx=0; (branch=get_msg_branch(idx))!=NULL ; idx++ ) {
777790
p_msg->force_send_socket = branch->force_send_socket;
778791
branch_ret = add_uac( t, p_msg, &branch->uri, &branch->dst_uri,
779-
branch->bflags, &branch->path, proxy);
792+
branch->bflags, &branch->path, branch->q, &branch->attrs, proxy);
780793
/* pick some of the errors in case things go wrong;
781794
note that picking lowest error is just as good as
782795
any other algorithm which picks any other negative

0 commit comments

Comments
 (0)