4 * The olsr.org Optimized Link-State Routing daemon(olsrd)
5 * Copyright (c) 2004, Andreas Tonnesen(andreto@olsr.org)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of olsr.org, olsrd nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * Visit http://www.olsr.org for more information.
37 * If you find this software useful feel free to make a donation
38 * to the project. For more information see the website or contact
39 * the copyright holders.
44 #define YYSTYPE struct conf_token *
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
54 #include "olsrd_conf.h"
59 int yyget_lineno(void);
60 FILE * yyget_in(void);
61 FILE* yyget_out(void);
62 char *yyget_text(void);
63 void yyset_lineno(int);
64 void yyset_in(FILE *);
65 void yyset_out(FILE *);
66 int yyget_debug(void);
67 void yyset_debug(int);
68 int yylex_destroy(void);
71 static struct conf_token *get_conf_token(void);
72 static struct conf_token *get_string_token(const char * const s, const size_t n);
73 static struct conf_token *get_integer_token(const char * const s);
74 static struct conf_token *get_floating_token(const char * const s);
75 static struct conf_token *get_boolean_token(const bool b);
77 static struct conf_token *get_conf_token(void)
79 struct conf_token *t = calloc(1, sizeof(struct conf_token));
81 fprintf(stderr, "Cannot allocate %d bytes for an configuration token.\n", (int)sizeof(struct conf_token));
86 static struct conf_token *get_string_token(const char * const s, const size_t n)
88 struct conf_token *rv = get_conf_token();
90 rv->string = malloc(n + 1);
91 if (rv->string == NULL) {
92 fprintf(stderr, "Cannot allocate %lu bytes for string token data.\n", (unsigned long)(n+1)); /* size_t on 64bit */
96 memcpy(rv->string, s, n);
102 static struct conf_token *get_integer_token(const char * const s)
104 struct conf_token *rv = get_conf_token();
106 rv->integer = strtol(s, NULL, 0);
111 static struct conf_token *get_floating_token(const char * const s)
113 struct conf_token *rv = get_conf_token();
116 sscanf(s, "%f", &rv->floating);
121 static struct conf_token *get_boolean_token(const bool b)
123 struct conf_token *rv = get_conf_token();
132 %option never-interactive
133 %option noalways-interactive
139 FLOAT {DECDIGIT}+\.{DECDIGIT}+
143 IPV4ADDR {QUAD}\.{QUAD}\.{QUAD}\.{QUAD}
147 IP6PAT2 ({HEX16}:){1}:({HEX16}:){0,5}{HEX16}
148 IP6PAT3 ({HEX16}:){2}:({HEX16}:){0,4}{HEX16}
149 IP6PAT4 ({HEX16}:){3}:({HEX16}:){0,3}{HEX16}
150 IP6PAT5 ({HEX16}:){4}:({HEX16}:){0,2}{HEX16}
151 IP6PAT6 ({HEX16}:){5}:({HEX16}:){0,1}{HEX16}
152 IP6PAT7 ({HEX16}:){6}:({HEX16})
153 IP6PAT1 ({HEX16}:){7}{HEX16}
154 IP6PAT8 ({HEX16}:){1,7}:
157 IPV6ADDR {IP6PAT1}|{IP6PAT2}|{IP6PAT3}|{IP6PAT4}|{IP6PAT5}|{IP6PAT6}|{IP6PAT7}|{IP6PAT8}|{IP6PAT9}
182 yylval = get_string_token(yytext + 1, yyleng - 2);
183 if (yylval == NULL) {
190 yylval = get_integer_token(yytext);
195 yylval = get_floating_token(yytext);
200 yylval = get_string_token(yytext, yyleng + 1);
201 if (yylval == NULL) {
207 yylval = get_string_token(yytext, yyleng + 1);
208 if (yylval == NULL) {
220 yylval = get_integer_token(yytext);
226 yylval = get_boolean_token(true);
231 yylval = get_boolean_token(false);
236 yylval = get_boolean_token(true);
241 yylval = get_boolean_token(false);
247 return TOK_HOSTLABEL;
262 return TOK_DEBUGLEVEL;
267 return TOK_IPVERSION;
272 return TOK_NICCHGSPOLLRT;
297 return TOK_INTERFACE;
328 return TOK_RTTABLE_DEFAULT;
333 return TOK_WILLINGNESS;
343 return TOK_FIBMETRIC;
353 return TOK_HYSTSCALE;
358 return TOK_HYSTUPPER;
363 return TOK_HYSTLOWER;
374 return TOK_TCREDUNDANCY;
379 return TOK_MPRCOVERAGE;
387 "LinkQualityFishEye" {
392 "LinkQualityDijkstraLimit" {
394 return TOK_LQ_DLIMIT;
402 "LinkQualityAlgorithm" {
404 return TOK_LQ_PLUGIN;
407 "LinkQualityWinSize" {
414 return TOK_LQ_NAT_THRESH;
424 return TOK_MIN_TC_VTIME;
429 return TOK_LOCK_FILE;
434 return TOK_CLEAR_SCREEN;
444 return TOK_IP4BROADCAST;
452 return TOK_IP6ADDRTYPE;
456 return TOK_IP6MULTISITE;
458 "Ip6MulticastGlobal" {
460 return TOK_IP6MULTIGLOBAL;
466 "HelloValidityTime" {
494 "AutoDetectChanges" {
496 return TOK_AUTODETCHG;
508 //fprintf(stderr, "Failed to parse line %d of configuration file.\n",
511 //yy_fatal_error("Parsing failed.\n");
513 /* To avoid compiler warning (stupid...) */