suricata
util-storage.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Storage API
24  */
25 
26 #ifndef __UTIL_STORAGE_H__
27 #define __UTIL_STORAGE_H__
28 
29 typedef enum StorageEnum_ {
34 
37 
38 /** void ptr array for now */
39 typedef void* Storage;
40 
41 void StorageInit(void);
42 void StorageCleanup(void);
43 
44 /** \brief Register new storage
45  *
46  * \param type type from StorageEnum
47  * \param name name
48  * \param size size of the per instance storage
49  * \param Alloc alloc function for per instance storage
50  * \param Free free function for per instance storage
51  *
52  * \note if size == ptr size (so sizeof(void *)) and Alloc == NULL the API just
53  * gives the caller a ptr to store something it alloc'ed itself.
54  */
55 int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *));
56 int StorageFinalize(void);
57 
58 unsigned int StorageGetCnt(const StorageEnum type);
59 unsigned int StorageGetSize(const StorageEnum type);
60 
61 /** \brief get storage for id */
62 void *StorageGetById(const Storage *storage, const StorageEnum type, const int id);
63 /** \brief set storage for id */
64 int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr);
65 
66 /** \brief AllocById func for prealloc'd base storage (storage ptrs are part
67  * of another memory block) */
68 void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id);
69 /** \brief AllocById func for when we manage the Storage ptr itself */
70 void *StorageAllocById(Storage **storage, const StorageEnum type, const int id);
71 void StorageFreeById(Storage *storage, const StorageEnum type, const int id);
72 void StorageFreeAll(Storage *storage, const StorageEnum type);
73 void StorageFree(Storage **storage, const StorageEnum type);
74 
75 void StorageRegisterTests(void);
76 #endif
StorageFreeAll
void StorageFreeAll(Storage *storage, const StorageEnum type)
Definition: util-storage.c:311
StorageFree
void StorageFree(Storage **storage, const StorageEnum type)
Definition: util-storage.c:334
StorageFreeById
void StorageFreeById(Storage *storage, const StorageEnum type, const int id)
Definition: util-storage.c:289
StorageFinalize
int StorageFinalize(void)
Definition: util-storage.c:140
STORAGE_IPPAIR
@ STORAGE_IPPAIR
Definition: util-storage.h:32
StorageAllocByIdPrealloc
void * StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
AllocById func for prealloc'd base storage (storage ptrs are part of another memory block)
Definition: util-storage.c:240
StorageEnum
enum StorageEnum_ StorageEnum
STORAGE_HOST
@ STORAGE_HOST
Definition: util-storage.h:30
StorageGetById
void * StorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
Definition: util-storage.c:217
STORAGE_DEVICE
@ STORAGE_DEVICE
Definition: util-storage.h:33
type
uint8_t type
Definition: decode-icmpv4.h:0
StorageGetSize
unsigned int StorageGetSize(const StorageEnum type)
get the size of the void array used to store the pointers
Definition: util-storage.c:212
StorageEnum_
StorageEnum_
Definition: util-storage.h:29
STORAGE_FLOW
@ STORAGE_FLOW
Definition: util-storage.h:31
StorageCleanup
void StorageCleanup(void)
Definition: util-storage.c:76
STORAGE_MAX
@ STORAGE_MAX
Definition: util-storage.h:35
StorageRegister
int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void(*Free)(void *))
Register new storage.
Definition: util-storage.c:100
StorageAllocById
void * StorageAllocById(Storage **storage, const StorageEnum type, const int id)
AllocById func for when we manage the Storage ptr itself.
Definition: util-storage.c:258
Storage
void * Storage
Definition: util-storage.h:39
StorageInit
void StorageInit(void)
Definition: util-storage.c:68
StorageSetById
int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
set storage for id
Definition: util-storage.c:228
StorageGetCnt
unsigned int StorageGetCnt(const StorageEnum type)
Definition: util-storage.c:201
StorageRegisterTests
void StorageRegisterTests(void)
Definition: util-storage.c:546