changeset 147:94b5831c017f

sip-manual-out code: split bye_in.c from uas.c
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Oct 2022 23:01:32 -0800
parents 54c2f271380d
children b51247739897
files sip-manual-out/Makefile sip-manual-out/bye_in.c sip-manual-out/uas.c
diffstat 3 files changed, 71 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/sip-manual-out/Makefile	Sat Oct 08 19:53:23 2022 -0800
+++ b/sip-manual-out/Makefile	Sat Oct 08 23:01:32 2022 -0800
@@ -1,7 +1,8 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	sip-manual-out
-OBJS=	disc_cmd.o dummy_rtp.o main.o readconf.o sip_log.o sip_udp.o uac.o uas.o
+OBJS=	bye_in.o disc_cmd.o dummy_rtp.o main.o readconf.o sip_log.o sip_udp.o \
+	uac.o uas.o
 LIBS=	../libsip/libsip.a ../libutil/libutil.a
 INSTBIN=/usr/local/bin
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-manual-out/bye_in.c	Sat Oct 08 23:01:32 2022 -0800
@@ -0,0 +1,68 @@
+/*
+ * Here we handle incoming BYE requests in the UAS role.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libsip/parse.h"
+#include "../libsip/uas_basic.h"
+#include "../libsip/out_msg.h"
+
+extern char call_id[];
+
+static void
+bye_correct_call(req, ess, sin)
+	struct sip_pkt_rx *req;
+	struct uas_parse_hdrs *ess;
+	struct sockaddr_in *sin;
+{
+	struct sip_msg_out resp;
+	int rc;
+
+	printf("Received BYE for our call, responding with 200\n");
+	start_response_out_msg(&resp, "200 OK");
+	rc = add_resp_basic_headers(&resp, ess, req->req_method);
+	if (rc < 0) {
+		fprintf(stderr, "sending 200 response: msg length exceeded\n");
+		return;
+	}
+	out_msg_finish(&resp);
+	sip_tx_packet(&resp, sin);
+}
+
+static void
+bye_unknown_call(req, ess, sin)
+	struct sip_pkt_rx *req;
+	struct uas_parse_hdrs *ess;
+	struct sockaddr_in *sin;
+{
+	struct sip_msg_out resp;
+	int rc;
+
+	printf("Received BYE for unknown call, responding with 481\n");
+	start_response_out_msg(&resp, "481 Call-ID not found");
+	rc = add_resp_basic_headers(&resp, ess, req->req_method);
+	if (rc < 0) {
+		fprintf(stderr, "sending 481 response: msg length exceeded\n");
+		return;
+	}
+	out_msg_finish(&resp);
+	sip_tx_packet(&resp, sin);
+}
+
+void
+handle_bye_req(req, ess, sin)
+	struct sip_pkt_rx *req;
+	struct uas_parse_hdrs *ess;
+	struct sockaddr_in *sin;
+{
+	if (!strcmp(ess->call_id, call_id))
+		bye_correct_call(req, ess, sin);
+	else
+		bye_unknown_call(req, ess, sin);
+}
--- a/sip-manual-out/uas.c	Sat Oct 08 19:53:23 2022 -0800
+++ b/sip-manual-out/uas.c	Sat Oct 08 23:01:32 2022 -0800
@@ -13,60 +13,6 @@
 #include "../libsip/uas_basic.h"
 #include "../libsip/out_msg.h"
 
-extern char call_id[];
-
-static void
-bye_correct_call(req, ess, sin)
-	struct sip_pkt_rx *req;
-	struct uas_parse_hdrs *ess;
-	struct sockaddr_in *sin;
-{
-	struct sip_msg_out resp;
-	int rc;
-
-	printf("Received BYE for our call, responding with 200\n");
-	start_response_out_msg(&resp, "200 OK");
-	rc = add_resp_basic_headers(&resp, ess, req->req_method);
-	if (rc < 0) {
-		fprintf(stderr, "sending 200 response: msg length exceeded\n");
-		return;
-	}
-	out_msg_finish(&resp);
-	sip_tx_packet(&resp, sin);
-}
-
-static void
-bye_unknown_call(req, ess, sin)
-	struct sip_pkt_rx *req;
-	struct uas_parse_hdrs *ess;
-	struct sockaddr_in *sin;
-{
-	struct sip_msg_out resp;
-	int rc;
-
-	printf("Received BYE for unknown call, responding with 481\n");
-	start_response_out_msg(&resp, "481 Call-ID not found");
-	rc = add_resp_basic_headers(&resp, ess, req->req_method);
-	if (rc < 0) {
-		fprintf(stderr, "sending 481 response: msg length exceeded\n");
-		return;
-	}
-	out_msg_finish(&resp);
-	sip_tx_packet(&resp, sin);
-}
-
-static void
-handle_bye(req, ess, sin)
-	struct sip_pkt_rx *req;
-	struct uas_parse_hdrs *ess;
-	struct sockaddr_in *sin;
-{
-	if (!strcmp(ess->call_id, call_id))
-		bye_correct_call(req, ess, sin);
-	else
-		bye_unknown_call(req, ess, sin);
-}
-
 static void
 unsupported_method(req, ess, sin)
 	struct sip_pkt_rx *req;
@@ -107,7 +53,7 @@
 	}
 	/* dispatch by method */
 	if (!strcmp(msg->req_method, "BYE"))
-		handle_bye(msg, &ess, sin);
+		handle_bye_req(msg, &ess, sin);
 	else if (!strcmp(msg->req_method, "ACK"))
 		printf("Received unexpected ACK, swallowing it\n");
 	else