syslog-ng source
function.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2014 Balabit
3  * Copyright (c) 1998-2014 Balázs Scheidler
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * As an additional exemption you are allowed to compile & link against the
20  * OpenSSL libraries as published by the OpenSSL project. See the file
21  * COPYING for details.
22  *
23  */
24 
25 #ifndef TEMPLATE_FUNCTION_H_INCLUDED
26 #define TEMPLATE_FUNCTION_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 #include "plugin-types.h"
31 
32 #define TEMPLATE_INVOKE_MAX_ARGS 64
33 
34 /* This structure contains the arguments for template-function
35  * expansion. It is defined in a struct because otherwise a large
36  * number of function arguments, that are passed around, possibly
37  * several times. */
38 typedef struct _LogTemplateInvokeArgs
39 {
40  /* context in case of correlation */
41  LogMessage **messages;
43 
47 
48 typedef struct _LogTemplateFunction LogTemplateFunction;
50 {
51  /* size of the state that carries information from parse-time to
52  * runtime. Can be used to store the results of expensive
53  * operations that don't need to be performed for all invocations */
55 
56  /* called when parsing the arguments to be compiled into an internal
57  * representation if necessary. Returns the compiled state in state */
58  gboolean (*prepare)(LogTemplateFunction *self, gpointer state, LogTemplate *parent, gint argc, gchar *argv[],
59  GError **error);
60 
61  /* evaluate arguments, storing argument buffers in arg_bufs in case it
62  * makes sense to reuse those buffers */
63  void (*eval)(LogTemplateFunction *self, gpointer state, LogTemplateInvokeArgs *args);
64 
65  /* call the function */
66  void (*call)(LogTemplateFunction *self, gpointer state, const LogTemplateInvokeArgs *args, GString *result,
67  LogMessageValueType *type);
68 
69  /* free data in state */
70  void (*free_state)(gpointer s);
71 
72  /* free LogTemplateFunction instance (if not static) */
73  void (*free_fn)(LogTemplateFunction *self);
74 
75  /* generic argument that can be used to pass information from registration time */
76  gpointer arg;
77 };
78 
79 #define TEMPLATE_FUNCTION_PROTOTYPE(prefix) \
80  gpointer \
81  prefix ## _construct(Plugin *self)
82 
83 #define TEMPLATE_FUNCTION_DECLARE(prefix) \
84  TEMPLATE_FUNCTION_PROTOTYPE(prefix);
85 
86 /* helper macros for template function plugins */
87 #define TEMPLATE_FUNCTION(state_struct, prefix, prepare, eval, call, free_state, arg) \
88  TEMPLATE_FUNCTION_PROTOTYPE(prefix) \
89  { \
90  static LogTemplateFunction func = { \
91  sizeof(state_struct), \
92  prepare, \
93  eval, \
94  call, \
95  free_state, \
96  NULL, \
97  arg \
98  }; \
99  return &func; \
100  }
101 
102 #define TEMPLATE_FUNCTION_PLUGIN(x, tf_name) \
103  { \
104  .type = LL_CONTEXT_TEMPLATE_FUNC, \
105  .name = tf_name, \
106  .construct = x ## _construct, \
107  }
108 
109 #endif
#define TEMPLATE_INVOKE_MAX_ARGS
Definition: function.h:32
gint argc
Definition: gprocess.c:130
gchar ** argv
Definition: gprocess.c:131
NVType LogMessageValueType
Definition: logmsg.h:195
Definition: eval.h:34
Definition: function.h:39
gint num_messages
Definition: function.h:42
LogMessage ** messages
Definition: function.h:41
LogTemplateEvalOptions * options
Definition: function.h:44
Definition: function.h:50
void(* free_state)(gpointer s)
Definition: function.h:70
gboolean(* prepare)(LogTemplateFunction *self, gpointer state, LogTemplate *parent, gint argc, gchar *argv[], GError **error)
Definition: function.h:58
void(* call)(LogTemplateFunction *self, gpointer state, const LogTemplateInvokeArgs *args, GString *result, LogMessageValueType *type)
Definition: function.h:66
gpointer arg
Definition: function.h:76
void(* free_fn)(LogTemplateFunction *self)
Definition: function.h:73
void(* eval)(LogTemplateFunction *self, gpointer state, LogTemplateInvokeArgs *args)
Definition: function.h:63
gint size_of_state
Definition: function.h:54
GString * result
Definition: test_lexer_block.c:34
struct @95 state