init
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/semphr.h> // Required for mutex
|
||||
|
||||
// Represents an active session.
|
||||
// An empty username (username[0] == '\0') indicates the slot is free.
|
||||
struct Session {
|
||||
char username[33];
|
||||
char token[17]; // 16 chars + null terminator
|
||||
unsigned long expiry_time; // Expiration timestamp from millis()
|
||||
};
|
||||
|
||||
class SessionManager {
|
||||
public:
|
||||
SessionManager();
|
||||
~SessionManager(); // Destructor to clean up the mutex
|
||||
|
||||
const char* createSession(const char* username);
|
||||
const char* validateSession(const char* token);
|
||||
bool endSession(const char* token);
|
||||
void cleanupExpiredSessions();
|
||||
|
||||
private:
|
||||
static constexpr size_t MAX_SESSIONS = 3;
|
||||
Session sessions_[MAX_SESSIONS];
|
||||
SemaphoreHandle_t session_mutex_; // Mutex to protect access to sessions_
|
||||
|
||||
void generateToken(char* buffer, size_t buffer_size);
|
||||
};
|
||||
|
||||
// Central, global instance.
|
||||
extern SessionManager sessionManager;
|
||||
Reference in New Issue
Block a user