* return 0 - restored * -1 - not restored or error */
| 515 | * -1 - not restored or error |
| 516 | */ |
| 517 | int restore_uri( struct sip_msg *msg, int to, int check_from) |
| 518 | { |
| 519 | struct hdr_field *old_hdr; |
| 520 | struct lump* l; |
| 521 | str param_val; |
| 522 | str old_uri, ou; |
| 523 | str new_uri; |
| 524 | str *rr_param; |
| 525 | char *p; |
| 526 | int i; |
| 527 | int flag; |
| 528 | |
| 529 | /* we should process only sequntial request, but since we are looking |
| 530 | * for Route param, the test is not really required -bogdan */ |
| 531 | |
| 532 | rr_param = to ? &rr_to_param : &rr_from_param; |
| 533 | |
| 534 | LM_DBG("getting '%.*s' Route param\n", |
| 535 | rr_param->len,rr_param->s); |
| 536 | /* is there something to restore ? */ |
| 537 | if (uac_rrb.get_route_param( msg, rr_param, ¶m_val)!=0) { |
| 538 | LM_DBG("route param '%.*s' not found\n", |
| 539 | rr_param->len,rr_param->s); |
| 540 | goto failed; |
| 541 | } |
| 542 | LM_DBG("route param is '%.*s' (len=%d)\n", |
| 543 | param_val.len,param_val.s,param_val.len); |
| 544 | |
| 545 | /* decode the parameter val to a URI */ |
| 546 | if (decode_uri( ¶m_val, &new_uri)<0 ) { |
| 547 | LM_ERR("failed to decode uri\n"); |
| 548 | goto failed; |
| 549 | } |
| 550 | |
| 551 | /* dencrypt parameter ;) */ |
| 552 | if (uac_passwd.len) |
| 553 | for( i=0 ; i<new_uri.len ; i++) |
| 554 | new_uri.s[i] ^= uac_passwd.s[i%uac_passwd.len]; |
| 555 | |
| 556 | /* check the request direction */ |
| 557 | if ( (check_from && uac_rrb.is_direction( msg, RR_FLOW_UPSTREAM)==0) || |
| 558 | (!check_from && uac_rrb.is_direction( msg, RR_FLOW_DOWNSTREAM)==0) ) { |
| 559 | /* replace the TO URI */ |
| 560 | if ( msg->to==0 && (parse_headers(msg,HDR_TO_F,0)!=0 || msg->to==0) ) { |
| 561 | LM_ERR("failed to parse TO hdr\n"); |
| 562 | goto failed; |
| 563 | } |
| 564 | ou = old_uri = ((struct to_body*)msg->to->parsed)->uri; |
| 565 | old_hdr = msg->to; |
| 566 | flag = FL_USE_UAC_TO; |
| 567 | } else { |
| 568 | /* replace the FROM URI */ |
| 569 | if ( parse_from_header(msg)<0 ) { |
| 570 | LM_ERR("failed to find/parse FROM hdr\n"); |
| 571 | goto failed; |
| 572 | } |
| 573 | ou = old_uri = ((struct to_body*)msg->from->parsed)->uri; |
| 574 | old_hdr = msg->from; |
no test coverage detected