File: templates.h

package info (click to toggle)
syslog-ng 4.8.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,456 kB
  • sloc: ansic: 177,631; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (104 lines) | stat: -rw-r--r-- 4,408 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2002-2013 Balabit
 * Copyright (c) 1998-2013 Balázs Scheidler
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * As an additional exemption you are allowed to compile & link against the
 * OpenSSL libraries as published by the OpenSSL project. See the file
 * COPYING for details.
 *
 */

#ifndef TEMPLATES_H_INCLUDED
#define TEMPLATES_H_INCLUDED

#include "syslog-ng.h"
#include "eval.h"
#include "timeutils/zoneinfo.h"
#include "logmsg/type-hinting.h"
#include "common-template-typedefs.h"
#include "atomic.h"
#include "on-error.h"

#define LOG_TEMPLATE_ERROR log_template_error_quark()

GQuark log_template_error_quark(void);

enum LogTemplateError
{
  LOG_TEMPLATE_ERROR_FAILED,
  LOG_TEMPLATE_ERROR_COMPILE,
};


/* structure that represents an expandable syslog-ng template */
struct _LogTemplate
{
  GAtomicCounter ref_cnt;
  gchar *name;
  gchar *template_str;
  GList *compiled_template;
  GlobalConfig *cfg;
  guint top_level:1, escape:1, def_inline:1, trivial:1, literal:1;

  /* This value stores the type-hint the user _explicitly_ specified.  If
   * this is an automatic cast to string (in compat mode), this would be
   * LM_VT_NONE while "type_hint" would be LM_VT_STRING */
  LogMessageValueType explicit_type_hint;

  /* This is the type-cast we do perform as we evaluate this template.  It
   * might differ from explicit_type_hint in case we are in compatibility
   * mode where the template would be cast to a string when the type-hint is
   * unspecified.  */
  LogMessageValueType type_hint;
};

/* appends the formatted output into result */

void log_template_set_escape(LogTemplate *self, gboolean enable);
gboolean log_template_set_type_hint(LogTemplate *self, const gchar *hint, GError **error);
void log_template_set_type_hint_value(LogTemplate *self, LogMessageValueType type);
gboolean log_template_compile(LogTemplate *self, const gchar *template_str, GError **error);
gboolean log_template_compile_with_type_hint(LogTemplate *self, const gchar *template_and_typehint, GError **error);
void log_template_forget_template_string(LogTemplate *self);
void log_template_compile_literal_string(LogTemplate *self, const gchar *literal);
gboolean log_template_is_literal_string(const LogTemplate *self);
const gchar *log_template_get_literal_value(const LogTemplate *self, gssize *value_len);
gboolean log_template_is_trivial(LogTemplate *self);
NVHandle log_template_get_trivial_value_handle(LogTemplate *self);
const gchar *log_template_get_trivial_value(LogTemplate *self, LogMessage *msg, gssize *value_len);
const gchar *log_template_get_trivial_value_and_type(LogTemplate *self, LogMessage *msg, gssize *value_len,
                                                     LogMessageValueType *type);
void log_template_set_name(LogTemplate *self, const gchar *name);

LogTemplate *log_template_new(GlobalConfig *cfg, const gchar *name);
LogTemplate *log_template_new_embedded(GlobalConfig *cfg);
LogTemplate *log_template_ref(LogTemplate *s);
void log_template_unref(LogTemplate *s);

void log_template_options_clone(LogTemplateOptions *source, LogTemplateOptions *dest);
void log_template_options_init(LogTemplateOptions *options, GlobalConfig *cfg);
void log_template_options_destroy(LogTemplateOptions *options);
void log_template_options_defaults(LogTemplateOptions *options);
void log_template_options_global_defaults(LogTemplateOptions *options);

gboolean log_template_on_error_parse(const gchar *on_error, gint *out);
void log_template_options_set_on_error(LogTemplateOptions *options, gint on_error);

EVTTAG *evt_tag_template(const gchar *name, LogTemplate *template_obj, LogMessage *msg,
                         LogTemplateEvalOptions *options);

#endif