1 |
dpavlin |
1.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 |
dpavlin |
1.8 |
#include "translate.c" |
32 |
dpavlin |
1.1 |
|
33 |
|
|
module MODULE_VAR_EXPORT mod_czs; |
34 |
|
|
|
35 |
|
|
FILE *in; |
36 |
|
|
int do_czs; |
37 |
|
|
|
38 |
|
|
static int czs_handler(request_rec *r) { |
39 |
|
|
|
40 |
|
|
char buffer[MAX_STRING_LEN] = "undefined buffer content"; |
41 |
|
|
int i; |
42 |
|
|
|
43 |
|
|
if(r->method_number != M_GET) |
44 |
|
|
return DECLINED; |
45 |
|
|
if(r->finfo.st_mode == 0) |
46 |
|
|
return NOT_FOUND; |
47 |
|
|
|
48 |
|
|
in = ap_pfopen(r->pool, r->filename, "r"); |
49 |
|
|
|
50 |
|
|
if(in == NULL) { |
51 |
|
|
ap_log_reason("file permissions deny server access", r->filename, r); |
52 |
|
|
return FORBIDDEN; |
53 |
|
|
} |
54 |
dpavlin |
1.7 |
#ifdef DEBUG |
55 |
dpavlin |
1.1 |
if(r->args != 0 || do_czs) { |
56 |
|
|
ap_table_setn(r->headers_out, "X-czs_filename", r->filename); |
57 |
dpavlin |
1.2 |
if (r->args != 0) { |
58 |
|
|
ap_table_setn(r->headers_out, "X-czs_args", r->args); |
59 |
|
|
} |
60 |
dpavlin |
1.1 |
} |
61 |
dpavlin |
1.7 |
#endif |
62 |
dpavlin |
1.1 |
|
63 |
|
|
ap_soft_timeout("send", r); |
64 |
|
|
ap_send_http_header(r); |
65 |
|
|
|
66 |
|
|
if(r->header_only) { |
67 |
|
|
ap_kill_timeout(r); |
68 |
|
|
ap_pfclose(r->pool, in); |
69 |
|
|
return OK; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
#ifdef TEST_QUERYSTRING |
73 |
|
|
if(r->args == 0 && !do_czs) { |
74 |
dpavlin |
1.5 |
#else |
75 |
|
|
if(!do_czs) { |
76 |
|
|
#endif |
77 |
dpavlin |
1.1 |
ap_send_fd(in, r); |
78 |
|
|
} else { |
79 |
dpavlin |
1.5 |
|
80 |
|
|
while(fgets(buffer,MAX_STRING_LEN,in)) { |
81 |
|
|
for(i=0; i<MAX_STRING_LEN && buffer[i]; i++) { |
82 |
|
|
switch ( buffer[i] ) { |
83 |
|
|
case '¹': buffer[i]='s'; break; |
84 |
|
|
case 'ð': buffer[i]='d'; break; |
85 |
|
|
case 'è': buffer[i]='c'; break; |
86 |
|
|
case 'æ': buffer[i]='c'; break; |
87 |
|
|
case '¾': buffer[i]='z'; break; |
88 |
|
|
case '©': buffer[i]='S'; break; |
89 |
|
|
case 'Ð': buffer[i]='D'; break; |
90 |
|
|
case 'È': buffer[i]='C'; break; |
91 |
|
|
case 'Æ': buffer[i]='C'; break; |
92 |
|
|
case '®': buffer[i]='Z'; break; |
93 |
|
|
} |
94 |
dpavlin |
1.1 |
} |
95 |
dpavlin |
1.5 |
ap_rprintf(r,"%s",buffer); |
96 |
dpavlin |
1.1 |
} |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
ap_kill_timeout(r); |
100 |
|
|
ap_pfclose(r->pool, in); |
101 |
|
|
return OK; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
/* Dispatch list of content handlers */ |
105 |
|
|
static const handler_rec czs_handlers[] = { |
106 |
|
|
{ "czs", czs_handler }, |
107 |
|
|
{ NULL, NULL } |
108 |
|
|
}; |
109 |
|
|
|
110 |
|
|
/* Dispatch list for API hooks */ |
111 |
|
|
module MODULE_VAR_EXPORT czs_module = { |
112 |
|
|
STANDARD_MODULE_STUFF, |
113 |
|
|
NULL, /* module initializer */ |
114 |
|
|
NULL, /* create per-dir config structures */ |
115 |
|
|
NULL, /* merge per-dir config structures */ |
116 |
|
|
NULL, /* create per-server config structures */ |
117 |
|
|
NULL, /* merge per-server config structures */ |
118 |
|
|
NULL, /* table of config file commands */ |
119 |
|
|
czs_handlers, /* [#8] MIME-typed-dispatched handlers */ |
120 |
|
|
translate_path, /* [#1] URI to filename translation */ |
121 |
|
|
NULL, /* [#4] validate user id from request */ |
122 |
|
|
NULL, /* [#5] check if the user is ok _here_ */ |
123 |
|
|
NULL, /* [#2] check access by host address */ |
124 |
|
|
NULL, /* [#6] determine MIME type */ |
125 |
|
|
NULL, /* [#7] pre-run fixups */ |
126 |
|
|
NULL, /* [#9] log a transaction */ |
127 |
|
|
NULL, /* [#3] header parser */ |
128 |
|
|
NULL, /* child_init */ |
129 |
|
|
NULL, /* child_exit */ |
130 |
|
|
NULL /* [#0] post read-request */ |
131 |
dpavlin |
1.8 |
#ifdef EAPI |
132 |
|
|
,NULL, /* EAPI: add_module */ |
133 |
|
|
NULL, /* EAPI: remove_module */ |
134 |
|
|
NULL, /* EAPI: rewrite_command */ |
135 |
|
|
NULL /* EAPI: new_connection */ |
136 |
|
|
#endif |
137 |
dpavlin |
1.1 |
}; |
138 |
|
|
|