From d5eb42a2db79dea58d28241c94464b6dcf085d64 Mon Sep 17 00:00:00 2001 From: Alexander Dahl Date: Thu, 16 Feb 2017 17:20:03 +0100 Subject: [PATCH] session: reset session initialized flag The flag `sess_initialized` was never reset. After introducing `cgi_session_free()` we can now reset it. While at it use `stdbool.h` and make the variable a proper boolean, and also drop the not really used `sess_finitialized` variable. fixes #33 Signed-off-by: Alexander Dahl --- src/CMakeLists.txt | 1 + src/session.c | 13 +++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 04810bc..5994132 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION} + C_STANDARD 99 ) target_include_directories(${PROJECT_NAME} diff --git a/src/session.c b/src/session.c index 190e95d..981d544 100644 --- a/src/session.c +++ b/src/session.c @@ -56,6 +56,7 @@ * @{ */ +#include #include #include #include @@ -83,8 +84,7 @@ static unsigned int save_path_len; char SESSION_SAVE_PATH[255] = "/tmp/"; char SESSION_COOKIE_NAME[50] = "CGISID"; -int sess_initialized = 0;; // true if the session has been initialized, otherwise false -int sess_finitialized = 0; // true if the session file has been created, otherwirte false +bool sess_initialized = false; int session_lasterror = 0; // We can use this variable to get the error message from a ( possible ) session error @@ -192,7 +192,7 @@ int cgi_session_destroy() { // Remember: unlink() returns 0 if success :) if (!unlink(sess_fname)) { - sess_finitialized = 0; + sess_initialized = false; slist_free(&sess_list_start); // hhhmmm.. @@ -492,7 +492,7 @@ int cgi_session_start() if (sess_create_file()) { cgi_add_cookie(SESSION_COOKIE_NAME, sess_id, 0, 0, 0, 0); - sess_initialized = 1; + sess_initialized = true; return 1; } @@ -518,7 +518,7 @@ int cgi_session_start() cgi_add_cookie(SESSION_COOKIE_NAME, sess_id, 0, 0, 0, 0); libcgi_error(E_WARNING, "Session Cookie exists, but file don't. A new one was created."); - sess_initialized = 1; + sess_initialized = true; return 1; } @@ -545,7 +545,7 @@ int cgi_session_start() process_data(buf, &sess_list_start, &sess_list_last, '=', ';'); fclose(fp); - sess_initialized = 1; + sess_initialized = true; free(buf); return 1; @@ -555,6 +555,7 @@ void cgi_session_free( void ) { free( sess_fname ); sess_fname = NULL; + sess_initialized = false; } /**