view mgw/dlcx.c @ 230:803829e6244f

themwi-update-numdb2: more sensible sort comparison functions
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 11:09:35 -0800
parents a6eb2de277f6
children
line wrap: on
line source

/*
 * In this module we implement our DLCX operation.
 */

#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 <unistd.h>
#include "../include/tmgw_ctrl.h"
#include "../include/tmgw_const.h"
#include "struct.h"
#include "select.h"

extern struct endpoint *find_ep_by_id();

static struct endpoint *delq;

static void
put_on_delq(ep)
	struct endpoint *ep;
{
	ep->next = delq;
	delq = ep;
}

void
process_dlcx(conn, req, resp)
	struct ctrl_conn *conn;
	struct tmgw_ctrl_req *req;
	struct tmgw_ctrl_resp *resp;
{
	struct endpoint *ep, **epp;

	for (epp = &conn->endp_list; ep = *epp; epp = &ep->next)
		if (ep->ep_id == req->ep_id)
			break;
	if (!ep) {
		resp->res = TMGW_RESP_ERR_PROT;
		return;
	}
	syslog(LOG_INFO, "DLCX endpoint id %u", ep->ep_id);
	*epp = ep->next;
	put_on_delq(ep);
	resp->res = TMGW_RESP_OK;
}

void
dlcx_all_on_conn(conn)
	struct ctrl_conn *conn;
{
	struct endpoint *ep, *np;

	for (ep = conn->endp_list; ep; ep = np) {
		np = ep->next;
		put_on_delq(ep);
	}
}

void
free_rtp_end(roe)
	struct rtp_one_end *roe;
{
	close(roe->rtp_fd);
	close(roe->rtcp_fd);
	FD_CLR(roe->rtp_fd, &select_for_read);
	FD_CLR(roe->rtcp_fd, &select_for_read);
}

void
free_deleted_endpoints()
{
	struct endpoint *ep, *np;

	for (ep = delq; ep; ep = np) {
		np = ep->next;
		if (ep->ep_type & TMGW_EP_HAS_GSM_SOCK)
			free_rtp_end(&ep->rtp_gsm);
		if (ep->ep_type & TMGW_EP_HAS_PSTN_SOCK)
			free_rtp_end(&ep->rtp_pstn);
		if (ep->gsm_encoder_state)
			free(ep->gsm_encoder_state);
		if (ep->gsm_decoder_state)
			free(ep->gsm_decoder_state);
		if (ep->gsm_decoder_extra_state)
			free(ep->gsm_decoder_extra_state);
		free(ep);
	}
	delq = 0;
}