syslog-ng source
templates.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2013 Balabit
3  * Copyright (c) 1998-2013 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 TEMPLATES_H_INCLUDED
26 #define TEMPLATES_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 #include "eval.h"
30 #include "timeutils/zoneinfo.h"
31 #include "logmsg/type-hinting.h"
33 #include "atomic.h"
34 #include "on-error.h"
35 
36 #define LOG_TEMPLATE_ERROR log_template_error_quark()
37 
38 GQuark log_template_error_quark(void);
39 
41 {
44 };
45 
46 
47 /* structure that represents an expandable syslog-ng template */
49 {
51  gchar *name;
52  gchar *template_str;
54  GlobalConfig *cfg;
55  guint top_level: 1, escape: 1, def_inline: 1, trivial: 1, literal: 1;
56 
57  /* This value stores the type-hint the user _explicitly_ specified. If
58  * this is an automatic cast to string (in compat mode), this would be
59  * LM_VT_NONE while "type_hint" would be LM_VT_STRING */
61 
62  /* This is the type-cast we do perform as we evaluate this template. It
63  * might differ from explicit_type_hint in case we are in compatibility
64  * mode where the template would be cast to a string when the type-hint is
65  * unspecified. */
67 };
68 
69 /* appends the formatted output into result */
70 
71 void log_template_set_escape(LogTemplate *self, gboolean enable);
72 gboolean log_template_set_type_hint(LogTemplate *self, const gchar *hint, GError **error);
73 void log_template_set_type_hint_value(LogTemplate *self, LogMessageValueType type);
74 gboolean log_template_compile(LogTemplate *self, const gchar *template_str, GError **error);
75 gboolean log_template_compile_with_type_hint(LogTemplate *self, const gchar *template_and_typehint, GError **error);
76 void log_template_forget_template_string(LogTemplate *self);
77 void log_template_compile_literal_string(LogTemplate *self, const gchar *literal);
78 gboolean log_template_is_literal_string(const LogTemplate *self);
79 const gchar *log_template_get_literal_value(const LogTemplate *self, gssize *value_len);
80 gboolean log_template_is_trivial(LogTemplate *self);
82 const gchar *log_template_get_trivial_value(LogTemplate *self, LogMessage *msg, gssize *value_len);
83 const gchar *log_template_get_trivial_value_and_type(LogTemplate *self, LogMessage *msg, gssize *value_len,
84  LogMessageValueType *type);
85 void log_template_set_name(LogTemplate *self, const gchar *name);
86 
87 LogTemplate *log_template_new(GlobalConfig *cfg, const gchar *name);
88 LogTemplate *log_template_new_embedded(GlobalConfig *cfg);
89 LogTemplate *log_template_ref(LogTemplate *s);
90 void log_template_unref(LogTemplate *s);
91 
92 void log_template_options_clone(LogTemplateOptions *source, LogTemplateOptions *dest);
93 void log_template_options_init(LogTemplateOptions *options, GlobalConfig *cfg);
94 void log_template_options_destroy(LogTemplateOptions *options);
95 void log_template_options_defaults(LogTemplateOptions *options);
96 void log_template_options_global_defaults(LogTemplateOptions *options);
97 
98 gboolean log_template_on_error_parse(const gchar *on_error, gint *out);
99 void log_template_options_set_on_error(LogTemplateOptions *options, gint on_error);
100 
101 EVTTAG *evt_tag_template(const gchar *name, LogTemplate *template_obj, LogMessage *msg,
102  LogTemplateEvalOptions *options);
103 
104 #endif
const gchar * name
Definition: debugger.c:265
FILE ** source
Definition: file_reader.c:47
NVType LogMessageValueType
Definition: logmsg.h:195
guint32 NVHandle
Definition: nvtable.h:35
Definition: atomic.h:31
Definition: eval.h:34
Definition: templates.h:49
GlobalConfig * cfg
Definition: templates.h:54
guint literal
Definition: templates.h:55
LogMessageValueType explicit_type_hint
Definition: templates.h:60
gchar * template_str
Definition: templates.h:52
GAtomicCounter ref_cnt
Definition: templates.h:50
gchar * name
Definition: templates.h:51
GList * compiled_template
Definition: templates.h:53
guint top_level
Definition: templates.h:55
guint escape
Definition: templates.h:55
guint trivial
Definition: templates.h:55
LogMessageValueType type_hint
Definition: templates.h:66
guint def_inline
Definition: templates.h:55
void log_template_compile_literal_string(LogTemplate *self, const gchar *literal)
Definition: templates.c:280
gboolean log_template_set_type_hint(LogTemplate *self, const gchar *hint, GError **error)
Definition: templates.c:302
void log_template_set_name(LogTemplate *self, const gchar *name)
Definition: templates.c:355
GQuark log_template_error_quark(void)
Definition: templates.c:491
void log_template_unref(LogTemplate *s)
Definition: templates.c:406
const gchar * log_template_get_literal_value(const LogTemplate *self, gssize *value_len)
Definition: templates.c:40
void log_template_options_init(LogTemplateOptions *options, GlobalConfig *cfg)
Definition: templates.c:414
EVTTAG * evt_tag_template(const gchar *name, LogTemplate *template_obj, LogMessage *msg, LogTemplateEvalOptions *options)
Definition: templates.c:509
void log_template_options_set_on_error(LogTemplateOptions *options, gint on_error)
Definition: templates.c:503
const gchar * log_template_get_trivial_value(LogTemplate *self, LogMessage *msg, gssize *value_len)
Definition: templates.c:120
void log_template_set_type_hint_value(LogTemplate *self, LogMessageValueType type)
Definition: templates.c:327
const gchar * log_template_get_trivial_value_and_type(LogTemplate *self, LogMessage *msg, gssize *value_len, LogMessageValueType *type)
Definition: templates.c:89
LogTemplate * log_template_ref(LogTemplate *s)
Definition: templates.c:398
gboolean log_template_compile_with_type_hint(LogTemplate *self, const gchar *template_and_typehint, GError **error)
Definition: templates.c:258
LogTemplateError
Definition: templates.h:41
@ LOG_TEMPLATE_ERROR_COMPILE
Definition: templates.h:43
@ LOG_TEMPLATE_ERROR_FAILED
Definition: templates.h:42
gboolean log_template_is_literal_string(const LogTemplate *self)
Definition: templates.c:34
void log_template_options_destroy(LogTemplateOptions *options)
Definition: templates.c:457
gboolean log_template_compile(LogTemplate *self, const gchar *template_str, GError **error)
Definition: templates.c:193
void log_template_options_defaults(LogTemplateOptions *options)
Definition: templates.c:472
void log_template_forget_template_string(LogTemplate *self)
Definition: templates.c:215
void log_template_options_global_defaults(LogTemplateOptions *options)
Definition: templates.c:482
NVHandle log_template_get_trivial_value_handle(LogTemplate *self)
Definition: templates.c:62
LogTemplate * log_template_new_embedded(GlobalConfig *cfg)
Definition: templates.c:381
gboolean log_template_is_trivial(LogTemplate *self)
Definition: templates.c:56
void log_template_set_escape(LogTemplate *self, gboolean enable)
Definition: templates.c:296
gboolean log_template_on_error_parse(const gchar *on_error, gint *out)
Definition: templates.c:497
void log_template_options_clone(LogTemplateOptions *source, LogTemplateOptions *dest)
Definition: templates.c:439
LogTemplate * log_template_new(GlobalConfig *cfg, const gchar *name)
Definition: templates.c:364
GlobalConfig * cfg
Definition: test_batched_ack_tracker.c:34
LogMessage * msg
Definition: test_rename.c:35