1 /*
2  * Copyright (c) 2012-2014 Balabit
3  * Copyright (c) 2012-2014 Gergely Nagy <algernon@balabit.hu>
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 TYPE_HINTING_H
26 #define TYPE_HINTING_H
27 
28 #include "syslog-ng.h"
29 
30 #define TYPE_HINTING_ERROR type_hinting_error_quark()
31 
32 GQuark type_hinting_error_quark(void);
33 
34 enum TypeHintingError
35 {
36   TYPE_HINTING_INVALID_TYPE,
37   TYPE_HINTING_INVALID_CAST,
38 };
39 
40 typedef enum
41 {
42   TYPE_HINT_STRING,
43   TYPE_HINT_LITERAL,
44   TYPE_HINT_BOOLEAN,
45   TYPE_HINT_INT32,
46   TYPE_HINT_INT64,
47   TYPE_HINT_DOUBLE,
48   TYPE_HINT_DATETIME,
49   TYPE_HINT_LIST,
50   TYPE_HINT_DEFAULT,
51 } TypeHint;
52 
53 gboolean type_hint_parse(const gchar *hint, TypeHint *out_hint, GError **error);
54 
55 gboolean type_cast_drop_helper(gint drop_flags, const gchar *value,
56                                const gchar *type_hint);
57 
58 gboolean type_cast_to_boolean(const gchar *value, gboolean *out, GError **error);
59 gboolean type_cast_to_int32(const gchar *value, gint32 *out, GError **error);
60 gboolean type_cast_to_int64(const gchar *value, gint64 *out, GError **error);
61 gboolean type_cast_to_double(const gchar *value, gdouble *out, GError **error);
62 gboolean type_cast_to_datetime_int(const gchar *value, guint64 *out, GError **error);
63 gboolean type_cast_to_datetime_str(const gchar *value, const char *format,
64                                    gchar **out, GError **error);
65 
66 #endif
67