1 #ifndef lint
2 static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
3 #endif
4
5 #include <stdlib.h>
6
7 #define YYBYACC 1
8 #define YYMAJOR 1
9 #define YYMINOR 9
10 #define YYPATCH 20050813
11
12 #define YYEMPTY (-1)
13 #define yyclearin (yychar = YYEMPTY)
14 #define yyerrok (yyerrflag = 0)
15 #define YYRECOVERING (yyerrflag != 0)
16
17 extern int yyparse(void);
18
19 static int yygrowstack(void);
20 #define YYPREFIX "yy"
21 #line 2 "parser.y"
22 /*
23 *
24 * BlueZ - Bluetooth protocol stack for Linux
25 *
26 * Copyright (C) 2002-2008 Marcel Holtmann <marcel@holtmann.org>
27 *
28 *
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
42 *
43 */
44
45 #ifdef HAVE_CONFIG_H
46 #include <config.h>
47 #endif
48
49 #include <stdio.h>
50 #include <errno.h>
51 #include <unistd.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <sys/param.h>
55 #include <sys/socket.h>
56
57 #include <bluetooth/bluetooth.h>
58 #include <bluetooth/rfcomm.h>
59
60 #include "kword.h"
61
62 int yylex(void);
63 int yyerror(char *s);
64
65 struct rfcomm_opts *opts;
66
67 #line 49 "parser.y"
68 typedef union {
69 int number;
70 char *string;
71 bdaddr_t *bdaddr;
72 } YYSTYPE;
73 #line 74 "y.tab.c"
74 #define K_BIND 257
75 #define K_DEVICE 258
76 #define K_CHANNEL 259
77 #define K_COMMENT 260
78 #define K_YES 261
79 #define K_NO 262
80 #define NUMBER 263
81 #define RFCOMM 264
82 #define STRING 265
83 #define WORD 266
84 #define BDADDR 267
85 #define YYERRCODE 256
86 short yylhs[] = { -1,
87 0, 0, 0, 2, 2, 2, 2, 3, 5, 4,
88 4, 4, 6, 6, 6, 6, 6, 1, 1,
89 };
90 short yylen[] = { 2,
91 0, 1, 2, 4, 4, 1, 1, 1, 1, 2,
92 2, 3, 2, 2, 2, 2, 1, 1, 1,
93 };
94 short yydefred[] = { 0,
95 7, 9, 0, 0, 2, 0, 0, 3, 0, 0,
96 0, 0, 0, 0, 0, 17, 0, 0, 0, 11,
97 18, 19, 13, 14, 15, 16, 4, 0, 10, 5,
98 12,
99 };
100 short yydgoto[] = { 4,
101 23, 5, 6, 17, 7, 18,
102 };
103 short yysindex[] = { -254,
104 0, 0, 0, -254, 0, -120, -109, 0, -251, -251,
105 -41, -245, -248, -243, -244, 0, -125, -37, -121, 0,
106 0, 0, 0, 0, 0, 0, 0, -36, 0, 0,
107 0,
108 };
109 short yyrindex[] = { 24,
110 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0,
114 };
115 short yygindex[] = { 0,
116 0, 21, 0, 16, 0, -6,
117 };
118 #define YYTABLESIZE 267
119 short yytable[] = { 27,
120 6, 1, 9, 30, 11, 12, 13, 14, 15, 2,
121 28, 3, 28, 10, 16, 21, 22, 20, 24, 25,
122 26, 29, 31, 1, 8, 19, 0, 0, 0, 0,
123 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
126 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 8, 0, 0, 0, 0, 0, 0,
133 0, 12, 13, 14, 15, 12, 13, 14, 15, 0,
134 16, 0, 0, 0, 16, 0, 0, 0, 0, 0,
135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
139 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
140 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
141 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
145 0, 0, 0, 0, 0, 0, 6, 0, 0, 0,
146 0, 0, 0, 0, 6, 0, 6,
147 };
148 short yycheck[] = { 125,
149 0, 256, 123, 125, 256, 257, 258, 259, 260, 264,
150 17, 266, 19, 123, 266, 261, 262, 59, 267, 263,
151 265, 59, 59, 0, 4, 10, -1, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
159 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
161 -1, -1, -1, 123, -1, -1, -1, -1, -1, -1,
162 -1, 257, 258, 259, 260, 257, 258, 259, 260, -1,
163 266, -1, -1, -1, 266, -1, -1, -1, -1, -1,
164 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
165 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
166 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
167 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
168 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
169 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
170 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
174 -1, -1, -1, -1, -1, -1, 256, -1, -1, -1,
175 -1, -1, -1, -1, 264, -1, 266,
176 };
177 #define YYFINAL 4
178 #ifndef YYDEBUG
179 #define YYDEBUG 0
180 #endif
181 #define YYMAXTOKEN 267
182 #if YYDEBUG
183 char *yyname[] = {
184 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
185 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"';'",0,0,0,0,0,0,0,0,0,0,0,0,
186 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
187 0,0,0,0,0,0,0,0,0,0,0,"'{'",0,"'}'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
188 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
189 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
190 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"K_BIND","K_DEVICE",
191 "K_CHANNEL","K_COMMENT","K_YES","K_NO","NUMBER","RFCOMM","STRING","WORD",
192 "BDADDR",
193 };
194 char *yyrule[] = {
195 "$accept : config",
196 "config :",
197 "config : statement",
198 "config : config statement",
199 "statement : section '{' rfcomm_options '}'",
200 "statement : rfcomm '{' rfcomm_options '}'",
201 "statement : WORD",
202 "statement : error",
203 "section : WORD",
204 "rfcomm : RFCOMM",
205 "rfcomm_options : rfcomm_option ';'",
206 "rfcomm_options : error ';'",
207 "rfcomm_options : rfcomm_options rfcomm_option ';'",
208 "rfcomm_option : K_BIND bool",
209 "rfcomm_option : K_DEVICE BDADDR",
210 "rfcomm_option : K_CHANNEL NUMBER",
211 "rfcomm_option : K_COMMENT STRING",
212 "rfcomm_option : WORD",
213 "bool : K_YES",
214 "bool : K_NO",
215 };
216 #endif
217 #if YYDEBUG
218 #include <stdio.h>
219 #endif
220
221 /* define the initial stack-sizes */
222 #ifdef YYSTACKSIZE
223 #undef YYMAXDEPTH
224 #define YYMAXDEPTH YYSTACKSIZE
225 #else
226 #ifdef YYMAXDEPTH
227 #define YYSTACKSIZE YYMAXDEPTH
228 #else
229 #define YYSTACKSIZE 500
230 #define YYMAXDEPTH 500
231 #endif
232 #endif
233
234 #define YYINITSTACKSIZE 500
235
236 int yydebug;
237 int yynerrs;
238 int yyerrflag;
239 int yychar;
240 short *yyssp;
241 YYSTYPE *yyvsp;
242 YYSTYPE yyval;
243 YYSTYPE yylval;
244
245 /* variables for the parser stack */
246 static short *yyss;
247 static short *yysslim;
248 static YYSTYPE *yyvs;
249 static int yystacksize;
250 #line 134 "parser.y"
251
yyerror(char * s)252 int yyerror(char *s)
253 {
254 fprintf(stderr, "%s line %d\n", s, lineno);
255 return 0;
256 }
257
rfcomm_read_config(char * filename)258 int rfcomm_read_config(char *filename)
259 {
260 extern FILE *yyin;
261 char file[MAXPATHLEN + 1];
262 int i;
263
264 for (i = 0; i < RFCOMM_MAX_DEV; i++) {
265 rfcomm_opts[i].bind = 0;
266 bacpy(&rfcomm_opts[i].bdaddr, BDADDR_ANY);
267 rfcomm_opts[i].channel = 1;
268 }
269
270 if (filename) {
271 snprintf(file, MAXPATHLEN, "%s", filename);
272 } else {
273 snprintf(file, MAXPATHLEN, "%s/.bluetooth/rfcomm.conf", getenv("HOME"));
274
275 if ((getuid() == 0) || (access(file, R_OK) < 0))
276 snprintf(file, MAXPATHLEN, "%s/rfcomm.conf", CONFIGDIR);
277 }
278
279 if (!(yyin = fopen(file, "r")))
280 return -1;
281
282 lineno = 1;
283 yyparse();
284
285 fclose(yyin);
286
287 return 0;
288 }
289 #line 290 "y.tab.c"
290 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
yygrowstack(void)291 static int yygrowstack(void)
292 {
293 int newsize, i;
294 short *newss;
295 YYSTYPE *newvs;
296
297 if ((newsize = yystacksize) == 0)
298 newsize = YYINITSTACKSIZE;
299 else if (newsize >= YYMAXDEPTH)
300 return -1;
301 else if ((newsize *= 2) > YYMAXDEPTH)
302 newsize = YYMAXDEPTH;
303
304 i = yyssp - yyss;
305 newss = (yyss != 0)
306 ? (short *)realloc(yyss, newsize * sizeof(*newss))
307 : (short *)malloc(newsize * sizeof(*newss));
308 if (newss == 0)
309 return -1;
310
311 yyss = newss;
312 yyssp = newss + i;
313 newvs = (yyvs != 0)
314 ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs))
315 : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
316 if (newvs == 0)
317 return -1;
318
319 yyvs = newvs;
320 yyvsp = newvs + i;
321 yystacksize = newsize;
322 yysslim = yyss + newsize - 1;
323 return 0;
324 }
325
326 #define YYABORT goto yyabort
327 #define YYREJECT goto yyabort
328 #define YYACCEPT goto yyaccept
329 #define YYERROR goto yyerrlab
330 int
yyparse(void)331 yyparse(void)
332 {
333 register int yym, yyn, yystate;
334 #if YYDEBUG
335 register const char *yys;
336
337 if ((yys = getenv("YYDEBUG")) != 0)
338 {
339 yyn = *yys;
340 if (yyn >= '0' && yyn <= '9')
341 yydebug = yyn - '0';
342 }
343 #endif
344
345 yynerrs = 0;
346 yyerrflag = 0;
347 yychar = YYEMPTY;
348
349 if (yyss == NULL && yygrowstack()) goto yyoverflow;
350 yyssp = yyss;
351 yyvsp = yyvs;
352 *yyssp = yystate = 0;
353
354 yyloop:
355 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
356 if (yychar < 0)
357 {
358 if ((yychar = yylex()) < 0) yychar = 0;
359 #if YYDEBUG
360 if (yydebug)
361 {
362 yys = 0;
363 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
364 if (!yys) yys = "illegal-symbol";
365 printf("%sdebug: state %d, reading %d (%s)\n",
366 YYPREFIX, yystate, yychar, yys);
367 }
368 #endif
369 }
370 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
371 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
372 {
373 #if YYDEBUG
374 if (yydebug)
375 printf("%sdebug: state %d, shifting to state %d\n",
376 YYPREFIX, yystate, yytable[yyn]);
377 #endif
378 if (yyssp >= yysslim && yygrowstack())
379 {
380 goto yyoverflow;
381 }
382 *++yyssp = yystate = yytable[yyn];
383 *++yyvsp = yylval;
384 yychar = YYEMPTY;
385 if (yyerrflag > 0) --yyerrflag;
386 goto yyloop;
387 }
388 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
389 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
390 {
391 yyn = yytable[yyn];
392 goto yyreduce;
393 }
394 if (yyerrflag) goto yyinrecovery;
395
396 yyerror("syntax error");
397
398 #ifdef lint
399 goto yyerrlab;
400 #endif
401
402 yyerrlab:
403 ++yynerrs;
404
405 yyinrecovery:
406 if (yyerrflag < 3)
407 {
408 yyerrflag = 3;
409 for (;;)
410 {
411 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
412 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
413 {
414 #if YYDEBUG
415 if (yydebug)
416 printf("%sdebug: state %d, error recovery shifting\
417 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
418 #endif
419 if (yyssp >= yysslim && yygrowstack())
420 {
421 goto yyoverflow;
422 }
423 *++yyssp = yystate = yytable[yyn];
424 *++yyvsp = yylval;
425 goto yyloop;
426 }
427 else
428 {
429 #if YYDEBUG
430 if (yydebug)
431 printf("%sdebug: error recovery discarding state %d\n",
432 YYPREFIX, *yyssp);
433 #endif
434 if (yyssp <= yyss) goto yyabort;
435 --yyssp;
436 --yyvsp;
437 }
438 }
439 }
440 else
441 {
442 if (yychar == 0) goto yyabort;
443 #if YYDEBUG
444 if (yydebug)
445 {
446 yys = 0;
447 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
448 if (!yys) yys = "illegal-symbol";
449 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
450 YYPREFIX, yystate, yychar, yys);
451 }
452 #endif
453 yychar = YYEMPTY;
454 goto yyloop;
455 }
456
457 yyreduce:
458 #if YYDEBUG
459 if (yydebug)
460 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
461 YYPREFIX, yystate, yyn, yyrule[yyn]);
462 #endif
463 yym = yylen[yyn];
464 yyval = yyvsp[1-yym];
465 switch (yyn)
466 {
467 case 6:
468 #line 74 "parser.y"
469 {
470 }
471 break;
472 case 7:
473 #line 77 "parser.y"
474 {
475 yyclearin;
476 yyerrok;
477 }
478 break;
479 case 8:
480 #line 84 "parser.y"
481 {
482 opts = NULL;
483 }
484 break;
485 case 9:
486 #line 90 "parser.y"
487 {
488 if ((yyvsp[0].number >= 0) && (yyvsp[0].number < RFCOMM_MAX_DEV))
489 opts = &rfcomm_opts[yyvsp[0].number];
490 else
491 opts = NULL;
492 }
493 break;
494 case 13:
495 #line 104 "parser.y"
496 {
497 if (opts)
498 opts->bind = yyvsp[0].number;
499 }
500 break;
501 case 14:
502 #line 109 "parser.y"
503 {
504 if (opts)
505 bacpy(&opts->bdaddr, yyvsp[0].bdaddr);
506 }
507 break;
508 case 15:
509 #line 114 "parser.y"
510 {
511 if (opts)
512 opts->channel = yyvsp[0].number;
513 }
514 break;
515 case 16:
516 #line 119 "parser.y"
517 {
518 if (opts)
519 snprintf(opts->comment, MAXCOMMENTLEN, "%s", yyvsp[0].string);
520 }
521 break;
522 case 17:
523 #line 124 "parser.y"
524 {
525 /* Unknown option*/
526 }
527 break;
528 case 18:
529 #line 129 "parser.y"
530 { yyval.number = 1; }
531 break;
532 case 19:
533 #line 130 "parser.y"
534 { yyval.number = 0; }
535 break;
536 #line 537 "y.tab.c"
537 }
538 yyssp -= yym;
539 yystate = *yyssp;
540 yyvsp -= yym;
541 yym = yylhs[yyn];
542 if (yystate == 0 && yym == 0)
543 {
544 #if YYDEBUG
545 if (yydebug)
546 printf("%sdebug: after reduction, shifting from state 0 to\
547 state %d\n", YYPREFIX, YYFINAL);
548 #endif
549 yystate = YYFINAL;
550 *++yyssp = YYFINAL;
551 *++yyvsp = yyval;
552 if (yychar < 0)
553 {
554 if ((yychar = yylex()) < 0) yychar = 0;
555 #if YYDEBUG
556 if (yydebug)
557 {
558 yys = 0;
559 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
560 if (!yys) yys = "illegal-symbol";
561 printf("%sdebug: state %d, reading %d (%s)\n",
562 YYPREFIX, YYFINAL, yychar, yys);
563 }
564 #endif
565 }
566 if (yychar == 0) goto yyaccept;
567 goto yyloop;
568 }
569 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
570 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
571 yystate = yytable[yyn];
572 else
573 yystate = yydgoto[yym];
574 #if YYDEBUG
575 if (yydebug)
576 printf("%sdebug: after reduction, shifting from state %d \
577 to state %d\n", YYPREFIX, *yyssp, yystate);
578 #endif
579 if (yyssp >= yysslim && yygrowstack())
580 {
581 goto yyoverflow;
582 }
583 *++yyssp = yystate;
584 *++yyvsp = yyval;
585 goto yyloop;
586
587 yyoverflow:
588 yyerror("yacc stack overflow");
589
590 yyabort:
591 return (1);
592
593 yyaccept:
594 return (0);
595 }
596