Module: sip-router Branch: master Commit: 8248a1b2ed725933f84a343b4936ed4fdef4a869 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8248a1b2...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Thu Jul 4 22:27:32 2013 +0200
core: helper function to generate sip reply content without removing top via
---
msg_translator.c | 45 ++++++++++++++++++++++++++++----------------- msg_translator.h | 2 ++ 2 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/msg_translator.c b/msg_translator.c index c1ae7c9..b7d4894 100644 --- a/msg_translator.c +++ b/msg_translator.c @@ -1956,8 +1956,8 @@ error00:
-char * build_res_buf_from_sip_res( struct sip_msg* msg, - unsigned int *returned_len) +char * generate_res_buf_from_sip_res( struct sip_msg* msg, + unsigned int *returned_len, unsigned int mode) { unsigned int new_len, via_len, body_delta; char* new_buf; @@ -1968,13 +1968,19 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg, buf=msg->buf; len=msg->len; new_buf=0; - /* we must remove the first via */ - if (msg->via1->next) { - via_len=msg->via1->bsize; - via_offset=msg->h_via1->body.s-buf; + + if(unlikely(mode&BUILD_NO_VIA1_UPDATE)) { + via_len = 0; + via_offset = 0; } else { - via_len=msg->h_via1->len; - via_offset=msg->h_via1->name.s-buf; + /* we must remove the first via */ + if (msg->via1->next) { + via_len=msg->via1->bsize; + via_offset=msg->h_via1->body.s-buf; + } else { + via_len=msg->h_via1->len; + via_offset=msg->h_via1->name.s-buf; + } }
/* Calculate message body difference and adjust @@ -1983,16 +1989,16 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg, body_delta = lumps_len(msg, msg->body_lumps, 0); if (adjust_clen(msg, body_delta, (msg->via2? msg->via2->proto:PROTO_UDP)) < 0) { - LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: Error while adjusting" - " Content-Length\n"); + LOG(L_ERR, "error while adjusting Content-Length\n"); goto error; }
- /* remove the first via*/ - if (del_lump( msg, via_offset, via_len, HDR_VIA_T)==0){ - LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first" - "via\n"); - goto error; + if(likely(!(mode&BUILD_NO_VIA1_UPDATE))) { + /* remove the first via*/ + if (del_lump( msg, via_offset, via_len, HDR_VIA_T)==0){ + LOG(L_ERR, "error trying to remove first via\n"); + goto error; + } }
new_len=len+body_delta+lumps_len(msg, msg->add_rm, 0); /*FIXME: we don't @@ -2002,7 +2008,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg, new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging (\0 to print it )*/ if (new_buf==0){ - LOG(L_ERR, "ERROR: build_res_buf_from_sip_res: out of mem\n"); + LOG(L_ERR, "out of mem\n"); goto error; } new_buf[new_len]=0; /* debug: print the message */ @@ -2015,7 +2021,7 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg, buf+s_offset, len-s_offset); /* send it! */ - DBG("build_res_from_sip_res: copied size: orig:%d, new: %d, rest: %d" + DBG("copied size: orig:%d, new: %d, rest: %d" " msg=\n%s\n", s_offset, offset, len-s_offset, new_buf);
*returned_len=new_len; @@ -2025,6 +2031,11 @@ error: return 0; }
+char * build_res_buf_from_sip_res( struct sip_msg* msg, + unsigned int *returned_len) +{ + return generate_res_buf_from_sip_res(msg, returned_len, 0); +}
char * build_res_buf_from_sip_req( unsigned int code, str *text ,str *new_tag, struct sip_msg* msg, unsigned int *returned_len, struct bookmark *bmark) diff --git a/msg_translator.h b/msg_translator.h index 33caa40..4848291 100644 --- a/msg_translator.h +++ b/msg_translator.h @@ -87,6 +87,8 @@ char * build_req_buf_from_sip_req(struct sip_msg* msg, char * build_res_buf_from_sip_res(struct sip_msg* msg, unsigned int *returned_len);
+char * generate_res_buf_from_sip_res(struct sip_msg* msg, + unsigned int *returned_len, unsigned int mode);
char * build_res_buf_from_sip_req(unsigned int code, str *text,