comparison 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
comparison
equal deleted inserted replaced
31:08d7794cdd0a 32:b3f74df7b808
1 /*
2 * In this module we implement our DLCX operation.
3 */
4
5 #include <sys/types.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <syslog.h>
13 #include <unistd.h>
14 #include "../include/tmgw_ctrl.h"
15 #include "../include/tmgw_const.h"
16 #include "struct.h"
17 #include "select.h"
18
19 extern struct endpoint *find_ep_by_id();
20
21 static struct endpoint *delq;
22
23 static void
24 put_on_delq(ep)
25 struct endpoint *ep;
26 {
27 ep->next = delq;
28 delq = ep;
29 }
30
31 void
32 process_dlcx(conn, req, resp)
33 struct ctrl_conn *conn;
34 struct tmgw_ctrl_req *req;
35 struct tmgw_ctrl_resp *resp;
36 {
37 struct endpoint *ep, **epp;
38
39 for (epp = &conn->endp_list; ep = *epp; epp = &ep->next)
40 if (ep->ep_id == req->ep_id)
41 break;
42 if (!ep) {
43 resp->res = TMGW_RESP_ERR_PROT;
44 return;
45 }
46 syslog(LOG_INFO, "DLCX endpoint id %u", ep->ep_id);
47 *epp = ep->next;
48 put_on_delq(ep);
49 resp->res = TMGW_RESP_OK;
50 }
51
52 void
53 dlcx_all_on_conn(conn)
54 struct ctrl_conn *conn;
55 {
56 struct endpoint *ep, *np;
57
58 for (ep = conn->endp_list; ep; ep = np) {
59 np = ep->next;
60 put_on_delq(ep);
61 }
62 }
63
64 void
65 free_rtp_end(roe)
66 struct rtp_one_end *roe;
67 {
68 close(roe->rtp_fd);
69 close(roe->rtcp_fd);
70 FD_CLR(roe->rtp_fd, &select_for_read);
71 FD_CLR(roe->rtcp_fd, &select_for_read);
72 }
73
74 void
75 free_deleted_endpoints()
76 {
77 struct endpoint *ep, *np;
78
79 for (ep = delq; ep; ep = np) {
80 np = ep->next;
81 if (ep->ep_type & TMGW_EP_HAS_GSM_SOCK)
82 free_rtp_end(&ep->rtp_gsm);
83 if (ep->ep_type & TMGW_EP_HAS_PSTN_SOCK)
84 free_rtp_end(&ep->rtp_pstn);
85 free(ep);
86 }
87 delq = 0;
88 }