File: config_gram.l

package info (click to toggle)
spread 3.17.4-2
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 1,800 kB
  • ctags: 2,322
  • sloc: ansic: 15,666; sh: 2,611; java: 2,291; perl: 556; yacc: 523; makefile: 255; lex: 204; xml: 77
file content (204 lines) | stat: -rw-r--r-- 9,386 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
%{
/*
 * The Spread Toolkit.
 *     
 * The contents of this file are subject to the Spread Open-Source
 * License, Version 1.0 (the ``License''); you may not use
 * this file except in compliance with the License.  You may obtain a
 * copy of the License at:
 *
 * http://www.spread.org/license/
 *
 * or in the file ``license.txt'' found in this distribution.
 *
 * Software distributed under the License is distributed on an AS IS basis, 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 * for the specific language governing rights and limitations under the 
 * License.
 *
 * The Creators of Spread are:
 *  Yair Amir, Michal Miskin-Amir, Jonathan Stanton.
 *
 *  Copyright (C) 1993-2002 Spread Concepts LLC <spread@spreadconcepts.com>
 *
 *  All Rights Reserved.
 *
 * Major Contributor(s):
 * ---------------
 *    Cristina Nita-Rotaru crisn@cnds.jhu.edu - group communication security.
 *    Theo Schlossnagle    jesus@omniti.com - Perl, skiplists, autoconf.
 *    Dan Schoenblum       dansch@cnds.jhu.edu - Java interface.
 *    John Schultz         jschultz@cnds.jhu.edu - contribution to process group membership.
 *
 */


#include "arch.h"
#include <string.h>

#ifndef  ARCH_PC_WIN95
#include <sys/types.h>
#include <netinet/in.h>

#else /* ARCH_PC_WIN95 */

#include <winsock.h>

#endif /* ARCH_PC_WIN95 */

#include "conf_body.h"
#include "y.tab.h"

extern int line_num;
extern int semantic_errors;
extern int yyerror(char *str);
extern void yywarn(char *str);
%}
qstring \"[^\"]*\"|\'[^\']*\'
string  [^ \t\r\n#{}]+
true    [Tt][Rr][Uu][Ee]
yes     [Yy][Ee][Ss]
on      [Oo][Nn]
false   [Ff][Aa][Ll][Ss][Ee]
no      [Nn][Oo]
off     [Oo][Ff][Ff]
auto    [Aa][Uu][Tt][Oo]
ipaddr  [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}
ipport  [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,5}
%option noyywrap
%%
#.*                             {} /* Comments */
[ \t\r]                         {} /* White space */
\n                              { line_num++;}
"{"                             { return OPENBRACE; }
"}"                             { return CLOSEBRACE; }
"="                             { return EQUALS; }
":"                             { return COLON; }
!/.+ 				{ return BANG; }
Spread_Segment                  { return SEGMENT; }
EventLogFile                    { return EVENTLOGFILE; }
EventTimeStamp                  { return EVENTTIMESTAMP; }
EventPriority                   { return EVENTPRIORITY; }
DebugFlags                      { return DEBUGFLAGS; }
DangerousMonitor                { return DANGEROUSMONITOR; }
SocketPortReuse                 { return SOCKETPORTREUSE; }
RuntimeDir                      { return RUNTIMEDIR; }
DaemonUser                      { return SPUSER; }
DaemonGroup                     { return SPGROUP; }
RequiredAuthMethods             { return REQUIREDAUTHMETHODS; }
AllowedAuthMethods              { return ALLOWEDAUTHMETHODS; }
AccessControlPolicy             { return ACCESSCONTROLPOLICY; }
LinkProtocol                    { return LINKPROTOCOL; }
Hop                             { return PHOP; }
TcpHop                          { return PTCPHOP; }
RouteMatrix                     { return ROUTEMATRIX; }
{true}|{yes}                    { yylval.boolean = TRUE; return SP_BOOL; }
{false}|{no}                    { yylval.boolean = FALSE; return SP_BOOL; }
{on}                            { yylval.number = 1; return SP_TRIVAL; }
{off}                           { yylval.number = 0; return SP_TRIVAL; }
{auto}                          { yylval.number = 2; return SP_TRIVAL; }
DEBUG	 			{ yylval.mask = 0x00000001; return DDEBUG; }
EXIT				{ yylval.mask = 0x00000002; return DEXIT; }
PRINT				{ yylval.mask = 0x00000004; return DPRINT; }
DATA_LINK			{ yylval.mask = 0x00000010; return DDATA_LINK; }
NETWORK				{ yylval.mask = 0x00000020; return DNETWORK; }
PROTOCOL			{ yylval.mask = 0x00000040; return DPROTOCOL; }
SESSION				{ yylval.mask = 0x00000080; return DSESSION; }
CONFIGURATION			{ yylval.mask = 0x00000100; return DCONF; }
MEMBERSHIP			{ yylval.mask = 0x00000200; return DMEMB; }
FLOW_CONTROL			{ yylval.mask = 0x00000400; return DFLOW_CONTROL; }
STATUS				{ yylval.mask = 0x00000800; return DSTATUS; }
EVENTS				{ yylval.mask = 0x00001000; return DEVENTS; }
GROUPS				{ yylval.mask = 0x00002000; return DGROUPS; }
MEMORY				{ yylval.mask = 0x00010000; return DMEMORY; }
SKIPLIST			{ yylval.mask = 0x00200000; return DSKIPLIST; }
ACM     			{ yylval.mask = 0x00400000; return DACM; }
ALL				{ yylval.mask = 0xffffffff; return DALL; }
NONE				{ yylval.mask = 0x00000000; return DNONE; }
M                               { yylval.mask = IFTYPE_MONITOR; return IMONITOR; }
C                               { yylval.mask = IFTYPE_CLIENT; return ICLIENT; }
D                               { yylval.mask = IFTYPE_DAEMON; return IDAEMON; }
pDEBUG                           { yylval.number = 1; return PDEBUG; }
INFO                            { yylval.number = 2; return PINFO; }
WARNING                         { yylval.number = 3; return PWARNING; }
ERROR                           { yylval.number = 4; return PERROR; }
CRITICAL                        { yylval.number = 5; return PCRITICAL; }
FATAL                           { yylval.number = 6; return PFATAL; }

{ipport}                        { struct in_addr inaddr;
                                  int a1,a2,a3,a4,a5;
                                  char *c1,*c2,*c3,*c4,*c5;
                                  c1=strdup(yytext);
                                  c2=strchr(c1, '.'); *(c2++)=0;
                                  c3=strchr(c2, '.'); *(c3++)=0;
                                  c4=strchr(c3, '.'); *(c4++)=0;
                                  c5=strchr(c4, ':'); *(c5++)=0;
                                  a1=atoi(c1); a2=atoi(c2);
                                  a3=atoi(c3); a4=atoi(c4);
                                  a5=atoi(c5);
                                  free(c1);
                                  if ((a1 < 0) || (a1 > 255) ||
				      (a2 < 0) || (a2 > 255) ||
				      (a3 < 0) || (a3 > 255) ||
				      (a4 < 0) || (a4 > 255))
                                    yyerror("Invalid IP");
                                  inaddr.s_addr =
                                      ((a1<<24)|(a2<<16)|(a3<<8)|a4);
                                  yylval.ip.addr = inaddr;
                                  yylval.ip.port = a5;
                                  return IPADDR;
                                }
{ipaddr}                        { struct in_addr inaddr;
                                  int a1,a2,a3,a4;
                                  char *c1,*c2,*c3,*c4;
                                  c1=strdup(yytext);
                                  c2=strchr(c1, '.'); *(c2++)=0;
                                  c3=strchr(c2, '.'); *(c3++)=0;
                                  c4=strchr(c3, '.'); *(c4++)=0;
                                  a1=atoi(c1); a2=atoi(c2);
                                  a3=atoi(c3); a4=atoi(c4);
                                  free(c1);
                                  if ((a1 < 0) || (a1 > 255) ||
				      (a2 < 0) || (a2 > 255) ||
				      (a3 < 0) || (a3 > 255) ||
				      (a4 < 0) || (a4 > 255))
                                    yyerror("Invalid IP");
                                  inaddr.s_addr =
                                      ((a1<<24)|(a2<<16)|(a3<<8)|a4);
                                  yylval.ip.addr = inaddr;
                                  yylval.ip.port = 0;
                                  return IPADDR;
                                }
([0-9]{1,3}[ \t]*)+[ \t]*    { 
                                  int fcost, i, done;
                                  char *c;
                                  char *ccur;
                                  i = 0;
                                  done = 0;
                                  c = ccur = strdup(yytext);
                                  while(!done) {
                                          fcost = atoi(ccur);
                                          if (fcost < 0) yyerror("Invalid Negative Cost");
                                          if (fcost > 100) {
                                                  yywarn("Cost clamped to 100");
                                                  fcost = 100;
                                          }
                                          yylval.cost[i] = fcost;
                                          i++;
                                          ccur = strchr(ccur, ' '); 
                                          if (ccur == NULL) done = 1;
                                          else ccur++;
                                  }
                                  free(c);
                                  for( ; i < MAX_SEGMENTS; i++) {
                                          yylval.cost[i] = -1;
                                  }
                                  return LINKCOST;
                                }
{qstring}                       { int l = strlen(yytext);
                                  yytext[l-1] = 0;
                                  yylval.string = strdup(yytext+1);
                                  return STRING; }
{string}                        { yylval.string = strdup(yytext);
                                  return STRING; }
%%