syslog-ng source
logproto.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 LOGPROTO_H_INCLUDED
26 #define LOGPROTO_H_INCLUDED
27 
29 
30 #define RFC6587_MAX_FRAME_LEN_DIGITS 10
31 
32 typedef enum
33 {
40 
41 /*
42  * log_proto_get_char_size_for_fixed_encoding:
43  *
44  * This function returns the number of bytes of a single character in the
45  * encoding specified by the @encoding parameter, provided it is listed in
46  * the limited set hard-wired in the fixed_encodings array above.
47  *
48  * syslog-ng sometimes needs to calculate the size of the original, raw data
49  * that relates to its already utf8 converted input buffer. For that the
50  * slow solution is to actually perform the utf8 -> raw conversion, however
51  * since we don't really need the actual conversion, just the size of the
52  * data in bytes we can be faster than that by multiplying the number of
53  * input characters with the size of the character in the known
54  * fixed-length-encodings in the list above.
55  *
56  * This function returns 0 if the encoding is not known, in which case the
57  * slow path is to be executed.
58  */
59 static inline gint
60 log_proto_get_char_size_for_fixed_encoding(const gchar *encoding)
61 {
62  static struct
63  {
64  const gchar *prefix;
65  gint scale;
66  } fixed_encodings[] =
67  {
68  { "ascii", 1 },
69  { "us-ascii", 1 },
70  { "iso-8859", 1 },
71  { "iso8859", 1 },
72  { "latin", 1 },
73  { "ucs2", 2 },
74  { "ucs-2", 2 },
75  { "ucs4", 4 },
76  { "ucs-4", 4 },
77  { "koi", 1 },
78  { "unicode", 2 },
79  { "windows", 1 },
80  { "wchar_t", sizeof(wchar_t) },
81  { NULL, 0 }
82  };
83  gint scale = 0;
84  gint i;
85 
86  for (i = 0; fixed_encodings[i].prefix; i++)
87  {
88  if (strncasecmp(encoding, fixed_encodings[i].prefix, strlen(fixed_encodings[i].prefix)) == 0)
89  {
90  scale = fixed_encodings[i].scale;
91  break;
92  }
93  }
94  return scale;
95 }
96 
97 #endif
LogProtoStatus
Definition: logproto.h:33
@ LPS_SUCCESS
Definition: logproto.h:34
@ LPS_AGAIN
Definition: logproto.h:38
@ LPS_EOF
Definition: logproto.h:36
@ LPS_PARTIAL
Definition: logproto.h:37
@ LPS_ERROR
Definition: logproto.h:35