blob: 70723e3e9a0bf05e4e6f8e49082269cabc0ef7d9 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001--- /dev/null
2+++ b/src/cfg_parser.c
3@@ -0,0 +1,1374 @@
4+
5+#line 1 "cfg_parser.rl"
6+/*
7+ * tcpproxy
8+ *
9+ * tcpproxy is a simple tcp connection proxy which combines the
10+ * features of rinetd and 6tunnel. tcpproxy supports IPv4 and
11+ * IPv6 and also supports connections from IPv6 to IPv4
12+ * endpoints and vice versa.
13+ *
14+ *
15+ * Copyright (C) 2010-2015 Christian Pointner <equinox@spreadspace.org>
16+ *
17+ * This file is part of tcpproxy.
18+ *
19+ * tcpproxy is free software: you can redistribute it and/or modify
20+ * it under the terms of the GNU General Public License as published by
21+ * the Free Software Foundation, either version 3 of the License, or
22+ * any later version.
23+ *
24+ * tcpproxy is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with tcpproxy. If not, see <http://www.gnu.org/licenses/>.
31+ */
32+
33+#include <stdlib.h>
34+#include <string.h>
35+#include <errno.h>
36+#include <sys/types.h>
37+#include <sys/stat.h>
38+#include <fcntl.h>
39+#include <unistd.h>
40+#include <sys/mman.h>
41+
42+#include "datatypes.h"
43+#include "log.h"
44+#include "options.h"
45+#include "tcp.h"
46+#include "listener.h"
47+
48+struct listener {
49+ char* la_;
50+ resolv_type_t lrt_;
51+ char* lp_;
52+ char* ra_;
53+ resolv_type_t rrt_;
54+ char* rp_;
55+ char* sa_;
56+};
57+
58+static void init_listener_struct(struct listener* l)
59+{
60+ if(!l) return;
61+
62+ l->la_ = NULL;
63+ l->lrt_ = ANY;
64+ l->lp_ = NULL;
65+ l->ra_ = NULL;
66+ l->rrt_ = ANY;
67+ l->rp_ = NULL;
68+ l->sa_ = NULL;
69+}
70+
71+static void clear_listener_struct(struct listener* l)
72+{
73+ if(!l) return;
74+
75+ if(l->la_)
76+ free(l->la_);
77+ if(l->lp_)
78+ free(l->lp_);
79+ if(l->ra_)
80+ free(l->ra_);
81+ if(l->rp_)
82+ free(l->rp_);
83+ if(l->sa_)
84+ free(l->sa_);
85+
86+ init_listener_struct(l);
87+}
88+
89+static int owrt_string(char** dest, char* start, char* end)
90+{
91+ if(!dest || start >= end)
92+ return -1;
93+
94+ if(*dest) free(*dest);
95+ int n = end - start;
96+ *dest = malloc(n+1);
97+ if(!(*dest))
98+ return -2;
99+
100+ memcpy(*dest, start, n);
101+ (*dest)[n] = 0;
102+
103+ return 0;
104+}
105+
106+
107+#line 162 "cfg_parser.rl"
108+
109+
110+
111+int parse_listener(char* p, char* pe, listeners_t* listener)
112+{
113+ int cs, ret = 0, cur_line = 1;
114+
115+
116+#line 114 "cfg_parser.c"
117+static const int cfg_parser_start = 67;
118+static const int cfg_parser_first_final = 67;
119+static const int cfg_parser_error = 0;
120+
121+static const int cfg_parser_en_main = 67;
122+
123+
124+#line 170 "cfg_parser.rl"
125+
126+#line 124 "cfg_parser.c"
127+ {
128+ cs = cfg_parser_start;
129+ }
130+
131+#line 171 "cfg_parser.rl"
132+
133+ char* cpy_start = NULL;
134+ struct listener lst;
135+ init_listener_struct(&lst);
136+
137+ char* eof = pe;
138+
139+#line 137 "cfg_parser.c"
140+ {
141+ if ( p == pe )
142+ goto _test_eof;
143+ goto _resume;
144+
145+_again:
146+ switch ( cs ) {
147+ case 67: goto st67;
148+ case 0: goto st0;
149+ case 1: goto st1;
150+ case 2: goto st2;
151+ case 3: goto st3;
152+ case 4: goto st4;
153+ case 5: goto st5;
154+ case 6: goto st6;
155+ case 7: goto st7;
156+ case 8: goto st8;
157+ case 9: goto st9;
158+ case 10: goto st10;
159+ case 11: goto st11;
160+ case 12: goto st12;
161+ case 13: goto st13;
162+ case 14: goto st14;
163+ case 15: goto st15;
164+ case 16: goto st16;
165+ case 17: goto st17;
166+ case 18: goto st18;
167+ case 19: goto st19;
168+ case 20: goto st20;
169+ case 21: goto st21;
170+ case 22: goto st22;
171+ case 23: goto st23;
172+ case 24: goto st24;
173+ case 25: goto st25;
174+ case 26: goto st26;
175+ case 27: goto st27;
176+ case 28: goto st28;
177+ case 29: goto st29;
178+ case 30: goto st30;
179+ case 31: goto st31;
180+ case 32: goto st32;
181+ case 33: goto st33;
182+ case 34: goto st34;
183+ case 35: goto st35;
184+ case 36: goto st36;
185+ case 37: goto st37;
186+ case 38: goto st38;
187+ case 39: goto st39;
188+ case 40: goto st40;
189+ case 41: goto st41;
190+ case 42: goto st42;
191+ case 43: goto st43;
192+ case 44: goto st44;
193+ case 45: goto st45;
194+ case 46: goto st46;
195+ case 47: goto st47;
196+ case 48: goto st48;
197+ case 49: goto st49;
198+ case 50: goto st50;
199+ case 51: goto st51;
200+ case 52: goto st52;
201+ case 53: goto st53;
202+ case 54: goto st54;
203+ case 55: goto st55;
204+ case 56: goto st56;
205+ case 57: goto st57;
206+ case 58: goto st58;
207+ case 59: goto st59;
208+ case 60: goto st60;
209+ case 61: goto st61;
210+ case 62: goto st62;
211+ case 63: goto st63;
212+ case 64: goto st64;
213+ case 65: goto st65;
214+ case 66: goto st66;
215+ default: break;
216+ }
217+
218+ if ( ++p == pe )
219+ goto _test_eof;
220+_resume:
221+ switch ( cs )
222+ {
223+tr1:
224+#line 127 "cfg_parser.rl"
225+ {cur_line++;}
226+ goto st67;
227+tr90:
228+#line 114 "cfg_parser.rl"
229+ {
230+ ret = listeners_add(listener, lst.la_, lst.lrt_, lst.lp_, lst.ra_, lst.rrt_, lst.rp_, lst.sa_);
231+ clear_listener_struct(&lst);
232+ }
233+ goto st67;
234+st67:
235+ if ( ++p == pe )
236+ goto _test_eof67;
237+case 67:
238+#line 236 "cfg_parser.c"
239+ switch( (*p) ) {
240+ case 10: goto tr1;
241+ case 32: goto st67;
242+ case 35: goto st1;
243+ case 108: goto st2;
244+ }
245+ if ( 9 <= (*p) && (*p) <= 13 )
246+ goto st67;
247+ goto tr2;
248+tr2:
249+#line 118 "cfg_parser.rl"
250+ {
251+ if(p == eof)
252+ log_printf(ERROR, "config file syntax error: unexpected end of file");
253+ else
254+ log_printf(ERROR, "config file syntax error at line %d", cur_line);
255+
256+ {cs = (cfg_parser_error); goto _again;}
257+ }
258+ goto st0;
259+#line 257 "cfg_parser.c"
260+st0:
261+cs = 0;
262+ goto _out;
263+st1:
264+ if ( ++p == pe )
265+ goto _test_eof1;
266+case 1:
267+ if ( (*p) == 10 )
268+ goto tr1;
269+ goto st1;
270+st2:
271+ if ( ++p == pe )
272+ goto _test_eof2;
273+case 2:
274+ if ( (*p) == 105 )
275+ goto st3;
276+ goto tr2;
277+st3:
278+ if ( ++p == pe )
279+ goto _test_eof3;
280+case 3:
281+ if ( (*p) == 115 )
282+ goto st4;
283+ goto tr2;
284+st4:
285+ if ( ++p == pe )
286+ goto _test_eof4;
287+case 4:
288+ if ( (*p) == 116 )
289+ goto st5;
290+ goto tr2;
291+st5:
292+ if ( ++p == pe )
293+ goto _test_eof5;
294+case 5:
295+ if ( (*p) == 101 )
296+ goto st6;
297+ goto tr2;
298+st6:
299+ if ( ++p == pe )
300+ goto _test_eof6;
301+case 6:
302+ if ( (*p) == 110 )
303+ goto st7;
304+ goto tr2;
305+st7:
306+ if ( ++p == pe )
307+ goto _test_eof7;
308+case 7:
309+ switch( (*p) ) {
310+ case 9: goto st8;
311+ case 32: goto st8;
312+ }
313+ goto tr2;
314+st8:
315+ if ( ++p == pe )
316+ goto _test_eof8;
317+case 8:
318+ switch( (*p) ) {
319+ case 9: goto st8;
320+ case 32: goto st8;
321+ case 42: goto st9;
322+ case 58: goto tr12;
323+ }
324+ if ( (*p) < 65 ) {
325+ if ( (*p) > 46 ) {
326+ if ( 48 <= (*p) && (*p) <= 57 )
327+ goto tr11;
328+ } else if ( (*p) >= 45 )
329+ goto tr10;
330+ } else if ( (*p) > 70 ) {
331+ if ( (*p) < 97 ) {
332+ if ( 71 <= (*p) && (*p) <= 90 )
333+ goto tr10;
334+ } else if ( (*p) > 102 ) {
335+ if ( 103 <= (*p) && (*p) <= 122 )
336+ goto tr10;
337+ } else
338+ goto tr11;
339+ } else
340+ goto tr11;
341+ goto tr2;
342+st9:
343+ if ( ++p == pe )
344+ goto _test_eof9;
345+case 9:
346+ switch( (*p) ) {
347+ case 9: goto st10;
348+ case 32: goto st10;
349+ }
350+ goto tr2;
351+tr91:
352+#line 105 "cfg_parser.rl"
353+ { ret = owrt_string(&(lst.la_), cpy_start, p); cpy_start = NULL; }
354+ goto st10;
355+st10:
356+ if ( ++p == pe )
357+ goto _test_eof10;
358+case 10:
359+#line 357 "cfg_parser.c"
360+ switch( (*p) ) {
361+ case 9: goto st10;
362+ case 32: goto st10;
363+ case 45: goto tr14;
364+ }
365+ if ( (*p) < 65 ) {
366+ if ( 48 <= (*p) && (*p) <= 57 )
367+ goto tr14;
368+ } else if ( (*p) > 90 ) {
369+ if ( 97 <= (*p) && (*p) <= 122 )
370+ goto tr14;
371+ } else
372+ goto tr14;
373+ goto tr2;
374+tr14:
375+#line 104 "cfg_parser.rl"
376+ { cpy_start = p; }
377+ goto st11;
378+st11:
379+ if ( ++p == pe )
380+ goto _test_eof11;
381+case 11:
382+#line 380 "cfg_parser.c"
383+ switch( (*p) ) {
384+ case 10: goto tr16;
385+ case 32: goto tr15;
386+ case 35: goto tr17;
387+ case 45: goto st11;
388+ case 123: goto tr19;
389+ }
390+ if ( (*p) < 48 ) {
391+ if ( 9 <= (*p) && (*p) <= 13 )
392+ goto tr15;
393+ } else if ( (*p) > 57 ) {
394+ if ( (*p) > 90 ) {
395+ if ( 97 <= (*p) && (*p) <= 122 )
396+ goto st11;
397+ } else if ( (*p) >= 65 )
398+ goto st11;
399+ } else
400+ goto st11;
401+ goto tr2;
402+tr21:
403+#line 127 "cfg_parser.rl"
404+ {cur_line++;}
405+ goto st12;
406+tr15:
407+#line 106 "cfg_parser.rl"
408+ { ret = owrt_string(&(lst.lp_), cpy_start, p); cpy_start = NULL; }
409+ goto st12;
410+tr16:
411+#line 106 "cfg_parser.rl"
412+ { ret = owrt_string(&(lst.lp_), cpy_start, p); cpy_start = NULL; }
413+#line 127 "cfg_parser.rl"
414+ {cur_line++;}
415+ goto st12;
416+st12:
417+ if ( ++p == pe )
418+ goto _test_eof12;
419+case 12:
420+#line 418 "cfg_parser.c"
421+ switch( (*p) ) {
422+ case 10: goto tr21;
423+ case 32: goto st12;
424+ case 35: goto st13;
425+ case 123: goto st14;
426+ }
427+ if ( 9 <= (*p) && (*p) <= 13 )
428+ goto st12;
429+ goto tr2;
430+tr17:
431+#line 106 "cfg_parser.rl"
432+ { ret = owrt_string(&(lst.lp_), cpy_start, p); cpy_start = NULL; }
433+ goto st13;
434+st13:
435+ if ( ++p == pe )
436+ goto _test_eof13;
437+case 13:
438+#line 436 "cfg_parser.c"
439+ if ( (*p) == 10 )
440+ goto tr21;
441+ goto st13;
442+tr24:
443+#line 127 "cfg_parser.rl"
444+ {cur_line++;}
445+ goto st14;
446+tr19:
447+#line 106 "cfg_parser.rl"
448+ { ret = owrt_string(&(lst.lp_), cpy_start, p); cpy_start = NULL; }
449+ goto st14;
450+tr48:
451+#line 110 "cfg_parser.rl"
452+ { ret = owrt_string(&(lst.rp_), cpy_start, p); cpy_start = NULL; }
453+ goto st14;
454+tr87:
455+#line 113 "cfg_parser.rl"
456+ { ret = owrt_string(&(lst.sa_), cpy_start, p); cpy_start = NULL; }
457+ goto st14;
458+st14:
459+ if ( ++p == pe )
460+ goto _test_eof14;
461+case 14:
462+#line 460 "cfg_parser.c"
463+ switch( (*p) ) {
464+ case 10: goto tr24;
465+ case 32: goto st14;
466+ case 35: goto st15;
467+ case 114: goto st16;
468+ case 115: goto st52;
469+ case 125: goto st63;
470+ }
471+ if ( 9 <= (*p) && (*p) <= 13 )
472+ goto st14;
473+ goto tr2;
474+st15:
475+ if ( ++p == pe )
476+ goto _test_eof15;
477+case 15:
478+ if ( (*p) == 10 )
479+ goto tr24;
480+ goto st15;
481+st16:
482+ if ( ++p == pe )
483+ goto _test_eof16;
484+case 16:
485+ if ( (*p) == 101 )
486+ goto st17;
487+ goto tr2;
488+st17:
489+ if ( ++p == pe )
490+ goto _test_eof17;
491+case 17:
492+ switch( (*p) ) {
493+ case 109: goto st18;
494+ case 115: goto st43;
495+ }
496+ goto tr2;
497+st18:
498+ if ( ++p == pe )
499+ goto _test_eof18;
500+case 18:
501+ if ( (*p) == 111 )
502+ goto st19;
503+ goto tr2;
504+st19:
505+ if ( ++p == pe )
506+ goto _test_eof19;
507+case 19:
508+ if ( (*p) == 116 )
509+ goto st20;
510+ goto tr2;
511+st20:
512+ if ( ++p == pe )
513+ goto _test_eof20;
514+case 20:
515+ if ( (*p) == 101 )
516+ goto st21;
517+ goto tr2;
518+st21:
519+ if ( ++p == pe )
520+ goto _test_eof21;
521+case 21:
522+ switch( (*p) ) {
523+ case 9: goto st22;
524+ case 32: goto st22;
525+ case 45: goto st31;
526+ case 58: goto st23;
527+ }
528+ goto tr2;
529+st22:
530+ if ( ++p == pe )
531+ goto _test_eof22;
532+case 22:
533+ switch( (*p) ) {
534+ case 9: goto st22;
535+ case 32: goto st22;
536+ case 58: goto st23;
537+ }
538+ goto tr2;
539+st23:
540+ if ( ++p == pe )
541+ goto _test_eof23;
542+case 23:
543+ switch( (*p) ) {
544+ case 9: goto st24;
545+ case 32: goto st24;
546+ }
547+ goto tr2;
548+st24:
549+ if ( ++p == pe )
550+ goto _test_eof24;
551+case 24:
552+ switch( (*p) ) {
553+ case 9: goto st24;
554+ case 32: goto st24;
555+ case 58: goto tr41;
556+ }
557+ if ( (*p) < 65 ) {
558+ if ( (*p) > 46 ) {
559+ if ( 48 <= (*p) && (*p) <= 57 )
560+ goto tr40;
561+ } else if ( (*p) >= 45 )
562+ goto tr39;
563+ } else if ( (*p) > 70 ) {
564+ if ( (*p) < 97 ) {
565+ if ( 71 <= (*p) && (*p) <= 90 )
566+ goto tr39;
567+ } else if ( (*p) > 102 ) {
568+ if ( 103 <= (*p) && (*p) <= 122 )
569+ goto tr39;
570+ } else
571+ goto tr40;
572+ } else
573+ goto tr40;
574+ goto tr2;
575+tr39:
576+#line 104 "cfg_parser.rl"
577+ { cpy_start = p; }
578+ goto st25;
579+st25:
580+ if ( ++p == pe )
581+ goto _test_eof25;
582+case 25:
583+#line 581 "cfg_parser.c"
584+ switch( (*p) ) {
585+ case 9: goto tr42;
586+ case 32: goto tr42;
587+ }
588+ if ( (*p) < 48 ) {
589+ if ( 45 <= (*p) && (*p) <= 46 )
590+ goto st25;
591+ } else if ( (*p) > 57 ) {
592+ if ( (*p) > 90 ) {
593+ if ( 97 <= (*p) && (*p) <= 122 )
594+ goto st25;
595+ } else if ( (*p) >= 65 )
596+ goto st25;
597+ } else
598+ goto st25;
599+ goto tr2;
600+tr42:
601+#line 109 "cfg_parser.rl"
602+ { ret = owrt_string(&(lst.ra_), cpy_start, p); cpy_start = NULL; }
603+ goto st26;
604+st26:
605+ if ( ++p == pe )
606+ goto _test_eof26;
607+case 26:
608+#line 606 "cfg_parser.c"
609+ switch( (*p) ) {
610+ case 9: goto st26;
611+ case 32: goto st26;
612+ case 45: goto tr45;
613+ }
614+ if ( (*p) < 65 ) {
615+ if ( 48 <= (*p) && (*p) <= 57 )
616+ goto tr45;
617+ } else if ( (*p) > 90 ) {
618+ if ( 97 <= (*p) && (*p) <= 122 )
619+ goto tr45;
620+ } else
621+ goto tr45;
622+ goto tr2;
623+tr45:
624+#line 104 "cfg_parser.rl"
625+ { cpy_start = p; }
626+ goto st27;
627+st27:
628+ if ( ++p == pe )
629+ goto _test_eof27;
630+case 27:
631+#line 629 "cfg_parser.c"
632+ switch( (*p) ) {
633+ case 9: goto tr46;
634+ case 32: goto tr46;
635+ case 45: goto st27;
636+ case 59: goto tr48;
637+ }
638+ if ( (*p) < 65 ) {
639+ if ( 48 <= (*p) && (*p) <= 57 )
640+ goto st27;
641+ } else if ( (*p) > 90 ) {
642+ if ( 97 <= (*p) && (*p) <= 122 )
643+ goto st27;
644+ } else
645+ goto st27;
646+ goto tr2;
647+tr46:
648+#line 110 "cfg_parser.rl"
649+ { ret = owrt_string(&(lst.rp_), cpy_start, p); cpy_start = NULL; }
650+ goto st28;
651+tr63:
652+#line 111 "cfg_parser.rl"
653+ { lst.rrt_ = IPV4_ONLY; }
654+ goto st28;
655+tr64:
656+#line 112 "cfg_parser.rl"
657+ { lst.rrt_ = IPV6_ONLY; }
658+ goto st28;
659+tr73:
660+#line 107 "cfg_parser.rl"
661+ { lst.lrt_ = IPV4_ONLY; }
662+ goto st28;
663+tr74:
664+#line 108 "cfg_parser.rl"
665+ { lst.lrt_ = IPV6_ONLY; }
666+ goto st28;
667+tr85:
668+#line 113 "cfg_parser.rl"
669+ { ret = owrt_string(&(lst.sa_), cpy_start, p); cpy_start = NULL; }
670+ goto st28;
671+st28:
672+ if ( ++p == pe )
673+ goto _test_eof28;
674+case 28:
675+#line 673 "cfg_parser.c"
676+ switch( (*p) ) {
677+ case 9: goto st28;
678+ case 32: goto st28;
679+ case 59: goto st14;
680+ }
681+ goto tr2;
682+tr40:
683+#line 104 "cfg_parser.rl"
684+ { cpy_start = p; }
685+ goto st29;
686+st29:
687+ if ( ++p == pe )
688+ goto _test_eof29;
689+case 29:
690+#line 688 "cfg_parser.c"
691+ switch( (*p) ) {
692+ case 9: goto tr42;
693+ case 32: goto tr42;
694+ case 58: goto st30;
695+ }
696+ if ( (*p) < 65 ) {
697+ if ( (*p) > 46 ) {
698+ if ( 48 <= (*p) && (*p) <= 57 )
699+ goto st29;
700+ } else if ( (*p) >= 45 )
701+ goto st25;
702+ } else if ( (*p) > 70 ) {
703+ if ( (*p) < 97 ) {
704+ if ( 71 <= (*p) && (*p) <= 90 )
705+ goto st25;
706+ } else if ( (*p) > 102 ) {
707+ if ( 103 <= (*p) && (*p) <= 122 )
708+ goto st25;
709+ } else
710+ goto st29;
711+ } else
712+ goto st29;
713+ goto tr2;
714+tr41:
715+#line 104 "cfg_parser.rl"
716+ { cpy_start = p; }
717+ goto st30;
718+st30:
719+ if ( ++p == pe )
720+ goto _test_eof30;
721+case 30:
722+#line 720 "cfg_parser.c"
723+ switch( (*p) ) {
724+ case 9: goto tr42;
725+ case 32: goto tr42;
726+ }
727+ if ( (*p) < 65 ) {
728+ if ( 48 <= (*p) && (*p) <= 58 )
729+ goto st30;
730+ } else if ( (*p) > 70 ) {
731+ if ( 97 <= (*p) && (*p) <= 102 )
732+ goto st30;
733+ } else
734+ goto st30;
735+ goto tr2;
736+st31:
737+ if ( ++p == pe )
738+ goto _test_eof31;
739+case 31:
740+ if ( (*p) == 114 )
741+ goto st32;
742+ goto tr2;
743+st32:
744+ if ( ++p == pe )
745+ goto _test_eof32;
746+case 32:
747+ if ( (*p) == 101 )
748+ goto st33;
749+ goto tr2;
750+st33:
751+ if ( ++p == pe )
752+ goto _test_eof33;
753+case 33:
754+ if ( (*p) == 115 )
755+ goto st34;
756+ goto tr2;
757+st34:
758+ if ( ++p == pe )
759+ goto _test_eof34;
760+case 34:
761+ if ( (*p) == 111 )
762+ goto st35;
763+ goto tr2;
764+st35:
765+ if ( ++p == pe )
766+ goto _test_eof35;
767+case 35:
768+ if ( (*p) == 108 )
769+ goto st36;
770+ goto tr2;
771+st36:
772+ if ( ++p == pe )
773+ goto _test_eof36;
774+case 36:
775+ if ( (*p) == 118 )
776+ goto st37;
777+ goto tr2;
778+st37:
779+ if ( ++p == pe )
780+ goto _test_eof37;
781+case 37:
782+ switch( (*p) ) {
783+ case 9: goto st37;
784+ case 32: goto st37;
785+ case 58: goto st38;
786+ }
787+ goto tr2;
788+st38:
789+ if ( ++p == pe )
790+ goto _test_eof38;
791+case 38:
792+ switch( (*p) ) {
793+ case 9: goto st39;
794+ case 32: goto st39;
795+ }
796+ goto tr2;
797+st39:
798+ if ( ++p == pe )
799+ goto _test_eof39;
800+case 39:
801+ switch( (*p) ) {
802+ case 9: goto st39;
803+ case 32: goto st39;
804+ case 73: goto st40;
805+ case 105: goto st40;
806+ }
807+ goto tr2;
808+st40:
809+ if ( ++p == pe )
810+ goto _test_eof40;
811+case 40:
812+ switch( (*p) ) {
813+ case 80: goto st41;
814+ case 112: goto st41;
815+ }
816+ goto tr2;
817+st41:
818+ if ( ++p == pe )
819+ goto _test_eof41;
820+case 41:
821+ switch( (*p) ) {
822+ case 86: goto st42;
823+ case 118: goto st42;
824+ }
825+ goto tr2;
826+st42:
827+ if ( ++p == pe )
828+ goto _test_eof42;
829+case 42:
830+ switch( (*p) ) {
831+ case 52: goto tr63;
832+ case 54: goto tr64;
833+ }
834+ goto tr2;
835+st43:
836+ if ( ++p == pe )
837+ goto _test_eof43;
838+case 43:
839+ if ( (*p) == 111 )
840+ goto st44;
841+ goto tr2;
842+st44:
843+ if ( ++p == pe )
844+ goto _test_eof44;
845+case 44:
846+ if ( (*p) == 108 )
847+ goto st45;
848+ goto tr2;
849+st45:
850+ if ( ++p == pe )
851+ goto _test_eof45;
852+case 45:
853+ if ( (*p) == 118 )
854+ goto st46;
855+ goto tr2;
856+st46:
857+ if ( ++p == pe )
858+ goto _test_eof46;
859+case 46:
860+ switch( (*p) ) {
861+ case 9: goto st46;
862+ case 32: goto st46;
863+ case 58: goto st47;
864+ }
865+ goto tr2;
866+st47:
867+ if ( ++p == pe )
868+ goto _test_eof47;
869+case 47:
870+ switch( (*p) ) {
871+ case 9: goto st48;
872+ case 32: goto st48;
873+ }
874+ goto tr2;
875+st48:
876+ if ( ++p == pe )
877+ goto _test_eof48;
878+case 48:
879+ switch( (*p) ) {
880+ case 9: goto st48;
881+ case 32: goto st48;
882+ case 73: goto st49;
883+ case 105: goto st49;
884+ }
885+ goto tr2;
886+st49:
887+ if ( ++p == pe )
888+ goto _test_eof49;
889+case 49:
890+ switch( (*p) ) {
891+ case 80: goto st50;
892+ case 112: goto st50;
893+ }
894+ goto tr2;
895+st50:
896+ if ( ++p == pe )
897+ goto _test_eof50;
898+case 50:
899+ switch( (*p) ) {
900+ case 86: goto st51;
901+ case 118: goto st51;
902+ }
903+ goto tr2;
904+st51:
905+ if ( ++p == pe )
906+ goto _test_eof51;
907+case 51:
908+ switch( (*p) ) {
909+ case 52: goto tr73;
910+ case 54: goto tr74;
911+ }
912+ goto tr2;
913+st52:
914+ if ( ++p == pe )
915+ goto _test_eof52;
916+case 52:
917+ if ( (*p) == 111 )
918+ goto st53;
919+ goto tr2;
920+st53:
921+ if ( ++p == pe )
922+ goto _test_eof53;
923+case 53:
924+ if ( (*p) == 117 )
925+ goto st54;
926+ goto tr2;
927+st54:
928+ if ( ++p == pe )
929+ goto _test_eof54;
930+case 54:
931+ if ( (*p) == 114 )
932+ goto st55;
933+ goto tr2;
934+st55:
935+ if ( ++p == pe )
936+ goto _test_eof55;
937+case 55:
938+ if ( (*p) == 99 )
939+ goto st56;
940+ goto tr2;
941+st56:
942+ if ( ++p == pe )
943+ goto _test_eof56;
944+case 56:
945+ if ( (*p) == 101 )
946+ goto st57;
947+ goto tr2;
948+st57:
949+ if ( ++p == pe )
950+ goto _test_eof57;
951+case 57:
952+ switch( (*p) ) {
953+ case 9: goto st57;
954+ case 32: goto st57;
955+ case 58: goto st58;
956+ }
957+ goto tr2;
958+st58:
959+ if ( ++p == pe )
960+ goto _test_eof58;
961+case 58:
962+ switch( (*p) ) {
963+ case 9: goto st59;
964+ case 32: goto st59;
965+ }
966+ goto tr2;
967+st59:
968+ if ( ++p == pe )
969+ goto _test_eof59;
970+case 59:
971+ switch( (*p) ) {
972+ case 9: goto st59;
973+ case 32: goto st59;
974+ case 58: goto tr84;
975+ }
976+ if ( (*p) < 65 ) {
977+ if ( (*p) > 46 ) {
978+ if ( 48 <= (*p) && (*p) <= 57 )
979+ goto tr83;
980+ } else if ( (*p) >= 45 )
981+ goto tr82;
982+ } else if ( (*p) > 70 ) {
983+ if ( (*p) < 97 ) {
984+ if ( 71 <= (*p) && (*p) <= 90 )
985+ goto tr82;
986+ } else if ( (*p) > 102 ) {
987+ if ( 103 <= (*p) && (*p) <= 122 )
988+ goto tr82;
989+ } else
990+ goto tr83;
991+ } else
992+ goto tr83;
993+ goto tr2;
994+tr82:
995+#line 104 "cfg_parser.rl"
996+ { cpy_start = p; }
997+ goto st60;
998+st60:
999+ if ( ++p == pe )
1000+ goto _test_eof60;
1001+case 60:
1002+#line 1000 "cfg_parser.c"
1003+ switch( (*p) ) {
1004+ case 9: goto tr85;
1005+ case 32: goto tr85;
1006+ case 59: goto tr87;
1007+ }
1008+ if ( (*p) < 48 ) {
1009+ if ( 45 <= (*p) && (*p) <= 46 )
1010+ goto st60;
1011+ } else if ( (*p) > 57 ) {
1012+ if ( (*p) > 90 ) {
1013+ if ( 97 <= (*p) && (*p) <= 122 )
1014+ goto st60;
1015+ } else if ( (*p) >= 65 )
1016+ goto st60;
1017+ } else
1018+ goto st60;
1019+ goto tr2;
1020+tr83:
1021+#line 104 "cfg_parser.rl"
1022+ { cpy_start = p; }
1023+ goto st61;
1024+st61:
1025+ if ( ++p == pe )
1026+ goto _test_eof61;
1027+case 61:
1028+#line 1026 "cfg_parser.c"
1029+ switch( (*p) ) {
1030+ case 9: goto tr85;
1031+ case 32: goto tr85;
1032+ case 58: goto st62;
1033+ case 59: goto tr87;
1034+ }
1035+ if ( (*p) < 65 ) {
1036+ if ( (*p) > 46 ) {
1037+ if ( 48 <= (*p) && (*p) <= 57 )
1038+ goto st61;
1039+ } else if ( (*p) >= 45 )
1040+ goto st60;
1041+ } else if ( (*p) > 70 ) {
1042+ if ( (*p) < 97 ) {
1043+ if ( 71 <= (*p) && (*p) <= 90 )
1044+ goto st60;
1045+ } else if ( (*p) > 102 ) {
1046+ if ( 103 <= (*p) && (*p) <= 122 )
1047+ goto st60;
1048+ } else
1049+ goto st61;
1050+ } else
1051+ goto st61;
1052+ goto tr2;
1053+tr84:
1054+#line 104 "cfg_parser.rl"
1055+ { cpy_start = p; }
1056+ goto st62;
1057+st62:
1058+ if ( ++p == pe )
1059+ goto _test_eof62;
1060+case 62:
1061+#line 1059 "cfg_parser.c"
1062+ switch( (*p) ) {
1063+ case 9: goto tr85;
1064+ case 32: goto tr85;
1065+ case 59: goto tr87;
1066+ }
1067+ if ( (*p) < 65 ) {
1068+ if ( 48 <= (*p) && (*p) <= 58 )
1069+ goto st62;
1070+ } else if ( (*p) > 70 ) {
1071+ if ( 97 <= (*p) && (*p) <= 102 )
1072+ goto st62;
1073+ } else
1074+ goto st62;
1075+ goto tr2;
1076+st63:
1077+ if ( ++p == pe )
1078+ goto _test_eof63;
1079+case 63:
1080+ if ( (*p) == 59 )
1081+ goto tr90;
1082+ goto tr2;
1083+tr10:
1084+#line 104 "cfg_parser.rl"
1085+ { cpy_start = p; }
1086+ goto st64;
1087+st64:
1088+ if ( ++p == pe )
1089+ goto _test_eof64;
1090+case 64:
1091+#line 1089 "cfg_parser.c"
1092+ switch( (*p) ) {
1093+ case 9: goto tr91;
1094+ case 32: goto tr91;
1095+ }
1096+ if ( (*p) < 48 ) {
1097+ if ( 45 <= (*p) && (*p) <= 46 )
1098+ goto st64;
1099+ } else if ( (*p) > 57 ) {
1100+ if ( (*p) > 90 ) {
1101+ if ( 97 <= (*p) && (*p) <= 122 )
1102+ goto st64;
1103+ } else if ( (*p) >= 65 )
1104+ goto st64;
1105+ } else
1106+ goto st64;
1107+ goto tr2;
1108+tr11:
1109+#line 104 "cfg_parser.rl"
1110+ { cpy_start = p; }
1111+ goto st65;
1112+st65:
1113+ if ( ++p == pe )
1114+ goto _test_eof65;
1115+case 65:
1116+#line 1114 "cfg_parser.c"
1117+ switch( (*p) ) {
1118+ case 9: goto tr91;
1119+ case 32: goto tr91;
1120+ case 58: goto st66;
1121+ }
1122+ if ( (*p) < 65 ) {
1123+ if ( (*p) > 46 ) {
1124+ if ( 48 <= (*p) && (*p) <= 57 )
1125+ goto st65;
1126+ } else if ( (*p) >= 45 )
1127+ goto st64;
1128+ } else if ( (*p) > 70 ) {
1129+ if ( (*p) < 97 ) {
1130+ if ( 71 <= (*p) && (*p) <= 90 )
1131+ goto st64;
1132+ } else if ( (*p) > 102 ) {
1133+ if ( 103 <= (*p) && (*p) <= 122 )
1134+ goto st64;
1135+ } else
1136+ goto st65;
1137+ } else
1138+ goto st65;
1139+ goto tr2;
1140+tr12:
1141+#line 104 "cfg_parser.rl"
1142+ { cpy_start = p; }
1143+ goto st66;
1144+st66:
1145+ if ( ++p == pe )
1146+ goto _test_eof66;
1147+case 66:
1148+#line 1146 "cfg_parser.c"
1149+ switch( (*p) ) {
1150+ case 9: goto tr91;
1151+ case 32: goto tr91;
1152+ }
1153+ if ( (*p) < 65 ) {
1154+ if ( 48 <= (*p) && (*p) <= 58 )
1155+ goto st66;
1156+ } else if ( (*p) > 70 ) {
1157+ if ( 97 <= (*p) && (*p) <= 102 )
1158+ goto st66;
1159+ } else
1160+ goto st66;
1161+ goto tr2;
1162+ }
1163+ _test_eof67: cs = 67; goto _test_eof;
1164+ _test_eof1: cs = 1; goto _test_eof;
1165+ _test_eof2: cs = 2; goto _test_eof;
1166+ _test_eof3: cs = 3; goto _test_eof;
1167+ _test_eof4: cs = 4; goto _test_eof;
1168+ _test_eof5: cs = 5; goto _test_eof;
1169+ _test_eof6: cs = 6; goto _test_eof;
1170+ _test_eof7: cs = 7; goto _test_eof;
1171+ _test_eof8: cs = 8; goto _test_eof;
1172+ _test_eof9: cs = 9; goto _test_eof;
1173+ _test_eof10: cs = 10; goto _test_eof;
1174+ _test_eof11: cs = 11; goto _test_eof;
1175+ _test_eof12: cs = 12; goto _test_eof;
1176+ _test_eof13: cs = 13; goto _test_eof;
1177+ _test_eof14: cs = 14; goto _test_eof;
1178+ _test_eof15: cs = 15; goto _test_eof;
1179+ _test_eof16: cs = 16; goto _test_eof;
1180+ _test_eof17: cs = 17; goto _test_eof;
1181+ _test_eof18: cs = 18; goto _test_eof;
1182+ _test_eof19: cs = 19; goto _test_eof;
1183+ _test_eof20: cs = 20; goto _test_eof;
1184+ _test_eof21: cs = 21; goto _test_eof;
1185+ _test_eof22: cs = 22; goto _test_eof;
1186+ _test_eof23: cs = 23; goto _test_eof;
1187+ _test_eof24: cs = 24; goto _test_eof;
1188+ _test_eof25: cs = 25; goto _test_eof;
1189+ _test_eof26: cs = 26; goto _test_eof;
1190+ _test_eof27: cs = 27; goto _test_eof;
1191+ _test_eof28: cs = 28; goto _test_eof;
1192+ _test_eof29: cs = 29; goto _test_eof;
1193+ _test_eof30: cs = 30; goto _test_eof;
1194+ _test_eof31: cs = 31; goto _test_eof;
1195+ _test_eof32: cs = 32; goto _test_eof;
1196+ _test_eof33: cs = 33; goto _test_eof;
1197+ _test_eof34: cs = 34; goto _test_eof;
1198+ _test_eof35: cs = 35; goto _test_eof;
1199+ _test_eof36: cs = 36; goto _test_eof;
1200+ _test_eof37: cs = 37; goto _test_eof;
1201+ _test_eof38: cs = 38; goto _test_eof;
1202+ _test_eof39: cs = 39; goto _test_eof;
1203+ _test_eof40: cs = 40; goto _test_eof;
1204+ _test_eof41: cs = 41; goto _test_eof;
1205+ _test_eof42: cs = 42; goto _test_eof;
1206+ _test_eof43: cs = 43; goto _test_eof;
1207+ _test_eof44: cs = 44; goto _test_eof;
1208+ _test_eof45: cs = 45; goto _test_eof;
1209+ _test_eof46: cs = 46; goto _test_eof;
1210+ _test_eof47: cs = 47; goto _test_eof;
1211+ _test_eof48: cs = 48; goto _test_eof;
1212+ _test_eof49: cs = 49; goto _test_eof;
1213+ _test_eof50: cs = 50; goto _test_eof;
1214+ _test_eof51: cs = 51; goto _test_eof;
1215+ _test_eof52: cs = 52; goto _test_eof;
1216+ _test_eof53: cs = 53; goto _test_eof;
1217+ _test_eof54: cs = 54; goto _test_eof;
1218+ _test_eof55: cs = 55; goto _test_eof;
1219+ _test_eof56: cs = 56; goto _test_eof;
1220+ _test_eof57: cs = 57; goto _test_eof;
1221+ _test_eof58: cs = 58; goto _test_eof;
1222+ _test_eof59: cs = 59; goto _test_eof;
1223+ _test_eof60: cs = 60; goto _test_eof;
1224+ _test_eof61: cs = 61; goto _test_eof;
1225+ _test_eof62: cs = 62; goto _test_eof;
1226+ _test_eof63: cs = 63; goto _test_eof;
1227+ _test_eof64: cs = 64; goto _test_eof;
1228+ _test_eof65: cs = 65; goto _test_eof;
1229+ _test_eof66: cs = 66; goto _test_eof;
1230+
1231+ _test_eof: {}
1232+ if ( p == eof )
1233+ {
1234+ switch ( cs ) {
1235+ case 1:
1236+ case 2:
1237+ case 3:
1238+ case 4:
1239+ case 5:
1240+ case 6:
1241+ case 7:
1242+ case 8:
1243+ case 9:
1244+ case 10:
1245+ case 11:
1246+ case 12:
1247+ case 13:
1248+ case 14:
1249+ case 15:
1250+ case 16:
1251+ case 17:
1252+ case 18:
1253+ case 19:
1254+ case 20:
1255+ case 21:
1256+ case 22:
1257+ case 23:
1258+ case 24:
1259+ case 25:
1260+ case 26:
1261+ case 27:
1262+ case 28:
1263+ case 29:
1264+ case 30:
1265+ case 31:
1266+ case 32:
1267+ case 33:
1268+ case 34:
1269+ case 35:
1270+ case 36:
1271+ case 37:
1272+ case 38:
1273+ case 39:
1274+ case 40:
1275+ case 41:
1276+ case 42:
1277+ case 43:
1278+ case 44:
1279+ case 45:
1280+ case 46:
1281+ case 47:
1282+ case 48:
1283+ case 49:
1284+ case 50:
1285+ case 51:
1286+ case 52:
1287+ case 53:
1288+ case 54:
1289+ case 55:
1290+ case 56:
1291+ case 57:
1292+ case 58:
1293+ case 59:
1294+ case 60:
1295+ case 61:
1296+ case 62:
1297+ case 63:
1298+ case 64:
1299+ case 65:
1300+ case 66:
1301+#line 118 "cfg_parser.rl"
1302+ {
1303+ if(p == eof)
1304+ log_printf(ERROR, "config file syntax error: unexpected end of file");
1305+ else
1306+ log_printf(ERROR, "config file syntax error at line %d", cur_line);
1307+
1308+ {cs = (cfg_parser_error); goto _again;}
1309+ }
1310+ break;
1311+#line 1309 "cfg_parser.c"
1312+ }
1313+ }
1314+
1315+ _out: {}
1316+ }
1317+
1318+#line 178 "cfg_parser.rl"
1319+
1320+ if(cs == cfg_parser_error) {
1321+ listeners_revert(listener);
1322+ ret = 1;
1323+ }
1324+ else
1325+ ret = listeners_update(listener);
1326+
1327+ clear_listener_struct(&lst);
1328+
1329+ return ret;
1330+}
1331+
1332+int read_configfile(const char* filename, listeners_t* listener)
1333+{
1334+ int fd = open(filename, 0);
1335+ if(fd < 0) {
1336+ log_printf(ERROR, "open('%s') failed: %s", filename, strerror(errno));
1337+ return -1;
1338+ }
1339+
1340+ struct stat sb;
1341+ if(fstat(fd, &sb) == -1) {
1342+ log_printf(ERROR, "fstat() error: %s", strerror(errno));
1343+ close(fd);
1344+ return -1;
1345+ }
1346+
1347+ if(!sb.st_size) {
1348+ log_printf(ERROR, "config file %s is empty", filename);
1349+ close(fd);
1350+ return -1;
1351+ }
1352+
1353+ if(!S_ISREG(sb.st_mode)) {
1354+ log_printf(ERROR, "config file %s is not a regular file", filename);
1355+ close(fd);
1356+ return -1;
1357+ }
1358+
1359+ char* p = (char*)mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
1360+ if(p == MAP_FAILED) {
1361+ log_printf(ERROR, "mmap() error: %s", strerror(errno));
1362+ close(fd);
1363+ return -1;
1364+ }
1365+ close(fd);
1366+
1367+ log_printf(DEBUG, "mapped %ld bytes from file %s at address 0x%08lX", sb.st_size, filename, p);
1368+ int ret = parse_listener(p, p + sb.st_size, listener);
1369+
1370+ if(munmap(p, sb.st_size) == -1) {
1371+ log_printf(ERROR, "munmap() error: %s", strerror(errno));
1372+ return -1;
1373+ }
1374+ log_printf(DEBUG, "unmapped file %s", filename);
1375+
1376+ return ret;
1377+}