--- parser3/src/main/pa_xml_io.C 2019/11/05 16:50:30 1.35 +++ parser3/src/main/pa_xml_io.C 2019/11/05 19:35:00 1.37 @@ -9,7 +9,7 @@ #ifdef XML -volatile const char * IDENT_PA_XML_IO_C="$Id: pa_xml_io.C,v 1.35 2019/11/05 16:50:30 moko Exp $" IDENT_PA_XML_IO_H; +volatile const char * IDENT_PA_XML_IO_C="$Id: pa_xml_io.C,v 1.37 2019/11/05 19:35:00 moko Exp $" IDENT_PA_XML_IO_H; #include "libxslt/extensions.h" @@ -44,6 +44,8 @@ struct MemoryStream : public PA_Allocate size_t m_size; size_t m_position; + MemoryStream(const char *a_buf) : m_buf(a_buf), m_size(strlen(m_buf)), m_position(0) {} + int read(char* a_buffer, size_t a_size) { size_t left=m_size-m_position; if(!left) @@ -58,12 +60,12 @@ struct MemoryStream : public PA_Allocate }; #endif -static void * xmlFileOpen_ReadIntoStream (const char* do_not_store_filename, bool adjust_path_to_root_from_document_root=false) { +static void * xmlFileOpen_ReadIntoStream (const char* afilename, bool adjust_path_to_root_from_document_root=false) { #ifdef PA_SAFE_MODE //copied from libxml/catalog.c # define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog" // disable attempts to consult default catalog [usually, that file belongs to other user/group] - if(strcmp(do_not_store_filename, XML_XML_DEFAULT_CATALOG)==0) + if(strcmp(afilename, XML_XML_DEFAULT_CATALOG)==0) return 0; #endif @@ -76,30 +78,25 @@ static void * xmlFileOpen_ReadIntoStream adjust_buf[0]=0; strcat(adjust_buf, document_root); - strcat(adjust_buf, &do_not_store_filename[16]); - do_not_store_filename=adjust_buf; + strcat(adjust_buf, &afilename[16]); + afilename=adjust_buf; } else - if(!strstr(do_not_store_filename, "http://")) { - if(strstr(do_not_store_filename, "file://")) { - do_not_store_filename+=7 /*strlen("file://")*/; + if(!strstr(afilename, "http://")) { + if(strstr(afilename, "file://")) { + afilename+=7 /*strlen("file://")*/; #ifdef WIN32 - if( - do_not_store_filename[0]=='/' - && do_not_store_filename[1] - && do_not_store_filename[2]==':' - && do_not_store_filename[3]=='/' - ) { + if(afilename[0]=='/' && afilename[1] && afilename[2]==':' && afilename[3]=='/') { // skip leading slash for absolute path file:///C:/path/to/file - do_not_store_filename++; + afilename++; } #endif - } else if(*do_not_store_filename && do_not_store_filename[1]!=':' && strstr(do_not_store_filename, "://")) { + } else if(afilename[0] && afilename[1]!=':' && strstr(afilename, "://")) { pa_xmlStopMonitoringDependencies(); return 0; // plug out [do not handle other prefixes] } } - const char* can_store_filename=pa_strdup(do_not_store_filename); + const char* can_store_filename=pa_strdup(afilename); add_dependency(can_store_filename); const char *buf; @@ -116,10 +113,7 @@ static void * xmlFileOpen_ReadIntoStream } catch(...) { buf="xmlFileOpen_ReadIntoStream: unknown error"; } - MemoryStream* stream=new MemoryStream; - stream->m_buf=buf; - stream->m_size=strlen(buf); - return (void *)stream; + return (void *)new MemoryStream(buf); } static int xmlFileMatchMonitor(const char* /*file_spec_cstr*/) { @@ -182,10 +176,7 @@ static void *xmlFileOpenMethod (const ch } catch(...) { buf="xmlFileOpenLocalhost: unknown error"; } - MemoryStream* stream=new MemoryStream; - stream->m_buf=buf; - stream->m_size=strlen(buf); - return (void *)stream; + return (void *)new MemoryStream(buf); } /** @@ -200,7 +191,6 @@ static void *xmlFileOpenMethod (const ch */ static int pa_xmlFileReadMethod (void* context, char* buffer, int len){ MemoryStream& stream=*static_cast(context); - return stream.read(buffer, len); } @@ -216,7 +206,7 @@ void pa_xml_io_init() { // http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc xmlRegisterInputCallbacks(xmlFileMatchLocalhost, xmlFileOpenLocalhost, pa_xmlFileReadMethod, pa_xmlFileCloseMethod); - // parser://method/param/here -> ^MAIN:method[/params/here] + // parser://method/param/here -> ^MAIN:method[/params/here] - should be last to be called first xmlRegisterInputCallbacks(xmlFileMatchMethod, xmlFileOpenMethod, pa_xmlFileReadMethod, pa_xmlFileCloseMethod); }