--- parser3/src/main/pa_charset.C 2002/01/21 16:44:48 1.16 +++ parser3/src/main/pa_charset.C 2002/03/27 15:30:36 1.23 @@ -1,10 +1,10 @@ /** @file Parser: Charset connection implementation. - Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) + Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan(http://paf.design.ru) - $Id: pa_charset.C,v 1.16 2002/01/21 16:44:48 paf Exp $ + $Id: pa_charset.C,v 1.23 2002/03/27 15:30:36 paf Exp $ */ #include "pa_charset.h" @@ -153,7 +153,7 @@ void Charset::loadDefinition(const Strin case 8: // charset if(tables.toTableSize>MAX_CHARSET_UNI_CODES) - throw Exception(0, 0, + throw Exception("parser.runtime", &request_file_spec, "charset must contain not more then %d unicode values", MAX_CHARSET_UNI_CODES); @@ -337,17 +337,17 @@ static int transcodeToUTF8( // here, so bump up the output pointer and work down as we go. outPtr+= encodedBytes; switch(encodedBytes) { - case 6: *--outPtr = (XMLByte)((curVal | 0x80UL) & 0xBFUL); + case 6: *--outPtr = XMLByte((curVal | 0x80UL) & 0xBFUL); curVal>>= 6; - case 5: *--outPtr = (XMLByte)((curVal | 0x80UL) & 0xBFUL); + case 5: *--outPtr = XMLByte((curVal | 0x80UL) & 0xBFUL); curVal>>= 6; - case 4: *--outPtr = (XMLByte)((curVal | 0x80UL) & 0xBFUL); + case 4: *--outPtr = XMLByte((curVal | 0x80UL) & 0xBFUL); curVal>>= 6; - case 3: *--outPtr = (XMLByte)((curVal | 0x80UL) & 0xBFUL); + case 3: *--outPtr = XMLByte((curVal | 0x80UL) & 0xBFUL); curVal>>= 6; - case 2: *--outPtr = (XMLByte)((curVal | 0x80UL) & 0xBFUL); + case 2: *--outPtr = XMLByte((curVal | 0x80UL) & 0xBFUL); curVal>>= 6; - case 1: *--outPtr = (XMLByte)(curVal | gFirstByteMark[encodedBytes]); + case 1: *--outPtr = XMLByte(curVal | gFirstByteMark[encodedBytes]); } // Add the encoded bytes back in again to indicate we've eaten them @@ -404,7 +404,7 @@ static size_t transcodeFromUTF8( break; default: - throw Exception(0, 0, + throw Exception(0, 0, "transcodeFromUTF8 error: wrong trailingBytes value(%d)", trailingBytes); } @@ -416,7 +416,7 @@ static size_t transcodeFromUTF8( if(!(tmpVal & 0xFFFF0000)) *outPtr++= xlatOneTo(tmpVal, tables); else - throw Exception(0, 0, + throw Exception(0, 0, "transcodeFromUTF8 error: too big tmpVal(0x%08X)", tmpVal); } @@ -448,7 +448,6 @@ void Charset::transcodeToUTF8(Pool& pool // return adest_body=dest_body; } -/// @test buf overflow void Charset::transcodeFromUTF8(Pool& pool, const void *source_body, size_t source_content_length, const void *& adest_body, size_t& dest_content_length) const { @@ -505,8 +504,8 @@ static int xml256CharEncodingInp int *inlen, void *info) { return transcodeToUTF8( - in, *(unsigned int*)inlen, - out, *(unsigned int*)outlen, + in, *(size_t*)inlen, + out, *(size_t*)outlen, *(const Charset::Tables *)info); } @@ -517,8 +516,8 @@ static int xml256CharEncodingOut int *inlen, void *info) { return transcodeFromUTF8( - in, *(unsigned int*)inlen, - out, *(unsigned int*)outlen, + in, *(size_t*)inlen, + out, *(size_t*)outlen, *(const Charset::Tables *)info); } @@ -540,7 +539,7 @@ void Charset::initTranscoder(const Strin xmlCharEncodingHandler *Charset::transcoder(const String *source) { if(!ftranscoder) - throw Exception(0, 0, + throw Exception("parser.runtime", source, "unsupported encoding"); return ftranscoder; @@ -554,12 +553,16 @@ const char *Charset::transcode_cstr(xmlC int outlen=inlen+1; // max char *out=(char *)malloc(outlen*sizeof(char)); - int size=transcoder(0)->output( - (unsigned char*)out, &outlen, - (const unsigned char*)s, &inlen, - transcoder(0)->outputInfo); + int size; + if(xmlCharEncodingOutputFunc output=transcoder(0)->output) { + size=output( + (unsigned char*)out, &outlen, + (const unsigned char*)s, &inlen, + transcoder(0)->outputInfo); + } else + memcpy(out, s, size=inlen); if(size<0) - throw Exception(0, 0, + throw Exception(0, 0, "transcode_cstr failed (%d)", size); @@ -580,12 +583,18 @@ String& Charset::transcode(GdomeDOMStrin GdomeDOMString_auto_ptr Charset::transcode_buf(const char *buf, size_t buf_size) { int outlen=buf_size*6/*max*/+1; unsigned char *out=(unsigned char*)malloc(outlen*sizeof(unsigned char)); - int size=transcoder(0)->input( - out, &outlen, - (const unsigned char *)buf, (int *)&buf_size, - transcoder(0)->inputInfo); + + int size; + if(xmlCharEncodingInputFunc input=transcoder(0)->input) { + size=input( + out, &outlen, + (const unsigned char *)buf, (int *)&buf_size, + transcoder(0)->inputInfo); + } else + memcpy(out, buf, size=buf_size); + if(size<0) - throw Exception(0, 0, + throw Exception(0, 0, "transcode_buf failed (%d)", size);