diff sip-out/uac_resp.c @ 155:2730ccb44549

sip-out: initial UAC response handling
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2022 23:30:00 -0800
parents sip-out/uac_out.c@e54b0a9e322f
children 0bacca1f2f7b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-out/uac_resp.c	Tue Oct 11 23:30:00 2022 -0800
@@ -0,0 +1,56 @@
+/*
+ * In this module we implement our handling of SIP responses in the UAC role.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include "../include/gsm48_const.h"
+#include "../include/out_routes.h"
+#include "../libsip/parse.h"
+#include "../libsip/resp_ident.h"
+#include "../libsip/sdp.h"
+#include "../libsip/out_msg.h"
+#include "call.h"
+
+extern struct call *find_call_by_sip_id();
+
+void
+process_sip_response(msg, sin)
+	struct sip_pkt_rx *msg;
+	struct sockaddr_in *sin;
+{
+	struct sip_resp_ident rid;
+	struct call *call;
+	int rc;
+
+	rc = sip_resp_extract_ident(msg, &rid);
+	if (rc < 0) {
+		syslog(LOG_ERR, "SIP %03u response: bad or missing %s header",
+			msg->status_code, rid.error_field);
+		return;
+	}
+	call = find_call_by_sip_id(rid.call_id);
+	if (!call) {
+		syslog(LOG_ERR, "SIP %03u response: unmatched Call-ID",
+			msg->status_code);
+		return;
+	}
+	if (rid.cseq_num == 1 && !strcmp(rid.cseq_method, "INVITE"))
+		handle_invite_response(call, msg, sin);
+	else if (rid.cseq_num == 1 && !strcmp(rid.cseq_method, "CANCEL"))
+		handle_cancel_response(call, msg, sin);
+	else if (rid.cseq_num == 2 && !strcmp(rid.cseq_method, "BYE"))
+		handle_bye_response(call, msg, sin);
+	else
+		syslog(LOG_ERR,
+			"UAC received %03u response with unknown CSeq %u %.32s",
+			msg->status_code, rid.cseq_num, rid.cseq_method);
+}