volta.h
author Mahlon E. Smith <mahlon@laika.com>
Wed, 25 Jul 2012 11:47:12 -0700
changeset 30 5cc836e06759
parent 29 c5d00a24af56
child 32 6dc2d52e4b13
permissions -rw-r--r--
branch merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     1
/* vim: set noet nosta sw=4 ts=4 ft=c : */
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     2
/*
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
     3
Copyright (c) 2011-2012, Mahlon E. Smith <mahlon@martini.nu>
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     4
All rights reserved.
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     5
Redistribution and use in source and binary forms, with or without
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     6
modification, are permitted provided that the following conditions are met:
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     7
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     8
    * Redistributions of source code must retain the above copyright
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
     9
      notice, this list of conditions and the following disclaimer.
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    10
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    11
    * Redistributions in binary form must reproduce the above copyright
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    12
      notice, this list of conditions and the following disclaimer in the
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    13
      documentation and/or other materials provided with the distribution.
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    14
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    15
    * Neither the name of Mahlon E. Smith nor the names of his
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    16
      contributors may be used to endorse or promote products derived
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    17
      from this software without specific prior written permission.
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    18
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    19
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    20
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    21
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    22
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    23
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    24
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    25
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    26
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    27
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    28
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    29
*/
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    30
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    31
#ifndef _VOLTA_H
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    32
#define _VOLTA_H
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    33
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    34
#ifndef PROG
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    35
#define PROG    "volta"
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    36
#endif
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    37
#define VERSION "$Version$" /* expanded by mercurial */
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    38
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    39
#include <stdio.h>
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    40
#include <stdlib.h>
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    41
#include <stdarg.h>
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    42
#include <errno.h>
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    43
#include <string.h>
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    44
#include <strings.h>
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    45
#include <unistd.h>
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    46
#include <ctype.h>
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    47
#include <time.h>
4
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    48
#include <sys/stat.h>
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    49
#include <signal.h>
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    50
#include <fcntl.h>
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    51
#include <sys/types.h>
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    52
#include <regex.h>
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    53
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    54
/*
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    55
#include <sys/socket.h>
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    56
#include <netinet/in.h>
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    57
#include <arpa/inet.h>
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    58
*/
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    59
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    60
#ifdef DEBUG
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    61
#include <google/profiler.h>
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    62
#endif
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    63
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
    64
/* Default line size we accept from squid, longer lines (huge URLs?) malloc. */
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    65
#define LINE_BUFSIZE 2048
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    66
/* Ceiling for how many bytes can be allocated at once for a single line. */
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    67
#define LINE_MAX 256000 /* 250k */
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    68
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    69
/* Parsed line types */
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    70
#define REQUEST 1
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    71
#define RULE 2
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    72
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    73
/* Aid debugging */
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
    74
#define LOC __FILE__, __LINE__
4
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    75
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
    76
#include <cdb.h>
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
    77
#include <lua.h>
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
    78
#include <lualib.h>
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
    79
#include <lauxlib.h>
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
    80
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    81
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    82
/*
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    83
 * a global struct for easy access to common vars 
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    84
 *
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    85
 */
4
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    86
struct v_globals {
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    87
	unsigned short int debugmode; /* debug level */
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    88
	char dbname[128];             /* path to database file */
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    89
	short int db_fd;              /* opened db file descriptor */
17
bd746609ba46 Retain the CDB struct between lookups, only freeing when reopening the
Mahlon E. Smith <mahlon@martini.nu>
parents: 15
diff changeset
    90
	struct cdb db;                /* the cdb struct */
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
    91
	lua_State *lua;               /* the lua interpreter */
13
23a242d7b7fa 1st iteration of volta actually doing something. Process the request,
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
    92
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    93
	struct {
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    94
		time_t start;             /* start time */
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    95
		unsigned long int lines;  /* line count for determining speed */
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
    96
		time_t db_lastcheck;      /* reopen db time */
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
    97
	} timer;
4
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    98
};
5701b7859a31 Groundwork for automatic database initialization and schema upgrades.
Mahlon E. Smith <mahlon@laika.com>
parents: 2
diff changeset
    99
extern struct v_globals v;        /* defined in main.c */
1
823d42546cea Dial in the Makefile and command line option parsing. Better debug
Mahlon E. Smith <mahlon@laika.com>
parents: 0
diff changeset
   100
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   101
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   102
/*
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   103
 * A line of parsed ascii DB input, for conversion into cdb.
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   104
 *
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   105
 */
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   106
struct db_input {
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   107
	unsigned int klen;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   108
	unsigned int vlen;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   109
	char *key;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   110
	char *val;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   111
	char *kstart;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   112
	char *vstart;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   113
};
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   114
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   115
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   116
/*
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   117
 * The parsed attributes from the request line as given to us by squid,
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   118
 * or from the rule string found in the database.  Unparsed
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   119
 * members are just left NULL.
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   120
 *
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   121
 */
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   122
typedef struct parsed {
29
c5d00a24af56 Add support for Squid's 'url_rewriter_concurrency' pipelining.
Mahlon E. Smith <mahlon@laika.com>
parents: 22
diff changeset
   123
	unsigned short int valid;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   124
	unsigned short int type;
18
d4ce82194b64 - 1st pass at documentation with the README.
Mahlon E. Smith <mahlon@laika.com>
parents: 17
diff changeset
   125
	unsigned short int negate;
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
   126
	unsigned short int lua;
29
c5d00a24af56 Add support for Squid's 'url_rewriter_concurrency' pipelining.
Mahlon E. Smith <mahlon@laika.com>
parents: 22
diff changeset
   127
	char   *chid;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   128
	char   *path_re;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   129
	char   *redir;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   130
	char   *scheme;
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   131
	char   *host;
12
191b3c25974a Clean up redundant parser actions via preprocessor macros, add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   132
	char   *tld;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   133
	char   *path;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   134
	char   *port;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   135
	/* struct in_addr *client_ip; */
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   136
	char   *client_ip;
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   137
	char   *user;
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   138
	char   *method;
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
   139
	char   *luapath;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   140
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   141
	struct {
29
c5d00a24af56 Add support for Squid's 'url_rewriter_concurrency' pipelining.
Mahlon E. Smith <mahlon@laika.com>
parents: 22
diff changeset
   142
		char *chid_start;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   143
		char *path_re_start;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   144
		char *redir_start;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   145
		char *scheme_start;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   146
		char *host_start;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   147
		char *port_start;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   148
		char *path_start;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   149
		char *meth_start;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   150
		char *c_ip_start;
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
   151
		char *luapath_start;
29
c5d00a24af56 Add support for Squid's 'url_rewriter_concurrency' pipelining.
Mahlon E. Smith <mahlon@laika.com>
parents: 22
diff changeset
   152
		unsigned short int chid_length;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   153
		unsigned short int path_re_length;
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   154
		unsigned short int redir_length;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   155
		unsigned short int scheme_length;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   156
		unsigned short int host_length;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   157
		unsigned short int port_length;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   158
		unsigned int       path_length;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   159
		unsigned short int meth_length;
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   160
		unsigned short int c_ip_length;
22
822094314703 Add the ability to optionally script rewrite logic using Lua.
Mahlon E. Smith <mahlon@martini.nu>
parents: 18
diff changeset
   161
		unsigned short int luapath_length;
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   162
	} tokens;
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   163
} parsed;
13
23a242d7b7fa 1st iteration of volta actually doing something. Process the request,
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
   164
23a242d7b7fa 1st iteration of volta actually doing something. Process the request,
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
   165
23a242d7b7fa 1st iteration of volta actually doing something. Process the request,
Mahlon E. Smith <mahlon@laika.com>
parents: 12
diff changeset
   166
/*
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   167
 *
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   168
 * Function prototypes
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   169
 *
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   170
 */
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   171
int  getopt( int, char * const [], const char *);
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   172
void shutdown_handler( int );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   173
void shutdown_actions( void );
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   174
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   175
void usage( char * );
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   176
void debug( int, char *, int, const char *, ... );
12
191b3c25974a Clean up redundant parser actions via preprocessor macros, add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 11
diff changeset
   177
void reverse_str( char * );
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   178
void lowercase_str( char *, unsigned short int );
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   179
void report_speed( void );
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   180
char *extend_line( char *, const char * );
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   181
char *copy_string_token( char *, unsigned short int );
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   182
/* struct in_addr *copy_ipv4_token( char *, unsigned short int ); */
2
8c88756f81b0 Ensure that parsing can't be subverted by requests larger than the
Mahlon E. Smith <mahlon@martini.nu>
parents: 1
diff changeset
   183
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   184
int  accept_loop( void );
10
d07309450285 Get the ragel line parser properly tokenizing the input lines. Add a
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   185
void process( char * );
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   186
parsed *init_parsed( void );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   187
parsed *parse_request( char * );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   188
parsed *parse_rule( char * );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   189
void populate_parsed( parsed * );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   190
void parse_tld( parsed * );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   191
void finish_parsed( parsed * );
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   192
void reset_results( parsed **, unsigned int );
15
2706fc514dea Add whitelisting rules, to negate other matches if they come first in
Mahlon E. Smith <mahlon@martini.nu>
parents: 14
diff changeset
   193
unsigned short int check_rule( parsed *, parsed * );
18
d4ce82194b64 - 1st pass at documentation with the README.
Mahlon E. Smith <mahlon@laika.com>
parents: 17
diff changeset
   194
void pass( parsed *, parsed * );
14
51eb85ae4de4 There isn't a fast way to look up ( value exists or null ) for every
Mahlon E. Smith <mahlon@martini.nu>
parents: 13
diff changeset
   195
void rewrite( parsed *, parsed * );
0
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   196
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   197
#endif
eac7211fe522 Initial commit of an experimental little Squid redirector.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
   198