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
38
39/** void ptr array for now */
40typedef struct Storage {
41 void *ptr;
43
44void StorageInit(void);
45void 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 */
58int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void (*Free)(void *));
59int StorageFinalize(void);
60
61unsigned int StorageGetCnt(const StorageEnum type);
62unsigned int StorageGetSize(const StorageEnum type);
63
64/** \brief get storage for id */
65void *StorageGetById(const Storage *storage, const StorageEnum type, const int id);
66/** \brief set storage for id */
67int 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) */
71void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id);
72void StorageFreeById(Storage *storage, const StorageEnum type, const int id);
73void StorageFreeAll(Storage *storage, const StorageEnum type);
74
75#endif
uint16_t type
void * ptr
const char * name
void * StorageGetById(const Storage *storage, const StorageEnum type, const int id)
get storage for id
unsigned int StorageGetCnt(const StorageEnum type)
enum StorageEnum_ StorageEnum
void StorageCleanup(void)
StorageEnum_
@ STORAGE_THREAD
@ STORAGE_HOST
@ STORAGE_MAX
@ STORAGE_FLOW
@ STORAGE_IPPAIR
@ STORAGE_DEVICE
int StorageRegister(const StorageEnum type, const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void(*Free)(void *))
Register new storage.
void StorageFreeAll(Storage *storage, const StorageEnum type)
void StorageFreeById(Storage *storage, const StorageEnum type, const int id)
unsigned int StorageGetSize(const StorageEnum type)
get the size of the void array used to store the pointers
int StorageFinalize(void)
int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
set storage for id
void StorageInit(void)
void * StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
AllocById func for prealloc'd base storage (storage ptrs are part of another memory block)