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 SURICATA_UTIL_STORAGE_H
27 #define SURICATA_UTIL_STORAGE_H
28 
29 typedef enum StorageEnum_ {
35 
38 
39 /** void ptr array for now */
40 typedef struct Storage {
41  void *ptr;
43 
44 void StorageInit(void);
45 void StorageCleanup(void);
46 
47 /** \brief Register new storage
48  *
49  * \param type type from StorageEnum
50  * \param name name
51  * \param size size of the per instance storage
52  * \param Alloc alloc function for per instance storage
53  * \param Free free function for per instance storage
54  *
55  * \note if size == ptr size (so sizeof(void *)) and Alloc == NULL the API just
56  * gives the caller a ptr to store something it alloc'ed itself.
57  */
58 int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *));
59 int StorageFinalize(void);
60 
61 unsigned int StorageGetCnt(const StorageEnum type);
62 unsigned int StorageGetSize(const StorageEnum type);
63 
64 /** \brief get storage for id */
65 void *StorageGetById(const Storage *storage, const StorageEnum type, const int id);
66 /** \brief set storage for id */
67 int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr);
68 
69 /** \brief AllocById func for prealloc'd base storage (storage ptrs are part
70  * of another memory block) */
71 void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id);
72 void StorageFreeById(Storage *storage, const StorageEnum type, const int id);
73 void StorageFreeAll(Storage *storage, const StorageEnum type);
74 
75 #endif
StorageFreeAll
void StorageFreeAll(Storage *storage, const StorageEnum type)
Definition: util-storage.c:278
StorageFreeById
void StorageFreeById(Storage *storage, const StorageEnum type, const int id)
Definition: util-storage.c:256
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:238
StorageEnum
enum StorageEnum_ StorageEnum
STORAGE_HOST
@ STORAGE_HOST
Definition: util-storage.h:30
Storage
Definition: util-storage.h:40
StorageGetById
void * StorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
Definition: util-storage.c:215
STORAGE_DEVICE
@ STORAGE_DEVICE
Definition: util-storage.h:33
STORAGE_THREAD
@ STORAGE_THREAD
Definition: util-storage.h:34
Storage::ptr
void * ptr
Definition: util-storage.h:41
StorageGetSize
unsigned int StorageGetSize(const StorageEnum type)
get the size of the void array used to store the pointers
Definition: util-storage.c:210
StorageEnum_
StorageEnum_
Definition: util-storage.h:29
STORAGE_FLOW
@ STORAGE_FLOW
Definition: util-storage.h:31
StorageCleanup
void StorageCleanup(void)
Definition: util-storage.c:78
type
uint16_t type
Definition: decode-vlan.c:107
STORAGE_MAX
@ STORAGE_MAX
Definition: util-storage.h:36
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:102
StorageInit
void StorageInit(void)
Definition: util-storage.c:70
StorageSetById
int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
set storage for id
Definition: util-storage.c:226
StorageGetCnt
unsigned int StorageGetCnt(const StorageEnum type)
Definition: util-storage.c:199
Storage
struct Storage Storage