Skip to content

Commit

Permalink
session: reset session initialized flag
Browse files Browse the repository at this point in the history
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 rafaelsteil#33

Signed-off-by: Alexander Dahl <[email protected]>
  • Loading branch information
LeSpocky committed Feb 16, 2017
1 parent 3cf4e29 commit b6fc028
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @{
*/

#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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..
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -555,6 +555,7 @@ void cgi_session_free( void )
{
free( sess_fname );
sess_fname = NULL;
sess_initialized = false;
}

/**
Expand Down

0 comments on commit b6fc028

Please sign in to comment.