FreeCalypso > hg > themwi-system-sw
diff 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 (2022-07-10) |
parents | |
children | 7dae2bae56a1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mgw/ctrl_prot.c Sat Jul 09 22:51:44 2022 -0800 @@ -0,0 +1,65 @@ +/* + * In this module we implement our control socket protocol. + */ + +#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 "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; + default: + resp.res = TMGW_RESP_ERR_PROT; + } + send(fd, &resp, sizeof resp, 0); +}