-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
SC_ATOMIC_DECLARE(unsigned int, num_tags); /**< Atomic counter, to know if we
have tagged hosts/sessions,
to avoid locking */
-static int host_tag_id = -1; /**< Host storage id for tags */
+static HostStorageId host_tag_id = { .id = -1 }; /**< Host storage id for tags */
static FlowStorageId flow_tag_id = { .id = -1 }; /**< Flow storage id for tags */
void TagInitCtx(void)
SC_ATOMIC_INIT(num_tags);
host_tag_id = HostStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
- if (host_tag_id == -1) {
+ if (host_tag_id.id == -1) {
FatalError(SC_ERR_FATAL, "Can't initiate host storage for tag");
}
flow_tag_id = FlowStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
-/* Copyright (C) 2014 Open Information Security Foundation
+/* Copyright (C) 2014-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-unittest.h"
#include "host-storage.h"
-static int host_bit_id = -1; /**< Host storage id for bits */
+static HostStorageId host_bit_id = { .id = -1 }; /**< Host storage id for bits */
static void HostBitFreeAll(void *store)
{
void HostBitInitCtx(void)
{
host_bit_id = HostStorageRegister("bit", sizeof(void *), NULL, HostBitFreeAll);
- if (host_bit_id == -1) {
+ if (host_bit_id.id == -1) {
FatalError(SC_ERR_FATAL, "Can't initiate host storage for bits");
}
}
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* It has to be called once during the init of the sub system
*/
-int HostStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *)) {
- return StorageRegister(STORAGE_HOST, name, size, Alloc, Free);
+HostStorageId HostStorageRegister(const char *name, const unsigned int size,
+ void *(*Alloc)(unsigned int), void (*Free)(void *))
+{
+ int id = StorageRegister(STORAGE_HOST, name, size, Alloc, Free);
+ HostStorageId hsi = { .id = id };
+ return hsi;
}
/**
* \param ptr pointer to the data to store
*/
-int HostSetStorageById(Host *h, int id, void *ptr)
+int HostSetStorageById(Host *h, HostStorageId id, void *ptr)
{
- return StorageSetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id, ptr);
+ return StorageSetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id, ptr);
}
/**
*
*/
-void *HostGetStorageById(Host *h, int id)
+void *HostGetStorageById(Host *h, HostStorageId id)
{
- return StorageGetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id);
+ return StorageGetById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id);
}
/**
/* Start of "private" function */
-void *HostAllocStorageById(Host *h, int id)
+void *HostAllocStorageById(Host *h, HostStorageId id)
{
- return StorageAllocByIdPrealloc((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id);
+ return StorageAllocByIdPrealloc((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id);
}
-void HostFreeStorageById(Host *h, int id)
+void HostFreeStorageById(Host *h, HostStorageId id)
{
- StorageFreeById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id);
+ StorageFreeById((Storage *)((void *)h + sizeof(Host)), STORAGE_HOST, id.id);
}
void HostFreeStorage(Host *h)
{
StorageInit();
- int id1 = HostStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
- if (id1 < 0)
+ HostStorageId id1 = HostStorageRegister("test", 8, StorageTestAlloc, StorageTestFree);
+ if (id1.id < 0)
goto error;
- int id2 = HostStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
- if (id2 < 0)
+ HostStorageId id2 = HostStorageRegister("variable", 24, StorageTestAlloc, StorageTestFree);
+ if (id2.id < 0)
goto error;
- int id3 = HostStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
- if (id3 < 0)
+ HostStorageId id3 =
+ HostStorageRegister("store", sizeof(void *), StorageTestAlloc, StorageTestFree);
+ if (id3.id < 0)
goto error;
if (StorageFinalize() < 0)
{
StorageInit();
- int id1 = HostStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
- if (id1 < 0)
+ HostStorageId id1 = HostStorageRegister("test", sizeof(void *), NULL, StorageTestFree);
+ if (id1.id < 0)
goto error;
if (StorageFinalize() < 0)
{
StorageInit();
- int id1 = HostStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
- if (id1 < 0)
+ HostStorageId id1 = HostStorageRegister("test1", sizeof(void *), NULL, StorageTestFree);
+ if (id1.id < 0)
goto error;
- int id2 = HostStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
- if (id2 < 0)
+ HostStorageId id2 = HostStorageRegister("test2", sizeof(void *), NULL, StorageTestFree);
+ if (id2.id < 0)
goto error;
- int id3 = HostStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
- if (id3 < 0)
+ HostStorageId id3 = HostStorageRegister("test3", 32, StorageTestAlloc, StorageTestFree);
+ if (id3.id < 0)
goto error;
if (StorageFinalize() < 0)
-/* Copyright (C) 2007-2013 Open Information Security Foundation
+/* Copyright (C) 2007-2021 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-storage.h"
#include "host.h"
+typedef struct HostStorageId_ {
+ int id;
+} HostStorageId;
+
unsigned int HostStorageSize(void);
-void *HostGetStorageById(Host *h, int id);
-int HostSetStorageById(Host *h, int id, void *ptr);
-void *HostAllocStorageById(Host *h, int id);
+void *HostGetStorageById(Host *h, HostStorageId id);
+int HostSetStorageById(Host *h, HostStorageId id, void *ptr);
+void *HostAllocStorageById(Host *h, HostStorageId id);
-void HostFreeStorageById(Host *h, int id);
+void HostFreeStorageById(Host *h, HostStorageId id);
void HostFreeStorage(Host *h);
void RegisterHostStorageTests(void);
-int HostStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *));
+HostStorageId HostStorageRegister(const char *name, const unsigned int size,
+ void *(*Alloc)(unsigned int), void (*Free)(void *));
#endif /* __HOST_STORAGE_H__ */