Example #1
0
int tps_request_sent(sip_msg_t *msg, int dialog, int direction, int local)
{
	tps_data_t mtsd;
	tps_data_t stsd;
	tps_data_t *ptsd;
	str lkey;

	memset(&mtsd, 0, sizeof(tps_data_t));
	memset(&stsd, 0, sizeof(tps_data_t));
	ptsd = &mtsd;

	if(tps_pack_request(msg, &mtsd)<0) {
		LM_ERR("failed to extract and pack the headers\n");
		return -1;
	}

	if(direction==TPS_DIR_DOWNSTREAM) {
		lkey = get_from(msg)->tag_value;
	} else {
		lkey = get_to(msg)->tag_value;
	}
	tps_storage_lock_get(&lkey);
	if(dialog==0) {
		if(tps_storage_record(msg, ptsd)<0) {
			goto error;
		}
	}

	/* local generated requests */
	if(local) {
		/* ACK and CANCEL go downstream */
		if(get_cseq(msg)->method_id==METHOD_ACK
				|| get_cseq(msg)->method_id==METHOD_CANCEL
				|| local==2) {
			// th_mask_callid(&msg);
			goto done;
		} else {
			/* should be for upstream */
			goto done;
		}
	}

	tps_remove_headers(msg, HDR_RECORDROUTE_T);
	tps_remove_headers(msg, HDR_CONTACT_T);
	tps_remove_headers(msg, HDR_VIA_T);

	tps_reinsert_via(msg, ptsd, &ptsd->x_via1);
	if(direction==TPS_DIR_UPSTREAM) {
		tps_reinsert_contact(msg, ptsd, &ptsd->as_contact);
	} else {
		tps_reinsert_contact(msg, ptsd, &ptsd->bs_contact);
	}

done:
	tps_storage_lock_release(&lkey);
	return 0;

error:
	tps_storage_lock_release(&lkey);
	return -1;
}
Example #2
0
int tps_request_sent(sip_msg_t *msg, int dialog, int local)
{
	tps_data_t mtsd;
	tps_data_t btsd;
	tps_data_t stsd;
	tps_data_t *ptsd;
	str lkey;
	str xuuid;
	int direction = TPS_DIR_DOWNSTREAM;

	LM_DBG("handling outgoing request\n");

	memset(&mtsd, 0, sizeof(tps_data_t));
	memset(&btsd, 0, sizeof(tps_data_t));
	memset(&stsd, 0, sizeof(tps_data_t));
	ptsd = &mtsd;

	if(tps_pack_message(msg, &mtsd)<0) {
		LM_ERR("failed to extract and pack the headers\n");
		return -1;
	}

	if(dialog!=0) {
		if(tps_get_xuuid(msg, &xuuid)<0) {
			LM_DBG("no x-uuid header - nothing to do\n");
			return 0;
		}
		mtsd.a_uuid = xuuid;
		tps_remove_xuuid(msg);
	}

	lkey = msg->callid->body;

	tps_storage_lock_get(&lkey);

	if(tps_storage_load_branch(msg, &mtsd, &btsd)!=0) {
		if(tps_storage_record(msg, ptsd, dialog)<0) {
			goto error;
		}
	} else {
		ptsd = &btsd;
	}

	if(dialog!=0) {
		if(tps_storage_load_dialog(msg, &mtsd, &stsd)==0) {
			ptsd = &stsd;
		}
	}

	/* local generated requests */
	if(local) {
		/* ACK and CANCEL go downstream */
		if(get_cseq(msg)->method_id==METHOD_ACK
				|| get_cseq(msg)->method_id==METHOD_CANCEL
				|| local==2) {
			// ts_mask_callid(&msg);
			goto done;
		} else {
			/* should be for upstream */
			goto done;
		}
	}

	tps_remove_headers(msg, HDR_RECORDROUTE_T);
	tps_remove_headers(msg, HDR_CONTACT_T);
	tps_remove_headers(msg, HDR_VIA_T);

	tps_reinsert_via(msg, &mtsd, &mtsd.x_via1);
	if(direction==TPS_DIR_UPSTREAM) {
		tps_reinsert_contact(msg, ptsd, &ptsd->as_contact);
	} else {
		tps_reinsert_contact(msg, ptsd, &ptsd->bs_contact);
	}

	if(dialog!=0) {
		tps_storage_end_dialog(msg, &mtsd, ptsd);
	}

done:
	tps_storage_lock_release(&lkey);
	return 0;

error:
	tps_storage_lock_release(&lkey);
	return -1;
}