summaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-18 14:09:50 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-27 13:02:00 +0200
commit107b17a51b9c0cdd13dfcdc11e7eec6e93a6a75d (patch)
treecb6b3dde4c8bee0e59c686238509e41d4d105b5d /sources
parentd491dfdb2deeb140d0d16cfa35362d8cab3c2ef4 (diff)
#915 add og_client_state_process_payload()
Move code that handles the message payload into function.
Diffstat (limited to 'sources')
-rw-r--r--sources/ogAdmServer.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index 3285fce..563984c 100644
--- a/sources/ogAdmServer.cpp
+++ b/sources/ogAdmServer.cpp
@@ -3560,12 +3560,38 @@ static int og_client_state_recv_hdr(struct og_client *cli)
return 1;
}
-static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events)
+static int og_client_state_process_payload(struct og_client *cli)
{
- struct og_client *cli;
TRAMA *ptrTrama;
- int ret, len;
char *data;
+ int len;
+
+ len = cli->msg_len - (LONGITUD_CABECERATRAMA + LONHEXPRM);
+ data = &cli->buf[LONGITUD_CABECERATRAMA + LONHEXPRM];
+
+ ptrTrama = (TRAMA *)reservaMemoria(sizeof(TRAMA));
+ if (!ptrTrama) {
+ syslog(LOG_ERR, "OOM\n");
+ return -1;
+ }
+
+ initParametros(ptrTrama, len);
+ memcpy(ptrTrama, cli->buf, LONGITUD_CABECERATRAMA);
+ memcpy(ptrTrama->parametros, data, len);
+ ptrTrama->lonprm = len;
+
+ gestionaTrama(ptrTrama, cli);
+
+ liberaMemoria(ptrTrama->parametros);
+ liberaMemoria(ptrTrama);
+
+ return 1;
+}
+
+static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events)
+{
+ struct og_client *cli;
+ int ret;
cli = container_of(io, struct og_client, io);
@@ -3619,24 +3645,9 @@ static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events
inet_ntoa(cli->addr.sin_addr),
ntohs(cli->addr.sin_port));
- len = cli->msg_len - (LONGITUD_CABECERATRAMA + LONHEXPRM);
- data = &cli->buf[LONGITUD_CABECERATRAMA + LONHEXPRM];
-
- ptrTrama = (TRAMA *)reservaMemoria(sizeof(TRAMA));
- if (!ptrTrama) {
- syslog(LOG_ERR, "OOM\n");
+ ret = og_client_state_process_payload(cli);
+ if (ret < 0)
goto close;
- }
-
- initParametros(ptrTrama, len);
- memcpy(ptrTrama, cli->buf, LONGITUD_CABECERATRAMA);
- memcpy(ptrTrama->parametros, data, len);
- ptrTrama->lonprm = len;
-
- gestionaTrama(ptrTrama, cli);
-
- liberaMemoria(ptrTrama->parametros);
- liberaMemoria(ptrTrama);
if (cli->keepalive_idx < 0) {
syslog(LOG_DEBUG, "server closing connection to %s:%hu\n",