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 struct Storage {
40  void *ptr;
42 
43 void StorageInit(void);
44 void StorageCleanup(void);
45 
46 /** \brief Register new storage
47  *
48  * \param type type from StorageEnum
49  * \param name name
50  * \param size size of the per instance storage
51  * \param Alloc alloc function for per instance storage
52  * \param Free free function for per instance storage
53  *
54  * \note if size == ptr size (so sizeof(void *)) and Alloc == NULL the API just
55  * gives the caller a ptr to store something it alloc'ed itself.
56  */
57 int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *));
58 int StorageFinalize(void);
59 
60 unsigned int StorageGetCnt(const StorageEnum type);
61 unsigned int StorageGetSize(const StorageEnum type);
62 
63 /** \brief get storage for id */
64 void *StorageGetById(const Storage *storage, const StorageEnum type, const int id);
65 /** \brief set storage for id */
66 int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr);
67 
68 /** \brief AllocById func for prealloc'd base storage (storage ptrs are part
69  * of another memory block) */
70 void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id);
71 void StorageFreeById(Storage *storage, const StorageEnum type, const int id);
72 void StorageFreeAll(Storage *storage, const StorageEnum type);
73 
74 void StorageRegisterTests(void);
75 #endif
StorageFreeAll
void StorageFreeAll(Storage *storage, const StorageEnum type)
Definition: util-storage.c:276
StorageFreeById
void StorageFreeById(Storage *storage, const StorageEnum type, const int id)
Definition: util-storage.c:254
StorageFinalize
int StorageFinalize(void)
Definition: util-storage.c:138
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:236
StorageEnum
enum StorageEnum_ StorageEnum
STORAGE_HOST
@ STORAGE_HOST
Definition: util-storage.h:30
Storage
Definition: util-storage.h:39
StorageGetById
void * StorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
Definition: util-storage.c:213
STORAGE_DEVICE
@ STORAGE_DEVICE
Definition: util-storage.h:33
type
uint8_t type
Definition: decode-icmpv4.h:0
Storage::ptr
void * ptr
Definition: util-storage.h:40
StorageGetSize
unsigned int StorageGetSize(const StorageEnum type)
get the size of the void array used to store the pointers
Definition: util-storage.c:208
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
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:224
StorageGetCnt
unsigned int StorageGetCnt(const StorageEnum type)
Definition: util-storage.c:197
Storage
struct Storage Storage
StorageRegisterTests
void StorageRegisterTests(void)
Definition: util-storage.c:404