Files
ocserv/src/occtl/session-cache.c
T
Dimitri Papadopoulos a2ec3bba9c Consistent include files and directives
* Import system headers as `#include <...>`.
* Import local headers as `#include "..."`.
* Use consistent header guards (starting with `OC_`).

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-06-06 15:23:54 +02:00

71 lines
1.9 KiB
C

/*
* Copyright (C) 2018 Nikos Mavrogiannopoulos
*
* Author: Nikos Mavrogiannopoulos
*
* This file is part of ocserv.
*
* ocserv is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* ocserv is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "occtl/occtl.h"
#include "common/common.h"
typedef struct session_entries_st {
char session[SAFE_ID_SIZE];
} session_entries_st;
static session_entries_st *session_entries;
static unsigned int session_entries_size;
static unsigned int max_session_entries_size;
void session_entries_clear(void)
{
session_entries_size = 0;
}
void session_entries_add(void *pool, const char *session)
{
if (session_entries_size + 1 > max_session_entries_size) {
max_session_entries_size += 128;
session_entries = talloc_realloc_size(
pool, session_entries,
sizeof(session_entries_st) * max_session_entries_size);
}
strlcpy(session_entries[session_entries_size].session, session,
sizeof(session_entries[session_entries_size].session));
session_entries_size++;
}
char *search_for_session(unsigned int idx, const char *match, int match_size)
{
unsigned int i;
if (idx >= session_entries_size)
return NULL;
for (i = idx; i < session_entries_size; i++) {
if (strncasecmp(match, session_entries[i].session,
MIN(match_size, SAFE_ID_SIZE)) == 0)
return strdup(session_entries[i].session);
}
return NULL;
}