68 { |
68 { |
69 /* machine required vars */ |
69 /* machine required vars */ |
70 unsigned short int cs = 1; |
70 unsigned short int cs = 1; |
71 char *p = line; |
71 char *p = line; |
72 char *pe = p + strlen(p); |
72 char *pe = p + strlen(p); |
73 char *eof = NULL; |
73 char *eof = pe; |
74 |
74 |
75 /* the client request pointer */ |
75 /* the client request pointer */ |
76 request *p_request = init_request(); |
76 request *p_request = init_request(); |
77 |
77 |
78 %%{ |
78 %%{ |
79 machine input_parser; |
79 machine squidline_parser; |
80 |
80 |
81 action channel_id_found { |
81 action channel_id_found { |
82 debug( 1, LOC, "Channel ID found in redirector input. Set 'url_rewrite_concurrency' to '0' in squid.\n" ); |
82 debug( 1, LOC, "Channel ID found in redirector input. Set 'url_rewrite_concurrency' to '0' in squid.\n" ); |
83 fbreak; |
83 fbreak; |
84 } |
84 } |
85 |
85 |
86 action scheme_start { MARK_S(scheme) } |
86 action scheme_start { MARK_S(scheme) } |
87 action scheme_finish { MARK_E(scheme) } |
87 action scheme_finish { MARK_E(scheme) } |
88 action host_start { MARK_S(host) } |
88 action host_start { MARK_S(host) } |
89 action host_finish { MARK_E(host) } |
89 action host_finish { MARK_E(host) } |
90 action port_start { MARK_S(port) } |
90 action port_start { p_request->tokens.port_start = p+1; } # strip leading colon |
91 action port_finish { MARK_E(port) } |
91 action port_finish { MARK_E(port) } |
92 action path_start { MARK_S(path) } |
92 action path_start { MARK_S(path) } |
93 action path_finish { MARK_E(path) } |
93 action path_finish { MARK_E(path) } |
94 action meth_start { MARK_S(meth) } |
94 action meth_start { MARK_S(meth) } |
95 action meth_finish { MARK_E(meth) } |
95 action meth_finish { MARK_E(meth) } |
190 } |
190 } |
191 |
191 |
192 p_request->scheme = NULL; |
192 p_request->scheme = NULL; |
193 p_request->host = NULL; |
193 p_request->host = NULL; |
194 p_request->tld = NULL; |
194 p_request->tld = NULL; |
195 p_request->port = NULL; |
195 p_request->port = 0; |
196 p_request->path = NULL; |
196 p_request->path = NULL; |
197 p_request->user = NULL; |
197 p_request->user = NULL; |
198 p_request->method = NULL; |
198 p_request->method = NULL; |
199 p_request->client_ip = NULL; |
199 p_request->client_ip = NULL; |
200 |
200 |
225 void |
225 void |
226 populate_request( request *p_request ) |
226 populate_request( request *p_request ) |
227 { |
227 { |
228 p_request->scheme = COPY_STR( scheme ); |
228 p_request->scheme = COPY_STR( scheme ); |
229 p_request->host = COPY_STR( host ); |
229 p_request->host = COPY_STR( host ); |
230 p_request->port = COPY_STR( port ); |
|
231 p_request->path = COPY_STR( path ); |
230 p_request->path = COPY_STR( path ); |
232 p_request->method = COPY_STR( meth ); |
231 p_request->method = COPY_STR( meth ); |
233 p_request->client_ip = COPY_IP4( c_ip ); |
232 p_request->client_ip = COPY_IP4( c_ip ); |
234 |
233 |
235 parse_tld( p_request ); |
234 (void)parse_port( p_request ); |
|
235 (void)parse_tld( p_request ); |
|
236 |
|
237 return; |
|
238 } |
|
239 |
|
240 |
|
241 /* |
|
242 * Pull out the port number and convert it to an integer before |
|
243 * storing in the request struct. |
|
244 * |
|
245 */ |
|
246 void |
|
247 parse_port( request *p_request ) |
|
248 { |
|
249 if ( p_request->tokens.port_start == NULL || p_request->tokens.port_length == 0 ) return; |
|
250 |
|
251 char port[5]; |
|
252 |
|
253 (void)strncpy( port, p_request->tokens.port_start, p_request->tokens.port_length ); |
|
254 port[ p_request->tokens.port_length ] = '\0'; |
|
255 (void)sscanf( port, "%hu", &p_request->port ); |
236 |
256 |
237 return; |
257 return; |
238 } |
258 } |
239 |
259 |
240 |
260 |
246 parse_tld( request *p_request ) |
266 parse_tld( request *p_request ) |
247 { |
267 { |
248 unsigned short int cs = 5, mark = 0; |
268 unsigned short int cs = 5, mark = 0; |
249 char *p = p_request->host; |
269 char *p = p_request->host; |
250 char *pe = p + p_request->tokens.host_length; |
270 char *pe = p + p_request->tokens.host_length; |
251 char *ts = 0, *te = 0, *eof = NULL; |
271 char *ts = 0, *te = 0, *eof = pe; |
252 |
272 |
253 %%{ |
273 %%{ |
254 machine tld_parser; |
274 machine tld_parser; |
255 |
275 |
256 host_component = alnum | ( alnum [a-zA-Z0-9\-_]* alnum ); |
276 host_component = alnum | ( alnum [a-zA-Z0-9\-_]* alnum ); |
289 /* |
309 /* |
290 * Release memory used by the request struct. |
310 * Release memory used by the request struct. |
291 * |
311 * |
292 */ |
312 */ |
293 void |
313 void |
294 cleanup_request( struct request *p_request ) |
314 finish_request( request *p_request ) |
295 { |
315 { |
296 if ( p_request == NULL ) return; |
316 if ( p_request == NULL ) return; |
297 |
317 |
298 free( p_request->scheme ); |
318 free( p_request->scheme ); |
299 free( p_request->host ); |
319 free( p_request->host ); |
300 free( p_request->tld ); |
320 free( p_request->tld ); |
301 free( p_request->port ); |
|
302 free( p_request->path ); |
321 free( p_request->path ); |
303 free( p_request->method ); |
322 free( p_request->method ); |
304 free( p_request->client_ip ); |
323 free( p_request->client_ip ); |
305 |
324 |
306 free( p_request ), p_request = NULL; |
325 free( p_request ), p_request = NULL; |