--- mod_czs.c 2000/08/13 18:30:24 1.12 +++ mod_czs.c 2000/08/13 20:11:51 1.13 @@ -40,7 +40,7 @@ static int czs_handler(request_rec *r) { char buffer[MAX_STRING_LEN] = "undefined buffer content"; - char *b; + char *b,*do_czs,*do_mac; char *rexp = "< *META *HTTP-EQUIV=\"(Content-Type)\" *CONTENT=\"(text/html[^\"]+)\" *>"; regex_t *regexp; int nsub = 10; @@ -52,6 +52,9 @@ if(r->finfo.st_mode == 0) return NOT_FOUND; + do_czs = (char *)ap_table_get(r->notes,"do_czs"); + do_mac = (char *)ap_table_get(r->notes,"do_mac"); + in = ap_pfopen(r->pool, r->filename, "r"); if(in == NULL) { @@ -59,21 +62,19 @@ return FORBIDDEN; } #ifdef DEBUG - if(r->args != 0 || ap_table_get(r->notes,"do_czs")) { - ap_table_setn(r->headers_out, "X-czs_filename", r->filename); - ap_table_setn(r->headers_out, "X-czs_content-type", r->content_type); - if (r->args != 0) { - ap_table_setn(r->headers_out, "X-czs_args", r->args); - } + ap_table_setn(r->headers_out, "X-czs_filename", r->filename); + if (r->args != 0) { + ap_table_setn(r->headers_out, "X-czs_args", r->args); } + ap_table_setn(r->headers_out, "X-do_czs", do_czs); + ap_table_setn(r->headers_out, "X-do_mac", do_mac); + ap_table_setn(r->headers_out, "X-content-type", r->content_type); #endif #ifdef TEST_QUERYSTRINGV - if(r->args == 0 && !ap_table_get(r->notes,"do_czs") || - ap_strcasestr(r->content_type,"cgi") != NULL) { + if (r->args == 0 && do_czs == NULL && do_mac == NULL || ap_strcasestr(r->content_type,"cgi") != NULL) { #else - if(!ap_table_get(r->notes,"do_czs") || - ap_strcasestr(r->content_type,"cgi") != NULL) { + if (do_czs == NULL && do_mac == NULL || ap_strcasestr(r->content_type,"cgi") != NULL) { #endif return DECLINED; /* ap_send_fd(in, r); */ @@ -98,18 +99,20 @@ while(fgets(buffer,MAX_STRING_LEN,in)) { - for(i=0; iuri; request_rec *subr; - char *type = NULL; + char *ct; + char *ua; #ifdef DEBUG - ap_table_setn(r->headers_out, "X-translate", r->uri); + ap_table_setn(r->headers_out, "X-translate-uri", r->uri); #endif - if (uri[0]=='/' && (uri[1] | 0x20) =='c' && (uri[2] | 0x20)=='z' && (uri[3] | 0x20) =='s') { -#if 0 - ap_table_setn(r->headers_out, "Location", ap_pstrcat(r->pool, uri+2, "?czs", NULL)); - return REDIRECT; + + if (uri[0]=='/' && (uri[1] | 0x20) =='c' && (uri[2] | 0x20)=='z' && (uri[3] | 0x20) =='s' && uri[4]=='/') { + subr = (request_rec *) ap_sub_req_lookup_uri(r->uri+4, r); + r->filename=ap_pstrdup(r->pool, subr->filename); + ct = (char *)subr->content_type; + if (ct == NULL) return DECLINED; /* hm? */ +#ifdef DEBUG + ap_table_setn(r->headers_out, "X-translate-sub-ct", ct); #endif + ap_table_setn(r->notes,"do_czs",ap_pstrdup(r->pool,"1")); + ap_destroy_sub_req(subr); + return OK; + } + + ua = (char *)ap_table_get(r->headers_in, "User-Agent"); + if (ua == NULL) ua = "unknown"; + +#ifdef DEBUG + ap_table_setn(r->headers_out, "X-translate-UA", ua); +#endif + + if (uri[0]=='/' && (uri[1] | 0x20) =='m' && (uri[2] | 0x20)=='a' && (uri[3] | 0x20) =='c' && uri[4]=='/') { subr = (request_rec *) ap_sub_req_lookup_uri(r->uri+4, r); r->filename=ap_pstrdup(r->pool, subr->filename); - type = subr->content_type; + ct = (char *)subr->content_type; + if (ct == NULL) return DECLINED; /* hm? */ #ifdef DEBUG - ap_table_setn(r->headers_out, "X-translate-content-type", type); + ap_table_setn(r->headers_out, "X-translate-sub-ct", ct); #endif - if (type == NULL) { - return DECLINED; /* hm? */ + /* will store User-Agent in do_mac as true value */ + if (ap_strcasestr(ua, "Mac")) + ap_table_setn(r->notes,"do_mac",ua); + else { + ap_table_setn(r->headers_out, "Location", r->uri+4); + return REDIRECT; } - ap_table_setn(r->notes,"do_czs",1); ap_destroy_sub_req(subr); return OK; } +#if 0 + if (ap_strcasestr(ua, "Mac")) { + ap_table_setn(r->headers_out, "Location", ap_pstrcat(r->pool, "/mac/", r->uri, NULL)); + return REDIRECT; + } +#endif + return DECLINED; } static int add_charset_header(request_rec * r) { - const char *ua, *ct; - - ua = ap_table_get(r->headers_in, "User-Agent"); - if (ua == NULL) - ua = ""; + char *ua, *ct; - ct = r->content_type; + ua = (char *)ap_table_get(r->notes, "do_mac"); + ct = (char *)r->content_type; if (ct != NULL && !ap_table_get(r->notes,"do_czs")) { - if (strstr(ct, "text/html") == NULL) + if (ap_strcasestr(ct, "text") == NULL) return DECLINED; /* Don't mess with other types */ - if (strstr(ua, "Mac") != NULL) { - if (strstr(ua, "MSIE") != NULL) - r->content_type = "text/html; charset=x-mac-roman"; + if (ua) { /* do_mac */ + if (ap_strcasestr(ua, "MSIE") != NULL) + r->content_type = ap_pstrcat(r->pool, ct,"; charset=x-mac-roman", NULL); else - r->content_type = "text/html; charset=MacCE"; + r->content_type = ap_pstrcat(r->pool, ct,"; charset=MacCE", NULL); } else - r->content_type = "text/html; charset=iso-8859-2"; + r->content_type = ap_pstrcat(r->pool, ct,"; charset=iso-8859-2", NULL); } #ifdef DEBUG