/[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

Diff of /mod_czs.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by dpavlin, Fri Aug 11 09:58:04 2000 UTC revision 1.11 by dpavlin, Sat Aug 12 21:38:04 2000 UTC
# Line 1  Line 1 
1  /*  /*
2   * mod_czs -- nuke iso8859-2 characters   * mod_czs -- nuke iso8859-2 characters
3     * sets `Contnet-type: text/html; charset=foobar' based on user agent string
4     * from client browser
5     *
6   * Dobrica Pavlinusic <dpavlin@rot13.org>   * Dobrica Pavlinusic <dpavlin@rot13.org>
7     * Robert Avilov <ravilov@linux.hr> (some fixes of ua_charset part)
8   *   *
9   * based on mod_format by Stephen F. Booth and   * based on mod_format by Stephen F. Booth and
10   * mod_mocrify by Peter Triller, Ernst Bachmann   * mod_mocrify by Peter Triller, Ernst Bachmann
# Line 32  Line 36 
36  module MODULE_VAR_EXPORT mod_czs;  module MODULE_VAR_EXPORT mod_czs;
37    
38  FILE *in;  FILE *in;
 int do_czs;  
39    
40  static int czs_handler(request_rec *r) {  static int czs_handler(request_rec *r) {
41    
42          char buffer[MAX_STRING_LEN] = "undefined buffer content";          char buffer[MAX_STRING_LEN] = "undefined buffer content";
43          int i;          char *b;
44            char *rexp = "< *META *HTTP-EQUIV=\"(Content-Type)\" *CONTENT=\"(text/html[^\"]+)\" *>";
45            regex_t *regexp;
46            int nsub = 10;
47            regmatch_t regm[10];
48            int i,f_ch=MAX_STRING_LEN,l_ch=0;
49    
50          if(r->method_number != M_GET)          if(r->method_number != M_GET)
51                  return DECLINED;                  return DECLINED;
# Line 51  static int czs_handler(request_rec *r) { Line 59  static int czs_handler(request_rec *r) {
59                  return FORBIDDEN;                      return FORBIDDEN;    
60          }          }
61  #ifdef DEBUG  #ifdef DEBUG
62          if(r->args != 0 || do_czs) {          if(r->args != 0 || ap_table_get(r->notes,"do_czs")) {
63                  ap_table_setn(r->headers_out, "X-czs_filename", r->filename);                  ap_table_setn(r->headers_out, "X-czs_filename", r->filename);
64                  ap_table_setn(r->headers_out, "X-czs_content-type", r->content_type);                  ap_table_setn(r->headers_out, "X-czs_content-type", r->content_type);
65                  if (r->args != 0) {                  if (r->args != 0) {
# Line 61  static int czs_handler(request_rec *r) { Line 69  static int czs_handler(request_rec *r) {
69  #endif  #endif
70    
71  #ifdef TEST_QUERYSTRINGV  #ifdef TEST_QUERYSTRINGV
72          if(r->args == 0 && !do_czs || strstr(r->content_type,"cgi") != NULL) {          if(r->args == 0 && !ap_table_get(r->notes,"do_czs") ||
73                     strstr(r->content_type,"cgi") != NULL) {
74  #else  #else
75          if(!do_czs || strstr(r->content_type,"cgi") != NULL) {          if(!ap_table_get(r->notes,"do_czs") ||
76                    strstr(r->content_type,"cgi") != NULL) {
77  #endif  #endif
78                  return DECLINED;                  return DECLINED;
79  /*              ap_send_fd(in, r); */  /*              ap_send_fd(in, r); */
80          } else {          } else {
81    
82                    regexp = ap_pregcomp(r->pool, rexp, REG_EXTENDED | REG_ICASE );
83    
84                    if (regexp == NULL) {
85                            ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
86                                    "unable to compile pattern \"%s\"", rexp);
87                            return DECLINED;
88                    }
89    
90                  ap_soft_timeout("send", r);                  ap_soft_timeout("send", r);
91                  ap_send_http_header(r);                  ap_send_http_header(r);
92        
# Line 78  static int czs_handler(request_rec *r) { Line 96  static int czs_handler(request_rec *r) {
96                          return OK;                          return OK;
97                  }                  }
98    
99    
100                  while(fgets(buffer,MAX_STRING_LEN,in)) {                  while(fgets(buffer,MAX_STRING_LEN,in)) {
101                          for(i=0; i<MAX_STRING_LEN && buffer[i]; i++) {                          for(i=0; i<MAX_STRING_LEN && buffer[i]; i++) {
102                                  switch ( buffer[i] ) {                                  switch ( buffer[i] ) {
# Line 93  static int czs_handler(request_rec *r) { Line 112  static int czs_handler(request_rec *r) {
112                                  case '®': buffer[i]='Z'; break;                                  case '®': buffer[i]='Z'; break;
113                                  }                                  }
114                          }                          }
115                          ap_rprintf(r,"%s",buffer);  
116    
117                            if (ap_regexec(regexp, buffer, nsub, regm, 0) == 0) {
118    #if 0
119                                    ap_rprintf(r,"<!-- num replacements: %02x buffer:\n%s\n",nsub,buffer);
120                                    ap_rprintf(r,"\n-->\n",i,regm[i].rm_so,regm[i].rm_eo);
121    #endif
122                                    for (i=0; i<10; i++) {
123                                            if (regm[i].rm_so != -1) {
124                                                    if (regm[i].rm_so < f_ch)
125                                                            f_ch = regm[i].rm_so;
126                                                    if (regm[i].rm_eo > l_ch)
127                                                            l_ch = regm[i].rm_eo;
128                                            }
129    #if 0
130                                            ap_rprintf(r,"<!-- %02x: %02x-%02x -->\n",i,regm[i].rm_so,regm[i].rm_eo);
131    #endif
132                                    }
133                                    buffer[f_ch]=0;
134                                    ap_rprintf(r,"%s", ap_pstrcat(r->pool, buffer,"<!-- removed charset -->", buffer+l_ch, NULL));
135                            } else {
136                                    ap_rprintf(r,"%s",buffer);
137                            }
138                  }                  }
139    /*              ap_pregfree(r->pool, regexp); */
140          }          }
141    
142          ap_kill_timeout(r);          ap_kill_timeout(r);
# Line 106  int translate_path(request_rec *r) { Line 148  int translate_path(request_rec *r) {
148          char *uri = r->uri;          char *uri = r->uri;
149          request_rec *subr;          request_rec *subr;
150          char *type = NULL;          char *type = NULL;
         extern do_czs;  
   
         do_czs=0;  
151    
152  #ifdef DEBUG  #ifdef DEBUG
153          ap_table_setn(r->headers_out, "X-translate", r->uri);          ap_table_setn(r->headers_out, "X-translate", r->uri);
# Line 127  int translate_path(request_rec *r) { Line 166  int translate_path(request_rec *r) {
166                  if (type == NULL) {                  if (type == NULL) {
167                          return DECLINED; /* hm? */                          return DECLINED; /* hm? */
168                  }                  }
169                  do_czs=1;                  ap_table_setn(r->notes,"do_czs",1);
170                  ap_destroy_sub_req(subr);                  ap_destroy_sub_req(subr);
 #ifdef XHEADER  
 # ifdef DEBUG  
                 ap_table_setn(r->headers_out, "X-debug", XHEADER);  
 # endif  
 #endif  
171                  return OK;                  return OK;
172          }          }
173    
174          return DECLINED;          return DECLINED;
175  }  }
176    
177    static int add_charset_header(request_rec * r)
178    {
179            const char *ua, *ct;
180    
181            ua = ap_table_get(r->headers_in, "User-Agent");
182            if (ua == NULL)
183                    ua = "<unknown>";
184    
185            ct = r->content_type;
186    
187            if (ct != NULL && !ap_table_get(r->notes,"do_czs")) {
188    
189                    if (strstr(ct, "text/html") == NULL)
190                            return DECLINED; /* Don't mess with other types */
191    
192                    if (strstr(ua, "Mac") != NULL) {
193                            if (strstr(ua, "MSIE") != NULL)
194                                    r->content_type = "text/html; charset=x-mac-roman";
195                            else
196                                    r->content_type = "text/html; charset=MacCE";
197                    } else
198                            r->content_type = "text/html; charset=iso-8859-2";
199            }
200    
201    #ifdef DEBUG
202            ap_table_setn(r->headers_out, "X-Content-Type", ct);
203            ap_table_setn(r->headers_out, "X-new-Content-Type", r->content_type);
204            ap_table_setn(r->headers_out, "X-User-Agent", ua);
205    #endif
206            return DECLINED;
207    }
208    
209    
210  /* Dispatch list of content handlers */  /* Dispatch list of content handlers */
211  static const handler_rec czs_handlers[] = {  static const handler_rec czs_handlers[] = {
212    { "czs", czs_handler },    { "czs", czs_handler },
# Line 160  module MODULE_VAR_EXPORT czs_module = { Line 228  module MODULE_VAR_EXPORT czs_module = {
228      NULL,               /* [#5] check if the user is ok _here_ */      NULL,               /* [#5] check if the user is ok _here_ */
229      NULL,               /* [#2] check access by host address   */      NULL,               /* [#2] check access by host address   */
230      NULL,               /* [#6] determine MIME type            */      NULL,               /* [#6] determine MIME type            */
231      NULL,               /* [#7] pre-run fixups                 */      add_charset_header, /* [#7] pre-run fixups                 */
232      NULL,               /* [#9] log a transaction              */      NULL,               /* [#9] log a transaction              */
233      NULL,               /* [#3] header parser                  */      NULL,               /* [#3] header parser                  */
234      NULL,               /* child_init                          */      NULL,               /* child_init                          */

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.26