view sip-out/call_clear.c @ 154:e54b0a9e322f

beginning of themwi-sip-out
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2022 23:04:01 -0800
parents sip-in/call_clear.c@3a1f0e13a3ac
children
line wrap: on
line source

/*
 * 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 "../include/out_routes.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;
}

void
check_dead_call(call)
	struct call *call;
{
	if (call->overall_state != OVERALL_STATE_TEARDOWN)
		return;
	if (call->mncc)
		return;
	if (call->mgw_state != MGW_STATE_NO_EXIST)
		return;
	if (call->mgw_xact)
		return;
	if (call->sip_call_exists)
		call->overall_state = OVERALL_STATE_SIP_FINISH;
	else
		call->overall_state = OVERALL_STATE_GC;
}

void
clear_dead_calls()
{
	struct call *call, **pp;

	for (pp = &call_list; *pp; ) {
		call = *pp;
		if (call->overall_state == OVERALL_STATE_GC ||
		    call->overall_state == OVERALL_STATE_SIP_FINISH &&
		    call->sip_state >= SIP_STATE_ACCEPT_100 &&
		    cur_event_time.tv_sec >= call->sip_clear_time) {
			*pp = call->next;
			free(call);
			continue;
		}
		pp = &call->next;
	}
}