changeset 109:9b87894704eb

sip-in: first step toward final call clearing
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 28 Sep 2022 16:32:13 -0800
parents 0d6435808bcd
children c1c94b7fc2e2
files sip-in/Makefile sip-in/bye_in.c sip-in/bye_out.c sip-in/call.h sip-in/call_clear.c sip-in/call_list.c sip-in/call_setup.c sip-in/cancel.c sip-in/disconnect.c sip-in/invite.c sip-in/mgw_ops.c sip-in/mncc_handle.c sip-in/prack.c sip-in/readconf.c sip-in/retrans.c sip-in/shutdown.c sip-in/sip_ack.c
diffstat 17 files changed, 92 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sip-in/Makefile	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/Makefile	Wed Sep 28 16:32:13 2022 -0800
@@ -1,9 +1,10 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	themwi-sip-in
-OBJS=	bye_in.o bye_out.o call_list.o call_setup.o cancel.o disconnect.o \
-	invite.o main.o mgw_ops.o mgw_sock.o mncc_handle.o mncc_sock.o prack.o \
-	readconf.o retrans.o shutdown.o sip_ack.o sip_log.o sip_uas.o sip_udp.o
+OBJS=	bye_in.o bye_out.o call_clear.o call_list.o call_setup.o cancel.o \
+	disconnect.o invite.o main.o mgw_ops.o mgw_sock.o mncc_handle.o \
+	mncc_sock.o prack.o readconf.o retrans.o shutdown.o sip_ack.o sip_log.o\
+	sip_uas.o sip_udp.o
 LIBS=	../libnumdb/libnumdb.a ../libsip/libsip.a ../libutil/libutil.a
 INSTBIN=/usr/local/bin
 
--- a/sip-in/bye_in.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/bye_in.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
@@ -19,6 +20,9 @@
 
 extern struct call *find_call_by_sip_id();
 
+extern unsigned sip_linger_gotbye;
+extern unsigned sip_linger_error;
+
 void
 handle_sip_bye(req, ess, sin)
 	struct sip_pkt_rx *req;
@@ -58,9 +62,11 @@
 				GSM48_CC_CAUSE_NORM_CALL_CLEAR);
 		disconnect_tmgw(call);
 		call->sip_state = SIP_STATE_ENDED;
+		sip_mark_end_time(call, sip_linger_gotbye);
 		break;
 	case SIP_STATE_BYE_SENT:
 		call->sip_state = SIP_STATE_ENDED;
+		sip_mark_end_time(call, sip_linger_gotbye);
 		break;
 	case SIP_STATE_INVITE_ERR:
 	case SIP_STATE_ENDED:
@@ -74,6 +80,7 @@
 	if (rc < 0) {
 msg_size_err:	syslog(LOG_ERR, "BYE 200 response length exceeded");
 		call->sip_state = SIP_STATE_MSG_SIZE_ERR;
+		sip_mark_end_time(call, sip_linger_error);
 		return;
 	}
 	rc = out_msg_add_header(&resp, "To", call->invite_to);
--- a/sip-in/bye_out.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/bye_out.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <stdio.h>
@@ -22,6 +23,8 @@
 extern struct in_addr sip_bind_ip;
 extern unsigned sip_bind_port;
 extern unsigned max_forwards;
+extern unsigned sip_linger_acked;
+extern unsigned sip_linger_error;
 
 fill_bye_out_msg(msg, call)
 	struct sip_msg_out *msg;
@@ -107,6 +110,11 @@
 	}
 	if (msg->status_code < 200)
 		return;
-	if (call->sip_state == SIP_STATE_BYE_SENT)
+	if (call->sip_state == SIP_STATE_BYE_SENT) {
 		call->sip_state = SIP_STATE_ENDED;
+		if (msg->status_code <= 299)
+			sip_mark_end_time(call, sip_linger_acked);
+		else
+			sip_mark_end_time(call, sip_linger_error);
+	}
 }
--- a/sip-in/call.h	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/call.h	Wed Sep 28 16:32:13 2022 -0800
@@ -40,6 +40,7 @@
 	uint32_t	mncc_callref;
 	char		invite_fail[80];
 	unsigned	sip_tx_count;
+	time_t		sip_clear_time;
 };
 
 #define	OVERALL_STATE_CRCX		1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/call_clear.c	Wed Sep 28 16:32:13 2022 -0800
@@ -0,0 +1,28 @@
+/*
+ * In this module we implement final clearing of calls, i.e., freeing
+ * of struct call, and all preliminary steps that need to happen
+ * toward this ultimate end state.
+ */
+
+#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 "call.h"
+
+extern struct call *call_list;
+extern struct timeval cur_event_time;
+
+void
+sip_mark_end_time(call, linger)
+	struct call *call;
+	unsigned linger;
+{
+	call->sip_clear_time = cur_event_time.tv_sec + linger;
+}
--- a/sip-in/call_list.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/call_list.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/call_setup.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/call_setup.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/cancel.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/cancel.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/disconnect.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/disconnect.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/invite.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/invite.c	Wed Sep 28 16:32:13 2022 -0800
@@ -4,6 +4,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <stdio.h>
@@ -26,6 +27,7 @@
 extern int cfg_use_100rel;
 extern int cfg_force_pcma;
 extern struct call *call_list;
+extern unsigned sip_linger_error;
 
 extern struct call *find_call_by_sip_id();
 extern char *get_single_header();
@@ -408,6 +410,7 @@
 		disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
 				GSM48_CC_CAUSE_INTERWORKING);
 		disconnect_tmgw(call);
+		sip_mark_end_time(call, sip_linger_error);
 		/* TODO: transition from TEARDOWN to DEAD_SIP */
 		return;
 	}
@@ -443,6 +446,7 @@
 		disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
 				GSM48_CC_CAUSE_INTERWORKING);
 		disconnect_tmgw(call);
+		sip_mark_end_time(call, sip_linger_error);
 		/* TODO: transition from TEARDOWN to DEAD_SIP */
 		return;
 	}
@@ -463,6 +467,7 @@
 	if (rc < 0) {
 		syslog(LOG_ERR, "INVITE late error response length exceeded");
 		call->sip_state = SIP_STATE_MSG_SIZE_ERR;
+		sip_mark_end_time(call, sip_linger_error);
 		/* TODO: transition from TEARDOWN to DEAD_SIP */
 		return;
 	}
--- a/sip-in/mgw_ops.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/mgw_ops.c	Wed Sep 28 16:32:13 2022 -0800
@@ -5,6 +5,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/mncc_handle.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/mncc_handle.c	Wed Sep 28 16:32:13 2022 -0800
@@ -5,6 +5,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/prack.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/prack.c	Wed Sep 28 16:32:13 2022 -0800
@@ -5,6 +5,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <ctype.h>
 #include <stdio.h>
@@ -22,6 +23,8 @@
 extern char *get_single_header();
 extern struct call *find_call_by_sip_id();
 
+extern unsigned sip_linger_error;
+
 void
 handle_sip_prack(req, ess, sin)
 	struct sip_pkt_rx *req;
@@ -90,6 +93,7 @@
 			disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
 					GSM48_CC_CAUSE_INTERWORKING);
 			disconnect_tmgw(call);
+			sip_mark_end_time(call, sip_linger_error);
 			/* TODO: transition from TEARDOWN to DEAD_SIP */
 			return;
 		}
--- a/sip-in/readconf.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/readconf.c	Wed Sep 28 16:32:13 2022 -0800
@@ -21,6 +21,9 @@
 unsigned cfg_retrans_timeout = 500;
 unsigned cfg_retrans_count = 10;
 unsigned max_forwards = 70;
+unsigned sip_linger_acked = 5;
+unsigned sip_linger_gotbye = 30;
+unsigned sip_linger_error = 180;
 
 static char config_file_pathname[] = "/var/gsm/themwi-sip-in.cfg";
 
@@ -174,6 +177,18 @@
 		handler = handle_retrans_conf;
 		var = (void *) 0;
 		set_id = 0;
+	} else if (!strcmp(kw, "sip-linger-acked")) {
+		handler = handle_num;
+		var = &sip_linger_acked;
+		set_id = 0;
+	} else if (!strcmp(kw, "sip-linger-got-bye")) {
+		handler = handle_num;
+		var = &sip_linger_gotbye;
+		set_id = 0;
+	} else if (!strcmp(kw, "sip-linger-error")) {
+		handler = handle_num;
+		var = &sip_linger_error;
+		set_id = 0;
 	} else if (!strcmp(kw, "max-forwards")) {
 		handler = &handle_num;
 		var = &max_forwards;
--- a/sip-in/retrans.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/retrans.c	Wed Sep 28 16:32:13 2022 -0800
@@ -5,6 +5,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
@@ -17,6 +18,7 @@
 #include "call.h"
 
 extern unsigned cfg_retrans_count;
+extern unsigned sip_linger_error;
 extern struct call *call_list;
 
 void
@@ -66,16 +68,20 @@
 				out_msg_finish(&msg);
 				sip_tx_packet(&msg, &call->udp_sin);
 				call->sip_tx_count++;
-			} else
+			} else {
 				call->sip_state = SIP_STATE_ENDED;
+				sip_mark_end_time(call, sip_linger_error);
+			}
 			break;
 		case SIP_STATE_BYE_SENT:
 			if (call->sip_tx_count < cfg_retrans_count) {
 				fill_bye_out_msg(&msg, call);
 				sip_tx_packet(&msg, &call->udp_sin);
 				call->sip_tx_count++;
-			} else
+			} else {
 				call->sip_state = SIP_STATE_ENDED;
+				sip_mark_end_time(call, sip_linger_error);
+			}
 			break;
 		}
 	}
--- a/sip-in/shutdown.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/shutdown.c	Wed Sep 28 16:32:13 2022 -0800
@@ -10,6 +10,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
--- a/sip-in/sip_ack.c	Wed Sep 28 14:29:10 2022 -0800
+++ b/sip-in/sip_ack.c	Wed Sep 28 16:32:13 2022 -0800
@@ -5,6 +5,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/time.h>
 #include <netinet/in.h>
 #include <stdio.h>
 #include <stdint.h>
@@ -18,6 +19,8 @@
 
 extern struct call *find_call_by_sip_id();
 
+extern unsigned sip_linger_acked;
+
 void
 handle_sip_ack(req, ess, sin)
 	struct sip_pkt_rx *req;
@@ -51,6 +54,7 @@
 		break;
 	case SIP_STATE_INVITE_ERR:
 		call->sip_state = SIP_STATE_ENDED;
+		sip_mark_end_time(call, sip_linger_acked);
 		break;
 	}
 }