%{ /* Package Name : twhttpd * File Name : parser.l * Author : Sam NG * * This package is an secure HTTP application proxy writen by Sam Ng. * Copyright (C) 2001 SAM NG * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ #include #include "y.tab.h" int yylineno=1; int yylong; %} %% \#[^\n]* ; /* ignore comments */ [\t ]+ ; /* ignore whitespaces */ [\n] yylineno++; /* these are single char token */ \" | "-" | "/" | "!" | "=" | "," | ";" | ":" | "(" | ")" | "{" | "}" return yytext[0]; "==" return EQ; "!=" return NE; ">=" return GE; ">" return GT; "<=" return LE; "<" return LT; "=~" return IS; "&&" return AND; "||" return OR; if return IF; elsif return ELSIF; else return ELSE; /* these are general configuration parameters */ \$debug return DEBUG; \$chroot return CHROOT; \$uid return UID; \$gid return GID; \$work_dir return WORK_DIR; \$cache_dir return CACHE_DIR; \$cookie_dir return COOKIE_DIR; \$cache_timeout return CACHE_TIMEOUT; \$cache_fast_timeout return CACHE_FAST_TIMEOUT; \$mime_type return MIME; server return SERVER; /* these are server options */ \$server_version return SERVER_VERSION; \$browser_version return BROWSER_VERSION; \$listen return LISTEN; \$cache return CACHE; \$cookie_check return COOKIE_CHECK; \$safe_url return SAFE_URL; \$https return HTTPS; \$access_log return ACCESS_LOG; \$header_check return HEADER_CHECK; /* these are server options as well as testing function */ \$forward return FORWARD; \$forward_proxy return FORWARD_PROXY; /* some thing you can "set" */ \$location return LOCATION; /* these are testers */ \$local_ip return LOCAL_IP; \$client_ip return CLIENT_IP; \$method return METHOD; \$host return HOST; \$path return PATH; \$user_agent return USER_AGENT; \$referer return REFERER; \$ext return EXT; \$query return QUERY; \$cookie return COOKIE; \$port return PORT; \$post_len return POST_LEN; \$auth return AUTH; \$proxy_auth return PROXY_AUTH; "return" return RETURN; /* these are testing functions */ include return INCLUDE; htpasswd return HTPASSWD; strlen return STRLEN; cgi_decode return CGI_DECODE; is_cgi return IS_CGI; is_valid_cookie return IS_VALID_COOKIE; clear_cookie return CLEAR_COOKIE; /* well, these are tokens have "VALUE" */ [0-9]+ { /* note max is 65535 */ yylong = strtol(yytext, NULL, 10); yylval.INT = (unsigned int)(yylong<65535 ? yylong:0); return NUMBER; } [1-2]?[0-9]?[0-9](.[1-2]?[0-9]?[0-9]){3} { yylval.STR = (char *)strdup(yytext); return IP_ADDR; } \"(([^\\\"])|(\\.))+*\" { /* the first and last \" is not needed */ yylval.STR = (char *)strdup(yytext+1); yylval.STR[strlen(yylval.STR)-1]='\0'; return STRING; } \/(([^\\\/]*)|(\\.))+\/s? { yylval.STR = (char *)strdup(yytext); /* the last "s" means case sensitive */ if ( 's' == yylval.STR[strlen(yylval.STR)-1] ) { /* the first "/" is not needed */ /* if it is 's' then it means this is case sensitive match */ yylval.STR[0] = 's'; /* the last "/" is also not needed */ yylval.STR[strlen(yylval.STR)-2] = '\0'; return REGEX_STR; } else { /* the first "/" is not needed */ /* if it is 's' then it means this is case sensitive match */ yylval.STR[0] = 'i'; /* the last "/" is also not needed */ yylval.STR[strlen(yylval.STR)-1] = '\0'; return REGEX_STR; } } %% int yywrap(void) { return 1; }