These all handle reading the tinyproxy configuration file.

This commit is contained in:
Robert James Kaes 2000-09-12 00:12:52 +00:00
parent 2b5c6be1d5
commit dc18c065b7
5 changed files with 3193 additions and 0 deletions

1093
src/grammar.c Normal file

File diff suppressed because it is too large Load Diff

35
src/grammar.h Normal file
View File

@ -0,0 +1,35 @@
typedef union {
unsigned int num;
char *cptr;
void *ptr;
} YYSTYPE;
#define KW_PORT 257
#define KW_LISTEN 258
#define KW_LOGFILE 259
#define KW_PIDFILE 260
#define KW_SYSLOG 261
#define KW_MAXCLIENTS 262
#define KW_MAXSPARESERVERS 263
#define KW_MINSPARESERVERS 264
#define KW_STARTSERVERS 265
#define KW_MAXREQUESTSPERCHILD 266
#define KW_TIMEOUT 267
#define KW_USER 268
#define KW_GROUP 269
#define KW_ANONYMOUS 270
#define KW_FILTER 271
#define KW_XTINYPROXY 272
#define KW_TUNNEL 273
#define KW_ALLOW 274
#define KW_DENY 275
#define KW_YES 276
#define KW_NO 277
#define IDENTIFIER 278
#define NUMBER 279
#define STRING 280
#define NUMERIC_ADDRESS 281
#define STRING_ADDRESS 282
#define NETMASK_ADDRESS 283
extern YYSTYPE yylval;

155
src/grammar.y Normal file
View File

@ -0,0 +1,155 @@
/* $Id: grammar.y,v 1.1 2000-09-12 00:12:52 rjkaes Exp $
*
* This is the grammar for tinyproxy's configuration file. It needs to be
* in sync with scanner.l. If you know more about yacc and lex than I do
* please update these files.
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, or (at your option) 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.
*/
%{
#include "tinyproxy.h"
#include "acl.h"
#include "anonymous.h"
#include "log.h"
#include "thread.h"
void yyerror(char *s);
int yylex(void);
%}
%union {
unsigned int num;
char *cptr;
void *ptr;
}
/* statements */
%token KW_PORT KW_LISTEN
%token KW_LOGFILE KW_PIDFILE KW_SYSLOG
%token KW_MAXCLIENTS KW_MAXSPARESERVERS KW_MINSPARESERVERS KW_STARTSERVERS
%token KW_MAXREQUESTSPERCHILD
%token KW_TIMEOUT
%token KW_USER KW_GROUP
%token KW_ANONYMOUS KW_FILTER KW_XTINYPROXY KW_TUNNEL
%token KW_ALLOW KW_DENY
/* yes/no switches */
%token KW_YES KW_NO
%token <cptr> IDENTIFIER
%token <num> NUMBER
%token <cptr> STRING
%token <cptr> NUMERIC_ADDRESS
%token <cptr> STRING_ADDRESS
%token <cptr> NETMASK_ADDRESS
%type <num> yesno
%type <cptr> string
%type <cptr> network_address
%type <cptr> unique_address
%%
start
: /* empty */
| start line
;
line
: '\n'
| statement '\n'
;
statement
: KW_PORT NUMBER { config.port = $2; }
| KW_TIMEOUT NUMBER { config.idletimeout = $2; }
| KW_SYSLOG yesno
{
#ifdef HAVE_SYSLOG_H
config.syslog = $2;
#else
log(LOG_WARNING, "Syslog support was not compiled in.");
#endif
}
| KW_MAXCLIENTS NUMBER { thread_configure(THREAD_MAXCLIENTS, $2); }
| KW_MAXSPARESERVERS NUMBER { thread_configure(THREAD_MAXSPARESERVERS, $2); }
| KW_MINSPARESERVERS NUMBER { thread_configure(THREAD_MINSPARESERVERS, $2); }
| KW_STARTSERVERS NUMBER { thread_configure(THREAD_STARTSERVERS, $2); }
| KW_MAXREQUESTSPERCHILD NUMBER { thread_configure(THREAD_MAXREQUESTSPERCHILD, $2); }
| KW_LOGFILE string
{
config.logf_name = $2;
if (!config.logf_name) {
fprintf(stderr, "bad log file\n");
}
}
| KW_PIDFILE string { config.pidpath = $2; }
| KW_USER string { config.username = $2; }
| KW_GROUP string { config.group = $2; }
| KW_ANONYMOUS string { anon_insert($2); }
| KW_FILTER string
{
#ifdef FILTER_ENABLE
config.filter = $2;
#else
log(LOG_WARNING, "Filter support was not compiled in.");
#endif
}
| KW_XTINYPROXY network_address { config.my_domain = $2; }
| KW_TUNNEL unique_address ':' NUMBER
{
#ifdef TUNNEL_SUPPORT
config.tunnel_name = $2;
config.tunnel_port = $4;
#else
log(LOG_WARNING, "Tunnel support was not compiled in.");
#endif
}
| KW_LISTEN NUMERIC_ADDRESS { config.ipAddr = $2; }
| KW_ALLOW network_address { insert_acl($2, ACL_ALLOW); }
| KW_DENY network_address { insert_acl($2, ACL_DENY); }
;
network_address
: unique_address
| NETMASK_ADDRESS
;
unique_address
: STRING_ADDRESS
| NUMERIC_ADDRESS
;
yesno
: KW_YES { $$ = 1; }
| KW_NO { $$ = 0; }
| NUMBER { $$ = $1; }
;
string
: IDENTIFIER
| STRING
;
%%
extern unsigned int yylineno;
void yyerror(char *s)
{
fprintf(stderr, "Line %d: %s\n", yylineno, s);
}

1763
src/scanner.c Normal file

File diff suppressed because it is too large Load Diff

147
src/scanner.l Normal file
View File

@ -0,0 +1,147 @@
/* $Id: scanner.l,v 1.1 2000-09-12 00:12:52 rjkaes Exp $
*
* This builds the scanner for the tinyproxy configuration file. This
* file needs to stay in sync with grammar.y. If someone knows lex and yacc
* better than I do, please update these files.
*
* Copyright (C) 2000 Robert James Kaes (rjkaes@flarenet.com)
*
* 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, or (at your option) 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.
*/
%{
#include "tinyproxy.h"
#include "grammar.h"
#include <string.h>
#include <stdio.h>
struct keyword {
char *kw_name;
int kw_token;
};
static struct keyword keywords[] = {
/* statements */
{ "port", KW_PORT },
{ "logfile", KW_LOGFILE },
{ "syslog", KW_SYSLOG },
{ "maxclients", KW_MAXCLIENTS },
{ "maxspareservers", KW_MAXSPARESERVERS },
{ "minspareservers", KW_MINSPARESERVERS },
{ "startservers", KW_STARTSERVERS },
{ "maxrequestsperchild", KW_MAXREQUESTSPERCHILD },
{ "pidfile", KW_PIDFILE },
{ "timeout", KW_TIMEOUT },
{ "listen", KW_LISTEN },
{ "user", KW_USER },
{ "group", KW_GROUP },
{ "anonymous", KW_ANONYMOUS },
{ "filter", KW_FILTER },
{ "xtinyproxy", KW_XTINYPROXY },
{ "tunnel", KW_TUNNEL },
{ "allow", KW_ALLOW },
{ "deny", KW_DENY },
/* on/off switches */
{ "yes", KW_YES },
{ "on", KW_YES },
{ "no", KW_NO },
{ "off", KW_NO }
};
#define YY_NO_UNPUT 1
#define MAX_REGEXP_LEN 1024
unsigned int yylineno = 1;
char tiny_buf[MAX_REGEXP_LEN];
char *tiny_str;
static int check_reserved_words(char *token);
static void append_string(int length, char *str);
static void append_char(char c);
%}
%option noyywrap
white [ \t]
digit [0-9]
alpha [a-zA-Z]
alphanum [a-zA-Z0-9]
word [^ \#'"\(\)\{\}\\;\n\t,|\.]
%x string
%%
\#.*$ ;
\n { yylineno++; return '\n'; }
{white}+ ;
0x{digit}+ { yylval.num = strtol(yytext, NULL, 16); return NUMBER; }
0{digit}+ { yylval.num = strtol(yytext, NULL, 8); return NUMBER; }
{digit}+ { yylval.num = atoi(yytext); return NUMBER; }
{alpha}+ { return check_reserved_words(yytext); }
':' { return ':'; }
'/' { return '/'; }
\" {
tiny_str = tiny_buf;
BEGIN(string);
}
<string>\\a { append_char(7); }
<string>\\n { append_char(10); }
<string>\\r { append_char(13); }
<string>\\t { append_char(9); }
<string>\\v { append_char(11); }
<string>\\[^anrtv] { append_string(1, yytext + 1); }
<string>\" {
BEGIN(INITIAL);
yylval.cptr = strdup(tiny_buf);
return STRING;
}
<string>[^"\\]+ { append_string(strlen(yytext), yytext); }
({digit}{1,3}\.){3}{digit}{1,3} { yylval.cptr = strdup(yytext); return NUMERIC_ADDRESS; }
({digit}{1,3}\.){3}{digit}{1,3}\/{digit}+ { yylval.cptr = strdup(yytext); return NETMASK_ADDRESS; }
([-_a-z0-9]+\.)+[a-z]+ { yylval.cptr = strdup(yytext); return STRING_ADDRESS; }
%%
int check_reserved_words(char *token)
{
int i;
for (i = 0; i < (sizeof(keywords) / sizeof(struct keyword)); i++) {
if (strcasecmp(keywords[i].kw_name, token) == 0) {
return keywords[i].kw_token;
}
}
yylval.cptr = strdup(token);
return IDENTIFIER;
}
static void append_string(int length, char *s)
{
int to_copy = min(MAX_REGEXP_LEN - (tiny_str - tiny_buf) - 1, length);
memcpy(tiny_str, s, to_copy);
tiny_str += to_copy;
*tiny_str = 0;
}
static void append_char(char c)
{
*tiny_str = c;
tiny_str++;
*tiny_str = 0;
}