diff sip-in/sip_uas.c @ 47:62f39c7cee15

themwi-sip-in skeleton started
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Sep 2022 20:33:56 -0800
parents
children 8117d8ee44a5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/sip_uas.c	Tue Sep 06 20:33:56 2022 -0800
@@ -0,0 +1,75 @@
+/*
+ * Basic UAS functions for themwi-sip-in.
+ */
+
+#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 <syslog.h>
+#include <unistd.h>
+#include "../libsip/parse.h"
+#include "../libsip/uas_basic.h"
+#include "../libsip/out_msg.h"
+
+static void
+method_tbi(req, ess, sin)
+	struct sip_pkt_rx *req;
+	struct uas_parse_hdrs *ess;
+	struct sockaddr_in *sin;
+{
+	syslog(LOG_ERR, "SIP method %s remains to be implemented",
+		req->req_method);
+}
+
+static void
+unsupported_method(req, ess, sin)
+	struct sip_pkt_rx *req;
+	struct uas_parse_hdrs *ess;
+	struct sockaddr_in *sin;
+{
+	struct sip_msg_out resp;
+	int rc;
+
+	start_response_out_msg(&resp, "405 Method not supported");
+	rc = add_resp_basic_headers(&resp, ess, req->req_method);
+	if (rc < 0) {
+too_long:	syslog(LOG_ERR, "sending 405 error: response length exceeded");
+		return;
+	}
+	rc = out_msg_add_header(&resp, "Allow", "INVITE,ACK,CANCEL,BYE");
+	if (rc < 0)
+		goto too_long;
+	out_msg_finish(&resp);
+	sip_tx_packet(&resp, sin);
+}
+
+void
+process_sip_request(msg, sin)
+	struct sip_pkt_rx *msg;
+	struct sockaddr_in *sin;
+{
+	struct uas_parse_hdrs ess;
+	int rc;
+
+	rc = uas_get_basic_headers(msg, &ess);
+	if (rc < 0) {
+		syslog(LOG_ERR, "SIP %.16s request: bad or missing %s header",
+			msg->req_method, ess.error_field);
+		return;
+	}
+	/* dispatch by method */
+	if (!strcmp(msg->req_method, "INVITE"))
+		method_tbi(msg, &ess, sin);
+	else if (!strcmp(msg->req_method, "ACK"))
+		method_tbi(msg, &ess, sin);
+	else if (!strcmp(msg->req_method, "CANCEL"))
+		method_tbi(msg, &ess, sin);
+	else if (!strcmp(msg->req_method, "BYE"))
+		method_tbi(msg, &ess, sin);
+	else
+		unsupported_method(msg, &ess, sin);
+}