! \brief removes first via & sends msg to the second */
| 492 | |
| 493 | /*! \brief removes first via & sends msg to the second */ |
| 494 | int forward_reply(struct sip_msg* msg) |
| 495 | { |
| 496 | char* new_buf; |
| 497 | union sockaddr_union* to; |
| 498 | unsigned int new_len; |
| 499 | struct sr_module *mod; |
| 500 | int proto; |
| 501 | unsigned int id; /* used only by tcp*/ |
| 502 | const struct socket_info *send_sock; |
| 503 | char* s; |
| 504 | int len; |
| 505 | |
| 506 | to=0; |
| 507 | id=0; |
| 508 | new_buf=0; |
| 509 | /*check if first via host = us */ |
| 510 | if (check_via){ |
| 511 | if (check_self(&msg->via1->host, |
| 512 | msg->via1->port?msg->via1->port:SIP_PORT, |
| 513 | msg->via1->proto)!=1){ |
| 514 | LM_ERR("host in first via!=me : %.*s:%d\n", |
| 515 | msg->via1->host.len, msg->via1->host.s, msg->via1->port); |
| 516 | /* send error msg back? */ |
| 517 | goto error; |
| 518 | } |
| 519 | } |
| 520 | /* quick hack, slower for multiple modules*/ |
| 521 | for (mod=modules;mod;mod=mod->next){ |
| 522 | if ((mod->exports) && (mod->exports->response_f)){ |
| 523 | LM_DBG("found module %s, passing reply to it\n", |
| 524 | mod->exports->name); |
| 525 | if (mod->exports->response_f(msg)==0) goto skip; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | /* if stateless fwd was disabled, we cannot have stateless replies here*/ |
| 530 | if (sl_fwd_disabled) |
| 531 | goto skip; |
| 532 | |
| 533 | /* we have to forward the reply stateless, so we need second via -bogdan*/ |
| 534 | if (parse_headers( msg, HDR_VIA2_F, 0 )==-1 |
| 535 | || (msg->via2==0) || (msg->via2->error!=PARSE_OK)) |
| 536 | { |
| 537 | /* no second via => error */ |
| 538 | LM_ERR("no 2nd via found in [%.*s] [%.*s] reply from [%s] for callid [%.*s]\n", |
| 539 | msg->first_line.u.reply.status.len, msg->first_line.u.reply.status.s, |
| 540 | msg->cseq->body.len, msg->cseq->body.s, |
| 541 | ip_addr2a(&msg->rcv.src_ip), |
| 542 | msg->callid->body.len, msg->callid->body.s); |
| 543 | goto error; |
| 544 | } |
| 545 | |
| 546 | to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union)); |
| 547 | if (to==0){ |
| 548 | LM_ERR("out of pkg memory\n"); |
| 549 | goto error; |
| 550 | } |
| 551 |
no test coverage detected