1 /*
2 * Copyright (c) 2002-2011 Balabit
3 * Copyright (c) 1998-2011 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 #include "pragma-parser.h"
26 #include "pragma-grammar.h"
27
28 #include <stdlib.h>
29
30 extern int pragma_debug;
31 int pragma_parse(CfgLexer *lexer, gpointer *result, gpointer arg);
32
33 guint
process_version_string(gchar * value)34 process_version_string(gchar *value)
35 {
36 gchar *p, *end;
37 gint major, minor;
38
39 if (strlen(value) > strlen("xxx.yyy"))
40 return 0;
41
42 if (value[0] == '+' || value[0] == '-')
43 return 0;
44
45 p = strchr(value, '.');
46 if (p == value)
47 return 0;
48 if (p)
49 {
50 major = strtol(value, &end, 10);
51 if (major < 0)
52 return 0;
53 if (end == p)
54 {
55 minor = strtol(p+1, &end, 10);
56 if (minor < 0)
57 return 0;
58 if (*end == '\0')
59 {
60 return (major << 8) + minor;
61 }
62 }
63 }
64 return 0;
65 }
66
67 static CfgLexerKeyword pragma_keywords[] =
68 {
69 { "version", KW_VERSION, },
70 { "current", KW_VERSION_CURRENT },
71 { "include", KW_INCLUDE, },
72 { "module", KW_MODULE, },
73 { "define", KW_DEFINE, },
74 { "requires", KW_REQUIRES, },
75 { CFG_KEYWORD_STOP },
76 };
77
78 CfgParser pragma_parser =
79 {
80 #if SYSLOG_NG_ENABLE_DEBUG
81 .debug_flag = &pragma_debug,
82 #endif
83 .name = "pragma",
84 .context = LL_CONTEXT_PRAGMA,
85 .keywords = pragma_keywords,
86 .parse = pragma_parse,
87 };
88
89 CFG_PARSER_IMPLEMENT_LEXER_BINDING(pragma_, PRAGMA_, gpointer *)
90