| 3070 | static struct hdr_field callid_hdr, from_hdr, to_hdr; |
| 3071 | |
| 3072 | static int build_extra_headers_from_msg(str buf, str *extra_hdr, |
| 3073 | str *new_hdrs, str *body) |
| 3074 | { |
| 3075 | struct sip_msg req; |
| 3076 | struct hdr_field *hdr; |
| 3077 | int len; |
| 3078 | char *p; |
| 3079 | |
| 3080 | memset( &req, 0, sizeof(req) ); |
| 3081 | req.buf = buf.s; |
| 3082 | req.len = buf.len; |
| 3083 | if (parse_msg(buf.s, buf.len, &req)!=0) { |
| 3084 | LM_CRIT("BUG - buffer parsing failed!\n"); |
| 3085 | return -1; |
| 3086 | } |
| 3087 | /* parse all headers */ |
| 3088 | if (parse_headers(&req, HDR_EOH_F, 0 )<0) { |
| 3089 | LM_ERR("parse_headers failed\n"); |
| 3090 | goto error; |
| 3091 | } |
| 3092 | |
| 3093 | /* first calculate the total len */ |
| 3094 | len = extra_hdr->len; |
| 3095 | for( hdr=req.headers; hdr ; hdr=hdr->next ) { |
| 3096 | /* skip all headers that are by default added by build_uac_req() |
| 3097 | * We want to propagete only custom headers !!! */ |
| 3098 | switch(hdr->type){ |
| 3099 | case HDR_VIA_T: |
| 3100 | case HDR_TO_T: |
| 3101 | case HDR_FROM_T: |
| 3102 | case HDR_ROUTE_T: |
| 3103 | case HDR_CSEQ_T: |
| 3104 | case HDR_CALLID_T: |
| 3105 | case HDR_MAXFORWARDS_T: |
| 3106 | case HDR_CONTENTLENGTH_T: |
| 3107 | case HDR_USERAGENT_T: |
| 3108 | break; |
| 3109 | default: |
| 3110 | /* count the header (includes the CRLF) */ |
| 3111 | len += hdr->len; |
| 3112 | } |
| 3113 | } |
| 3114 | |
| 3115 | /* allocate */ |
| 3116 | new_hdrs->len = len; |
| 3117 | new_hdrs->s = pkg_malloc( len ); |
| 3118 | if (new_hdrs->s==NULL) { |
| 3119 | LM_ERR("failed to allocate pkg mem (needed %d)\n",len); |
| 3120 | goto error; |
| 3121 | } |
| 3122 | |
| 3123 | /* copy headers */ |
| 3124 | for( p=new_hdrs->s,hdr=req.headers; hdr ; hdr=hdr->next ) { |
| 3125 | switch(hdr->type){ |
| 3126 | case HDR_VIA_T: |
| 3127 | case HDR_TO_T: |
| 3128 | case HDR_FROM_T: |
| 3129 | case HDR_ROUTE_T: |
no test coverage detected