6 #include <sys/socket.h>
8 #include <netinet/in.h>
20 extern int yy_flex_debug;
38 enum filter_action action;
44 static size_t parsed_lines;
54 %token ACTION IN OUT FROM QUICK LOG SOCKET
55 %token TOPIC WORD WORD2
58 %type <number> ACTION QUICK LOG get_dir get_log get_quick
59 %type <string> get_from get_topic WORD SOCKET
67 | ruleset error { errors++; }
73 mqttrule : get_log ACTION get_quick get_dir get_topic get_from
77 memset(&r, 0, sizeof(r));
81 strlcpy(r.topic, $5, sizeof r.topic);
83 strlcpy(r.from, $6, sizeof r.from);
87 printf("\t#%zu: %c %s %c %s <from> %s;\n", nrule, $3?'!':' ', r.action == GTW_DROP ? "Drop" : "pass",
88 r.dir==GTW_INOUT ? '=' : r.dir==GTW_IN ? '<' :'>',
89 r.topic[0]!=0 ? r.topic :"*", r.from[0]!=0 ? r.from : "<all>");
93 get_quick : /*empty*/ {$$=0;}
96 get_log : /*empty*/ {$$=0;}
100 get_topic : ANY {$$=NULL;}
104 get_from : /*empty*/ {$$=NULL;}
108 get_dir : /*empty*/ {$$=GTW_INOUT;}
118 fprintf(stderr, "while parsing line %d: error occured \"%s\"\n",
125 int main( int argc, char **argv )
127 ++argv, --argc; /* skip over program name */
129 yyin = fopen( argv[0], "r" );
133 int devNull = open("/dev/null", O_WRONLY);
134 int dup2Result = dup2(devNull, STDERR_FILENO);
137 printf("#%zu. R: %zu\tE: %zu\n", parsed_lines, nrule, errors);