From ff9dbd9033cf12670e855c3f6164976b049224d7 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Thu, 2 Dec 2021 09:15:23 +0100 Subject: #1065 split og_status_session_toggle Handles non usual situations like a client sending more than one event of same type. When toggling, receiving two events of the same type is the same as receiving two different ones (eg. start, then stop). Split into _session_start and _session_stop in order to check valid client status. --- src/client.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/client.c b/src/client.c index f56bffe..a70c9e4 100644 --- a/src/client.c +++ b/src/client.c @@ -24,23 +24,34 @@ #include #include -static int og_status_session_toggle(struct og_client *cli) +static int og_status_session_start(struct og_client *cli) { switch (cli->status) { case OG_CLIENT_STATUS_LINUX: cli->status = OG_CLIENT_STATUS_LINUX_SESSION; break; - case OG_CLIENT_STATUS_LINUX_SESSION: - cli->status = OG_CLIENT_STATUS_LINUX; - break; case OG_CLIENT_STATUS_WIN: cli->status = OG_CLIENT_STATUS_WIN_SESSION; break; + default: + syslog(LOG_ERR, "%s:%d: invalid session start for status %d\n", + __FILE__, __LINE__, cli->status); + return -1; + } + return 0; +} + +static int og_status_session_stop(struct og_client *cli) +{ + switch (cli->status) { case OG_CLIENT_STATUS_WIN_SESSION: cli->status = OG_CLIENT_STATUS_WIN; break; + case OG_CLIENT_STATUS_LINUX_SESSION: + cli->status = OG_CLIENT_STATUS_LINUX; + break; default: - syslog(LOG_ERR, "%s:%d: invalid toggle session for status %d\n", + syslog(LOG_ERR, "%s:%d: invalid session stop for status %d\n", __FILE__, __LINE__, cli->status); return -1; } @@ -78,11 +89,13 @@ static int og_resp_early_hints(struct og_client *cli, json_t *data) if (strncmp(event, "session", strlen("session"))) return -1; - if (strncmp(action, "start", strlen("start")) && - strncmp(action, "stop", strlen("stop"))) - return -1; + if (!strncmp(action, "start", strlen("start"))) + return og_status_session_start(cli); + if (!strncmp(action, "stop", strlen("stop"))) + return og_status_session_stop(cli); - return og_status_session_toggle(cli); + syslog(LOG_ERR, "Invalid action for event %s %s %s\n", event, action, user); + return -1; } static int og_resp_probe(struct og_client *cli, json_t *data) -- cgit v1.2.3-18-g5258