view mncc/gsm_call.c @ 124:7e04d28fae8b

sip-in: default use-100rel to no BulkVS servers act badly when we send a reliable 180 Ringing response to an incoming call, even though they advertise 100rel support in the Supported header in the INVITE packet, and we probably won't be implementing 100rel for outbound because doing per-the-spec PRACK as a UAC is just too burdensome. Therefore, we need to consider 100rel extension as not-really-supported in themwi-system-sw.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 01 Oct 2022 15:54:50 -0800
parents 660126bd5f59
children
line wrap: on
line source

/*
 * In this module we implement allocation, freeing and retrieval
 * of gsm_call structures.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <syslog.h>
#include "struct.h"
#include "gsm_call.h"

struct gsm_call *call_list_head;

static uint32_t mt_callref;

struct gsm_call *
find_gsm_callref(callref)
	uint32_t callref;
{
	struct gsm_call *call;

	for (call = call_list_head; call; call = call->next) {
		if (call->gc_flag)
			continue;
		if (call->callref == callref)
			return call;
	}
	return 0;
}

struct gsm_call *
find_socket_call(conn, ref)
	struct socket_conn *conn;
	uint32_t ref;
{
	struct gsm_call *call;

	for (call = call_list_head; call; call = call->next) {
		if (call->gc_flag)
			continue;
		if (call->socket == conn && call->socket_ref == ref)
			return call;
	}
	return 0;
}

struct gsm_call *
create_gsm_call(callref)
	uint32_t callref;
{
	struct gsm_call *call;

	call = malloc(sizeof(struct gsm_call));
	if (call) {
		bzero(call, sizeof(struct gsm_call));
		call->callref = callref;
		call->next = call_list_head;
		call_list_head = call;
	}
	return call;
}

uint32_t
alloc_mt_callref()
{
	mt_callref++;
	if (mt_callref > 0x7FFFFFFF)
		mt_callref = 1;
	return mt_callref;
}

struct gsm_call *
create_new_mt_call()
{
	uint32_t callref;

	for (;;) {
		callref = alloc_mt_callref();
		if (!find_gsm_callref(callref))
			break;
	}
	syslog(LOG_DEBUG, "creating new MT callref 0x%x", callref);
	return create_gsm_call(callref);
}

gc_call_list()
{
	struct gsm_call *call, **cp;

	for (cp = &call_list_head; call = *cp; ) {
		if (call->gc_flag) {
			*cp = call->next;
			free(call);
			continue;
		}
		cp = &call->next;
	}
}