syslog-ng source
msg-format.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 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 MSG_FORMAT_H_INCLUDED
26 #define MSG_FORMAT_H_INCLUDED
27 
28 #include "syslog-ng.h"
29 #include "timeutils/zoneinfo.h"
31 
32 #include <regex.h>
33 
34 enum
35 {
36  /* don't parse the message, put everything into $MSG */
37  LP_NOPARSE = 0x0001,
38  /* check if the hostname contains valid characters and assume it is part of the program field if it isn't */
40  /* message is using RFC5424 format */
42  /* the caller knows the message is valid UTF-8 */
43  LP_ASSUME_UTF8 = 0x0008,
44  /* validate that all characters are indeed UTF-8 and mark the message as valid when relaying */
45  LP_VALIDATE_UTF8 = 0x0010,
46  /* sanitize input and force it to be valid UTF-8 by escaping */
47  LP_SANITIZE_UTF8 = 0x0020,
48  /* the message may not contain NL characters, strip them if it does */
49  LP_NO_MULTI_LINE = 0x0040,
50  /* don't store MSGHDR in the LEGACY_MSGHDR macro */
52  /* expect a hostname field in the message */
54  /* message is locally generated and should be marked with LF_LOCAL */
55  LP_LOCAL = 0x0200,
56  /* for the date part of a message, only skip it, don't fully parse - recommended for keep_timestamp(no) */
57  LP_NO_PARSE_DATE = 0x0400,
60  LP_NO_HEADER = 0x2000,
63  LP_CHECK_PROGRAM = 0x10000,
64 };
65 
66 typedef struct _MsgFormatHandler MsgFormatHandler;
67 
68 typedef struct _MsgFormatOptions
69 {
70  gboolean initialized;
71  gchar *format;
72  MsgFormatHandler *format_handler;
73  guint32 flags;
74  guint16 default_pri;
76  TimeZoneInfo *recv_time_zone_info;
77  regex_t *bad_hostname;
78  gchar *sdata_prefix;
81  gboolean use_fqdn;
83 
85 {
86  /* this method has a chance to change the LogProto related options to
87  * match the requirements of the "format" in question. This is used by
88  * the "pacct" plugin to set the record length the proper size
89  */
90  LogProtoServer *(*construct_proto)(const MsgFormatOptions *options, LogTransport *transport,
91  const LogProtoServerOptionsStorage *proto_options);
92  gboolean (*parse)(const MsgFormatOptions *options, LogMessage *msg,
93  const guchar *data, gsize length,
94  gsize *problem_position);
95 };
96 
97 gboolean msg_format_try_parse_into(MsgFormatOptions *options, LogMessage *msg,
98  const guchar *data, gsize length,
99  gsize *problem_position);
100 void msg_format_parse_into(MsgFormatOptions *options, LogMessage *msg,
101  const guchar *data, gsize length);
102 gsize msg_format_from_string(MsgFormatOptions *format_options, const char *msg_cstring, LogMessage **out_msg);
103 
104 LogMessage *msg_format_construct_message(MsgFormatOptions *options, const guchar *data, gsize length);
105 LogMessage *msg_format_parse(MsgFormatOptions *options, const guchar *data, gsize length);
106 
107 gboolean msg_format_options_set_sdata_prefix(MsgFormatOptions *options, const gchar *prefix);
108 
113 
114 gboolean msg_format_options_process_flag(MsgFormatOptions *options, const gchar *flag);
115 
116 #endif
FILE ** source
Definition: file_reader.c:47
void msg_format_options_copy(MsgFormatOptions *options, const MsgFormatOptions *source)
Definition: msg-format.c:292
gboolean msg_format_try_parse_into(MsgFormatOptions *options, LogMessage *msg, const guchar *data, gsize length, gsize *problem_position)
Definition: msg-format.c:154
gboolean msg_format_options_set_sdata_prefix(MsgFormatOptions *options, const gchar *prefix)
Definition: msg-format.c:238
gboolean msg_format_options_process_flag(MsgFormatOptions *options, const gchar *flag)
Definition: msg-format.c:350
LogMessage * msg_format_parse(MsgFormatOptions *options, const guchar *data, gsize length)
Definition: msg-format.c:228
void msg_format_options_defaults(MsgFormatOptions *options)
Definition: msg-format.c:249
@ LP_STORE_LEGACY_MSGHDR
Definition: msg-format.h:51
@ LP_SYSLOG_PROTOCOL
Definition: msg-format.h:41
@ LP_VALIDATE_UTF8
Definition: msg-format.h:45
@ LP_NO_MULTI_LINE
Definition: msg-format.h:49
@ LP_SANITIZE_UTF8
Definition: msg-format.h:47
@ LP_NO_RFC3164_FALLBACK
Definition: msg-format.h:61
@ LP_STORE_RAW_MESSAGE
Definition: msg-format.h:58
@ LP_PIGGYBACK_ERRORS
Definition: msg-format.h:62
@ LP_GUESS_TIMEZONE
Definition: msg-format.h:59
@ LP_CHECK_PROGRAM
Definition: msg-format.h:63
@ LP_NO_HEADER
Definition: msg-format.h:60
@ LP_ASSUME_UTF8
Definition: msg-format.h:43
@ LP_EXPECT_HOSTNAME
Definition: msg-format.h:53
@ LP_CHECK_HOSTNAME
Definition: msg-format.h:39
@ LP_LOCAL
Definition: msg-format.h:55
@ LP_NOPARSE
Definition: msg-format.h:37
@ LP_NO_PARSE_DATE
Definition: msg-format.h:57
void msg_format_options_destroy(MsgFormatOptions *parse_options)
Definition: msg-format.c:305
void msg_format_options_init(MsgFormatOptions *parse_options, GlobalConfig *cfg)
Definition: msg-format.c:263
gsize msg_format_from_string(MsgFormatOptions *format_options, const char *msg_cstring, LogMessage **out_msg)
Definition: msg-format.c:199
void msg_format_parse_into(MsgFormatOptions *options, LogMessage *msg, const guchar *data, gsize length)
Definition: msg-format.c:177
LogMessage * msg_format_construct_message(MsgFormatOptions *options, const guchar *data, gsize length)
Definition: msg-format.c:221
Definition: msg-format.h:69
regex_t * bad_hostname
Definition: msg-format.h:77
gchar * recv_time_zone
Definition: msg-format.h:75
gsize sdata_prefix_len
Definition: msg-format.h:79
gboolean use_fqdn
Definition: msg-format.h:81
gchar * format
Definition: msg-format.h:71
MsgFormatHandler * format_handler
Definition: msg-format.h:72
TimeZoneInfo * recv_time_zone_info
Definition: msg-format.h:76
gint sdata_param_value_max
Definition: msg-format.h:80
gchar * sdata_prefix
Definition: msg-format.h:78
guint32 flags
Definition: msg-format.h:73
gboolean initialized
Definition: msg-format.h:70
guint16 default_pri
Definition: msg-format.h:74
Definition: msg-format.h:85
gboolean(* parse)(const MsgFormatOptions *options, LogMessage *msg, const guchar *data, gsize length, gsize *problem_position)
Definition: msg-format.h:92
GlobalConfig * cfg
Definition: test_batched_ack_tracker.c:34
CSVScannerOptions options
Definition: test_csv_scanner.c:30
MsgFormatOptions parse_options
Definition: test_filters_common.c:49
LogMessage * msg
Definition: test_rename.c:35