upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / 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 apr_status_t ap_init_ebcdic(apr_pool_t *pool)
28 {
29     apr_status_t rv;
30     char buf[80];
31
32     rv = apr_xlate_open(&ap_hdrs_to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, pool);
33     if (rv) {
34         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
35                      "apr_xlate_open() failed");
36         return rv;
37     }
38
39     rv = apr_xlate_open(&ap_hdrs_from_ascii, APR_DEFAULT_CHARSET, "ISO8859-1", pool);
40     if (rv) {
41         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
42                      "apr_xlate_open() failed");
43         return rv;
44     }
45
46     rv = apr_xlate_open(&ap_locale_to_ascii, "ISO8859-1", APR_LOCALE_CHARSET, pool);
47     if (rv) {
48         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
49                      "apr_xlate_open() failed");
50         return rv;
51     }
52
53     rv = apr_xlate_open(&ap_locale_from_ascii, APR_LOCALE_CHARSET, "ISO8859-1", pool);
54     if (rv) {
55         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
56                      "apr_xlate_open() failed");
57         return rv;
58     }
59
60     rv = apr_MD5InitEBCDIC(ap_hdrs_to_ascii);
61     if (rv) {
62         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
63                      "apr_MD5InitEBCDIC() failed");
64         return rv;
65     }
66     
67     rv = apr_base64init_ebcdic(ap_hdrs_to_ascii, ap_hdrs_from_ascii);
68     if (rv) {
69         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
70                      "apr_base64init_ebcdic() failed");
71         return rv;
72     }
73     
74     rv = apr_SHA1InitEBCDIC(ap_hdrs_to_ascii);
75     if (rv) {
76         ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
77                      "apr_SHA1InitEBCDIC() failed");
78         return rv;
79     }
80     
81     return APR_SUCCESS;
82 }
83
84 void ap_xlate_proto_to_ascii(char *buffer, apr_size_t len)
85 {
86     apr_size_t inbytes_left, outbytes_left;
87
88     inbytes_left = outbytes_left = len;
89     apr_xlate_conv_buffer(ap_hdrs_to_ascii, buffer, &inbytes_left,
90                           buffer, &outbytes_left);
91 }
92
93 void ap_xlate_proto_from_ascii(char *buffer, apr_size_t len)
94 {
95     apr_size_t inbytes_left, outbytes_left;
96
97     inbytes_left = outbytes_left = len;
98     apr_xlate_conv_buffer(ap_hdrs_from_ascii, buffer, &inbytes_left,
99                           buffer, &outbytes_left);
100 }
101
102 int ap_rvputs_proto_in_ascii(request_rec *r, ...)
103 {
104     va_list va;
105     const char *s;
106     char *ascii_s;
107     apr_size_t len;
108     apr_size_t written = 0;
109
110     va_start(va, r);
111     while (1) {
112         s = va_arg(va, const char *);
113         if (s == NULL)
114             break;
115         len = strlen(s);
116         ascii_s = apr_pstrndup(r->pool, s, len);
117         ap_xlate_proto_to_ascii(ascii_s, len);
118         if (ap_rputs(ascii_s, r) < 0)
119             return -1;
120         written += len;
121     }
122     va_end(va);
123  
124     return written;
125 }    
126 #endif /* APR_CHARSET_EBCDIC */