mirror of
https://github.com/sigmasternchen/CShore
synced 2025-03-15 08:08:56 +00:00
fixed issues in implementation
This commit is contained in:
parent
cbe3920b12
commit
491c4d929a
2 changed files with 16 additions and 5 deletions
|
@ -1,14 +1,19 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <uuid.h>
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <headers.h>
|
||||
|
||||
// SESSION_PTR_TYPE doesn't matter for this file
|
||||
#define SESSION_PTR_TYPE int
|
||||
#include "sessions.h"
|
||||
|
||||
struct session {
|
||||
#include "cookies.h"
|
||||
|
||||
static struct session {
|
||||
bool inUse;
|
||||
uuid_t id;
|
||||
time_t lastAccess;
|
||||
|
@ -20,7 +25,7 @@ static size_t sessionno = 0;
|
|||
|
||||
int resizeSessionList() {
|
||||
// TODO synchronization
|
||||
struct session* tmp = realloc(session, sizeof(struct session) * (sessionno + SESSION_BLOCK_SIZE));
|
||||
struct session* tmp = realloc(sessions, sizeof(struct session) * (sessionno + SESSION_BLOCK_SIZE));
|
||||
if (tmp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -41,6 +46,7 @@ struct session* newSession(size_t size) {
|
|||
sessions[i].inUse = false;
|
||||
return NULL;
|
||||
}
|
||||
memset(sessions[i].data, 0, size);
|
||||
return &(sessions[i]);
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +100,11 @@ void* _session_start(ctx_t* ctx, const char* cookie, size_t size) {
|
|||
}
|
||||
|
||||
uuid_generate_time(session->id);
|
||||
|
||||
char buffer[36 + 1];
|
||||
uuid_unparse(session->id, buffer);
|
||||
|
||||
setCookie(ctx, cookie, buffer, cookieSettingsNull());
|
||||
}
|
||||
|
||||
session->lastAccess = time(NULL);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define SESSIONS_H_
|
||||
|
||||
#ifndef SESSION_PTR_TYPE
|
||||
#warning "session ptr type not defined"
|
||||
#pragma GCC warning "session ptr type not defined"
|
||||
#define SESSION_PTR_TYPE int
|
||||
#endif
|
||||
|
||||
|
@ -18,6 +18,6 @@
|
|||
|
||||
void* _session_start(ctx_t*, const char*, size_t);
|
||||
|
||||
#define session_start(c) (SESSION_PTR_TYPE*) _session_start(c, SESSION_COOKIE_NAME, sizeof(SESSION_PTR_TYPE))
|
||||
#define session_start(c) ((SESSION_PTR_TYPE*) _session_start(c, SESSION_COOKIE_NAME, sizeof(SESSION_PTR_TYPE)))
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue