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 
36 } StorageEnum;
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
void StorageCleanup(void)
Definition: util-storage.c:75
void * StorageAllocById(Storage **storage, const StorageEnum type, const int id)
AllocById func for when we manage the Storage ptr itself.
Definition: util-storage.c:257
unsigned int StorageGetCnt(const StorageEnum type)
Definition: util-storage.c:200
void * StorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
Definition: util-storage.c:216
void StorageFree(Storage **storage, const StorageEnum type)
Definition: util-storage.c:333
int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
set storage for id
Definition: util-storage.c:227
uint8_t type
void StorageInit(void)
Definition: util-storage.c:67
void StorageFreeAll(Storage *storage, const StorageEnum type)
Definition: util-storage.c:310
enum StorageEnum_ StorageEnum
void StorageRegisterTests(void)
Definition: util-storage.c:545
void * Storage
Definition: util-storage.h:39
void StorageFreeById(Storage *storage, const StorageEnum type, const int id)
Definition: util-storage.c:288
int StorageFinalize(void)
Definition: util-storage.c:139
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:99
void * StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
AllocById func for prealloc&#39;d base storage (storage ptrs are part of another memory block) ...
Definition: util-storage.c:239
unsigned int StorageGetSize(const StorageEnum type)
get the size of the void array used to store the pointers
Definition: util-storage.c:211
StorageEnum_
Definition: util-storage.h:29