view mncc/gsm_call.c @ 20:b13acb024fc6

libutil: add is_valid_ext_digit()
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 26 Jun 2022 23:35:19 -0800
parents ccc5ab6d8388
children 660126bd5f59
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;
	}
	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;
	}
}