int dlg_th_pre_raw(str *data) { struct sip_msg msg; memset(&msg,0,sizeof(struct sip_msg)); msg.buf=data->s; msg.len=data->len; if (dlg_th_callid_pre_parse(&msg,0) < 0) goto done; if (msg.first_line.type==SIP_REQUEST) { if (get_to(&msg)->tag_value.len>0) { /* sequential request, check if callid needs to be unmasked */ if (dlg_th_needs_decoding(&msg)) { if (dlg_th_decode_callid(&msg) < 0) { LM_ERR("Failed to decode callid for sequential request\n"); goto error; } goto rebuild_msg; } } else { /* initial request, don't do anything callid masking will be done on the out side */ } } else if (msg.first_line.type==SIP_REPLY) { /* we might need to decode callid if mangled */ if (dlg_th_needs_decoding(&msg)) { if (dlg_th_decode_callid(&msg) < 0) { LM_ERR("Failed to decode callid for reply\n"); goto error; } goto rebuild_rpl; } else { /* encoding will be done on the out side */ } } else { /* non sip, most likely, let it through */ return 0; } done: free_sip_msg(&msg); return 0; rebuild_msg: data->s = dlg_th_rebuild_req(&msg,&data->len); free_sip_msg(&msg); return 0; rebuild_rpl: data->s = dlg_th_rebuild_rpl(&msg,&data->len); free_sip_msg(&msg); return 0; error: free_sip_msg(&msg); return -1; }
int dlg_th_pre_raw(str *data) { struct sip_msg msg; memset(&msg,0,sizeof(struct sip_msg)); msg.buf=data->s; msg.len=data->len; if (parse_msg(msg.buf,msg.len,&msg)!=0) { LM_ERR("Invalid SIP msg \n"); goto error; } if (parse_headers(&msg,HDR_EOH_F,0)<0) { LM_ERR("Failed to parse SIP headers\n"); goto error; } if (msg.cseq==NULL || get_cseq(&msg)==NULL) { LM_ERR("Failed to parse CSEQ header \n"); goto error; } if((get_cseq(&msg)->method_id)&MSG_SKIP_BITMASK) { LM_DBG("Skipping %d for DLG callid topo hiding\n",get_cseq(&msg)->method_id); goto error; } if (parse_to_header(&msg)<0 || msg.to==NULL || get_to(&msg)==NULL) { LM_ERR("cannot parse TO header\n"); goto error; } if (msg.first_line.type==SIP_REQUEST) { if (get_to(&msg)->tag_value.len>0) { /* sequential request, check if callid needs to be unmasked */ if (dlg_th_needs_decoding(&msg)) { if (dlg_th_decode_callid(&msg) < 0) { LM_ERR("Failed to decode callid for sequential request \n"); goto error; } goto rebuild_msg; } } else { /* initial request, don't do anything callid masking will be done on the out side */ } } else if (msg.first_line.type==SIP_REPLY) { /* we might need to decode callid if mangled */ if (dlg_th_needs_decoding(&msg)) { if (dlg_th_decode_callid(&msg) < 0) { LM_ERR("Failed to decode callid for reply \n"); goto error; } goto rebuild_rpl; } else { /* encoding will be done on the out side */ } } else { /* non sip, most likely, let it through */ return 0; } free_sip_msg(&msg); return 0; rebuild_msg: data->s = dlg_th_rebuild_req(&msg,&data->len); free_sip_msg(&msg); return 0; rebuild_rpl: data->s = dlg_th_rebuild_rpl(&msg,&data->len); free_sip_msg(&msg); return 0; error: free_sip_msg(&msg); return -1; }