FreeCalypso > hg > themwi-system-sw
comparison mgw/ctrl_prot.c @ 32:b3f74df7b808
beginning of themwi-mgw
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 09 Jul 2022 22:51:44 -0800 |
| parents | |
| children | 7dae2bae56a1 |
comparison
equal
deleted
inserted
replaced
| 31:08d7794cdd0a | 32:b3f74df7b808 |
|---|---|
| 1 /* | |
| 2 * In this module we implement our control socket protocol. | |
| 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 "struct.h" | |
| 16 #include "select.h" | |
| 17 | |
| 18 struct endpoint * | |
| 19 find_ep_by_id(conn, id) | |
| 20 struct ctrl_conn *conn; | |
| 21 unsigned id; | |
| 22 { | |
| 23 struct endpoint *ep; | |
| 24 | |
| 25 for (ep = conn->endp_list; ep; ep = ep->next) | |
| 26 if (ep->ep_id == id) | |
| 27 return ep; | |
| 28 return 0; | |
| 29 } | |
| 30 | |
| 31 void | |
| 32 ctrl_message_handler(fd, conn) | |
| 33 struct ctrl_conn *conn; | |
| 34 { | |
| 35 struct tmgw_ctrl_req req; | |
| 36 struct tmgw_ctrl_resp resp; | |
| 37 int rc; | |
| 38 | |
| 39 rc = recv(fd, &req, sizeof req, 0); | |
| 40 if (rc < sizeof req) { | |
| 41 syslog(LOG_INFO, "ctrl connection closing %s active endpoints", | |
| 42 conn->endp_list ? "with" : "without"); | |
| 43 close(fd); | |
| 44 FD_CLR(fd, &select_for_read); | |
| 45 dlcx_all_on_conn(conn); | |
| 46 free(conn); | |
| 47 return; | |
| 48 } | |
| 49 bzero(&resp, sizeof resp); | |
| 50 resp.transact_ref = req.transact_ref; | |
| 51 switch (req.opcode) { | |
| 52 case TMGW_CTRL_OP_CRCX: | |
| 53 process_crcx(conn, &req, &resp); | |
| 54 break; | |
| 55 case TMGW_CTRL_OP_MDCX: | |
| 56 process_mdcx(conn, &req, &resp); | |
| 57 break; | |
| 58 case TMGW_CTRL_OP_DLCX: | |
| 59 process_dlcx(conn, &req, &resp); | |
| 60 break; | |
| 61 default: | |
| 62 resp.res = TMGW_RESP_ERR_PROT; | |
| 63 } | |
| 64 send(fd, &resp, sizeof resp, 0); | |
| 65 } |
