diff sip-out/invite.c @ 157:7643b779dbea

sip-out: handle INVITE errors, except for cause mapping
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 07:56:14 -0800
parents 0bacca1f2f7b
children 51cf5ea7f320
line wrap: on
line diff
--- a/sip-out/invite.c	Wed Oct 12 07:13:55 2022 -0800
+++ b/sip-out/invite.c	Wed Oct 12 07:56:14 2022 -0800
@@ -22,6 +22,7 @@
 extern char *get_single_header();
 extern char *extract_to_tag();
 
+extern unsigned sip_linger_invite_err;
 extern unsigned sip_linger_response_err;
 
 static
@@ -236,7 +237,38 @@
 	char *tag;
 	struct sockaddr_in *sin;
 {
+	int rc;
 
+	rc = send_ack(call, tag, sin);
+	if (rc < 0)
+		syslog(LOG_CRIT, "ACK to %03u response exceeds msg size!",
+			msg->status_code);
+	switch (call->sip_state) {
+	case SIP_STATE_INV_SENT:
+	case SIP_STATE_100_RCVD:
+		call->overall_state = OVERALL_STATE_TEARDOWN;
+		disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND,
+				sip_error_to_gsm_cause(msg->status_code));
+		disconnect_tmgw(call);
+		call->sip_state = SIP_STATE_ENDED;
+		sip_mark_end_time(call, sip_linger_invite_err);
+		return;
+	case SIP_STATE_CANCEL_SENT:
+	case SIP_STATE_ACCEPT_100:
+	case SIP_STATE_ACCEPT_200:
+		call->sip_state = SIP_STATE_ENDED;
+		sip_mark_end_time(call, sip_linger_invite_err);
+		return;
+	case SIP_STATE_CONNECTED:
+	case SIP_STATE_BYE_SENT:
+	case SIP_STATE_ENDED:
+		return;
+	default:
+		syslog(LOG_CRIT,
+			"FATAL: invalid SIP state 0x%x on INVITE %03u response",
+			call->sip_state, msg->status_code);
+		exit(1);
+	}
 }
 
 void