changeset 77:fe39404092d9

sip-in: generate To tags
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 16:49:24 -0800
parents 21276f045026
children 72b7d85d6354
files sip-in/invite.c
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sip-in/invite.c	Tue Sep 20 16:40:07 2022 -0800
+++ b/sip-in/invite.c	Tue Sep 20 16:49:24 2022 -0800
@@ -88,6 +88,7 @@
 	struct uas_parse_hdrs *ess;
 	struct sockaddr_in *sin;
 {
+	static unsigned cycle_tag_num, cycle_sdp_addend;
 	char uri_user[13], *called_nanp;
 	struct sip_msg_out resp;
 	struct grok_from gfrom;
@@ -244,14 +245,19 @@
 	}
 	/* stateful processing begins */
 	call = malloc(sizeof(struct call) + strlen(ess->call_id) +
-			strlen(ess->from) + strlen(ess->to) + strlen(ess->via)
-			+ 4);
+		      strlen(ess->from) + req_uri_len + strlen(ess->via) + 19);
 	if (!call) {
 		syslog(LOG_CRIT, "failed malloc for incoming call!");
 		start_response_out_msg(&resp,
 			"503 Gateway resource allocation failure");
 		goto error_resp;
 	}
+	cycle_tag_num++;
+	if (cycle_tag_num >= 1000000)
+		cycle_tag_num = 0;
+	cycle_sdp_addend++;
+	if (cycle_sdp_addend >= 0x10000)
+		cycle_sdp_addend = 0;
 	bzero(call, sizeof(struct call));
 	dp = (char *)(call + 1);
 	copylen = strlen(ess->call_id) + 1;
@@ -262,10 +268,13 @@
 	call->invite_from = dp;
 	bcopy(ess->from, dp, copylen);
 	dp += copylen;
-	copylen = strlen(ess->to) + 1;
 	call->invite_to = dp;
-	bcopy(ess->to, dp, copylen);
-	dp += copylen;
+	*dp++ = '<';
+	bcopy(req->req_uri, dp, req_uri_len);
+	dp += req_uri_len;
+	*dp++ = '>';
+	sprintf(dp, ";tag=in%06u", cycle_tag_num);
+	dp += 14;
 	copylen = strlen(ess->via) + 1;
 	call->invite_via = dp;
 	bcopy(ess->via, dp, copylen);
@@ -281,6 +290,7 @@
 	call->pstn_rtp_remote.sin_addr = sdp_parse.ip_addr;
 	call->pstn_rtp_remote.sin_port = htons(sdp_parse.audio_port);
 	call->use_pcma = use_pcma;
+	call->sdp_addend = cycle_sdp_addend;
 	/* generate 100 response */
 	start_response_out_msg(&resp, "100 Proceeding");
 	rc = fill_invite_resp_from_call(&resp, call);