Beispiel #1
0
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;
}
Beispiel #2
0
int dlg_th_post_raw(str *data)
{
	struct sip_msg msg;
	struct dlg_cell *dlg; 

	dlg = get_current_dialog(); 
	if (dlg == NULL || (dlg->flags & DLG_FLAG_TOPH_HIDE_CALLID) == 0 ) {
		/* dialog module not involved or not callid topo hiding
		 - let is pass freely */
		return 0;
	}

	memset(&msg,0,sizeof(struct sip_msg));
	msg.buf=data->s;
	msg.len=data->len;
	if (dlg_th_callid_pre_parse(&msg,1) < 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 (get_from(&msg)->tag_value.len != 0) {
				if (memcmp(get_from(&msg)->tag_value.s,
				dlg->legs[0].tag.s,dlg->legs[0].tag.len) == 0) {
					/* request from caller -  need to encode callid */
					if (dlg_th_encode_callid(&msg) < 0) {
						LM_ERR("Failed to mask callid for initial request\n");
						goto error;
					}
					goto rebuild_req;
				} else {
					/* let request go through - was decoded on the in side */
				}
			} else {
				/* no from tag in request - kinda foobar ? - let it through */
				goto done;
			}
		} else {
			/* initial request, mask callid */
			if (dlg_th_encode_callid(&msg) < 0) {
				LM_ERR("Failed to mask callid for initial request\n");
				goto error;
			}
			goto rebuild_req;
		}
	} else if (msg.first_line.type==SIP_REPLY) {
		/* we need to look at the direction */
		if (get_from(&msg)->tag_value.len != 0) {
			if (memcmp(get_from(&msg)->tag_value.s,
			dlg->legs[0].tag.s,dlg->legs[0].tag.len) == 0) {
				/* reply going to caller - 
				decode was done on the receiving end, let it unchanged */
			} else {
				/* reply going to callee , need to encode callid */
				if (dlg_th_encode_callid(&msg) < 0) {
					LM_ERR("Failed to decode callid for reply\n");
					goto error;
				}
				goto rebuild_rpl;
			}
		} else {
			/* no from tag in reply - kinda foobar ? - let it through */
			goto done;
		}
	}

done:
	free_sip_msg(&msg);
	return 0;

rebuild_req:
	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;
}
Beispiel #3
0
int dlg_th_post_raw(str *data)
{
	struct sip_msg msg;
	struct dlg_cell *dlg; 

	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 (parse_from_header(&msg)<0 || msg.from==NULL || get_from(&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 */
			dlg = get_current_dialog(); 
			if (dlg == NULL || (dlg->flags & DLG_FLAG_TOPH_HIDE_CALLID) == 0 ) {
				/* dialog module not involved or not callid topo hiding
				 - let is pass freely */
			} else {
				if (get_from(&msg)->tag_value.len != 0) {
					if (memcmp(get_from(&msg)->tag_value.s,
					dlg->legs[0].tag.s,dlg->legs[0].tag.len) == 0) {
						/* request from caller -  need to encode callid */
						if (dlg_th_encode_callid(&msg) < 0) {
							LM_ERR("Failed to mask callid for initial request \n");
							goto error;
						}
						goto rebuild_req;
					} else {
						/* let request go through - was decoded on the in side */
					}
				} else {
					/* no from tag in request - kinda foobar ? - let it through */
				}
			}
		} else {
			/* initial request */
			dlg = get_current_dialog(); 
			if (dlg == NULL || (dlg->flags & DLG_FLAG_TOPH_HIDE_CALLID) == 0 ) {
				/* dialog module not involved or not callid topo hiding
				 - let is pass freely */
			} else {
				/* mask callid */
				if (dlg_th_encode_callid(&msg) < 0) {
					LM_ERR("Failed to mask callid for initial request \n");
					goto error;
				}
				goto rebuild_req;
			}	
		}
	} else if (msg.first_line.type==SIP_REPLY) {
		/* we need to look at the direction */
		dlg = get_current_dialog(); 
		if (dlg == NULL || (dlg->flags & DLG_FLAG_TOPH_HIDE_CALLID) == 0 ) {
			/* dialog module not involved or not callid topo hiding
			 - let is pass freely */
		} else {
			if (get_from(&msg)->tag_value.len != 0) {
				if (memcmp(get_from(&msg)->tag_value.s,
				dlg->legs[0].tag.s,dlg->legs[0].tag.len) == 0) {
					/* reply going to caller - 
					decode was done on the receiving end, let it unchanged */
				} else {
					/* reply going to callee , need to encode callid */
					if (dlg_th_encode_callid(&msg) < 0) {
						LM_ERR("Failed to decode callid for reply \n");
						goto error;
					}
					goto rebuild_rpl;
				}
			} else {
				/* no from tag in reply - kinda foobar ? - let it through */
			}
		}
	}

	free_sip_msg(&msg);
	return 0;

rebuild_req:
	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;
}
Beispiel #4
0
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;
}