volta.h
changeset 10 d07309450285
parent 9 bdf20e6eefd7
child 11 9aa5114326e8
equal deleted inserted replaced
9:bdf20e6eefd7 10:d07309450285
    42 #include <errno.h>
    42 #include <errno.h>
    43 #include <string.h>
    43 #include <string.h>
    44 #include <unistd.h>
    44 #include <unistd.h>
    45 #include <time.h>
    45 #include <time.h>
    46 #include <sys/stat.h>
    46 #include <sys/stat.h>
       
    47 #include <signal.h>
    47 
    48 
    48 #include <sys/types.h>
    49 #include <sys/types.h>
    49 #include <sys/socket.h>
    50 #include <sys/socket.h>
    50 #include <netinet/in.h>
    51 #include <netinet/in.h>
    51 #include <arpa/inet.h>
    52 #include <arpa/inet.h>
    54 #include <google/profiler.h>
    55 #include <google/profiler.h>
    55 #endif
    56 #endif
    56 
    57 
    57 /* Default line size we accept from squid, longer lines (huge URLs?) malloc. */
    58 /* Default line size we accept from squid, longer lines (huge URLs?) malloc. */
    58 #define LINE_BUFSIZE 2048
    59 #define LINE_BUFSIZE 2048
       
    60 /* Ceiling for how many bytes can be allocated at one for a single line. */
       
    61 #define LINE_MAX 256000 /* 250k */
       
    62 
       
    63 /* Redirect types */
       
    64 #define REDIR_TEMPORARY   0
       
    65 #define REDIR_PERMANENT   1
       
    66 #define REDIR_TRANSPARENT 2
    59 
    67 
    60 /* Aid debugging */
    68 /* Aid debugging */
    61 #define LOC __FILE__, __LINE__
    69 #define LOC __FILE__, __LINE__
    62 
    70 
    63 /* a global struct for easy access to common vars */
    71 /*
       
    72  * a global struct for easy access to common vars 
       
    73  *
       
    74  */
    64 struct v_globals {
    75 struct v_globals {
    65 	unsigned short int debugmode; /* debug level */
    76 	unsigned short int debugmode; /* debug level */
    66 	char dbname[128];             /* path to database file */
    77 	char dbname[128];             /* path to database file */
    67 	struct sqlite3 *db;           /* database handle */
    78 	struct sqlite3 *db;           /* database handle */
       
    79 
       
    80 	struct {
       
    81 		time_t start;            /* start time */
       
    82 		unsigned long int lines; /* line count for determining speed */
       
    83 	} timer;
    68 };
    84 };
    69 extern struct v_globals v;        /* defined in main.c */
    85 extern struct v_globals v;        /* defined in main.c */
    70 
    86 
    71 /* The parsed attributes from the request line, as given to us by squid.
    87 /*
    72  * URL <SP> client_ip "/" fqdn <SP> user <SP> method [<SP> kvpairs]<NL> */
    88  * The parsed attributes from the request line, as given to us by squid.
       
    89  *
       
    90  */
    73 typedef struct request {
    91 typedef struct request {
    74 	char   *url;
    92 	char   *scheme;
    75 	char   *host;
    93 	char   *host;
    76 	struct sockaddr_in ip;
    94 	char   *path;
    77 	char   *ip_fqdn;
    95 	char   *port;
       
    96 	struct in_addr *client_ip;
    78 	char   *user;
    97 	char   *user;
    79 	char   *method;
    98 	char   *method;
    80 	char   *kvpairs;
    99 
       
   100 	struct {
       
   101 		char *scheme_start;
       
   102 		char *host_start;
       
   103 		char *port_start;
       
   104 		char *path_start;
       
   105 		char *meth_start;
       
   106 		char *c_ip_start;
       
   107 		unsigned short int scheme_length;
       
   108 		unsigned short int host_length;
       
   109 		unsigned short int port_length;
       
   110 		unsigned short int path_length;
       
   111 		unsigned short int meth_length;
       
   112 		unsigned short int c_ip_length;
       
   113 	} tokens;
    81 } request;
   114 } request;
    82 
   115 
    83 /*
   116 /*
    84  *
   117  *
    85  * Function prototypes
   118  * Function prototypes
    86  *
   119  *
    87  */
   120  */
    88 int getopt( int, char * const [], const char *);
   121 int getopt( int, char * const [], const char *);
    89 
   122 
    90 void usage( char *prg );
   123 void usage( char * );
    91 void debug( int level, char *file, int line, const char *fmt, ... );
   124 void debug( int, char *, int, const char *, ... );
    92 char *slurp_file( char *file );
   125 void report_speed( void );
    93 char *extend_line( char *line, const char *buf );
   126 char *slurp_file( char * );
       
   127 char *extend_line( char *, const char * );
       
   128 char *copy_string_token( char *, unsigned short int );
       
   129 struct in_addr *copy_ipv4_token( char *, unsigned short int );
    94 
   130 
    95 int accept_loop( void );
   131 int accept_loop( void );
    96 struct request *parse( char *p );
   132 struct request *parse( char *p );
       
   133 void process( char * );
       
   134 struct request *parse( char * );
       
   135 void populate_request( struct request * );
       
   136 void cleanup_request( struct request * );
    97 
   137 
    98 #endif
   138 #endif
    99 
   139