volta.h
changeset 4 5701b7859a31
parent 2 8c88756f81b0
child 9 bdf20e6eefd7
equal deleted inserted replaced
3:97f767832c52 4:5701b7859a31
    41 #include <stdarg.h>
    41 #include <stdarg.h>
    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 
    47 
    47 #include <sys/types.h>
    48 #include <sys/types.h>
    48 #include <sys/socket.h>
    49 #include <sys/socket.h>
    49 #include <netinet/in.h>
    50 #include <netinet/in.h>
    50 #include <arpa/inet.h>
    51 #include <arpa/inet.h>
    51 
       
    52 #include <sqlite3.h>
       
    53 
    52 
    54 #ifdef DEBUG
    53 #ifdef DEBUG
    55 #include <google/profiler.h>
    54 #include <google/profiler.h>
    56 #endif
    55 #endif
    57 
    56 
    58 /* Default line size we accept from squid, longer lines (huge URLs?) malloc. */
    57 /* Default line size we accept from squid, longer lines (huge URLs?) malloc. */
    59 #define LINE_BUFSIZE 2048
    58 #define LINE_BUFSIZE 2048
    60 
    59 
    61 /* Aid debugging */
    60 /* Aid debugging */
    62 #define LOC __FILE__, __LINE__
    61 #define LOC __FILE__, __LINE__
    63 /* Global debug toggle */
    62 
    64 extern unsigned short int debugmode;
    63 /* a global struct for easy access to common vars */
       
    64 struct v_globals {
       
    65 	unsigned short int debugmode; /* debug level */
       
    66 	char dbname[128];             /* path to database file */
       
    67 	struct sqlite3 *db;           /* database handle */
       
    68 };
       
    69 extern struct v_globals v;        /* defined in main.c */
    65 
    70 
    66 /* The parsed attributes from the request line, as given to us by squid.
    71 /* The parsed attributes from the request line, as given to us by squid.
    67  * URL <SP> client_ip "/" fqdn <SP> user <SP> method [<SP> kvpairs]<NL> */
    72  * URL <SP> client_ip "/" fqdn <SP> user <SP> method [<SP> kvpairs]<NL> */
    68 typedef struct request {
    73 typedef struct request {
    69 	char   *url;
    74 	char   *url;
    73 	char   *user;
    78 	char   *user;
    74 	char   *method;
    79 	char   *method;
    75 	char   *kvpairs;
    80 	char   *kvpairs;
    76 } request;
    81 } request;
    77 
    82 
    78 /* FIXME: An "empty" request struct used for re-assignment */
       
    79 static const struct request reset_request;
       
    80 
       
    81 /*
    83 /*
    82  *
    84  *
    83  * Function prototypes
    85  * Function prototypes
    84  *
    86  *
    85  */
    87  */
    86 
    88 
    87 void usage( char *prg );
    89 void usage( char *prg );
    88 void debug( int level, char *file, int line, const char *fmt, ... );
    90 void debug( int level, char *file, int line, const char *fmt, ... );
       
    91 char *slurp_file( char *file );
    89 char *extend_line( char *line, const char *buf );
    92 char *extend_line( char *line, const char *buf );
    90 
       
    91 int db_initialize( void );
       
    92 
    93 
    93 int accept_loop( void );
    94 int accept_loop( void );
    94 struct request *parse( char *p );
    95 struct request *parse( char *p );
    95 
    96 
    96 #endif
    97 #endif