summaryrefslogtreecommitdiff
path: root/xlate
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2003-01-10 15:17:43 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2003-01-10 15:17:43 +0000
commit7d4d88c5aa75a507c49cdcc0da3161faf0010a7f (patch)
treed614936ceb35ea345647a73b425772be7d7b94f3 /xlate
parent0806ffa770cea7d08b5784451d0fa9ff814c5a9d (diff)
downloadlibapr-util-7d4d88c5aa75a507c49cdcc0da3161faf0010a7f.tar.gz
Some problematic code since Mr. Stoddard recognized we weren't setting
or testing the correct #defines. git-svn-id: http://svn.apache.org/repos/asf/apr/apr-util/trunk@58823 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'xlate')
-rw-r--r--xlate/xlate.c54
1 files changed, 46 insertions, 8 deletions
diff --git a/xlate/xlate.c b/xlate/xlate.c
index 68b005e8..ae52ff1c 100644
--- a/xlate/xlate.c
+++ b/xlate/xlate.c
@@ -96,8 +96,10 @@ struct apr_xlate_t {
char *frompage;
char *topage;
char *sbcs_table;
-#if APU_HAVE_APR_ICONV || APU_HAVE_ICONV
+#if APU_HAVE_ICONV
iconv_t ich;
+#else APU_HAVE_APR_ICONV
+ apr_iconv_t ich;
#endif
};
@@ -121,7 +123,7 @@ static apr_status_t apr_xlate_cleanup(void *convset)
#if APU_HAVE_APR_ICONV
if (old->ich != (apr_iconv_t)-1) {
- return apr_iconv_close(old->ich);
+ return apr_iconv_close(old->ich, old->pool);
}
#elif APU_HAVE_ICONV
@@ -171,7 +173,43 @@ static void check_sbcs(apr_xlate_t *convset)
/* TODO: add the table to the cache */
}
}
-#endif /* APU_HAVE_ICONV */
+#elif defined(APU_HAVE_APR_ICONV)
+static void check_sbcs(apr_xlate_t *convset)
+{
+ char inbuf[256], outbuf[256];
+ char *inbufptr = inbuf;
+ char *outbufptr = outbuf;
+ apr_size_t inbytes_left, outbytes_left;
+ int i;
+ apr_size_t translated;
+ apr_status_t rv;
+
+ for (i = 0; i < sizeof(inbuf); i++) {
+ inbuf[i] = i;
+ }
+
+ inbytes_left = outbytes_left = sizeof(inbuf);
+ rv = apr_iconv(convset->ich, (ICONV_INBUF_TYPE)&inbufptr,
+ &inbytes_left, &outbufptr, &outbytes_left,
+ &translated);
+
+ if ((rv == APR_SUCCESS)
+ && (translated != (apr_size_t)-1)
+ && inbytes_left == 0
+ && outbytes_left == 0) {
+ /* hurray... this is simple translation; save the table,
+ * close the iconv descriptor
+ */
+
+ convset->sbcs_table = apr_palloc(convset->pool, sizeof(outbuf));
+ memcpy(convset->sbcs_table, outbuf, sizeof(outbuf));
+ apr_iconv_close(convset->ich, convset->pool);
+ convset->ich = (apr_iconv_t)-1;
+
+ /* TODO: add the table to the cache */
+ }
+}
+#endif /* APU_HAVE_APR_ICONV */
static void make_identity_table(apr_xlate_t *convset)
{
@@ -187,7 +225,7 @@ APU_DECLARE(apr_status_t) apr_xlate_open(apr_xlate_t **convset,
const char *frompage,
apr_pool_t *pool)
{
- apr_status_t status;
+ apr_status_t rv;
apr_xlate_t *new;
int found = 0;
@@ -251,14 +289,14 @@ APU_DECLARE(apr_status_t) apr_xlate_open(apr_xlate_t **convset,
*convset = new;
apr_pool_cleanup_register(pool, (void *)new, apr_xlate_cleanup,
apr_pool_cleanup_null);
- status = APR_SUCCESS;
+ rv = APR_SUCCESS;
}
else {
- status = APR_EINVAL; /* iconv() would return EINVAL if it
+ rv = APR_EINVAL; /* iconv() would return EINVAL if it
couldn't handle the pair */
}
- return status;
+ return rv;
}
APU_DECLARE(apr_status_t) apr_xlate_sb_get(apr_xlate_t *convset, int *onoff)
@@ -276,7 +314,7 @@ APU_DECLARE(apr_status_t) apr_xlate_conv_buffer(apr_xlate_t *convset,
apr_status_t status = APR_SUCCESS;
#if APU_HAVE_APR_ICONV
- if (convset->ich != (iconv_t)-1) {
+ if (convset->ich != (apr_iconv_t)-1) {
const char *inbufptr = inbuf;
apr_size_t translated;
char *outbufptr = outbuf;