syslog-ng source
radix.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2012 Balabit
3  * Copyright (c) 1998-2012 Balázs Scheidler
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #ifndef CORRELATION_RADIX_H_INCLUDED
25 #define CORRELATION_RADIX_H_INCLUDED
26 
27 #include "logmsg/logmsg.h"
28 #include "messages.h"
29 
30 /* parser types, these are saved in the serialized log message along with
31  * the match information thus they have to remain the same in order to keep
32  * compatibility, thus add new stuff at the end */
33 enum
34 {
52 };
53 
54 typedef struct _RParserMatch
55 {
56  /* if this pointer is non-NULL, it means that we've transformed the
57  * original message to something else, and thus we couldn't get a
58  * reference from the original payload */
59 
60  gchar *match;
61  /* the value in which to store this match */
63  guint16 len;
64  guint16 ofs;
65  guint8 type;
66 } RParserMatch;
67 
68 typedef struct _RParserNode
69 {
70  /* user supplied parameters */
71 
72  /* user supplied parameters */
73  gchar *param;
74  /* internal state of the parser node */
75  gpointer state;
76 
77  gchar first;
78  gchar last;
79  guint8 parser_type;
82 
83  gboolean (*parse)(gchar *str, gint *len, const gchar *param, gpointer state, RParserMatch *match);
84  void (*free_state)(gpointer state);
85 } RParserNode;
86 
87 typedef gchar *(*RNodeGetValueFunc) (gpointer value);
88 
89 typedef struct _RNode RNode;
90 
91 struct _RNode
92 {
93  gchar *key;
94  gint keylen;
96  gpointer value;
97  gchar *pdb_location;
98  guint num_children;
99  RNode **children;
100 
102  RNode **pchildren;
103 };
104 
105 typedef struct _RDebugInfo
106 {
107  RNode *node;
109  gint i;
110  gint match_off;
111  gint match_len;
112 } RDebugInfo;
113 
114 static inline const gchar *
115 r_parser_type_name(guint8 type)
116 {
117  switch (type)
118  {
119  case RPT_STRING:
120  return "STRING";
121  case RPT_QSTRING:
122  return "QSTRING";
123  case RPT_ESTRING:
124  return "ESTRING";
125  case RPT_IPV4:
126  return "IPv4";
127  case RPT_NUMBER:
128  return "NUMBER";
129  case RPT_ANYSTRING:
130  return "ANYSTRING";
131  case RPT_IPV6:
132  return "IPv6";
133  case RPT_IP:
134  return "IP";
135  case RPT_FLOAT:
136  return "FLOAT";
137  case RPT_SET:
138  return "SET";
139  case RPT_MACADDR:
140  return "MACADDR";
141  case RPT_EMAIL:
142  return "EMAIL";
143  case RPT_HOSTNAME:
144  return "HOSTNAME";
145  case RPT_LLADDR:
146  return "LLADDR";
147  case RPT_PCRE:
148  return "PCRE";
149  case RPT_NLSTRING:
150  return "NLSTRING";
151  default:
152  return "UNKNOWN";
153  }
154 }
155 
156 RNode *r_new_node(const gchar *key, gpointer value);
157 void r_free_node(RNode *node, void (*free_fn)(gpointer data));
158 void r_insert_node(RNode *root, gchar *key, gpointer value,
159  const gchar *capture_prefix, RNodeGetValueFunc value_func, const gchar *location);
160 RNode *r_find_node(RNode *root, gchar *key, gint keylen, GArray *matches);
161 RNode *r_find_node_dbg(RNode *root, gchar *key, gint keylen, GArray *matches, GArray *dbg_list);
162 gchar **r_find_all_applicable_nodes(RNode *root, gchar *key, gint keylen, RNodeGetValueFunc value_func);
163 
164 #endif
NVType LogMessageValueType
Definition: logmsg.h:195
guint32 NVHandle
Definition: nvtable.h:35
@ RPT_PCRE
Definition: radix.h:46
@ RPT_MACADDR
Definition: radix.h:45
@ RPT_IPV4
Definition: radix.h:38
@ RPT_EMAIL
Definition: radix.h:47
@ RPT_NUMBER
Definition: radix.h:39
@ RPT_ANYSTRING
Definition: radix.h:40
@ RPT_NLSTRING
Definition: radix.h:50
@ RPT_IPV6
Definition: radix.h:41
@ RPT_LLADDR
Definition: radix.h:49
@ RPT_SET
Definition: radix.h:44
@ RPT_OPTIONALSET
Definition: radix.h:51
@ RPT_IP
Definition: radix.h:42
@ RPT_HOSTNAME
Definition: radix.h:48
@ RPT_STRING
Definition: radix.h:35
@ RPT_QSTRING
Definition: radix.h:36
@ RPT_ESTRING
Definition: radix.h:37
@ RPT_FLOAT
Definition: radix.h:43
gchar ** r_find_all_applicable_nodes(RNode *root, gchar *key, gint keylen, RNodeGetValueFunc value_func)
Definition: radix.c:1574
void r_insert_node(RNode *root, gchar *key, gpointer value, const gchar *capture_prefix, RNodeGetValueFunc value_func, const gchar *location)
Definition: radix.c:1010
void r_free_node(RNode *node, void(*free_fn)(gpointer data))
Definition: radix.c:1621
RNode * r_find_node_dbg(RNode *root, gchar *key, gint keylen, GArray *matches, GArray *dbg_list)
Definition: radix.c:1561
gchar *(* RNodeGetValueFunc)(gpointer value)
Definition: radix.h:87
RNode * r_new_node(const gchar *key, gpointer value)
Definition: radix.c:1602
RNode * r_find_node(RNode *root, gchar *key, gint keylen, GArray *matches)
Definition: radix.c:1549
Definition: radix.h:106
gint match_len
Definition: radix.h:111
RParserNode * pnode
Definition: radix.h:108
gint match_off
Definition: radix.h:110
RNode * node
Definition: radix.h:107
gint i
Definition: radix.h:109
Definition: radix.h:55
guint8 type
Definition: radix.h:65
guint16 len
Definition: radix.h:63
guint16 ofs
Definition: radix.h:64
gchar * match
Definition: radix.h:60
NVHandle handle
Definition: radix.h:62
Definition: radix.h:69
LogMessageValueType value_type
Definition: radix.h:80
gchar last
Definition: radix.h:78
gchar first
Definition: radix.h:77
NVHandle handle
Definition: radix.h:81
gchar * param
Definition: radix.h:73
guint8 parser_type
Definition: radix.h:79
gpointer state
Definition: radix.h:75
Definition: radix.h:92
gchar * pdb_location
Definition: radix.h:97
gchar * key
Definition: radix.h:93
gpointer value
Definition: radix.h:96
RNode ** pchildren
Definition: radix.h:102
guint num_pchildren
Definition: radix.h:101
RNode ** children
Definition: radix.h:99
guint num_children
Definition: radix.h:98
RParserNode * parser
Definition: radix.h:95
gint keylen
Definition: radix.h:94
void free_fn(CacheResolver *self)
Definition: test_cache.c:38
GString * value
Definition: test_decode.c:28
struct @95 state
struct tm key
Definition: cache.c:63