From a3f34674c6317930362c99f0fc40d835234843e5 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 14 Feb 2019 20:51:41 +0100 Subject: Moved code around --- src/state.c | 80 ------------------------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 src/state.c (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c deleted file mode 100644 index dd9cbf3..0000000 --- a/src/state.c +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include - -#include "../config.h" -#include "state.h" - -struct state { - unsigned long long session_id; - char * destination; - char * bastion_username; -}; - -static struct state state = {0}; - -char // returns 0 if ok, greater than 0 otherwise -state_set_ssh_destination(const char * name) -{ - if (state.destination != NULL) { - fprintf(stderr, "BUG found, attempting to overwrite state.destination that has already been set\n"); - return 1; - } - size_t len = strnlen(name, MAX_HOSTNAME_LENGTH + 1); - if (len >= MAX_HOSTNAME_LENGTH + 1) { - fprintf(stderr, "Hostname too long, max length is %d.\n", MAX_HOSTNAME_LENGTH); - return 2; - } - state.destination = malloc(len+1); - strncpy(state.destination, name, len+1); - return 0; -} - -const char * state_get_ssh_destination(void) -{ - return state.destination; -} - -char // return 0 if ok, greater than 0 otherwise -state_set_bastion_username(const char * name) -{ - if (state.bastion_username != NULL) { - fprintf(stderr, "BUG found, attempting to overwrite state.bastion_username that has already been set\n"); - return 1; - } - size_t len = strnlen(name, MAX_USERNAME_LENGTH + 1); - if (len >= MAX_USERNAME_LENGTH + 1) { - fprintf(stderr, "Username too long, max length is %d.\n", MAX_USERNAME_LENGTH); - return 1; - } - state.bastion_username = malloc(len+1); - strncpy(state.bastion_username, name, len+1); - return 0; -} - -const char * state_get_bastion_username(void) -{ - return state.bastion_username; -} - -char // return 0 if ok, greater than 0 otherwise -state_set_session_id(const unsigned long long id) -{ - if (state.session_id != 0) { - fprintf(stderr, "BUG found, attempting to set a state.session_id that has already been set\n"); - return 1; - } - state.session_id = id; - return 0; -} - -unsigned long long state_get_session_id(void) -{ - return state.session_id; -} - -void state_clean(void) -{ - free(state.destination); - state.destination = NULL; -} -- cgit v1.2.3