Diff for /parser3/src/main/pa_xml_io.C between versions 1.10 and 1.16

version 1.10, 2003/11/28 10:41:11 version 1.16, 2004/02/11 15:33:16
Line 1 Line 1
 /** @file  /** @file
         Parser: plugins to xml library, controlling i/o; implementation          Parser: plugins to xml library, controlling i/o; implementation
   
         Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
Line 28  struct MemoryStream { Line 28  struct MemoryStream {
                         return 0;                          return 0;
   
                 size_t to_read=min(a_size, left);                  size_t to_read=min(a_size, left);
                 memcpy(a_buffer, m_buf, to_read);                  memcpy(a_buffer, m_buf+m_position, to_read);
                 m_position+=to_read;                  m_position+=to_read;
                 return to_read;                  return to_read;
         }          }
Line 36  struct MemoryStream { Line 36  struct MemoryStream {
 };  };
 #endif  #endif
   
   static void *
   xmlFileOpen_ReadIntoStream (const char* filename, bool adjust_path_to_root_from_document_root=false) {
           Request& r=pa_thread_request();
           char adjust_buf[MAX_STRING];    
           if(adjust_path_to_root_from_document_root) {
                   const char* document_root=r.request_info.document_root;
                   if(!document_root)
                           document_root=".";
   
                   adjust_buf[0]=0;
                   strcat(adjust_buf, document_root);
                   strcat(adjust_buf, &filename[16]);
                   filename=adjust_buf;
           } else
                   if(strstr(filename, "file://"))
                           filename+=7/*strlen("file://")*/; 
                   else if(strstr(filename, "://")) 
                           return 0; // plug out [do not handle other prefixes]
   
           const char *buf;
           try {
                   buf=file_read_text(r.charsets, *new String(filename));
           } catch(const Exception& e) {
                   buf=e.comment();
           } catch(...) {
                   buf="xmlFileOpenLocalhost: unknown error";
           }
           MemoryStream* stream=new(UseGC) MemoryStream;
           stream->m_buf=buf;
           stream->m_size=strlen(buf);
           return (void *)stream;
   }
   
 #ifdef PA_SAFE_MODE  #ifdef PA_SAFE_MODE
 static int  static int
 xmlFileMatchSafeMode(const char* file_spec_cstr) {  xmlFileMatchSafeMode(const char* file_spec_cstr) {
         if(strstr(filename, "://")) {          return 1; // always intercept, causing xmlFileOpenSafeMode to be called
                 String* file_spec=new String(file_spec_cstr, true);  }
                 struct stat finfo;  static void *
                 if(stat(file_spec_cstr, &finfo)!=0)  xmlFileOpenSafeMode(const char* filename) {
                         throw Exception("file.missing",           return xmlFileOpen_ReadIntoStream(filename); // handles localfile case, else returns 0
                                 file_spec,   
                                 "stat failed: %s (%d)",   
                                         strerror(errno), errno);  
   
                 check_safe_mode(finfo, file_spec, file_spec_cstr);  
         }  
         return 0;  
 }  }
 #endif  #endif
   
Line 71  xmlFileMatchLocalhost(const char* filena Line 96  xmlFileMatchLocalhost(const char* filena
         return(0);          return(0);
 }  }
   
   
 /**  /**
  * xmlFileOpenHttpLocalhost :   * xmlFileOpenLocalhost:
  * filename:  the URI for matching   * filename:  the URI for matching
  *   *
  * http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc   * http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc
  *   *
  * input from FILE *, supports compressed input  
  * if filename is " " then the standard input is used  
  *  
  * Returns an I/O context or NULL in case of error   * Returns an I/O context or NULL in case of error
  */   */
 static void *  static void *
 xmlFileOpenLocalhost (const char* filename) {  xmlFileOpenLocalhost (const char* filename) {
         Request& r=pa_thread_request();          return xmlFileOpen_ReadIntoStream(filename, true/*adjust path to root from document_root*/);
         const char* document_root=r.request_info.document_root;  
         if(!document_root)  
                 document_root=".";  
   
         char path[MAX_STRING];    
         path[0]=0;  
         strcat(path, document_root);  
         strcat(path, &filename[16]);  
   
         MemoryStream *stream=new(UseGC) MemoryStream;  
         stream->m_buf=file_read_text(r.charsets, *new String(filename), true);  
         stream->m_size=strlen(stream->m_buf);  
   
         return (void *)stream;  
 }  }
   
 static int  static int
Line 112  xmlFileMatchMethod(const char* filename) Line 119  xmlFileMatchMethod(const char* filename)
 /// parser://method/param/here -> ^MAIN:method[/params/here]  /// parser://method/param/here -> ^MAIN:method[/params/here]
 static void *  static void *
 xmlFileOpenMethod (const char* afilename) {  xmlFileOpenMethod (const char* afilename) {
         Request& r=pa_thread_request();          const char* buf;
           try {
         char* s=pa_strdup(afilename+9 /*strlen("parser://")*/);                  Request& r=pa_thread_request();
         const char* method_cstr=lsplit(&s, '/');  
         const String* method=new String(method_cstr);                  char* s=pa_strdup(afilename+9 /*strlen("parser://")*/);
         String::Body param_body("/");                    const char* method_cstr=lsplit(&s, '/');
         if(s)                  const String* method=new String(method_cstr);
                 param_body.append_know_length(s, strlen(s));                  String::Body param_body("/");  
                   if(s)
         VString* vparam=new VString(*new String(param_body, String::L_TAINTED));                          param_body.append_know_length(s, strlen(s));
         {  
                 Temp_lang temp_lang(r, String::L_XML); // default language: XML                  VString* vparam=new VString(*new String(param_body, String::L_TAINTED));
                 Request::Execute_nonvirtual_method_result body=                  {
                         r.execute_nonvirtual_method(r.main_class, *method, vparam, true);                          Temp_lang temp_lang(r, String::L_XML); // default language: XML
                 if(body.string) {                          Request::Execute_nonvirtual_method_result body=
                         MemoryStream *stream=new(UseGC) MemoryStream;                                  r.execute_nonvirtual_method(r.main_class, *method, vparam, true);
                         stream->m_buf=body.string->cstr(String::L_UNSPECIFIED);                          if(body.string) {
                         stream->m_size=strlen(stream->m_buf);                                  buf=body.string->cstr(String::L_UNSPECIFIED);
                         return (void*)stream;                          } else
                                   throw Exception(0,
                                           new String(afilename),
                                           "'%s' method not found in %s class", 
                                                           method_cstr, MAIN_CLASS_NAME);
                 }                  }
           } catch(const Exception& e) {
                   buf=e.comment();
           } catch(...) {
                   buf="xmlFileOpenLocalhost: unknown error";
         }          }
           MemoryStream* stream=new(UseGC) MemoryStream;
         throw Exception(0,          stream->m_buf=buf;
                 new String(afilename),          stream->m_size=strlen(buf);
                 "'%s' method not found in %s class",           return (void *)stream;
                         method_cstr, MAIN_CLASS_NAME);  
 }  }
   
   /**
    * pa_xmlFileReadMethod:
    * @context:  the I/O context
    * @buffer:  where to drop data
    * @len:  number of bytes to write
    *
    * Read @len bytes to @buffer from the I/O channel.
    *
    * Returns the number of bytes written
    */
 static int  static int
 pa_xmlFileReadMethod (void * context, //< MemoryStream actually  pa_xmlFileReadMethod (void * context, //< MemoryStream actually
                                           char * buffer, int len)                                             char * buffer, int len) 
Line 160  void pa_xml_io_init() { Line 184  void pa_xml_io_init() {
 #ifdef PA_SAFE_MODE  #ifdef PA_SAFE_MODE
         // safe mode checker, always fail match, but checks non-"://" there          // safe mode checker, always fail match, but checks non-"://" there
         xmlRegisterInputCallbacks(          xmlRegisterInputCallbacks(
                 xmlFileMatchSafeMode, 0,                  xmlFileMatchSafeMode, xmlFileOpenSafeMode,
                 0, 0);                  pa_xmlFileReadMethod, pa_xmlFileCloseMethod);
 #endif  #endif
         // http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc          // http://localhost/abc -> $ENV{DOCUMENT_ROOT}/abc | ./abc
         xmlRegisterInputCallbacks(          xmlRegisterInputCallbacks(

Removed from v.1.10  
changed lines
  Added in v.1.16


E-mail: