summaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-18 14:05:59 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-27 13:01:35 +0200
commitd491dfdb2deeb140d0d16cfa35362d8cab3c2ef4 (patch)
tree7e8c9abba51c9f4038471e363ea9aa7875730791 /sources
parent0d6dc8266947bdc88a74edefa4fc773b1ba84326 (diff)
#915 add og_client_state_recv_hdr()
Move code that handles the receiving header state into function.
Diffstat (limited to 'sources')
-rw-r--r--sources/ogAdmServer.cpp58
1 files changed, 35 insertions, 23 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index cf78079..3285fce 100644
--- a/sources/ogAdmServer.cpp
+++ b/sources/ogAdmServer.cpp
@@ -3529,9 +3529,39 @@ static void og_client_reset_state(struct og_client *cli)
cli->buf_len = 0;
}
-static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events)
+static int og_client_state_recv_hdr(struct og_client *cli)
{
char hdrlen[LONHEXPRM];
+
+ /* Still too short to validate protocol fingerprint and message
+ * length.
+ */
+ if (cli->buf_len < 15 + LONHEXPRM)
+ return 0;
+
+ if (strncmp(cli->buf, "@JMMLCAMDJ_MCDJ", 15)) {
+ syslog(LOG_ERR, "bad fingerprint from client %s:%hu, closing\n",
+ inet_ntoa(cli->addr.sin_addr),
+ ntohs(cli->addr.sin_port));
+ return -1;
+ }
+
+ memcpy(hdrlen, &cli->buf[LONGITUD_CABECERATRAMA], LONHEXPRM);
+ cli->msg_len = strtol(hdrlen, NULL, 16);
+
+ /* Header announces more that we can fit into buffer. */
+ if (cli->msg_len >= sizeof(cli->buf)) {
+ syslog(LOG_ERR, "too large message %u bytes from %s:%hu\n",
+ cli->msg_len, inet_ntoa(cli->addr.sin_addr),
+ ntohs(cli->addr.sin_port));
+ return -1;
+ }
+
+ return 1;
+}
+
+static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events)
+{
struct og_client *cli;
TRAMA *ptrTrama;
int ret, len;
@@ -3569,29 +3599,11 @@ static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events
switch (cli->state) {
case OG_CLIENT_RECEIVING_HEADER:
- /* Still too short to validate protocol fingerprint and message
- * length.
- */
- if (cli->buf_len < 15 + LONHEXPRM)
- return;
-
- if (strncmp(cli->buf, "@JMMLCAMDJ_MCDJ", 15)) {
- syslog(LOG_ERR, "bad fingerprint from client %s:%hu, closing\n",
- inet_ntoa(cli->addr.sin_addr),
- ntohs(cli->addr.sin_port));
+ ret = og_client_state_recv_hdr(cli);
+ if (ret < 0)
goto close;
- }
-
- memcpy(hdrlen, &cli->buf[LONGITUD_CABECERATRAMA], LONHEXPRM);
- cli->msg_len = strtol(hdrlen, NULL, 16);
-
- /* Header announces more that we can fit into buffer. */
- if (cli->msg_len >= sizeof(cli->buf)) {
- syslog(LOG_ERR, "too large message %u bytes from %s:%hu\n",
- cli->msg_len, inet_ntoa(cli->addr.sin_addr),
- ntohs(cli->addr.sin_port));
- goto close;
- }
+ if (!ret)
+ return;
cli->state = OG_CLIENT_RECEIVING_PAYLOAD;
/* Fall through. */