equal
deleted
inserted
replaced
1 /* vim: set noet nosta sw=4 ts=4 ft=c : */ |
1 /* vim: set noet nosta sw=4 ts=4 ft=c : */ |
2 /* |
2 /* |
3 Copyright (c) 2011, Mahlon E. Smith <mahlon@martini.nu> |
3 Copyright (c) 2011-2012, Mahlon E. Smith <mahlon@martini.nu> |
4 All rights reserved. |
4 All rights reserved. |
5 Redistribution and use in source and binary forms, with or without |
5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are met: |
6 modification, are permitted provided that the following conditions are met: |
7 |
7 |
8 * Redistributions of source code must retain the above copyright |
8 * Redistributions of source code must retain the above copyright |
55 #include <sys/socket.h> |
55 #include <sys/socket.h> |
56 #include <netinet/in.h> |
56 #include <netinet/in.h> |
57 #include <arpa/inet.h> |
57 #include <arpa/inet.h> |
58 */ |
58 */ |
59 |
59 |
60 #include <cdb.h> |
|
61 |
|
62 #ifdef DEBUG |
60 #ifdef DEBUG |
63 #include <google/profiler.h> |
61 #include <google/profiler.h> |
64 #endif |
62 #endif |
65 |
63 |
66 /* Default line size we accept from squid, longer lines (huge URLs?) malloc. */ |
64 /* Default line size we accept from squid, longer lines (huge URLs?) malloc. */ |
73 #define RULE 2 |
71 #define RULE 2 |
74 |
72 |
75 /* Aid debugging */ |
73 /* Aid debugging */ |
76 #define LOC __FILE__, __LINE__ |
74 #define LOC __FILE__, __LINE__ |
77 |
75 |
|
76 #include <cdb.h> |
|
77 #include <lua.h> |
|
78 #include <lualib.h> |
|
79 #include <lauxlib.h> |
|
80 |
78 |
81 |
79 /* |
82 /* |
80 * a global struct for easy access to common vars |
83 * a global struct for easy access to common vars |
81 * |
84 * |
82 */ |
85 */ |
83 struct v_globals { |
86 struct v_globals { |
84 unsigned short int debugmode; /* debug level */ |
87 unsigned short int debugmode; /* debug level */ |
85 char dbname[128]; /* path to database file */ |
88 char dbname[128]; /* path to database file */ |
86 short int db_fd; /* opened db file descriptor */ |
89 short int db_fd; /* opened db file descriptor */ |
87 struct cdb db; /* the cdb struct */ |
90 struct cdb db; /* the cdb struct */ |
|
91 lua_State *lua; /* the lua interpreter */ |
88 |
92 |
89 struct { |
93 struct { |
90 time_t start; /* start time */ |
94 time_t start; /* start time */ |
91 unsigned long int lines; /* line count for determining speed */ |
95 unsigned long int lines; /* line count for determining speed */ |
92 time_t db_lastcheck; /* reopen db time */ |
96 time_t db_lastcheck; /* reopen db time */ |
116 * |
120 * |
117 */ |
121 */ |
118 typedef struct parsed { |
122 typedef struct parsed { |
119 unsigned short int type; |
123 unsigned short int type; |
120 unsigned short int negate; |
124 unsigned short int negate; |
|
125 unsigned short int lua; |
121 char *path_re; |
126 char *path_re; |
122 char *redir; |
127 char *redir; |
123 char *scheme; |
128 char *scheme; |
124 char *host; |
129 char *host; |
125 char *tld; |
130 char *tld; |
127 char *port; |
132 char *port; |
128 /* struct in_addr *client_ip; */ |
133 /* struct in_addr *client_ip; */ |
129 char *client_ip; |
134 char *client_ip; |
130 char *user; |
135 char *user; |
131 char *method; |
136 char *method; |
|
137 char *luapath; |
132 |
138 |
133 struct { |
139 struct { |
134 char *path_re_start; |
140 char *path_re_start; |
135 char *redir_start; |
141 char *redir_start; |
136 char *scheme_start; |
142 char *scheme_start; |
137 char *host_start; |
143 char *host_start; |
138 char *port_start; |
144 char *port_start; |
139 char *path_start; |
145 char *path_start; |
140 char *meth_start; |
146 char *meth_start; |
141 char *c_ip_start; |
147 char *c_ip_start; |
|
148 char *luapath_start; |
142 unsigned short int path_re_length; |
149 unsigned short int path_re_length; |
143 unsigned short int redir_length; |
150 unsigned short int redir_length; |
144 unsigned short int scheme_length; |
151 unsigned short int scheme_length; |
145 unsigned short int host_length; |
152 unsigned short int host_length; |
146 unsigned short int port_length; |
153 unsigned short int port_length; |
147 unsigned int path_length; |
154 unsigned int path_length; |
148 unsigned short int meth_length; |
155 unsigned short int meth_length; |
149 unsigned short int c_ip_length; |
156 unsigned short int c_ip_length; |
|
157 unsigned short int luapath_length; |
150 } tokens; |
158 } tokens; |
151 } parsed; |
159 } parsed; |
152 |
160 |
153 |
161 |
154 /* |
162 /* |