diff mgw/dlcx.c @ 32:b3f74df7b808

beginning of themwi-mgw
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Jul 2022 22:51:44 -0800
parents
children 020ba624bdd8
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mgw/dlcx.c	Sat Jul 09 22:51:44 2022 -0800
@@ -0,0 +1,88 @@
+/*
+ * In this module we implement our DLCX operation.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <stdio.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;
+}