view mgw/dlcx.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 f280328e7e2e
children f062c32a5116
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);
		if (ep->gsm_encoder_state)
			free(ep->gsm_encoder_state);
		if (ep->gsm_decoder_state)
			free(ep->gsm_decoder_state);
		free(ep);
	}
	delq = 0;
}