changeset 82:ff4b76a107a1

sip-in: process responses as UAC for BYE
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 20:33:09 -0800
parents 915f0f397fb6
children 3e3fbf44f9d7
files sip-in/bye_out.c sip-in/sip_udp.c
diffstat 2 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sip-in/bye_out.c	Tue Sep 20 20:11:44 2022 -0800
+++ b/sip-in/bye_out.c	Tue Sep 20 20:33:09 2022 -0800
@@ -16,6 +16,9 @@
 #include "../libsip/out_msg.h"
 #include "call.h"
 
+extern char *get_single_header();
+extern struct call *find_call_by_sip_id();
+
 extern struct in_addr sip_bind_ip;
 extern unsigned sip_bind_port;
 
@@ -72,3 +75,32 @@
 	call->sip_state = SIP_STATE_BYE_SENT;
 	call->sip_tx_count = 1;
 }
+
+void
+process_sip_response(msg, sin)
+	struct sip_pkt_rx *msg;
+	struct sockaddr_in *sin;
+{
+	char *call_id_hdr, *cseq_hdr;
+	struct call *call;
+
+	call_id_hdr = get_single_header(msg, "Call-ID", "i", (int *) 0);
+	if (!call_id_hdr)
+		return;
+	call = find_call_by_sip_id(call_id_hdr);
+	if (!call)
+		return;
+	cseq_hdr = get_single_header(msg, "CSeq", (char *) 0, (int *) 0);
+	if (!cseq_hdr)
+		return;
+	if (strcmp(cseq_hdr, "1 BYE")) {
+		syslog(LOG_ERR,
+			"UAC received response with unknown CSeq %.32s",
+			cseq_hdr);
+		return;
+	}
+	if (msg->status_code < 200)
+		return;
+	if (call->sip_state == SIP_STATE_BYE_SENT)
+		call->sip_state = SIP_STATE_ENDED;
+}
--- a/sip-in/sip_udp.c	Tue Sep 20 20:11:44 2022 -0800
+++ b/sip-in/sip_udp.c	Tue Sep 20 20:33:09 2022 -0800
@@ -73,6 +73,8 @@
 	/* dispatch good-so-far SIP message */
 	if (pkt.parse_msgtype == SIP_MSG_TYPE_REQ)
 		process_sip_request(&pkt, &sin);
+	else if (pkt.parse_msgtype == SIP_MSG_TYPE_RESP)
+		process_sip_response(&pkt, &sin);
 }
 
 void