diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2021-12-02 09:15:23 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2021-12-03 09:14:07 +0100 |
commit | ff9dbd9033cf12670e855c3f6164976b049224d7 (patch) | |
tree | 7d2b8d71094330c2ba9a43870e0b3c84ff769f6c | |
parent | 772811e76ff82184864aff8e29f29df7f0d64c88 (diff) |
#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.
-rw-r--r-- | src/client.c | 31 |
1 files 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 <jansson.h> #include <time.h> -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) |