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"
30 #include "logproto/logproto-server.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 */
39   LP_CHECK_HOSTNAME  = 0x0002,
40   /* message is using RFC5424 format */
41   LP_SYSLOG_PROTOCOL = 0x0004,
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 */
51   LP_STORE_LEGACY_MSGHDR = 0x0080,
52   /* expect a hostname field in the message */
53   LP_EXPECT_HOSTNAME = 0x0100,
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,
58   LP_STORE_RAW_MESSAGE = 0x0800,
59   LP_GUESS_TIMEZONE = 0x1000,
60   LP_NO_HEADER = 0x2000,
61 };
62 
63 typedef struct _MsgFormatHandler MsgFormatHandler;
64 
65 typedef struct _MsgFormatOptions
66 {
67   gboolean initialized;
68   gchar *format;
69   MsgFormatHandler *format_handler;
70   guint32 flags;
71   guint16 default_pri;
72   gchar *recv_time_zone;
73   TimeZoneInfo *recv_time_zone_info;
74   regex_t *bad_hostname;
75   gint sdata_param_value_max;
76 } MsgFormatOptions;
77 
78 struct _MsgFormatHandler
79 {
80   /* this method has a chance to change the LogProto related options to
81    * match the requirements of the "format" in question.  This is used by
82    * the "pacct" plugin to set the record length the proper size
83    */
84   LogProtoServer *(*construct_proto)(const MsgFormatOptions *options, LogTransport *transport,
85                                      const LogProtoServerOptions *proto_options);
86   gboolean (*parse)(const MsgFormatOptions *options, LogMessage *msg,
87                     const guchar *data, gsize length,
88                     gsize *problem_position);
89 };
90 
91 gboolean msg_format_parse_conditional(MsgFormatOptions *options, LogMessage *msg,
92                                       const guchar *data, gsize length,
93                                       gsize *problem_position);
94 void msg_format_parse(MsgFormatOptions *options, LogMessage *msg,
95                       const guchar *data, gsize length);
96 
97 void msg_format_options_defaults(MsgFormatOptions *options);
98 void msg_format_options_init(MsgFormatOptions *parse_options, GlobalConfig *cfg);
99 void msg_format_options_destroy(MsgFormatOptions *parse_options);
100 void msg_format_options_copy(MsgFormatOptions *options, const MsgFormatOptions *source);
101 
102 gboolean msg_format_options_process_flag(MsgFormatOptions *options, const gchar *flag);
103 
104 #endif
105