]> granicus.if.org Git - apache/blob - server/util_ebcdic.c
Add an END flag to RewriteRule that acts like L=LAST but also prevents
[apache] / server / util_ebcdic.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "ap_config.h"
18
19 #if APR_CHARSET_EBCDIC
20
21 #include "apr_strings.h"
22 #include "httpd.h"
23 #include "http_log.h"
24 #include "http_core.h"
25 #include "util_ebcdic.h"
26
27 APLOG_USE_MODULE(core);
28
29 apr_status_t ap_init_ebcdic(apr_pool_t *pool)
30 {
31     apr_status_t rv;
32
33     rv = apr_xlate_open(&ap_hdrs_to_ascii, "ISO-8859-1", APR_DEFAULT_CHARSET, pool);
34     if (rv) {
35         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
36                      "apr_xlate_open() failed");
37         return rv;
38     }
39
40     rv = apr_xlate_open(&ap_hdrs_from_ascii, APR_DEFAULT_CHARSET, "ISO-8859-1", pool);
41     if (rv) {
42         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
43                      "apr_xlate_open() failed");
44         return rv;
45     }
46
47     rv = apr_MD5InitEBCDIC(ap_hdrs_to_ascii);
48     if (rv) {
49         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
50                      "apr_MD5InitEBCDIC() failed");
51         return rv;
52     }
53
54     rv = apr_base64init_ebcdic(ap_hdrs_to_ascii, ap_hdrs_from_ascii);
55     if (rv) {
56         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
57                      "apr_base64init_ebcdic() failed");
58         return rv;
59     }
60
61     rv = apr_SHA1InitEBCDIC(ap_hdrs_to_ascii);
62     if (rv) {
63         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
64                      "apr_SHA1InitEBCDIC() failed");
65         return rv;
66     }
67
68     return APR_SUCCESS;
69 }
70
71 void ap_xlate_proto_to_ascii(char *buffer, apr_size_t len)
72 {
73     apr_size_t inbytes_left, outbytes_left;
74
75     inbytes_left = outbytes_left = len;
76     apr_xlate_conv_buffer(ap_hdrs_to_ascii, buffer, &inbytes_left,
77                           buffer, &outbytes_left);
78 }
79
80 void ap_xlate_proto_from_ascii(char *buffer, apr_size_t len)
81 {
82     apr_size_t inbytes_left, outbytes_left;
83
84     inbytes_left = outbytes_left = len;
85     apr_xlate_conv_buffer(ap_hdrs_from_ascii, buffer, &inbytes_left,
86                           buffer, &outbytes_left);
87 }
88
89 int ap_rvputs_proto_in_ascii(request_rec *r, ...)
90 {
91     va_list va;
92     const char *s;
93     char *ascii_s;
94     apr_size_t len;
95     apr_size_t written = 0;
96
97     va_start(va, r);
98     while (1) {
99         s = va_arg(va, const char *);
100         if (s == NULL)
101             break;
102         len = strlen(s);
103         ascii_s = apr_pstrndup(r->pool, s, len);
104         ap_xlate_proto_to_ascii(ascii_s, len);
105         if (ap_rputs(ascii_s, r) < 0)
106             return -1;
107         written += len;
108     }
109     va_end(va);
110
111     return written;
112 }
113 #endif /* APR_CHARSET_EBCDIC */