1 |
/* |
2 |
* mod_czs -- nuke iso8859-2 characters |
3 |
* Dobrica Pavlinusic <dpavlin@rot13.org> |
4 |
* |
5 |
* based on mod_format by Stephen F. Booth and |
6 |
* mod_mocrify by Peter Triller, Ernst Bachmann |
7 |
* |
8 |
* Usage: httpd.conf |
9 |
* AddHandler czs .html |
10 |
* |
11 |
* This program is free software; you can redistribute it and/or modify |
12 |
* it under the terms of the GNU General Public License as published by |
13 |
* the Free Software Foundation; either version 2 of the License, or |
14 |
* (at your option) any later version. |
15 |
* |
16 |
* This program is distributed in the hope that it will be useful, |
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
* GNU General Public License for more details. |
20 |
* |
21 |
* You should have received a copy of the GNU General Public License |
22 |
* along with this program; if not, write to the Free Software |
23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
*/ |
25 |
|
26 |
#include "httpd.h" |
27 |
#include "http_main.h" |
28 |
#include "http_config.h" |
29 |
#include "http_log.h" |
30 |
#include "http_protocol.h" |
31 |
|
32 |
module MODULE_VAR_EXPORT mod_czs; |
33 |
|
34 |
FILE *in; |
35 |
int do_czs; |
36 |
|
37 |
static int czs_handler(request_rec *r) { |
38 |
|
39 |
char buffer[MAX_STRING_LEN] = "undefined buffer content"; |
40 |
int i; |
41 |
|
42 |
if(r->method_number != M_GET) |
43 |
return DECLINED; |
44 |
if(r->finfo.st_mode == 0) |
45 |
return NOT_FOUND; |
46 |
|
47 |
in = ap_pfopen(r->pool, r->filename, "r"); |
48 |
|
49 |
if(in == NULL) { |
50 |
ap_log_reason("file permissions deny server access", r->filename, r); |
51 |
return FORBIDDEN; |
52 |
} |
53 |
if(r->args != 0 || do_czs) { |
54 |
ap_table_setn(r->headers_out, "X-czs_filename", r->filename); |
55 |
if (r->args != 0) { |
56 |
ap_table_setn(r->headers_out, "X-czs_args", r->args); |
57 |
} |
58 |
} |
59 |
|
60 |
r->content_type = "text/html"; /* hm? */ |
61 |
|
62 |
ap_soft_timeout("send", r); |
63 |
ap_send_http_header(r); |
64 |
|
65 |
if(r->header_only) { |
66 |
ap_kill_timeout(r); |
67 |
ap_pfclose(r->pool, in); |
68 |
return OK; |
69 |
} |
70 |
|
71 |
#ifdef TEST_QUERYSTRING |
72 |
if(r->args == 0 && !do_czs) { |
73 |
ap_send_fd(in, r); |
74 |
} else { |
75 |
#endif |
76 |
while(fgets(buffer,MAX_STRING_LEN,in)) { |
77 |
for(i=0; i<MAX_STRING_LEN && buffer[i]; i++) { |
78 |
switch ( buffer[i] ) { |
79 |
case '¹': buffer[i]='s'; break; |
80 |
case 'ð': buffer[i]='d'; break; |
81 |
case 'è': buffer[i]='c'; break; |
82 |
case 'æ': buffer[i]='c'; break; |
83 |
case '¾': buffer[i]='z'; break; |
84 |
case '©': buffer[i]='S'; break; |
85 |
case 'Ð': buffer[i]='D'; break; |
86 |
case 'È': buffer[i]='C'; break; |
87 |
case 'Æ': buffer[i]='C'; break; |
88 |
case '®': buffer[i]='Z'; break; |
89 |
} |
90 |
} |
91 |
ap_rprintf(r,"%s",buffer); |
92 |
} |
93 |
#ifdef TEST_QUERYSTRING |
94 |
} |
95 |
#endif |
96 |
|
97 |
ap_kill_timeout(r); |
98 |
ap_pfclose(r->pool, in); |
99 |
return OK; |
100 |
} |
101 |
|
102 |
int translate_path(request_rec *r) { |
103 |
char *uri = r->uri; |
104 |
request_rec *subr; |
105 |
|
106 |
if (uri[0]=='/' && uri[1]=='_' && uri[2]=='/') { |
107 |
#if 0 |
108 |
ap_table_setn(r->headers_out, "Location", ap_pstrcat(r->pool, uri+2, "?czs", NULL)); |
109 |
return REDIRECT; |
110 |
#endif |
111 |
subr = (request_rec *) ap_sub_req_lookup_uri(r->uri+2, r); |
112 |
r->filename=ap_pstrdup(r->pool, subr->filename); |
113 |
ap_destroy_sub_req(subr); |
114 |
do_czs=1; |
115 |
return OK; |
116 |
} |
117 |
|
118 |
return DECLINED; |
119 |
} |
120 |
|
121 |
/* Dispatch list of content handlers */ |
122 |
static const handler_rec czs_handlers[] = { |
123 |
{ "czs", czs_handler }, |
124 |
{ NULL, NULL } |
125 |
}; |
126 |
|
127 |
/* Dispatch list for API hooks */ |
128 |
module MODULE_VAR_EXPORT czs_module = { |
129 |
STANDARD_MODULE_STUFF, |
130 |
NULL, /* module initializer */ |
131 |
NULL, /* create per-dir config structures */ |
132 |
NULL, /* merge per-dir config structures */ |
133 |
NULL, /* create per-server config structures */ |
134 |
NULL, /* merge per-server config structures */ |
135 |
NULL, /* table of config file commands */ |
136 |
czs_handlers, /* [#8] MIME-typed-dispatched handlers */ |
137 |
translate_path, /* [#1] URI to filename translation */ |
138 |
NULL, /* [#4] validate user id from request */ |
139 |
NULL, /* [#5] check if the user is ok _here_ */ |
140 |
NULL, /* [#2] check access by host address */ |
141 |
NULL, /* [#6] determine MIME type */ |
142 |
NULL, /* [#7] pre-run fixups */ |
143 |
NULL, /* [#9] log a transaction */ |
144 |
NULL, /* [#3] header parser */ |
145 |
NULL, /* child_init */ |
146 |
NULL, /* child_exit */ |
147 |
NULL /* [#0] post read-request */ |
148 |
}; |
149 |
|