|
@@ -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;
|
|
unsigned int new_len, via_len, body_delta;
|
|
char* new_buf;
|
|
char* new_buf;
|
|
@@ -1968,13 +1968,19 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
|
|
buf=msg->buf;
|
|
buf=msg->buf;
|
|
len=msg->len;
|
|
len=msg->len;
|
|
new_buf=0;
|
|
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 {
|
|
} 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
|
|
/* 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);
|
|
body_delta = lumps_len(msg, msg->body_lumps, 0);
|
|
if (adjust_clen(msg, body_delta, (msg->via2? msg->via2->proto:PROTO_UDP))
|
|
if (adjust_clen(msg, body_delta, (msg->via2? msg->via2->proto:PROTO_UDP))
|
|
< 0) {
|
|
< 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;
|
|
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
|
|
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
|
|
new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging
|
|
(\0 to print it )*/
|
|
(\0 to print it )*/
|
|
if (new_buf==0){
|
|
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;
|
|
goto error;
|
|
}
|
|
}
|
|
new_buf[new_len]=0; /* debug: print the message */
|
|
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,
|
|
buf+s_offset,
|
|
len-s_offset);
|
|
len-s_offset);
|
|
/* send it! */
|
|
/* 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);
|
|
" msg=\n%s\n", s_offset, offset, len-s_offset, new_buf);
|
|
|
|
|
|
*returned_len=new_len;
|
|
*returned_len=new_len;
|
|
@@ -2025,6 +2031,11 @@ error:
|
|
return 0;
|
|
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,
|
|
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)
|
|
struct sip_msg* msg, unsigned int *returned_len, struct bookmark *bmark)
|