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 |
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ |
29 */ |
30 |
30 |
31 #include "volta.h" |
31 #include "volta.h" |
32 #include "db.h" |
32 #include "db.h" |
|
33 #include "lua.h" |
33 |
34 |
34 |
35 |
35 /* |
36 /* |
36 * Given a redirect +line+ from squid, send it to the parser, |
37 * Given a redirect +line+ from squid, send it to the parser, |
37 * perform database lookups, and conditonally perform the rewrite. |
38 * perform database lookups, and conditonally perform the rewrite. |
80 return pass( p_request, rule ); |
81 return pass( p_request, rule ); |
81 |
82 |
82 /* avoid trivial redirect loops */ |
83 /* avoid trivial redirect loops */ |
83 if ( |
84 if ( |
84 ( rule->redir ) && |
85 ( rule->redir ) && |
85 ( rule->scheme == NULL || ( strcmp(p_request->scheme, rule->scheme) == 0) ) && |
86 ( rule->scheme == NULL || ( p_request->scheme && ( strcmp(p_request->scheme, rule->scheme) == 0) )) && |
86 ( rule->path == NULL || ( strcmp(p_request->path, rule->path) == 0) ) && |
87 ( rule->path == NULL || ( strcmp(p_request->path, rule->path) == 0) ) && |
87 ( strcmp( p_request->host, rule->host) == 0 ) |
88 ( strcmp( p_request->host, rule->host ) == 0 ) |
88 ) { |
89 ) { |
89 debug( 2, LOC, "Potential rewrite loop, skipping rewrite.\n" ); |
90 debug( 2, LOC, "Potential rewrite loop, skipping rewrite.\n" ); |
90 return pass( p_request, rule ); |
91 return pass( p_request, rule ); |
91 } |
92 } |
92 |
93 |
93 /* otherwise, perform the rewrite. */ |
94 /* At this point we know we'll be doing a rewrite. */ |
94 rewrite( p_request, rule ); |
95 |
|
96 /* Pass the request to lua for processing if we saw a 'lua:' tag. */ |
|
97 if ( rule->lua == 1 ) { |
|
98 char *rewrite_string = luaV_run( p_request, rule->luapath ); |
|
99 |
|
100 /* the script returned nil, or otherwise had an error. */ |
|
101 if ( rewrite_string == NULL ) return pass( p_request, rule ); |
|
102 |
|
103 /* send squid the lua return value. */ |
|
104 if ( v.debugmode < 5 ) { |
|
105 puts( rewrite_string ); |
|
106 fflush( stdout ); |
|
107 } |
|
108 } |
|
109 |
|
110 /* otherwise, perform the rewrite internally. */ |
|
111 else { |
|
112 rewrite( p_request, rule ); |
|
113 } |
95 |
114 |
96 finish_parsed( rule ); |
115 finish_parsed( rule ); |
97 finish_parsed( p_request ); |
116 finish_parsed( p_request ); |
98 return; |
117 return; |
99 } |
118 } |