--- parser3/src/classes/xdoc.C 2011/10/11 13:40:16 1.170 +++ parser3/src/classes/xdoc.C 2012/06/15 11:54:18 1.176 @@ -1,7 +1,7 @@ /** @file Parser: @b xdoc parser class. - Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -9,8 +9,6 @@ #ifdef XML -static const char * const IDENT_XDOC_C="$Date: 2011/10/11 13:40:16 $"; - #include "libxml/tree.h" #include "libxml/HTMLtree.h" #include "libxslt/xsltInternals.h" @@ -28,6 +26,9 @@ static const char * const IDENT_XDOC_C=" #include "pa_vfile.h" #include "pa_xml_exception.h" #include "xnode.h" +#include "pa_charsets.h" + +volatile const char * IDENT_XDOC_C="$Id: xdoc.C,v 1.176 2012/06/15 11:54:18 moko Exp $"; // defines @@ -469,24 +470,22 @@ String::C xdoc2buf(Request& r, VXdoc& vd XDocOutputOptions& oo, const String* file_spec, bool use_source_charset_to_render_and_client_charset_to_write_to_header=false) { - const char* render_encoding; - const char* header_encoding; + Charset* render=0; + Charset* header=0; if(use_source_charset_to_render_and_client_charset_to_write_to_header) { - render_encoding=r.charsets.source().NAME_CSTR(); - header_encoding=r.charsets.client().NAME_CSTR(); + render=&r.charsets.source(); + header=&r.charsets.client(); } else { - header_encoding=render_encoding=oo.encoding->cstr(); + header=render=&charsets.get(oo.encoding->change_case(r.charsets.source(), String::CC_UPPER)); } + const char* render_encoding=render->NAME_CSTR(); + const char* header_encoding=header->NAME_CSTR(); xmlCharEncodingHandler *renderer=xmlFindCharEncodingHandler(render_encoding); - if(!renderer) - throw Exception(PARSER_RUNTIME, - 0, - "encoding '%s' not supported", render_encoding); // UTF-8 renderer contains empty input/output converters, // which is wrong for xmlOutputBufferCreateIO // while zero renderer goes perfectly - if(strcmp(render_encoding, "UTF-8")==0) + if(render->isUTF8()) renderer=0; xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(renderer)); @@ -561,10 +560,7 @@ static void _file(Request& r, MethodPara String::Body("charset"), new VString(*oo.encoding)); - vfile.set(false/*tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, - (oo.filename)?oo.filename->taint_cstr(String::L_FILE_SPEC):0, &vhcontent_type); - - vfile.set_mode(true/*text*/); + vfile.set_binary(false/*not tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, oo.filename, &vhcontent_type); // write out result r.write_no_lang(vfile); @@ -642,7 +638,7 @@ static void _transform(Request& r, Metho Array transform_strings; const xmlChar** transform_params=0; if(params.count()>1) - if(HashStringValue* hash=params.as_hash(1)) { + if(HashStringValue* hash=params.as_hash(1, "transform options")) { transform_params=new(UseGC) const xmlChar*[hash->count()*2+1]; Add_xslt_param_info info={ &r,