You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1378 lines
28 KiB

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