diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2000-05-16 03:11:09 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2000-05-16 03:11:09 +0000 |
commit | aedde2ecf6d61182baea454c0c9e4ae5ab81e7ca (patch) | |
tree | 0a079b1699efffe6d506f7954bae10a5c21c57a5 /encoding | |
parent | f5b6550754ec9c31c36ffd5934a8184ecc8a7a8a (diff) | |
download | libapr-util-aedde2ecf6d61182baea454c0c9e4ae5ab81e7ca.tar.gz |
APR-ize the CHARSET_EBCDIC support in ap_base64encode() and
ap_base64decode(). The app (e.g., Apache, ab) must call a function
to set up translation.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr-util/trunk@57800 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'encoding')
-rw-r--r-- | encoding/ap_base64.c | 34 | ||||
-rw-r--r-- | encoding/apr_base64.c | 34 |
2 files changed, 58 insertions, 10 deletions
diff --git a/encoding/ap_base64.c b/encoding/ap_base64.c index 545fdb35..63394669 100644 --- a/encoding/ap_base64.c +++ b/encoding/ap_base64.c @@ -65,7 +65,7 @@ #include "ap_config.h" #include "ap_base64.h" #ifdef CHARSET_EBCDIC -#include "ebcdic.h" +#include "apr_xlate.h" #endif /* CHARSET_EBCDIC */ /* aaaack but it's fast and const should make it shared text page. */ @@ -110,6 +110,29 @@ static const unsigned char pr2six[256] = #endif /*CHARSET_EBCDIC*/ }; +#ifdef CHARSET_EBCDIC +static ap_xlate_t *xlate_to_ebcdic; +static unsigned char os_toascii[256]; + +API_EXPORT(ap_status_t) ap_base64init_ebcdic(ap_xlate_t *to_ascii, + ap_xlate_t *to_ebcdic) +{ + int i; + ap_size_t inbytes_left, outbytes_left; + ap_status_t rv; + + xlate_to_ebcdic = to_ebcdic; + for (i = 0; i < sizeof(os_toascii); i++) { + os_toascii[i] = i; + } + inbytes_left = outbytes_left = sizeof(os_toascii); + ap_xlate_conv_buffer(to_ascii, os_toascii, &inbytes_left, + os_toascii, &outbytes_left); + + return APR_SUCCESS; +} +#endif /*CHARSET_EBCDIC*/ + API_EXPORT(int) ap_base64decode_len(const char *bufcoded) { int nbytesdecoded; @@ -128,20 +151,21 @@ API_EXPORT(int) ap_base64decode_len(const char *bufcoded) API_EXPORT(int) ap_base64decode(char *bufplain, const char *bufcoded) { #ifdef CHARSET_EBCDIC - int i; + ap_size_t inbytes_left, outbytes_left; #endif /* CHARSET_EBCDIC */ int len; len = ap_base64decode_binary((unsigned char *) bufplain, bufcoded); #ifdef CHARSET_EBCDIC - for (i = 0; i < len; i++) - bufplain[i] = os_toebcdic[bufplain[i]]; + inbytes_left = outbytes_left = len; + ap_xlate_conv_buffer(xlate_to_ebcdic, bufplain, &inbytes_left, + bufplain, &outbytes_left); #endif /* CHARSET_EBCDIC */ bufplain[len] = '\0'; return len; } -/* This is the same as ap_base64udecode() except on EBCDIC machines, where +/* This is the same as ap_base64decode() except on EBCDIC machines, where * the conversion of the output to ebcdic is left out. */ API_EXPORT(int) ap_base64decode_binary(unsigned char *bufplain, diff --git a/encoding/apr_base64.c b/encoding/apr_base64.c index 545fdb35..63394669 100644 --- a/encoding/apr_base64.c +++ b/encoding/apr_base64.c @@ -65,7 +65,7 @@ #include "ap_config.h" #include "ap_base64.h" #ifdef CHARSET_EBCDIC -#include "ebcdic.h" +#include "apr_xlate.h" #endif /* CHARSET_EBCDIC */ /* aaaack but it's fast and const should make it shared text page. */ @@ -110,6 +110,29 @@ static const unsigned char pr2six[256] = #endif /*CHARSET_EBCDIC*/ }; +#ifdef CHARSET_EBCDIC +static ap_xlate_t *xlate_to_ebcdic; +static unsigned char os_toascii[256]; + +API_EXPORT(ap_status_t) ap_base64init_ebcdic(ap_xlate_t *to_ascii, + ap_xlate_t *to_ebcdic) +{ + int i; + ap_size_t inbytes_left, outbytes_left; + ap_status_t rv; + + xlate_to_ebcdic = to_ebcdic; + for (i = 0; i < sizeof(os_toascii); i++) { + os_toascii[i] = i; + } + inbytes_left = outbytes_left = sizeof(os_toascii); + ap_xlate_conv_buffer(to_ascii, os_toascii, &inbytes_left, + os_toascii, &outbytes_left); + + return APR_SUCCESS; +} +#endif /*CHARSET_EBCDIC*/ + API_EXPORT(int) ap_base64decode_len(const char *bufcoded) { int nbytesdecoded; @@ -128,20 +151,21 @@ API_EXPORT(int) ap_base64decode_len(const char *bufcoded) API_EXPORT(int) ap_base64decode(char *bufplain, const char *bufcoded) { #ifdef CHARSET_EBCDIC - int i; + ap_size_t inbytes_left, outbytes_left; #endif /* CHARSET_EBCDIC */ int len; len = ap_base64decode_binary((unsigned char *) bufplain, bufcoded); #ifdef CHARSET_EBCDIC - for (i = 0; i < len; i++) - bufplain[i] = os_toebcdic[bufplain[i]]; + inbytes_left = outbytes_left = len; + ap_xlate_conv_buffer(xlate_to_ebcdic, bufplain, &inbytes_left, + bufplain, &outbytes_left); #endif /* CHARSET_EBCDIC */ bufplain[len] = '\0'; return len; } -/* This is the same as ap_base64udecode() except on EBCDIC machines, where +/* This is the same as ap_base64decode() except on EBCDIC machines, where * the conversion of the output to ebcdic is left out. */ API_EXPORT(int) ap_base64decode_binary(unsigned char *bufplain, |