view mgw/ctrl_prot.c @ 156:0bacca1f2f7b

sip-out: handle all INVITE responses, except errors
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 07:13:55 -0800
parents f062c32a5116
children
line wrap: on
line source

/*
 * In this module we implement our control socket protocol.
 */

#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 "struct.h"
#include "select.h"

struct endpoint *
find_ep_by_id(conn, id)
	struct ctrl_conn *conn;
	unsigned id;
{
	struct endpoint *ep;

	for (ep = conn->endp_list; ep; ep = ep->next)
		if (ep->ep_id == id)
			return ep;
	return 0;
}

void
ctrl_message_handler(fd, conn)
	struct ctrl_conn *conn;
{
	struct tmgw_ctrl_req req;
	struct tmgw_ctrl_resp resp;
	int rc;

	rc = recv(fd, &req, sizeof req, 0);
	if (rc < sizeof req) {
		syslog(LOG_INFO, "ctrl connection closing %s active endpoints",
			conn->endp_list ? "with" : "without");
		close(fd);
		FD_CLR(fd, &select_for_read);
		dlcx_all_on_conn(conn);
		free(conn);
		return;
	}
	bzero(&resp, sizeof resp);
	resp.transact_ref = req.transact_ref;
	switch (req.opcode) {
	case TMGW_CTRL_OP_CRCX:
		process_crcx(conn, &req, &resp);
		break;
	case TMGW_CTRL_OP_MDCX:
		process_mdcx(conn, &req, &resp);
		break;
	case TMGW_CTRL_OP_DLCX:
		process_dlcx(conn, &req, &resp);
		break;
	case TMGW_CTRL_OP_DTMF_START:
		process_dtmf_start(conn, &req, &resp);
		break;
	case TMGW_CTRL_OP_DTMF_STOP:
		process_dtmf_stop(conn, &req, &resp);
		break;
	default:
		resp.res = TMGW_RESP_ERR_OPCODE;
	}
	send(fd, &resp, sizeof resp, 0);
}