You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jeff Trawick <tr...@bellsouth.net> on 2000/04/27 17:24:31 UTC
BUFF, CHARSET_EBCDIC, charset translation requirements in general
You may wish to page down a few times to get to "proposed 2.0 changes
to BUFF". To me they seem pretty straightforward and uncontroversial,
but I've been wrong before :)
---------------------------------------------------------------------
Background info on 1.3 EBCDIC support model
In 1.3, BUFF has a couple of flags (B_EBCDIC2ASCII and B_ASCII2EBCDIC)
which are turned on and off during processing as different types of
data are being processed. A useful view of this is to consider two
types of data:
1) headers and content which must be translated
2) content which must not be translated
When the appropriate flag is enabled, buff.c routines call
ebcdic2ascii() or ascii2ebcdic() to do the appropriate translation (to
ASCII or from ASCII). Aside from some tricks with an extra pair of
translation tables that don't touch CR-LF, only one pair of
translation tables is used. It is assumed that all data translated to
or from EBCDIC should use the same EBCDIC character set and that all
data translated to or from ASCII should use the same ASCII character
set.
---------------------------------------------------------------------
Problems with 1.3 EBCDIC support model
It does not take into account that there is more than one pair of
charsets. This is a showstopper for serious use.
It only handles translation between two single-byte character sets.
A more useful mode is that there are three types of data:
1) headers which must be translated (between a fixed pair of
character sets)
2) content which must be translated (between a variable pair of
character sets)
3) content which must not be translated
---------------------------------------------------------------------
Background info on 1.3 Russian Apache model
Russian Apache doesn't modify BUFF and related functions. Instead,
when it is time to read or write from/to a BUFF it places a wrapper
around the BUFF calls as follows:
read-type call:
+ #ifdef RUSSIAN_APACHE
+ len_read = charset_bread(r->connection->client, buffer,
+ len_to_read,r->ra_codep);
+ #else
len_read = ap_bread(r->connection->client, buffer, len_to_read);
+ #endif
If no codepage info is stored in the request_rec (r->ra_codep),
charset_bread() calls ap_bread() directly rather than performing
translation.
write-type call:
while (n && !r->connection->aborted) {
! #ifdef RUSSIAN_APACHE
! unsigned char *newbuf,*p;
! int newlen=0;
! if (ra_charset_active(r))
! {
! if(ra_flag(r,RA_WIDE_CHARS_SC))
! {
! ra_data_server2client(r,&buf[o],n,&newbuf,&newlen);
! p=newbuf;
! while(newlen > 0)
! {
! w = ap_bwrite(r->connection->client, p, newlen);
! if(w<=0) goto RECODE_DONE;
! newlen-=w;
! p+=w;
! }
! w=n;
! }
! else /* avoid performance penalty */
! {
! unsigned char *t = r->ra_codep->cp_otabl_p;
! unsigned char *b = (unsigned char *)&buf[o];
! unsigned char *end = b+n;
! while(b<end) {
! *b=t[*b]; b++;
! }
! w = ap_bwrite(r->connection->client, &buf[o],n);
! }
! }
! else
! w = ap_bwrite(r->connection->client, &buf[o], n);
! RECODE_DONE:;
! #else
! w = ap_bwrite(r->connection->client, &buf[o], n);
! #endif
!
Things that I don't like about the 1.3 Russian Apache model:
More code has to be aware of translation requirements; it doesn't
simply maintain flags in BUFF as appropriate and let magic happen.
Low-level details of translation are spread around (faster, but nicer
to hide under an API like ap_xlate_buffer()).
Things I think I like about the Russian Apache model:
It is always clear whether or not it is SBCS translation and faster
paths through the code are used when possible.
-------------------------------------------------------------------------
minor addition to apr_xlate.h
It is common to pass around a pair of related handles -- one to use
when reading+translating data and one to use when translating+writing
data. apr_xlate.h could be friendly and define something like this
for client code to use
typedef struct ap_xlate_pair_t {
ap_xlate_t *read;
ap_xlate_t *write;
} ap_xlate_pair_t;
---------------------------------------------------------------------
proposed 2.0 changes to BUFF
Charset translation will be done in buff.c, as in the 1.3 EBCDIC
support. Higher layers are responsible for telling BUFF (for both
read and write) whether or not to translate and what APR translation
handle to use.
All that BUFF needs to know is
whether to translate on write, and which APR translation handle to
use to do that
flag B_XLATE_ON_WRITE, write_xlate
whether to translate on read, and which APR translation handle to
use to do that
flag B_XLATE_ON_READ, write_xlate
bsetopt()/bgetopt() can be used to set/retrieve the translation
handles. The value of the opt can be an instance of ap_xlate_pair_t.
The routines need to be beefed up to handle non-SBCS translation
(yuck) so some extra buffers (one for read, one for write) may get
chained to BUFF.
The BUFF stuff isn't EBCDIC-specific, so some new preprocessor symbol
will be used in buff.c/buff.h. I suggest XLATE_CHARSET, which will be
turned on automatically whenever CHARSET_EBCDIC is turned on.
---------------------------------------------------------------------
Recap of differences when compared with 1.3 EBCDIC support:
1) handle non-SBCS where needed
2) don't use "EBCDIC" as this support is more widely applicable
3) no hard-coded translation table; the client tells BUFF what
translation handle to use and that handle is passed to APR
(this seems to be working fine now)
If CHARSET_EBCDIC isn't defined, XLATE_CHARSET won't be defined either
so everyone else will be executing exactly the same code.
---------------------------------------------------------------------
What besides these BUFF changes make a working solution for EBCDIC?
Right now I haven't done anything with configuration issues :)
I store translation handles for read/write in the server_rec and copy
them to new request_recs and then copy them again when needed to BUFF.
The next step is to distinguish between headers to translate and
content to translate. Whereas headers are translated between the
charset of the source code and ISO8859-1, content by default is
translated between the charset of the current locale and ISO8859-1.
Beyond that it is time to talk about the Russian Apache controls and
the mod_ebcdic controls and compare with controls of other web servers
that allow the same stuff. Certainly if a script spits out a charset
header then we trust it. If mod_mime decides the charset then we
trust it.
(Hopefully somebody else will get very interested in these
configuration issues soon. For now, I want to get the BUFF operations
ready to support any possible decisions made by higher-layer code.)
---------------------------------------------------------------------
What could Russian Apache do with these 2.0 changes?
Their current design could be carried over to 2.0 without too much
trouble. I would rather see them do the following:
1) integrate their translation table support into APR's
ap_xlate_whatever()
this would hopefully mean that the administrator no longer tells
Apache where to find the translation tables but instead
ap_xlate_*() has a search path or a config file or something like
that
Apache doesn't really want to know too much about translation tables
2) use appropriate routines to manipulate flags/translation handles in
BUFF rather than doing translation and/or calling a wrapper
function in the caller of ap_bXXX()
The decisions for when to translate would remain the same. (Martin
Kraemer's ideas for mod_ebcdic could influence this.)
-----------------------------------------------------------------------
Note about EBCDIC+OS/390 support with 2.0:
Greg Ames and I have been working on this quite a lot lately. It
seems to work fine with prefork and mpmt_pthread. A fair-sized (??)
patch must be applied to the current 2.0 code to run on OS/390. I've
been a bit lazy/ignorant about solving certain auto configuration
issues so we still have some required #ifdef __MVS__ #else #endif junk
to deal with before committing the code. Also, some of the diffs
we're carrying are wrapped up in the suggested BUFF changes.
To me, it is higher priority to get the EBCDIC changes into CVS so
that more platforms can get involved (BS/2000, AS/400). The OS/390
changes aren't very interesting.
We are certainly not hoarding the code, so if you want it please ask.
We are eager for more eyes and keyboards.
--
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
http://www.geocities.com/SiliconValley/Park/9289/
Born in Roswell... married an alien...