--- parser3/src/classes/xdoc.C 2015/10/26 01:21:55 1.183 +++ parser3/src/classes/xdoc.C 2018/01/11 00:03:56 1.194 @@ -1,7 +1,7 @@ /** @file Parser: @b xdoc parser class. - Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -28,7 +28,7 @@ #include "xnode.h" #include "pa_charsets.h" -volatile const char * IDENT_XDOC_C="$Id: xdoc.C,v 1.183 2015/10/26 01:21:55 moko Exp $"; +volatile const char * IDENT_XDOC_C="$Id: xdoc.C,v 1.194 2018/01/11 00:03:56 moko Exp $"; // defines @@ -47,7 +47,8 @@ public: // global variable -DECLARE_CLASS_VAR(xdoc, new MXdoc, 0); +DECLARE_CLASS_VAR(xnode, new MXnode); // must be here as Xdoc is inherited from Xnode and should be inited before +DECLARE_CLASS_VAR(xdoc, new MXdoc); // helper classes @@ -159,7 +160,7 @@ static void writeNode(Request& r, VXdoc& "error creating node"); // OOM, bad name, things like that // write out result - r.write_no_lang(xdoc.wrap(*node)); + r.write(xdoc.wrap(*node)); } struct IdsIteratorInfo { @@ -378,11 +379,11 @@ static void _create(Request& r, MethodPa xmlDoc* xmldoc; bool set_encoding=false; if(param.get_junction()) { // {...} - Temp_lang temp_lang(r, String::L_XML); + const String& xml=r.process_to_string(param); + String::Body sbody=xml.cstr_to_string_body_untaint(String::L_XML, r.connection(false), &r.charsets); - String::Body sbody=xml.cstr_to_string_body_untaint(r.flang, r.connection(false), &r.charsets); - xmldoc=xmlParseMemory(sbody.cstr(), sbody.length()); + xmldoc=xmlReadMemory(sbody.cstr(), sbody.length(), NULL, NULL, XML_PARSE_HUGE); //printf("document=0x%p\n", document); if(!xmldoc || xmlHaveGenericErrors()) @@ -420,7 +421,7 @@ static void _create(Request& r, MethodPa // must be last action in if, see after if} } else { VFile* vfile=param.as_vfile(String::L_AS_IS); - xmldoc=xmlParseMemory(vfile->value_ptr(), vfile->value_size()); + xmldoc=xmlReadMemory(vfile->value_ptr(), vfile->value_size(), NULL, NULL, XML_PARSE_HUGE); if(!xmldoc || xmlHaveGenericErrors()) throw XmlException(0, r); } @@ -457,7 +458,7 @@ static void _load(Request& r, MethodPara uri_cstr=uri->taint_cstr(String::L_AS_IS); // leave as-is for xmlParseFile to handle /// @todo!! add SAFE MODE!! - xmlDoc* xmldoc=xmlParseFile(uri_cstr); + xmlDoc* xmldoc=xmlReadFile(uri_cstr, NULL, XML_PARSE_HUGE); if(!xmldoc || xmlHaveGenericErrors()) throw XmlException(uri, r); @@ -476,7 +477,7 @@ String::C xdoc2buf(Request& r, VXdoc& vd render=&r.charsets.source(); header=&r.charsets.client(); } else { - header=render=&charsets.get(oo.encoding->change_case(r.charsets.source(), String::CC_UPPER)); + header=render=&pa_charsets.get(*oo.encoding); } const char* render_encoding=render->NAME_CSTR(); const char* header_encoding=header->NAME_CSTR(); @@ -570,7 +571,7 @@ static void _file(Request& r, MethodPara 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); + r.write(vfile); } static void _save(Request& r, MethodParams& params) { @@ -593,7 +594,7 @@ static void _string(Request& r, MethodPa true/*use source charset to render, client charset to put to header*/); // write out result - r.write_no_lang(String(buf, String::L_AS_IS)); + r.write(String(buf, String::L_AS_IS)); } #ifndef DOXYGEN @@ -674,7 +675,7 @@ static void _transform(Request& r, Metho const xmlChar** transform_params=0; if(params.count()>1) if(HashStringValue* hash=params.as_hash(1, "transform options")) { - transform_params=new const xmlChar*[hash->count()*2+1]; + transform_params=new(PointerGC) const xmlChar*[hash->count()*2+1]; Add_xslt_param_info info={ &r, &transform_strings, @@ -686,23 +687,21 @@ static void _transform(Request& r, Metho VXdoc* result; if(Value *vxdoc=params[0].as(VXDOC_TYPE)) { // stylesheet (xdoc) - xmlDoc& stylesheetdoc=static_cast(vxdoc)->get_xmldoc(); - // compile xdoc stylesheet - xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(&stylesheetdoc)); - if(xmlHaveGenericErrors()) - throw XmlException(0, r); - if(!stylesheet_ptr.get()) - throw Exception("xml", - 0, - "stylesheet failed to compile"); - // strange thing - xsltParseStylesheetDoc records document and destroys it in stylesheet destructor - // we don't need that - stylesheet_ptr->doc=0; + VXdoc& vstylesheet=static_cast(*vxdoc); + + if(!vstylesheet.stylesheet){ + xmlDoc& stylesheetdoc=vstylesheet.get_xmldoc(); + + // compile xdoc stylesheet + vstylesheet.stylesheet=xsltParseStylesheetDoc(&stylesheetdoc); + if(xmlHaveGenericErrors()) + throw XmlException(0, r); + if(!vstylesheet.stylesheet) + throw Exception("xml", 0, "stylesheet failed to compile"); + } // transform! - result=&_transform(r, 0, - vdoc, stylesheet_ptr.get(), - transform_params); + result=&_transform(r, 0, vdoc, vstylesheet.stylesheet, transform_params); } else { // stylesheet (file name) // extablish stylesheet connection const String& stylesheet_filespec= @@ -711,18 +710,19 @@ static void _transform(Request& r, Metho // load and compile file to stylesheet [or get cached if any] // transform! - result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(), - transform_params); + result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(), transform_params); } // write out result - r.write_no_lang(*result); + r.write(*result); } // constructor /// @test how to create empty type html? -MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME, xnode_class) { +MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME) { + set_base(xnode_class); + /// DOM1 // Element createElement(in DOMString tagName) raises(DOMException); @@ -792,6 +792,7 @@ MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME, // global variable -DECLARE_CLASS_VAR(xdoc, 0, 0); // fictive +DECLARE_CLASS_VAR(xnode, 0); // fictive +DECLARE_CLASS_VAR(xdoc, 0); // fictive #endif