/[mod_czs]/mod_czs.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /mod_czs.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations)
Fri Aug 11 09:58:04 2000 UTC (23 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.9: +37 -1 lines
File MIME type: text/plain
support for upper and lower case URLs /CZS and /czs

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    
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 dpavlin 1.7 #ifdef DEBUG
54 dpavlin 1.1 if(r->args != 0 || do_czs) {
55     ap_table_setn(r->headers_out, "X-czs_filename", r->filename);
56 dpavlin 1.9 ap_table_setn(r->headers_out, "X-czs_content-type", r->content_type);
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 dpavlin 1.9 #ifdef TEST_QUERYSTRINGV
64     if(r->args == 0 && !do_czs || strstr(r->content_type,"cgi") != NULL) {
65 dpavlin 1.5 #else
66 dpavlin 1.9 if(!do_czs || strstr(r->content_type,"cgi") != NULL) {
67 dpavlin 1.5 #endif
68 dpavlin 1.9 return DECLINED;
69     /* ap_send_fd(in, r); */
70 dpavlin 1.1 } else {
71 dpavlin 1.9
72     ap_soft_timeout("send", r);
73     ap_send_http_header(r);
74    
75     if(r->header_only) {
76     ap_kill_timeout(r);
77     ap_pfclose(r->pool, in);
78     return OK;
79     }
80 dpavlin 1.5
81     while(fgets(buffer,MAX_STRING_LEN,in)) {
82     for(i=0; i<MAX_STRING_LEN && buffer[i]; i++) {
83     switch ( buffer[i] ) {
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     case '©': buffer[i]='S'; break;
90     case 'Ð': buffer[i]='D'; break;
91     case 'È': buffer[i]='C'; break;
92     case 'Æ': buffer[i]='C'; break;
93     case '®': buffer[i]='Z'; break;
94     }
95 dpavlin 1.1 }
96 dpavlin 1.5 ap_rprintf(r,"%s",buffer);
97 dpavlin 1.1 }
98     }
99    
100     ap_kill_timeout(r);
101     ap_pfclose(r->pool, in);
102     return OK;
103     }
104    
105 dpavlin 1.10 int translate_path(request_rec *r) {
106     char *uri = r->uri;
107     request_rec *subr;
108     char *type = NULL;
109     extern do_czs;
110    
111     do_czs=0;
112    
113     #ifdef DEBUG
114     ap_table_setn(r->headers_out, "X-translate", r->uri);
115     #endif
116     if (uri[0]=='/' && (uri[1] | 0x20) =='c' && (uri[2] | 0x20)=='z' && (uri[3] | 0x20) =='s') {
117     #if 0
118     ap_table_setn(r->headers_out, "Location", ap_pstrcat(r->pool, uri+2, "?czs", NULL));
119     return REDIRECT;
120     #endif
121     subr = (request_rec *) ap_sub_req_lookup_uri(r->uri+4, r);
122     r->filename=ap_pstrdup(r->pool, subr->filename);
123     type = subr->content_type;
124     #ifdef DEBUG
125     ap_table_setn(r->headers_out, "X-translate-content-type", type);
126     #endif
127     if (type == NULL) {
128     return DECLINED; /* hm? */
129     }
130     do_czs=1;
131     ap_destroy_sub_req(subr);
132     #ifdef XHEADER
133     # ifdef DEBUG
134     ap_table_setn(r->headers_out, "X-debug", XHEADER);
135     # endif
136     #endif
137     return OK;
138     }
139    
140     return DECLINED;
141     }
142 dpavlin 1.1 /* Dispatch list of content handlers */
143     static const handler_rec czs_handlers[] = {
144     { "czs", czs_handler },
145     { NULL, NULL }
146     };
147    
148     /* Dispatch list for API hooks */
149     module MODULE_VAR_EXPORT czs_module = {
150     STANDARD_MODULE_STUFF,
151     NULL, /* module initializer */
152     NULL, /* create per-dir config structures */
153     NULL, /* merge per-dir config structures */
154     NULL, /* create per-server config structures */
155     NULL, /* merge per-server config structures */
156     NULL, /* table of config file commands */
157     czs_handlers, /* [#8] MIME-typed-dispatched handlers */
158     translate_path, /* [#1] URI to filename translation */
159     NULL, /* [#4] validate user id from request */
160     NULL, /* [#5] check if the user is ok _here_ */
161     NULL, /* [#2] check access by host address */
162     NULL, /* [#6] determine MIME type */
163     NULL, /* [#7] pre-run fixups */
164     NULL, /* [#9] log a transaction */
165     NULL, /* [#3] header parser */
166     NULL, /* child_init */
167     NULL, /* child_exit */
168     NULL /* [#0] post read-request */
169 dpavlin 1.8 #ifdef EAPI
170     ,NULL, /* EAPI: add_module */
171     NULL, /* EAPI: remove_module */
172     NULL, /* EAPI: rewrite_command */
173     NULL /* EAPI: new_connection */
174     #endif
175 dpavlin 1.1 };
176    

  ViewVC Help
Powered by ViewVC 1.1.26