view sip-out/retrans.c @ 203:e89619893c1e

sip-out: require minimum of 7 digits for E.164 numbers
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 04 Apr 2023 21:09:50 -0800
parents e54b0a9e322f
children
line wrap: on
line source

/*
 * In this module we handle retransmission of our outgoing SIP UAC packets.
 */

#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/out_msg.h"
#include "call.h"

extern unsigned cfg_retrans_count;
extern unsigned sip_linger_timeout;
extern unsigned sip_linger_bye_out_err;
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_INV_SENT:
			if (call->sip_tx_count < cfg_retrans_count) {
				fill_invite_req_msg(&msg, call);
				sip_tx_packet(&msg, &call->udp_sin);
				call->sip_tx_count++;
			} else {
				syslog(LOG_ERR,
					"outbound INVITE retrans timeout");
				call->overall_state = OVERALL_STATE_TEARDOWN;
				disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU,
						GSM48_CC_CAUSE_DEST_OOO);
				disconnect_tmgw(call);
				call->sip_state = SIP_STATE_ACCEPT_100;
				sip_mark_end_time(call, sip_linger_timeout);
			}
			break;
		case SIP_STATE_CANCEL_SENT:
			if (call->sip_tx_count < cfg_retrans_count) {
				fill_cancel_req_msg(&msg, call);
				sip_tx_packet(&msg, &call->udp_sin);
				call->sip_tx_count++;
			} else {
				syslog(LOG_ERR,
					"outbound CANCEL retrans timeout");
				call->sip_state = SIP_STATE_ACCEPT_200;
				sip_mark_end_time(call, sip_linger_timeout);
			}
			break;
		case SIP_STATE_BYE_SENT:
			if (call->sip_tx_count < cfg_retrans_count) {
				fill_bye_req_msg(&msg, call);
				sip_tx_packet(&msg, &call->udp_sin);
				call->sip_tx_count++;
			} else {
				syslog(LOG_ERR, "outbound BYE retrans timeout");
				call->sip_state = SIP_STATE_ENDED;
				sip_mark_end_time(call, sip_linger_bye_out_err);
			}
			break;
		}
	}
}