This commit is contained in:
2025-10-06 18:27:50 +02:00
commit 3e191a4f60
213 changed files with 22261 additions and 0 deletions
+33
View File
@@ -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;