apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject cvs commit: apr-util/xlate xlate.c
Date Sun, 06 Jun 2004 10:07:07 GMT
jorton      2004/06/06 03:07:07

  Modified:    xlate    xlate.c
  Log:
  * xlate/xlate.c (check_sbcs): Reinstate function with fix to reset
  iconv handle per 0.9 branch pending any progress on API issues.
  
  Revision  Changes    Path
  1.21      +85 -0     apr-util/xlate/xlate.c
  
  Index: xlate.c
  ===================================================================
  RCS file: /home/cvs/apr-util/xlate/xlate.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -d -w -u -r1.20 -r1.21
  --- xlate.c	30 Mar 2004 09:58:22 -0000	1.20
  +++ xlate.c	6 Jun 2004 10:07:07 -0000	1.21
  @@ -101,6 +101,89 @@
       return APR_SUCCESS;
   }
   
  +#if APU_HAVE_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;
  +
  +    for (i = 0; i < sizeof(inbuf); i++) {
  +        inbuf[i] = i;
  +    }
  +
  +    inbytes_left = outbytes_left = sizeof(inbuf);
  +    translated = iconv(convset->ich, (ICONV_INBUF_TYPE)&inbufptr,
  +                       &inbytes_left, &outbufptr, &outbytes_left);
  +
  +    if (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));
  +        iconv_close(convset->ich);
  +        convset->ich = (iconv_t)-1;
  +
  +        /* TODO: add the table to the cache */
  +    }
  +    else {
  +        /* reset the iconv descriptor, since it's now in an undefined
  +         * state. */
  +        iconv_close(convset->ich);
  +        convset->ich = iconv_open(convset->topage, convset->frompage);
  +    }
  +}
  +#elif 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 */
  +    }
  +    else {
  +        /* reset the iconv descriptor, since it's now in an undefined
  +         * state. */
  +        apr_iconv_close(convset->ich);
  +        convset->ich = apr_iconv_open(convset->topage, convset->frompage);
  +    }
  +}
  +#endif /* APU_HAVE_APR_ICONV */
  +
   static void make_identity_table(apr_xlate_t *convset)
   {
     int i;
  @@ -157,6 +240,7 @@
               return rv;
           }
           found = 1;
  +        check_sbcs(new);
       } else
           new->ich = (apr_iconv_t)-1;
   
  @@ -169,6 +253,7 @@
               return rv ? rv : APR_EINVAL;
           }
           found = 1;
  +        check_sbcs(new);
       } else
           new->ich = (iconv_t)-1;
   #endif /* APU_HAVE_ICONV */
  
  
  

Mime
View raw message