Return-Path: Delivered-To: apmail-new-httpd-archive@apache.org Received: (qmail 95807 invoked by uid 500); 23 May 2000 11:46:34 -0000 Mailing-List: contact new-httpd-help@apache.org; run by ezmlm Precedence: bulk X-No-Archive: yes Reply-To: new-httpd@apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list new-httpd@apache.org Received: (qmail 95796 invoked from network); 23 May 2000 11:46:33 -0000 Date: Tue, 23 May 2000 07:46:58 -0400 Message-Id: <200005231146.HAA28453@k5.localdomain> X-Authentication-Warning: k5.localdomain: trawick set sender to trawickj@bellsouth.net using -f From: Jeff Trawick To: new-httpd@apache.org Subject: [PATCH] ap_xlateattr_t for passing options to ap_xlate_open() Reply-to: trawickj@bellsouth.net X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This arose out of: 1) discussion a few weekends ago with Dw about information that ap_xlate_open() could use in the future, such as the language 2) fear that not adding the extra parm to ap_xlate_open() Real Soon Now would make it harder to add in the future 3) immediate desire to do some single-byte-only checking, before and after ap_xlate_open() new structure: ap_xlateattr_t, to contain attributes related to the creation of ap_xlate_t new functions for manipulating ap_xlateattr_t: ap_xlate_create_xlateattr() - create an empty (default) xlateattr ap_xlate_set_xlateattr_sb() - manipulate the single-byte-only attribute (whereby the application can state whether or not it requires single-byte conversions) new function for retrieving a certain attribute after creation of ap_xlate_t: ap_xlate_get_sb() - retrieve the value of the single-byte-only attribute Looking at the names of existing functions in APR... . for consistency with procattr and threadattr functions, it would seem that the _xlate_ part of the name should be dropped (but the pattern ap_xlate_XXX() seems nice to maintain) . "create" and "set" are not treated similarly with the procattr and threadattr functions; with create, there is always _ after create, but with set there is never _ after set Index: src/lib/apr/include/apr_xlate.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_xlate.h,v retrieving revision 1.2 diff -u -r1.2 apr_xlate.h --- src/lib/apr/include/apr_xlate.h 2000/05/10 19:45:31 1.2 +++ src/lib/apr/include/apr_xlate.h 2000/05/23 02:41:19 @@ -74,13 +74,20 @@ #if ! APR_HAS_XLATE typedef void ap_xlate_t; +typedef void ap_xlateattr_t; /* For platforms where we don't bother with translating between charsets, * these are macros which always return failure. */ -#define ap_xlate_open(convset, topage, frompage, pool) APR_ENOTIMPL +#define ap_xlate_open(convset, xattr, topage, frompage, pool) APR_ENOTIMPL +#define ap_xlate_create_xlateattr(newxattr, pool) APR_ENOTIMPL + +#define ap_xlate_set_xlateattr_sb(xattr, onoff) APR_ENOTIMPL + +#define ap_xlate_get_sb(convset, onoff) APR_ENOTIMPL + #define ap_xlate_conv_buffer(convset, inbuf, inbytes_left, outbuf, \ outbytes_left) APR_ENOTIMPL @@ -97,17 +104,20 @@ #else /* ! APR_HAS_XLATE */ typedef struct ap_xlate_t ap_xlate_t; +typedef struct ap_xlateattr_t ap_xlateattr_t; /* -=head1 ap_status_t ap_xlate_open(ap_xlate_t **convset, const char *topage, const char *frompage, ap_pool_t *pool) +=head1 ap_status_t ap_xlate_open(ap_xlate_t **convset, ap_xlateattr_t *xattr, const char *topage, const char *frompage, ap_pool_t *pool) B arg 1) The handle to be filled in by this function - arg 2) The name of the target charset - arg 3) The name of the source charset - arg 4) The pool to use + arg 2) The xlateattr to use to determine characteristics of the conversion, + or NULL if defaults are to be used + arg 3) The name of the target charset + arg 4) The name of the source charset + arg 5) The pool to use B: Specify APR_DEFAULT_CHARSET for one of the charset names to indicate the charset of the source code at @@ -120,10 +130,58 @@ =cut */ -ap_status_t ap_xlate_open(ap_xlate_t **convset, const char *topage, - const char *frompage, ap_pool_t *pool); +ap_status_t ap_xlate_open(ap_xlate_t **convset, ap_xlateattr_t *xattr, + const char *topage, const char *frompage, + ap_pool_t *pool); #define APR_DEFAULT_CHARSET NULL + +/* + +=head1 ap_status_t ap_xlate_create_xlateattr(ap_xlateattr_t **newxattr, ap_pool_t *pool) + +B + + arg 1) The newly created xlateattr + arg 2) The pool to use + +=cut + */ +ap_status_t ap_xlate_create_xlateattr(ap_xlateattr_t **newxattr, ap_pool_t *pool); + +/* + +=head1 ap_status_t ap_xlate_set_xlateattr_sb(ap_xlateattr_t *xattr, int onoff) + +B + + arg 1) The xlateattr to affect + arg 2) Single-byte-only flag + +B: When the single-byte-only flag is set, ap_xlate_open() will + fail if the specified conversion is not single-byte. + Applications which can only handle single-byte conversions + (i.e., bytes on output always the same as bytes on input) + should set this attribute. + +=cut + */ +ap_status_t ap_xlate_set_xlateattr_sb(ap_xlateattr_t *xattr, int onoff); + +/* + +=head1 ap_status_t ap_xlate_get_sb(ap_xlate_t *convset, int *onoff) + +B + + arg 1) The handle allocated by ap_xlate_open, specifying the parameters + of conversion + arg 2) Output: whether or not the conversion is single-byte-only + +=cut + */ + +ap_status_t ap_xlate_get_sb(ap_xlate_t *convset, int *onoff); /* Index: src/lib/apr/i18n/unix/xlate.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/i18n/unix/xlate.c,v retrieving revision 1.4 diff -u -r1.4 xlate.c --- src/lib/apr/i18n/unix/xlate.c 2000/05/23 01:58:46 1.4 +++ src/lib/apr/i18n/unix/xlate.c 2000/05/23 02:41:19 @@ -81,6 +81,10 @@ #endif }; +struct ap_xlateattr_t { + int sb_only; /* caller can only handle single-byte conversion */ +}; + /* get_default_codepage() * * simple heuristic to determine codepage of source code so that @@ -168,8 +172,9 @@ } #endif /* HAVE_ICONV */ -ap_status_t ap_xlate_open(ap_xlate_t **convset, const char *topage, - const char *frompage, ap_pool_t *pool) +ap_status_t ap_xlate_open(ap_xlate_t **convset, ap_xlateattr_t *xattr, + const char *topage, const char *frompage, + ap_pool_t *pool) { ap_status_t status; ap_xlate_t *new; @@ -217,6 +222,13 @@ #endif /* HAVE_ICONV */ if (found) { + /* Make sure any desired conversion characteristics are met. + */ + if (xattr) { + if (xattr->sb_only && !new->sbcs_table) { + return EINVAL; + } + } *convset = new; ap_register_cleanup(pool, (void *)new, ap_xlate_cleanup, ap_null_cleanup); @@ -228,6 +240,28 @@ } return status; +} + +ap_status_t ap_xlate_create_xlateattr(ap_xlateattr_t **new, ap_pool_t *pool) +{ + *new = ap_pcalloc(pool, sizeof(ap_xlateattr_t)); + if (!*new) { + return APR_ENOMEM; + } + + return APR_SUCCESS; +} + +ap_status_t ap_xlate_set_xlateattr_sb(ap_xlateattr_t *xattr, int onoff) +{ + xattr->sb_only = onoff; + return APR_SUCCESS; +} + +ap_status_t ap_xlate_get_sb(ap_xlate_t *convset, int *onoff) +{ + *onoff = convset->sbcs_table != NULL; + return APR_SUCCESS; } ap_status_t ap_xlate_conv_buffer(ap_xlate_t *convset, const char *inbuf, Index: src/lib/apr/test/testmd5.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/test/testmd5.c,v retrieving revision 1.1 diff -u -r1.1 testmd5.c --- src/lib/apr/test/testmd5.c 2000/05/06 13:41:58 1.1 +++ src/lib/apr/test/testmd5.c 2000/05/23 02:41:21 @@ -156,7 +156,7 @@ if (src) { #if APR_HAS_XLATE - rv = ap_xlate_open(&xlate, dst, src, pool); + rv = ap_xlate_open(&xlate, NULL, dst, src, pool); if (rv) { char buf[80]; Index: src/main/util_ebcdic.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/util_ebcdic.c,v retrieving revision 1.6 diff -u -r1.6 util_ebcdic.c --- src/main/util_ebcdic.c 2000/05/18 19:54:44 1.6 +++ src/main/util_ebcdic.c 2000/05/23 02:41:23 @@ -110,14 +110,16 @@ ap_status_t rv; char buf[80]; - rv = ap_xlate_open(&ap_hdrs_to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, pool); + rv = ap_xlate_open(&ap_hdrs_to_ascii, NULL, + "ISO8859-1", APR_DEFAULT_CHARSET, pool); if (rv) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "ap_xlate_open() failed"); return rv; } - rv = ap_xlate_open(&ap_hdrs_from_ascii, APR_DEFAULT_CHARSET, "ISO8859-1", pool); + rv = ap_xlate_open(&ap_hdrs_from_ascii, NULL, + APR_DEFAULT_CHARSET, "ISO8859-1", pool); if (rv) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "ap_xlate_open() failed"); Index: src/support/ab.c =================================================================== RCS file: /home/cvs/apache-2.0/src/support/ab.c,v retrieving revision 1.16 diff -u -r1.16 ab.c --- src/support/ab.c 2000/05/19 22:39:40 1.16 +++ src/support/ab.c 2000/05/23 02:41:26 @@ -967,12 +967,14 @@ ap_create_pool(&cntxt, NULL); #ifdef NOT_ASCII - status = ap_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt); + status = ap_xlate_open(&to_ascii, NULL, + "ISO8859-1", APR_DEFAULT_CHARSET, cntxt); if (status) { fprintf(stderr, "ap_xlate_open(to ASCII)->%d\n", status); exit(1); } - status = ap_xlate_open(&from_ascii, APR_DEFAULT_CHARSET, "ISO8859-1", cntxt); + status = ap_xlate_open(&from_ascii, NULL, + APR_DEFAULT_CHARSET, "ISO8859-1", cntxt); if (status) { fprintf(stderr, "ap_xlate_open(from ASCII)->%d\n", status); exit(1); Index: src/support/htdigest.c =================================================================== RCS file: /home/cvs/apache-2.0/src/support/htdigest.c,v retrieving revision 1.9 diff -u -r1.9 htdigest.c --- src/support/htdigest.c 2000/05/06 13:41:59 1.9 +++ src/support/htdigest.c 2000/05/23 02:41:26 @@ -235,7 +235,8 @@ ap_create_pool(&cntxt, NULL); #ifdef CHARSET_EBCDIC - rv = ap_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, cntxt); + rv = ap_xlate_open(&to_ascii, NULL, + "ISO8859-1", APR_DEFAULT_CHARSET, cntxt); if (rv) { fprintf(stderr, "ap_xlate_open(): %s (%d)\n", ap_strerror(rv, line, sizeof(line)), rv); Index: src/support/htpasswd.c =================================================================== RCS file: /home/cvs/apache-2.0/src/support/htpasswd.c,v retrieving revision 1.14 diff -u -r1.14 htpasswd.c --- src/support/htpasswd.c 2000/05/16 19:48:08 1.14 +++ src/support/htpasswd.c 2000/05/23 02:41:27 @@ -386,7 +386,8 @@ atexit(ap_terminate); ap_create_pool(&pool, NULL); - rv = ap_xlate_open(&to_ascii, "ISO8859-1", APR_DEFAULT_CHARSET, pool); + rv = ap_xlate_open(&to_ascii, NULL, + "ISO8859-1", APR_DEFAULT_CHARSET, pool); if (rv) { fprintf(stderr, "ap_xlate_open(to ASCII)->%d\n", rv); exit(1); -- Jeff Trawick | trawick@ibm.net | PGP public key at web site: http://www.geocities.com/SiliconValley/Park/9289/ Born in Roswell... married an alien...