diff sip-in/bye_out.c @ 81:915f0f397fb6

sip-in: beginning of outgoing BYE support
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 20 Sep 2022 20:11:44 -0800
parents
children ff4b76a107a1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/bye_out.c	Tue Sep 20 20:11:44 2022 -0800
@@ -0,0 +1,74 @@
+/*
+ * In this module we implement our UAC functionality of sending BYE.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include "../libsip/parse.h"
+#include "../libsip/out_msg.h"
+#include "call.h"
+
+extern struct in_addr sip_bind_ip;
+extern unsigned sip_bind_port;
+
+fill_bye_out_msg(msg, call)
+	struct sip_msg_out *msg;
+	struct call *call;
+{
+	char strbuf[80];
+	int rc;
+
+	rc = start_request_out_msg_urilen(msg, "BYE", call->from_uri,
+					  call->from_uri_len);
+	if (rc < 0)
+		return rc;
+	sprintf(strbuf, "SIP/2.0/UDP %s:%u",
+		inet_ntoa(sip_bind_ip), sip_bind_port);
+	rc = out_msg_add_header(msg, "Via", strbuf);
+	if (rc < 0)
+		return rc;
+	rc = out_msg_add_header(msg, "From", call->invite_to);
+	if (rc < 0)
+		return rc;
+	rc = out_msg_add_header(msg, "To", call->invite_from);
+	if (rc < 0)
+		return rc;
+	rc = out_msg_add_header(msg, "Call-ID", call->sip_call_id);
+	if (rc < 0)
+		return rc;
+	rc = out_msg_add_header(msg, "CSeq", "1 BYE");
+	if (rc < 0)
+		return rc;
+	rc = out_msg_add_header(msg, "Max-Forwards", "70");
+	if (rc < 0)
+		return rc;
+	out_msg_finish(msg);
+	return 0;
+}
+
+void
+initiate_bye(call)
+	struct call *call;
+{
+	struct sip_msg_out msg;
+	int rc;
+
+	rc = fill_bye_out_msg(&msg, call);
+	if (rc < 0) {
+		syslog(LOG_ERR, "outgoing BYE request msg length exceeded");
+		call->sip_state = SIP_STATE_MSG_SIZE_ERR;
+		/* TODO: transition from TEARDOWN to DEAD_SIP */
+		return;
+	}
+	sip_tx_packet(&msg, &call->udp_sin);
+	call->sip_state = SIP_STATE_BYE_SENT;
+	call->sip_tx_count = 1;
+}