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  * \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
23  */
24 
25 #ifndef __FLOW_VAR_H__
26 #define __FLOW_VAR_H__
27 
28 #include "flow.h"
29 #include "util-var.h"
30 
31 /** Available data types for Flowvars */
32 
33 #define FLOWVAR_TYPE_STR 1
34 #define FLOWVAR_TYPE_INT 2
35 
36 /** Struct used to hold the string data type for flowvars */
37 typedef struct FlowVarTypeStr {
38     uint8_t *value;
39     uint16_t value_len;
40 } FlowVarTypeStr;
41 
42 /** Struct used to hold the integer data type for flowvars */
43 typedef struct FlowVarTypeInt_ {
44     uint32_t value;
45 } FlowVarTypeInt;
46 
47 /** Generic Flowvar Structure */
48 typedef struct FlowVar_ {
49     uint8_t type;       /* type, DETECT_FLOWVAR in this case */
50     uint8_t datatype;
51     uint16_t keylen;
52     uint32_t idx;       /* name idx */
53     GenericVar *next;   /* right now just implement this as a list,
54                          * in the long run we have think of something
55                          * faster. */
56     union {
57         FlowVarTypeStr fv_str;
58         FlowVarTypeInt fv_int;
59     } data;
60     uint8_t *key;
61 } FlowVar;
62 
63 /** Flowvar Interface API */
64 
65 void FlowVarAddIdValue(Flow *, uint32_t id, uint8_t *value, uint16_t size);
66 void FlowVarAddKeyValue(Flow *f, uint8_t *key, uint16_t keysize, uint8_t *value, uint16_t size);
67 
68 void FlowVarAddIntNoLock(Flow *, uint32_t, uint32_t);
69 void FlowVarAddInt(Flow *, uint32_t, uint32_t);
70 FlowVar *FlowVarGet(Flow *, uint32_t);
71 FlowVar *FlowVarGetByKey(Flow *f, const uint8_t *key, uint16_t keylen);
72 void FlowVarFree(FlowVar *);
73 void FlowVarPrint(GenericVar *);
74 
75 #endif /* __FLOW_VAR_H__ */
76 
77