summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-18 17:42:58 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-27 13:02:33 +0200
commit222637848bf96ba38a0153bf081649560b9153d7 (patch)
tree9fcade660eca82b9baadceeabf0826bec2f6ef9f
parente979fd2020df13bf4eb1dc9388f43fd7e39a42cb (diff)
#915 add og_msg_alloc() and og_msg_free()
Add function to allocate and release the legacy message format.
-rw-r--r--sources/ogAdmServer.cpp34
1 files changed, 25 insertions, 9 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index 8e1173e..6ec9c2d 100644
--- a/sources/ogAdmServer.cpp
+++ b/sources/ogAdmServer.cpp
@@ -3572,30 +3572,46 @@ static int og_client_state_recv_hdr(struct og_client *cli)
return 1;
}
-static int og_client_state_process_payload(struct og_client *cli)
+static TRAMA *og_msg_alloc(char *data, unsigned int len)
{
TRAMA *ptrTrama;
- 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;
+ return NULL;
}
initParametros(ptrTrama, len);
- memcpy(ptrTrama, cli->buf, LONGITUD_CABECERATRAMA);
+ memcpy(ptrTrama, "@JMMLCAMDJ_MCDJ", LONGITUD_CABECERATRAMA);
memcpy(ptrTrama->parametros, data, len);
ptrTrama->lonprm = len;
- gestionaTrama(ptrTrama, cli);
+ return ptrTrama;
+}
+static void og_msg_free(TRAMA *ptrTrama)
+{
liberaMemoria(ptrTrama->parametros);
liberaMemoria(ptrTrama);
+}
+
+static int og_client_state_process_payload(struct og_client *cli)
+{
+ TRAMA *ptrTrama;
+ char *data;
+ int len;
+
+ len = cli->msg_len - (LONGITUD_CABECERATRAMA + LONHEXPRM);
+ data = &cli->buf[LONGITUD_CABECERATRAMA + LONHEXPRM];
+
+ ptrTrama = og_msg_alloc(data, len);
+ if (!ptrTrama)
+ return -1;
+
+ gestionaTrama(ptrTrama, cli);
+
+ og_msg_free(ptrTrama);
return 1;
}