| 319 | |
| 320 | |
| 321 | char* clen_builder(struct sip_msg* msg, int *clen_len, int diff) |
| 322 | { |
| 323 | char *buf, * value_s; |
| 324 | int len, value, value_len; |
| 325 | str body; |
| 326 | |
| 327 | if ( (get_body(msg,&body)!=0) ) { |
| 328 | ser_error=E_BAD_REQ; |
| 329 | LM_ERR("no message body found (missing crlf?)"); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* with SDP ops, the body len is fully known (ignore diff) */ |
| 334 | value = body.len + (have_sdp_ops(msg) ? 0 : diff); |
| 335 | value_s=int2str(value, &value_len); |
| 336 | LM_DBG("content-length: %d (%s)\n", value, value_s); |
| 337 | |
| 338 | len=CONTENT_LENGTH_LEN+value_len+CRLF_LEN; |
| 339 | buf=pkg_malloc(sizeof(char)*(len+1)); |
| 340 | if (buf==0){ |
| 341 | ser_error=E_OUT_OF_MEM; |
| 342 | LM_ERR("out of pkg memory\n"); |
| 343 | return 0; |
| 344 | } |
| 345 | memcpy(buf, CONTENT_LENGTH, CONTENT_LENGTH_LEN); |
| 346 | memcpy(buf+CONTENT_LENGTH_LEN, value_s, value_len); |
| 347 | memcpy(buf+CONTENT_LENGTH_LEN+value_len, CRLF, CRLF_LEN); |
| 348 | buf[len]=0; /* null terminate it */ |
| 349 | *clen_len=len; |
| 350 | return buf; |
| 351 | } |
| 352 | |
| 353 | |
| 354 |
no test coverage detected