Skip to content

Commit

Permalink
rtjson: proper access to items in routes array
Browse files Browse the repository at this point in the history
- more debug messages to show the internal operations

(cherry picked from commit 8025761)
  • Loading branch information
miconda committed Jun 24, 2015
1 parent c6b64b2 commit f1a39a6
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions modules/rtjson/rtjson_routing.c
Expand Up @@ -312,24 +312,27 @@ int rtjson_push_routes(sip_msg_t *msg)
*/
int rtjson_init_serial(sip_msg_t *msg, srjson_doc_t *jdoc, sr_xavp_t *iavp)
{
srjson_t *tj = NULL;
srjson_t *nj = NULL;
srjson_t *rj = NULL;
str val;
unsigned int bflags = 0;
unsigned int old_bflags = 0;

nj = srjson_GetObjectItem(jdoc, jdoc->root, "routes");
if(nj==NULL || nj->type!=srjson_Array || nj->child==NULL) {
tj = srjson_GetObjectItem(jdoc, jdoc->root, "routes");
if(tj==NULL || tj->type!=srjson_Array || tj->child==NULL) {
LM_ERR("missing or invalid routes field\n");
goto error;
}
nj = tj->child;

clear_branches();

rj = srjson_GetObjectItem(jdoc, nj, "uri");
if(rj!=NULL && rj->type==srjson_String && rj->valuestring!=NULL) {
val.s = rj->valuestring;
val.len = strlen(val.s);
LM_DBG("rewrite r-uri to: [%.*s]\n", val.len, val.s);
if (rewrite_uri(msg, &val) < 0) {
LM_ERR("unable to rewrite Request-URI\n");
goto error;
Expand All @@ -349,6 +352,7 @@ int rtjson_init_serial(sip_msg_t *msg, srjson_doc_t *jdoc, sr_xavp_t *iavp)
if(rj!=NULL && rj->type==srjson_String && rj->valuestring!=NULL) {
val.s = rj->valuestring;
val.len = strlen(val.s);
LM_DBG("rewrite dst-uri to: [%.*s]\n", val.len, val.s);
if (set_dst_uri(msg, &val) < 0) {
LM_ERR("unable to set destination uri\n");
goto error;
Expand All @@ -359,6 +363,7 @@ int rtjson_init_serial(sip_msg_t *msg, srjson_doc_t *jdoc, sr_xavp_t *iavp)
if(rj!=NULL && rj->type==srjson_String && rj->valuestring!=NULL) {
val.s = rj->valuestring;
val.len = strlen(val.s);
LM_DBG("rewrite path to: [%.*s]\n", val.len, val.s);
if (set_path_vector(msg, &val) < 0) {
LM_ERR("unable to set path\n");
goto error;
Expand Down Expand Up @@ -423,6 +428,7 @@ int rtjson_prepare_branch(sip_msg_t *msg, srjson_doc_t *jdoc, srjson_t *nj)
}

if(xhdr.len>4) {
LM_DBG("appending extra headers: [%.*s]\n", xhdr.len, xhdr.s);
anchor = anchor_lump(msg, msg->unparsed - msg->buf, 0, 0);
if(anchor == 0) {
LM_ERR("can't get anchor\n");
Expand Down Expand Up @@ -532,14 +538,16 @@ int rtjson_append_branch(sip_msg_t *msg, srjson_doc_t *jdoc, srjson_t *nj)
*/
int rtjson_init_parallel(sip_msg_t *msg, srjson_doc_t *jdoc, sr_xavp_t *iavp)
{
srjson_t *tj = NULL;
srjson_t *nj = NULL;
int ret;

nj = srjson_GetObjectItem(jdoc, jdoc->root, "routes");
if(nj==NULL || nj->type!=srjson_Array || nj->child==NULL) {
tj = srjson_GetObjectItem(jdoc, jdoc->root, "routes");
if(tj==NULL || tj->type!=srjson_Array || tj->child==NULL) {
LM_ERR("missing or invalid routes field\n");
goto error;
}
nj = tj->child;

ret = rtjson_init_serial(msg, jdoc, iavp);
if(ret<0)
Expand Down Expand Up @@ -569,6 +577,7 @@ int rtjson_next_route(sip_msg_t *msg)
sr_xavp_t *javp = NULL;
sr_xavp_t *iavp = NULL;
srjson_doc_t tdoc;
srjson_t *tj = NULL;
srjson_t *nj = NULL;
str val;
str xname;
Expand Down Expand Up @@ -612,11 +621,12 @@ int rtjson_next_route(sip_msg_t *msg)
goto error;
}

nj = srjson_GetObjectItem(&tdoc, tdoc.root, "routes");
if(nj==NULL || nj->type!=srjson_Array || nj->child==NULL) {
tj = srjson_GetObjectItem(&tdoc, tdoc.root, "routes");
if(tj==NULL || tj->type!=srjson_Array || tj->child==NULL) {
LM_ERR("missing or invalid routes field\n");
goto error;
}
nj = tj->child;

i = 0;
while(nj && i<iavp->val.v.i) {
Expand Down Expand Up @@ -646,6 +656,7 @@ int rtjson_update_branch(sip_msg_t *msg)
sr_xavp_t *javp = NULL;
sr_xavp_t *iavp = NULL;
srjson_doc_t tdoc;
srjson_t *tj = NULL;
srjson_t *nj = NULL;
str val;
str xname;
Expand Down Expand Up @@ -689,11 +700,12 @@ int rtjson_update_branch(sip_msg_t *msg)
goto error;
}

nj = srjson_GetObjectItem(&tdoc, tdoc.root, "routes");
if(nj==NULL || nj->type!=srjson_Array || nj->child==NULL) {
tj = srjson_GetObjectItem(&tdoc, tdoc.root, "routes");
if(tj==NULL || tj->type!=srjson_Array || tj->child==NULL) {
LM_ERR("missing or invalid routes field\n");
goto error;
}
nj = tj->child;

i = 0;
while(nj && i<iavp->val.v.i) {
Expand Down

0 comments on commit f1a39a6

Please sign in to comment.