Skip to content

Commit

Permalink
topos: split storage of record route for a, b and server sides
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Mar 21, 2016
1 parent 6497b9a commit a215b92
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/topos/tps_msg.c
Expand Up @@ -308,6 +308,7 @@ int tps_pack_request(sip_msg_t *msg, tps_data_t *ptsd)
rr_t *rr;
int i;
int vlen;
int r2;

if(ptsd->cp==NULL) {
ptsd->cp = ptsd->cbuf;
Expand Down Expand Up @@ -353,6 +354,8 @@ int tps_pack_request(sip_msg_t *msg, tps_data_t *ptsd)

i = 0;
ptsd->a_rr.len = 0;
ptsd->s_rr.len = 0;
r2 = 0;
for(hdr=msg->record_route; hdr; hdr=next_sibling_hdr(hdr)) {
if (parse_rr(hdr) < 0) {
LM_ERR("failed to parse RR\n");
Expand All @@ -366,14 +369,30 @@ int tps_pack_request(sip_msg_t *msg, tps_data_t *ptsd)
return -1;
}
if(i>1) {
if(i==2 &&r2==0) {
ptsd->s_rr.len = ptsd->a_rr.len;
}
if(i==3 &&r2==1) {
ptsd->s_rr.len = ptsd->a_rr.len;
}
*ptsd->cp = ',';
ptsd->cp++;
ptsd->a_rr.len++;
}
*ptsd->cp = '<';
if(i==1) {
ptsd->a_rr.s = ptsd->cp;
ptsd->s_rr.s = ptsd->cp;
}
if(i==2 && r2==0) {
ptsd->a_rr.s = ptsd->cp;
ptsd->a_rr.len = 0;
}
if(i==3 && r2==1) {
ptsd->a_rr.s = ptsd->cp;
ptsd->a_rr.len = 0;
}

ptsd->cp++;
ptsd->a_rr.len++;

Expand All @@ -386,6 +405,8 @@ int tps_pack_request(sip_msg_t *msg, tps_data_t *ptsd)
LM_DBG("single record routing by proxy\n");
ptsd->as_contact.s = ptsd->cp;
ptsd->as_contact.len = rr->nameaddr.uri.len;
} else {
r2 = 1;
}
} else {
if(i==2 && ptsd->as_contact.len==0) {
Expand Down Expand Up @@ -520,6 +541,7 @@ int tps_response_received(sip_msg_t *msg)
tps_storage_lock_release(&lkey);

tps_reappend_via(msg, &btsd, &btsd.x_via);
tps_reappend_rr(msg, &btsd, &btsd.s_rr);
tps_reappend_rr(msg, &btsd, &btsd.x_rr);

return 0;
Expand Down
24 changes: 24 additions & 0 deletions modules/topos/tps_storage.c
Expand Up @@ -354,6 +354,7 @@ str td_col_a_tag = str_init("a_tag");
str td_col_b_tag = str_init("b_tag");
str td_col_a_rr = str_init("a_rr");
str td_col_b_rr = str_init("b_rr");
str td_col_s_rr = str_init("s_rr");
str td_col_iflags = str_init("iflags");
str td_col_a_uri = str_init("a_uri");
str td_col_b_uri = str_init("b_uri");
Expand All @@ -372,6 +373,8 @@ str tt_col_direction = str_init("direction");
str tt_col_x_via = str_init("x_via");
str tt_col_x_vbranch = str_init("x_vbranch");
str tt_col_x_rr = str_init("x_rr");
str tt_col_y_rr = str_init("y_rr");
str tt_col_s_rr = str_init("s_rr");
str tt_col_x_uri = str_init("x_uri");
str tt_col_x_tag = str_init("x_tag");
str tt_col_s_method = str_init("s_method");
Expand Down Expand Up @@ -455,6 +458,11 @@ int tps_db_insert_dialog(tps_data_t *td)
db_vals[nr_keys].val.str_val = TPS_STRZ(td->b_rr);
nr_keys++;

db_keys[nr_keys] = &td_col_s_rr;
db_vals[nr_keys].type = DB1_STR;
db_vals[nr_keys].val.str_val = TPS_STRZ(td->s_rr);
nr_keys++;

db_keys[nr_keys] = &td_col_iflags;
db_vals[nr_keys].type = DB1_INT;
db_vals[nr_keys].val.int_val = td->iflags;
Expand Down Expand Up @@ -595,6 +603,16 @@ int tps_db_insert_branch(tps_data_t *td)
db_vals[nr_keys].val.str_val = TPS_STRZ(td->x_rr);
nr_keys++;

db_keys[nr_keys] = &tt_col_y_rr;
db_vals[nr_keys].type = DB1_STR;
db_vals[nr_keys].val.str_val = TPS_STRZ(td->y_rr);
nr_keys++;

db_keys[nr_keys] = &tt_col_s_rr;
db_vals[nr_keys].type = DB1_STR;
db_vals[nr_keys].val.str_val = TPS_STRZ(td->s_rr);
nr_keys++;

db_keys[nr_keys] = &tt_col_x_uri;
db_vals[nr_keys].type = DB1_STR;
db_vals[nr_keys].val.str_val = TPS_STRZ(td->x_uri);
Expand Down Expand Up @@ -743,6 +761,8 @@ int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
db_cols[nr_cols++] = &tt_col_x_via;
db_cols[nr_cols++] = &tt_col_x_vbranch;
db_cols[nr_cols++] = &tt_col_x_rr;
db_cols[nr_cols++] = &tt_col_y_rr;
db_cols[nr_cols++] = &tt_col_s_rr;
db_cols[nr_cols++] = &tt_col_x_uri;
db_cols[nr_cols++] = &tt_col_x_tag;
db_cols[nr_cols++] = &tt_col_s_method;
Expand Down Expand Up @@ -776,6 +796,8 @@ int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_via); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_vbranch1); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_rr); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->y_rr); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_rr); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_uri); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->x_tag); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_method); n++;
Expand Down Expand Up @@ -832,6 +854,7 @@ int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
db_cols[nr_cols++] = &td_col_b_tag;
db_cols[nr_cols++] = &td_col_a_rr;
db_cols[nr_cols++] = &td_col_b_rr;
db_cols[nr_cols++] = &td_col_s_rr;
db_cols[nr_cols++] = &td_col_iflags;
db_cols[nr_cols++] = &td_col_a_uri;
db_cols[nr_cols++] = &td_col_b_uri;
Expand Down Expand Up @@ -874,6 +897,7 @@ int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_tag); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_rr); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_rr); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->s_rr); n++;
n++; /*iflags*/
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->a_uri); n++;
TPS_DATA_APPEND_DB(sd, db_res, n, &sd->b_uri); n++;
Expand Down
2 changes: 2 additions & 0 deletions modules/topos/tps_storage.h
Expand Up @@ -43,6 +43,7 @@ typedef struct tps_data {
str a_callid;
str a_rr;
str b_rr;
str s_rr;
str a_contact;
str b_contact;
str as_contact;
Expand All @@ -60,6 +61,7 @@ typedef struct tps_data {
str x_via;
str x_tag;
str x_rr;
str y_rr;
str x_uri;
str s_method;
str s_cseq;
Expand Down

0 comments on commit a215b92

Please sign in to comment.