view mgw/dlcx.c @ 62:75b7a7b61824

sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 17 Sep 2022 18:43:08 -0800
parents 020ba624bdd8
children f280328e7e2e
line wrap: on
line source

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

#include <sys/types.h>
#include <sys/socket.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);
		free(ep);
	}
	delq = 0;
}