|
@@ -53,7 +53,8 @@
|
|
* build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
|
|
* build_req_fomr_sip_req no longer adds 1 for ipv6 via parameter
|
|
* position calculations ([] are part of host.s now) (andrei)
|
|
* position calculations ([] are part of host.s now) (andrei)
|
|
* 2003-10-02 via+lump dst address/port can be set to preset values (andrei)
|
|
* 2003-10-02 via+lump dst address/port can be set to preset values (andrei)
|
|
- * 2003-10-08 receive_test function-alized (jiri)
|
|
|
|
|
|
+ * 2003-10-08 receive_test function-alized (jiri)
|
|
|
|
+ * 2003-10-20 added body_lump list (sip_msg), adjust_clen (andrei & jan)
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
/* Via special params:
|
|
/* Via special params:
|
|
@@ -121,6 +122,7 @@
|
|
#include "dprint.h"
|
|
#include "dprint.h"
|
|
#include "config.h"
|
|
#include "config.h"
|
|
#include "md5utils.h"
|
|
#include "md5utils.h"
|
|
|
|
+#include "data_lump.h"
|
|
#include "data_lump_rpl.h"
|
|
#include "data_lump_rpl.h"
|
|
#include "ip_addr.h"
|
|
#include "ip_addr.h"
|
|
#include "resolve.h"
|
|
#include "resolve.h"
|
|
@@ -394,7 +396,7 @@ char* id_builder(struct sip_msg* msg, unsigned int *id_len)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
|
|
|
|
|
|
+char* clen_builder(struct sip_msg* msg, unsigned int *clen_len, int diff)
|
|
{
|
|
{
|
|
char* buf;
|
|
char* buf;
|
|
int len;
|
|
int len;
|
|
@@ -411,7 +413,7 @@ char* clen_builder(struct sip_msg* msg, unsigned int *clen_len)
|
|
" (missing crlf?)");
|
|
" (missing crlf?)");
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
- value=msg->len-(int)(body-msg->buf);
|
|
|
|
|
|
+ value=msg->len-(int)(body-msg->buf)+diff;
|
|
value_s=int2str(value, &value_len);
|
|
value_s=int2str(value, &value_len);
|
|
DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
|
|
DBG("clen_builder: content-length: %d (%s)\n", value, value_s);
|
|
|
|
|
|
@@ -499,7 +501,7 @@ static inline int lump_check_opt( enum lump_conditions cond,
|
|
|
|
|
|
/* computes the "unpacked" len of a lump list,
|
|
/* computes the "unpacked" len of a lump list,
|
|
code moved from build_req_from_req */
|
|
code moved from build_req_from_req */
|
|
-static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
|
|
|
|
|
|
+static inline int lumps_len(struct sip_msg* msg, struct lump* lumps, struct socket_info* send_sock)
|
|
{
|
|
{
|
|
int s_offset;
|
|
int s_offset;
|
|
int new_len;
|
|
int new_len;
|
|
@@ -672,7 +674,7 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
|
|
send_port_str=&(send_sock->port_no_str);
|
|
send_port_str=&(send_sock->port_no_str);
|
|
|
|
|
|
|
|
|
|
- for(t=msg->add_rm;t;t=t->next){
|
|
|
|
|
|
+ for(t=lumps;t;t=t->next){
|
|
/* skip if this is an OPT lump and the condition is not satisfied */
|
|
/* skip if this is an OPT lump and the condition is not satisfied */
|
|
if ((t->op==LUMP_ADD_OPT) && !lump_check_opt(t->u.cond, msg, send_sock))
|
|
if ((t->op==LUMP_ADD_OPT) && !lump_check_opt(t->u.cond, msg, send_sock))
|
|
continue;
|
|
continue;
|
|
@@ -763,7 +765,8 @@ skip_after:
|
|
/* another helper functions, adds/Removes the lump,
|
|
/* another helper functions, adds/Removes the lump,
|
|
code moved form build_req_from_req */
|
|
code moved form build_req_from_req */
|
|
|
|
|
|
-static inline void process_lumps( struct sip_msg* msg,
|
|
|
|
|
|
+static inline void process_lumps( struct sip_msg* msg,
|
|
|
|
+ struct lump* lumps,
|
|
char* new_buf,
|
|
char* new_buf,
|
|
unsigned int* new_buf_offs,
|
|
unsigned int* new_buf_offs,
|
|
unsigned int* orig_offs,
|
|
unsigned int* orig_offs,
|
|
@@ -1027,7 +1030,7 @@ static inline void process_lumps( struct sip_msg* msg,
|
|
offset=*new_buf_offs;
|
|
offset=*new_buf_offs;
|
|
s_offset=*orig_offs;
|
|
s_offset=*orig_offs;
|
|
|
|
|
|
- for (t=msg->add_rm;t;t=t->next){
|
|
|
|
|
|
+ for (t=lumps;t;t=t->next){
|
|
switch(t->op){
|
|
switch(t->op){
|
|
case LUMP_ADD:
|
|
case LUMP_ADD:
|
|
case LUMP_ADD_SUBST:
|
|
case LUMP_ADD_SUBST:
|
|
@@ -1184,12 +1187,109 @@ skip_nop_after:
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * Adjust/insert Content-Length if necesarry
|
|
|
|
+ */
|
|
|
|
+static inline int adjust_clen(struct sip_msg* msg, int body_delta, int proto)
|
|
|
|
+{
|
|
|
|
+ struct lump* anchor;
|
|
|
|
+ char* clen_buf;
|
|
|
|
+ int clen_len;
|
|
|
|
+
|
|
|
|
+ /* Calculate message length difference caused by lumps modifying message
|
|
|
|
+ * body, from this point on the message body must not be modified. Zero
|
|
|
|
+ * value indicates that the body hasn't been modified
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ clen_buf = 0;
|
|
|
|
+ anchor=0;
|
|
|
|
+
|
|
|
|
+ /* check to see if we need to add clen */
|
|
|
|
+#ifdef USE_TCP
|
|
|
|
+ if (proto == PROTO_TCP
|
|
|
|
+#ifdef USE_TLS
|
|
|
|
+ || proto == PROTO_TLS
|
|
|
|
+#endif
|
|
|
|
+ ) {
|
|
|
|
+ if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
|
|
|
|
+ LOG(L_ERR, "adjust_clen: error parsing content-length\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ if (msg->content_length==0){
|
|
|
|
+ /* not present, we need to add it */
|
|
|
|
+ /* msg->unparsed should point just before the final crlf
|
|
|
|
+ * - whole message was parsed by the above parse_headers
|
|
|
|
+ * which did not find content-length */
|
|
|
|
+ anchor=anchor_lump(msg, msg->unparsed-msg->buf, 0,
|
|
|
|
+ HDR_CONTENTLENGTH);
|
|
|
|
+ if (anchor==0){
|
|
|
|
+ LOG(L_ERR, "adjust_clen: cannot set clen anchor\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if ((anchor==0) && body_delta){
|
|
|
|
+ if (parse_headers(msg, HDR_CONTENTLENGTH, 0) == -1) {
|
|
|
|
+ LOG(L_ERR, "adjust_clen: Error parsing Content-Length\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* The body has been changed, try to find
|
|
|
|
+ * existing Content-Length
|
|
|
|
+ */
|
|
|
|
+ /* no need for Content-Length if it's and UDP packet and
|
|
|
|
+ * it hasn't Content-Lentgh already */
|
|
|
|
+ if ((msg->content_length==0)){
|
|
|
|
+ /* content-length doesn't exist, append it */
|
|
|
|
+ /* msg->unparsed should point just before the final crlf
|
|
|
|
+ * - whole message was parsed by the above parse_headers
|
|
|
|
+ * which did not find content-length */
|
|
|
|
+ if (proto!=PROTO_UDP){
|
|
|
|
+ anchor=anchor_lump(msg, msg->unparsed-msg->buf, 0,
|
|
|
|
+ HDR_CONTENTLENGTH);
|
|
|
|
+ if (anchor==0){
|
|
|
|
+ LOG(L_ERR, "adjust_clen: cannot set clen anchor\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ DBG("add_clen: UDP packet with no clen => not adding one \n");
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ /* Content-Length has been found, remove it */
|
|
|
|
+ anchor = del_lump( msg, msg->content_length->name.s - msg->buf,
|
|
|
|
+ msg->content_length->len, HDR_CONTENTLENGTH);
|
|
|
|
+ if (anchor==0) {
|
|
|
|
+ LOG(L_ERR, "adjust_clen: Can't remove original"
|
|
|
|
+ " Content-Length\n");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (anchor){
|
|
|
|
+ clen_buf = clen_builder(msg, &clen_len, body_delta);
|
|
|
|
+ if (!clen_buf) goto error;
|
|
|
|
+ if (insert_new_lump_after(anchor, clen_buf, clen_len,
|
|
|
|
+ HDR_CONTENTLENGTH) == 0)
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+error:
|
|
|
|
+ if (clen_buf) pkg_free(clen_buf);
|
|
|
|
+ return -1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
char * build_req_buf_from_sip_req( struct sip_msg* msg,
|
|
char * build_req_buf_from_sip_req( struct sip_msg* msg,
|
|
unsigned int *returned_len,
|
|
unsigned int *returned_len,
|
|
struct socket_info* send_sock, int proto)
|
|
struct socket_info* send_sock, int proto)
|
|
{
|
|
{
|
|
- unsigned int len, new_len, received_len, rport_len, uri_len, via_len;
|
|
|
|
|
|
+ unsigned int len, new_len, received_len, rport_len, uri_len, via_len, body_delta;
|
|
char* line_buf;
|
|
char* line_buf;
|
|
char* received_buf;
|
|
char* received_buf;
|
|
char* rport_buf;
|
|
char* rport_buf;
|
|
@@ -1201,18 +1301,14 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
|
|
str branch;
|
|
str branch;
|
|
str extra_params;
|
|
str extra_params;
|
|
struct hostport hp;
|
|
struct hostport hp;
|
|
-
|
|
|
|
|
|
+
|
|
#ifdef USE_TCP
|
|
#ifdef USE_TCP
|
|
char* id_buf;
|
|
char* id_buf;
|
|
unsigned int id_len;
|
|
unsigned int id_len;
|
|
- char* clen_buf;
|
|
|
|
- unsigned int clen_len;
|
|
|
|
|
|
|
|
|
|
|
|
id_buf=0;
|
|
id_buf=0;
|
|
id_len=0;
|
|
id_len=0;
|
|
- clen_buf=0;
|
|
|
|
- clen_len=0;
|
|
|
|
#endif
|
|
#endif
|
|
via_insert_param=0;
|
|
via_insert_param=0;
|
|
extra_params.len=0;
|
|
extra_params.len=0;
|
|
@@ -1226,7 +1322,6 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
|
|
received_buf=0;
|
|
received_buf=0;
|
|
rport_buf=0;
|
|
rport_buf=0;
|
|
line_buf=0;
|
|
line_buf=0;
|
|
-
|
|
|
|
|
|
|
|
#ifdef USE_TCP
|
|
#ifdef USE_TCP
|
|
/* add id if tcp */
|
|
/* add id if tcp */
|
|
@@ -1246,31 +1341,17 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
|
|
extra_params.s=id_buf;
|
|
extra_params.s=id_buf;
|
|
extra_params.len=id_len;
|
|
extra_params.len=id_len;
|
|
}
|
|
}
|
|
- /* if sending proto == tcp, check if Content-Length needs to be added*/
|
|
|
|
- if (proto==PROTO_TCP
|
|
|
|
-#ifdef USE_TLS
|
|
|
|
- || proto==PROTO_TLS
|
|
|
|
#endif
|
|
#endif
|
|
- ){
|
|
|
|
- DBG("build_req_from_req: checking for clen; proto=%d,"
|
|
|
|
- " rcv->proto=%d\n", proto, msg->rcv.proto);
|
|
|
|
- /* first of all parse content-length */
|
|
|
|
- if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
|
|
|
|
- LOG(L_ERR, "build_req_buf_from_sip_req:"
|
|
|
|
- " error parsing content-length\n");
|
|
|
|
- goto skip_clen;
|
|
|
|
- }
|
|
|
|
- if (msg->content_length==0){
|
|
|
|
- /* we need to add it */
|
|
|
|
- if ((clen_buf=clen_builder(msg, &clen_len))==0){
|
|
|
|
- LOG(L_ERR, "build_req_buf_from_sip_req:"
|
|
|
|
- " clen_builder failed\n");
|
|
|
|
- goto skip_clen;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ /* Calculate message body difference and adjust
|
|
|
|
+ * Content-Length
|
|
|
|
+ */
|
|
|
|
+ body_delta = lumps_len(msg, msg->body_lumps, send_sock);
|
|
|
|
+ if (adjust_clen(msg, body_delta, proto) < 0) {
|
|
|
|
+ LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: Error while adjusting"
|
|
|
|
+ " Content-Length\n");
|
|
|
|
+ goto error00;
|
|
}
|
|
}
|
|
-skip_clen:
|
|
|
|
-#endif
|
|
|
|
|
|
+
|
|
branch.s=msg->add_to_branch_s;
|
|
branch.s=msg->add_to_branch_s;
|
|
branch.len=msg->add_to_branch_len;
|
|
branch.len=msg->add_to_branch_len;
|
|
set_hostport(&hp, msg);
|
|
set_hostport(&hp, msg);
|
|
@@ -1306,7 +1387,7 @@ skip_clen:
|
|
/* add via header to the list */
|
|
/* add via header to the list */
|
|
/* try to add it before msg. 1st via */
|
|
/* try to add it before msg. 1st via */
|
|
/* add first via, as an anchor for second via*/
|
|
/* add first via, as an anchor for second via*/
|
|
- anchor=anchor_lump(&(msg->add_rm), msg->via1->hdr.s-buf, 0, HDR_VIA);
|
|
|
|
|
|
+ anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA);
|
|
if (anchor==0) goto error01;
|
|
if (anchor==0) goto error01;
|
|
if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)
|
|
if (insert_new_lump_before(anchor, line_buf, via_len, HDR_VIA)==0)
|
|
goto error01;
|
|
goto error01;
|
|
@@ -1332,11 +1413,11 @@ skip_clen:
|
|
* overwrite the previous one if already present */
|
|
* overwrite the previous one if already present */
|
|
if (received_len){
|
|
if (received_len){
|
|
if (msg->via1->received){ /* received already present => overwrite it*/
|
|
if (msg->via1->received){ /* received already present => overwrite it*/
|
|
- via_insert_param=del_lump(&(msg->add_rm),
|
|
|
|
|
|
+ via_insert_param=del_lump(msg,
|
|
msg->via1->received->start-buf-1, /*;*/
|
|
msg->via1->received->start-buf-1, /*;*/
|
|
msg->via1->received->size+1, /*;*/ HDR_VIA);
|
|
msg->via1->received->size+1, /*;*/ HDR_VIA);
|
|
}else if (via_insert_param==0){ /* receive not present, ok */
|
|
}else if (via_insert_param==0){ /* receive not present, ok */
|
|
- via_insert_param=anchor_lump(&(msg->add_rm),
|
|
|
|
|
|
+ via_insert_param=anchor_lump(msg,
|
|
msg->via1->hdr.s-buf+size,0, HDR_VIA);
|
|
msg->via1->hdr.s-buf+size,0, HDR_VIA);
|
|
}
|
|
}
|
|
if (via_insert_param==0) goto error02; /* free received_buf */
|
|
if (via_insert_param==0) goto error02; /* free received_buf */
|
|
@@ -1346,12 +1427,12 @@ skip_clen:
|
|
/* if rport needs to be updated, delete it if present and add it's value */
|
|
/* if rport needs to be updated, delete it if present and add it's value */
|
|
if (rport_len){
|
|
if (rport_len){
|
|
if (msg->via1->rport){ /* rport already present */
|
|
if (msg->via1->rport){ /* rport already present */
|
|
- via_insert_param=del_lump(&(msg->add_rm),
|
|
|
|
|
|
+ via_insert_param=del_lump(msg,
|
|
msg->via1->rport->start-buf-1, /*';'*/
|
|
msg->via1->rport->start-buf-1, /*';'*/
|
|
msg->via1->rport->size+1 /* ; */, HDR_VIA);
|
|
msg->via1->rport->size+1 /* ; */, HDR_VIA);
|
|
}else if (via_insert_param==0){ /*force rport, no rport present */
|
|
}else if (via_insert_param==0){ /*force rport, no rport present */
|
|
/* no rport, add it */
|
|
/* no rport, add it */
|
|
- via_insert_param=anchor_lump(&(msg->add_rm),
|
|
|
|
|
|
+ via_insert_param=anchor_lump(msg,
|
|
msg->via1->hdr.s-buf+size,0, HDR_VIA);
|
|
msg->via1->hdr.s-buf+size,0, HDR_VIA);
|
|
}
|
|
}
|
|
if (via_insert_param==0) goto error03; /* free rport_buf */
|
|
if (via_insert_param==0) goto error03; /* free rport_buf */
|
|
@@ -1360,22 +1441,9 @@ skip_clen:
|
|
goto error03; /* free rport_buf */
|
|
goto error03; /* free rport_buf */
|
|
|
|
|
|
}
|
|
}
|
|
-#ifdef USE_TCP
|
|
|
|
- /* if clen needs to be added, add it */
|
|
|
|
- if (clen_len){
|
|
|
|
- /* msg->unparsed should point just before the final crlf,
|
|
|
|
- * parse_headers is called from clen_builder */
|
|
|
|
- anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0,
|
|
|
|
- HDR_CONTENTLENGTH);
|
|
|
|
- if (anchor==0) goto error04; /* free clen_buf */
|
|
|
|
- if (insert_new_lump_after(anchor, clen_buf, clen_len,
|
|
|
|
- HDR_CONTENTLENGTH)==0)
|
|
|
|
- goto error04; /* free clen_buf*/
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
/* compute new msg len and fix overlapping zones*/
|
|
/* compute new msg len and fix overlapping zones*/
|
|
- new_len=len+lumps_len(msg, send_sock);
|
|
|
|
|
|
+ new_len=len+body_delta+lumps_len(msg, msg->add_rm, send_sock);
|
|
#ifdef XL_DEBUG
|
|
#ifdef XL_DEBUG
|
|
LOG(L_ERR, "DEBUG: new_len(%d)=len(%d)+lumps_len\n", new_len, len);
|
|
LOG(L_ERR, "DEBUG: new_len(%d)=len(%d)+lumps_len\n", new_len, len);
|
|
#endif
|
|
#endif
|
|
@@ -1405,7 +1473,8 @@ skip_clen:
|
|
}
|
|
}
|
|
new_buf[new_len]=0;
|
|
new_buf[new_len]=0;
|
|
/* copy msg adding/removing lumps */
|
|
/* copy msg adding/removing lumps */
|
|
- process_lumps(msg, new_buf, &offset, &s_offset, send_sock);
|
|
|
|
|
|
+ process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, send_sock);
|
|
|
|
+ process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset,send_sock);
|
|
/* copy the rest of the message */
|
|
/* copy the rest of the message */
|
|
memcpy(new_buf+offset, buf+s_offset, len-s_offset);
|
|
memcpy(new_buf+offset, buf+s_offset, len-s_offset);
|
|
new_buf[new_len]=0;
|
|
new_buf[new_len]=0;
|
|
@@ -1431,10 +1500,6 @@ error02:
|
|
if (received_buf) pkg_free(received_buf);
|
|
if (received_buf) pkg_free(received_buf);
|
|
error03:
|
|
error03:
|
|
if (rport_buf) pkg_free(rport_buf);
|
|
if (rport_buf) pkg_free(rport_buf);
|
|
-#ifdef USE_TCP
|
|
|
|
-error04:
|
|
|
|
- if (clen_buf) pkg_free(clen_buf);
|
|
|
|
-#endif
|
|
|
|
error00:
|
|
error00:
|
|
#ifdef USE_TCP
|
|
#ifdef USE_TCP
|
|
if (id_buf) pkg_free(id_buf);
|
|
if (id_buf) pkg_free(id_buf);
|
|
@@ -1448,19 +1513,12 @@ error00:
|
|
char * build_res_buf_from_sip_res( struct sip_msg* msg,
|
|
char * build_res_buf_from_sip_res( struct sip_msg* msg,
|
|
unsigned int *returned_len)
|
|
unsigned int *returned_len)
|
|
{
|
|
{
|
|
- unsigned int new_len, via_len;
|
|
|
|
|
|
+ unsigned int new_len, via_len, body_delta;
|
|
char* new_buf;
|
|
char* new_buf;
|
|
unsigned offset, s_offset, via_offset;
|
|
unsigned offset, s_offset, via_offset;
|
|
char* buf;
|
|
char* buf;
|
|
unsigned int len;
|
|
unsigned int len;
|
|
-#ifdef USE_TCP
|
|
|
|
- struct lump* anchor;
|
|
|
|
- char* clen_buf;
|
|
|
|
- unsigned int clen_len;
|
|
|
|
-
|
|
|
|
- clen_buf=0;
|
|
|
|
- clen_len=0;
|
|
|
|
-#endif
|
|
|
|
|
|
+
|
|
buf=msg->buf;
|
|
buf=msg->buf;
|
|
len=msg->len;
|
|
len=msg->len;
|
|
new_buf=0;
|
|
new_buf=0;
|
|
@@ -1473,57 +1531,26 @@ char * build_res_buf_from_sip_res( struct sip_msg* msg,
|
|
via_offset=msg->h_via1->name.s-buf;
|
|
via_offset=msg->h_via1->name.s-buf;
|
|
}
|
|
}
|
|
|
|
|
|
-#ifdef USE_TCP
|
|
|
|
-
|
|
|
|
- /* if sending proto == tcp, check if Content-Length needs to be added*/
|
|
|
|
- if (msg->via2 && ((msg->via2->proto==PROTO_TCP)
|
|
|
|
-#ifdef USE_TLS
|
|
|
|
- || (msg->via2->proto==PROTO_TLS)
|
|
|
|
-#endif
|
|
|
|
- )){
|
|
|
|
- DBG("build_res_from_sip_res: checking content-length for \n%.*s\n",
|
|
|
|
- (int)msg->len, msg->buf);
|
|
|
|
- /* first of all parse content-length */
|
|
|
|
- if (parse_headers(msg, HDR_CONTENTLENGTH, 0)==-1){
|
|
|
|
- LOG(L_ERR, "build_res_buf_from_sip_res:"
|
|
|
|
- " error parsing content-length\n");
|
|
|
|
- goto skip_clen;
|
|
|
|
- }
|
|
|
|
- if (msg->content_length==0){
|
|
|
|
- DBG("build_res_from_sip_res: no content_length hdr found\n");
|
|
|
|
- /* we need to add it */
|
|
|
|
- if ((clen_buf=clen_builder(msg, &clen_len))==0){
|
|
|
|
- LOG(L_ERR, "build_res_buf_from_sip_res:"
|
|
|
|
- " clen_builder failed\n");
|
|
|
|
- goto skip_clen;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ /* Calculate message body difference and adjust
|
|
|
|
+ * Content-Length
|
|
|
|
+ */
|
|
|
|
+ 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");
|
|
|
|
+ goto error;
|
|
}
|
|
}
|
|
-skip_clen:
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/* remove the first via*/
|
|
/* remove the first via*/
|
|
- if (del_lump( &(msg->add_rm), via_offset, via_len, HDR_VIA)==0){
|
|
|
|
|
|
+ if (del_lump( msg, via_offset, via_len, HDR_VIA)==0){
|
|
LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
|
|
LOG(L_ERR, "build_res_buf_from_sip_res: error trying to remove first"
|
|
"via\n");
|
|
"via\n");
|
|
goto error;
|
|
goto error;
|
|
}
|
|
}
|
|
-#ifdef USE_TCP
|
|
|
|
- /* if clen needs to be added, add it */
|
|
|
|
- if (clen_len){
|
|
|
|
- /* msg->unparsed should point just before the final crlf,
|
|
|
|
- * parse_headers is called from clen_builder */
|
|
|
|
- anchor=anchor_lump(&(msg->add_rm), msg->unparsed-buf, 0,
|
|
|
|
- HDR_CONTENTLENGTH);
|
|
|
|
- DBG("build_res_from_sip_res: adding content-length: %.*s\n",
|
|
|
|
- (int)clen_len, clen_buf);
|
|
|
|
- if (anchor==0) goto error_clen; /* free clen_buf*/
|
|
|
|
- if (insert_new_lump_after(anchor, clen_buf, clen_len,
|
|
|
|
- HDR_CONTENTLENGTH)==0)
|
|
|
|
- goto error_clen; /* free clen_buf*/
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
- new_len=len+lumps_len(msg, 0); /*FIXME: we don't know the send sock */
|
|
|
|
|
|
+
|
|
|
|
+ new_len=len+body_delta+lumps_len(msg, msg->add_rm, 0); /*FIXME: we don't
|
|
|
|
+ know the send sock */
|
|
|
|
|
|
DBG(" old size: %d, new size: %d\n", len, new_len);
|
|
DBG(" old size: %d, new size: %d\n", len, new_len);
|
|
new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging
|
|
new_buf=(char*)pkg_malloc(new_len+1); /* +1 is for debugging
|
|
@@ -1534,7 +1561,9 @@ skip_clen:
|
|
}
|
|
}
|
|
new_buf[new_len]=0; /* debug: print the message */
|
|
new_buf[new_len]=0; /* debug: print the message */
|
|
offset=s_offset=0;
|
|
offset=s_offset=0;
|
|
- process_lumps(msg, new_buf, &offset, &s_offset, 0); /*FIXME: no send sock*/
|
|
|
|
|
|
+ /*FIXME: no send sock*/
|
|
|
|
+ process_lumps(msg, msg->add_rm, new_buf, &offset, &s_offset, 0);/*FIXME:*/
|
|
|
|
+ process_lumps(msg, msg->body_lumps, new_buf, &offset, &s_offset, 0);
|
|
/* copy the rest of the message */
|
|
/* copy the rest of the message */
|
|
memcpy(new_buf+offset,
|
|
memcpy(new_buf+offset,
|
|
buf+s_offset,
|
|
buf+s_offset,
|
|
@@ -1545,10 +1574,6 @@ skip_clen:
|
|
|
|
|
|
*returned_len=new_len;
|
|
*returned_len=new_len;
|
|
return new_buf;
|
|
return new_buf;
|
|
-#ifdef USE_TCP
|
|
|
|
-error_clen:
|
|
|
|
- if (clen_buf) pkg_free(clen_buf);
|
|
|
|
-#endif
|
|
|
|
error:
|
|
error:
|
|
*returned_len=0;
|
|
*returned_len=0;
|
|
return 0;
|
|
return 0;
|