diff sip-in/retrans.c @ 68:709b78a4ebf0

sip-in: implement retransmission of INVITE responses
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Sep 2022 21:56:20 -0800
parents
children 72b7d85d6354
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/retrans.c	Sun Sep 18 21:56:20 2022 -0800
@@ -0,0 +1,49 @@
+/*
+ * In this module we handle retransmission of INVITE responses
+ * and BYE requests.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <syslog.h>
+#include "../libsip/out_msg.h"
+#include "call.h"
+
+extern unsigned cfg_retrans_count;
+extern struct call *call_list;
+
+void
+run_periodic_retrans()
+{
+	struct call *call;
+	struct sip_msg_out msg;
+
+	for (call = call_list; call; call = call->next) {
+		switch (call->sip_state) {
+		case SIP_STATE_INVITE_200:
+			if (call->sip_tx_count < cfg_retrans_count) {
+				fill_invite_200_resp(&msg, call);
+				sip_tx_packet(&msg, &call->udp_sin);
+				call->sip_tx_count++;
+			} else
+				/* error handling to be implemented */;
+			break;
+		case SIP_STATE_INVITE_ERR:
+			if (call->sip_tx_count < cfg_retrans_count) {
+				start_response_out_msg(&msg, call->invite_fail);
+				fill_invite_resp_from_call(&msg, call);
+				out_msg_finish(&msg);
+				sip_tx_packet(&msg, &call->udp_sin);
+				call->sip_tx_count++;
+			} else
+				/* error handling to be implemented */;
+			break;
+		}
+	}
+}