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 SCStorageInit(void);
45 void SCStorageCleanup(void);
46 
47 /** \brief Register new storage
48  *
49  * \param type type from StorageEnum
50  * \param name name
51  * \param Free free function for per instance storage
52  */
53 int SCStorageRegister(const StorageEnum type, const char *name, void (*Free)(void *));
54 int SCStorageFinalize(void);
55 
56 unsigned int SCStorageGetCnt(const StorageEnum type);
57 unsigned int SCStorageGetSize(const StorageEnum type);
58 
59 /** \brief get storage for id */
60 void *SCStorageGetById(const Storage *storage, const StorageEnum type, const int id);
61 /** \brief set storage for id */
62 int SCStorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr);
63 
64 /** \brief AllocById func for prealloc'd base storage (storage ptrs are part
65  * of another memory block) */
67 void SCStorageFreeById(Storage *storage, const StorageEnum type, const int id);
68 void SCStorageFreeAll(Storage *storage, const StorageEnum type);
69 
70 #endif
SCStorageGetCnt
unsigned int SCStorageGetCnt(const StorageEnum type)
Definition: util-storage.c:191
SCStorageFreeAll
void SCStorageFreeAll(Storage *storage, const StorageEnum type)
Definition: util-storage.c:252
name
const char * name
Definition: detect-engine-proto.c:48
STORAGE_IPPAIR
@ STORAGE_IPPAIR
Definition: util-storage.h:32
StorageEnum
enum StorageEnum_ StorageEnum
STORAGE_HOST
@ STORAGE_HOST
Definition: util-storage.h:30
Storage
Definition: util-storage.h:40
SCStorageFinalize
int SCStorageFinalize(void)
Definition: util-storage.c:135
STORAGE_DEVICE
@ STORAGE_DEVICE
Definition: util-storage.h:33
SCStorageInit
void SCStorageInit(void)
Definition: util-storage.c:68
STORAGE_THREAD
@ STORAGE_THREAD
Definition: util-storage.h:34
Storage::ptr
void * ptr
Definition: util-storage.h:41
StorageEnum_
StorageEnum_
Definition: util-storage.h:29
SCStorageFreeById
void SCStorageFreeById(Storage *storage, const StorageEnum type, const int id)
Definition: util-storage.c:230
STORAGE_FLOW
@ STORAGE_FLOW
Definition: util-storage.h:31
SCStorageCleanup
void SCStorageCleanup(void)
Definition: util-storage.c:76
SCStorageRegister
int SCStorageRegister(const StorageEnum type, const char *name, void(*Free)(void *))
Register new storage.
Definition: util-storage.c:100
type
uint16_t type
Definition: decode-vlan.c:106
STORAGE_MAX
@ STORAGE_MAX
Definition: util-storage.h:36
SCStorageGetSize
unsigned int SCStorageGetSize(const StorageEnum type)
get the size of the void array used to store the pointers
Definition: util-storage.c:202
SCStorageAllocByIdPrealloc
void * SCStorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
AllocById func for prealloc'd base storage (storage ptrs are part of another memory block)
SCStorageGetById
void * SCStorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
Definition: util-storage.c:207
SCStorageSetById
int SCStorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
set storage for id
Definition: util-storage.c:218
Storage
struct Storage Storage