[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[xml] patch: custom I/O BufferCreateFilename handlers



Here is the completed patch which will allow custom implementations of the xmlParserInputBufferCreateFilename and xmlOutputBufferCreateFilename functions. This allows the capabilities of isolating an app from the I/O callbacks.
 
Hopefully this is the correct solution to the issue.
 
Rob
Index: globals.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/globals.c,v
retrieving revision 1.37
diff -c -r1.37 globals.c
*** globals.c	20 Dec 2003 02:10:21 -0000	1.37
--- globals.c	1 Jun 2004 17:29:19 -0000
***************
*** 169,174 ****
--- 169,176 ----
  #undef	xmlMemStrdup
  #undef	xmlRealloc
  
+ #undef  xmlParserInputBufferCreateFilenameValue
+ #undef  xmlOutputBufferCreateFilenameValue
  /**
   * xmlParserVersion:
   *
***************
*** 282,287 ****
--- 284,295 ----
  xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL;
  static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL;
  
+ xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue = NULL;
+ static xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValueThrDef = NULL;
+ 
+ xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue = NULL;
+ static xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValueThrDef = NULL;
+ 
  /*
   * Error handling
   */
***************
*** 545,550 ****
--- 553,561 ----
      gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
      gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
      gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
+ 
+ 	gs->xmlParserInputBufferCreateFilenameValue = xmlParserInputBufferCreateFilenameValueThrDef;
+ 	gs->xmlOutputBufferCreateFilenameValue = xmlOutputBufferCreateFilenameValueThrDef;
      memset(&gs->xmlLastError, 0, sizeof(xmlError));
  
      xmlMutexUnlock(xmlThrDefMutex);
***************
*** 639,644 ****
--- 650,716 ----
      return(old);
  }
  
+ /**
+  * xmlParserInputBufferCreateFilename:
+  * @func: function pointer to the new ParserInputBufferCreateFilenameFunc
+  *
+  * Registers a callback for URI input file handling
+  *
+  * Returns the old value of the registration function
+  */
+ xmlParserInputBufferCreateFilenameFunc
+ xmlParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func)
+ {
+     xmlParserInputBufferCreateFilenameFunc old = xmlParserInputBufferCreateFilenameValue;
+     
+     xmlParserInputBufferCreateFilenameValue = func;
+     return(old);
+ }
+ 
+ xmlParserInputBufferCreateFilenameFunc
+ xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func)
+ {
+     xmlParserInputBufferCreateFilenameFunc old;
+     
+     xmlMutexLock(xmlThrDefMutex);
+     old = xmlParserInputBufferCreateFilenameValueThrDef;
+     
+     xmlParserInputBufferCreateFilenameValueThrDef = func;
+     xmlMutexUnlock(xmlThrDefMutex);
+ 
+     return(old);
+ }
+ 
+ /**
+  * xmlOutputBufferCreateFilename:
+  * @func: function pointer to the new OutputBufferCreateFilenameFunc
+  *
+  * Registers a callback for URI output file handling
+  *
+  * Returns the old value of the registration function
+  */
+ xmlOutputBufferCreateFilenameFunc
+ xmlOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func)
+ {
+     xmlOutputBufferCreateFilenameFunc old = xmlOutputBufferCreateFilenameValue;
+     
+     xmlOutputBufferCreateFilenameValue = func;
+     return(old);
+ }
+ 
+ xmlOutputBufferCreateFilenameFunc
+ xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func)
+ {
+     xmlOutputBufferCreateFilenameFunc old;
+     
+     xmlMutexLock(xmlThrDefMutex);
+     old = xmlOutputBufferCreateFilenameValueThrDef;
+     
+     xmlOutputBufferCreateFilenameValueThrDef = func;
+     xmlMutexUnlock(xmlThrDefMutex);
+ 
+     return(old);
+ }
  
  #ifdef LIBXML_DOCB_ENABLED
  #undef	docbDefaultSAXHandler
***************
*** 981,983 ****
--- 1053,1073 ----
      else
  	return (&xmlGetGlobalState()->xmlDeregisterNodeDefaultValue);
  }
+ 
+ #undef	xmlParserInputBufferCreateFilenameValue
+ xmlParserInputBufferCreateFilenameFunc *
+ __xmlParserInputBufferCreateFilenameValue(void) {
+     if (IS_MAIN_THREAD)
+ 	return (&xmlParserInputBufferCreateFilenameValue);
+     else
+ 	return (&xmlGetGlobalState()->xmlParserInputBufferCreateFilenameValue);
+ }
+ 
+ #undef	xmlOutputBufferCreateFilenameValue
+ xmlOutputBufferCreateFilenameFunc *
+ __xmlOutputBufferCreateFilenameValue(void) {
+     if (IS_MAIN_THREAD)
+ 	return (&xmlOutputBufferCreateFilenameValue);
+     else
+ 	return (&xmlGetGlobalState()->xmlOutputBufferCreateFilenameValue);
+ }
\ No newline at end of file
Index: xmlIO.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/xmlIO.c,v
retrieving revision 1.144
diff -c -r1.144 xmlIO.c
*** xmlIO.c	14 May 2004 21:50:42 -0000	1.144
--- xmlIO.c	1 Jun 2004 17:29:21 -0000
***************
*** 2125,2145 ****
  }
  #endif /* LIBXML_OUTPUT_ENABLED */
  
! /**
!  * xmlParserInputBufferCreateFilename:
!  * @URI:  a C string containing the URI or filename
!  * @enc:  the charset encoding if known
!  *
!  * Create a buffered parser input for the progressive parsing of a file
!  * If filename is "-' then we use stdin as the input.
!  * Automatic support for ZLIB/Compress compressed document is provided
!  * by default if found at compile-time.
!  * Do an encoding check if enc == XML_CHAR_ENCODING_NONE
!  *
!  * Returns the new parser input or NULL
!  */
! xmlParserInputBufferPtr
! xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
      xmlParserInputBufferPtr ret;
      int i = 0;
      void *context = NULL;
--- 2125,2132 ----
  }
  #endif /* LIBXML_OUTPUT_ENABLED */
  
! static xmlParserInputBufferPtr
! __xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
      xmlParserInputBufferPtr ret;
      int i = 0;
      void *context = NULL;
***************
*** 2196,2221 ****
      return(ret);
  }
  
- #ifdef LIBXML_OUTPUT_ENABLED
  /**
!  * xmlOutputBufferCreateFilename:
   * @URI:  a C string containing the URI or filename
!  * @encoder:  the encoding converter or NULL
!  * @compression:  the compression ration (0 none, 9 max).
   *
!  * Create a buffered  output for the progressive saving of a file
!  * If filename is "-' then we use stdout as the output.
   * Automatic support for ZLIB/Compress compressed document is provided
   * by default if found at compile-time.
!  * TODO: currently if compression is set, the library only support
!  *       writing to a local file.
   *
!  * Returns the new output or NULL
   */
! xmlOutputBufferPtr
! xmlOutputBufferCreateFilename(const char *URI,
                                xmlCharEncodingHandlerPtr encoder,
! 			      int compression ATTRIBUTE_UNUSED) {
      xmlOutputBufferPtr ret;
      xmlURIPtr puri;
      int i = 0;
--- 2183,2214 ----
      return(ret);
  }
  
  /**
!  * xmlParserInputBufferCreateFilename:
   * @URI:  a C string containing the URI or filename
!  * @enc:  the charset encoding if known
   *
!  * Create a buffered parser input for the progressive parsing of a file
!  * If filename is "-' then we use stdin as the input.
   * Automatic support for ZLIB/Compress compressed document is provided
   * by default if found at compile-time.
!  * Do an encoding check if enc == XML_CHAR_ENCODING_NONE
   *
!  * Returns the new parser input or NULL
   */
! xmlParserInputBufferPtr
! xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) {
!     if ((xmlParserInputBufferCreateFilenameValue)) {
! 		return xmlParserInputBufferCreateFilenameValue(URI, enc);
! 	}
! 	return __xmlParserInputBufferCreateFilename(URI, enc);
! }
! 
! #ifdef LIBXML_OUTPUT_ENABLED
! static xmlOutputBufferPtr
! __xmlOutputBufferCreateFilename(const char *URI,
                                xmlCharEncodingHandlerPtr encoder,
!                               int compression ATTRIBUTE_UNUSED) {
      xmlOutputBufferPtr ret;
      xmlURIPtr puri;
      int i = 0;
***************
*** 2328,2333 ****
--- 2321,2351 ----
  	ret->closecallback = xmlOutputCallbackTable[i].closecallback;
      }
      return(ret);
+ }
+ 
+ /**
+  * xmlOutputBufferCreateFilename:
+  * @URI:  a C string containing the URI or filename
+  * @encoder:  the encoding converter or NULL
+  * @compression:  the compression ration (0 none, 9 max).
+  *
+  * Create a buffered  output for the progressive saving of a file
+  * If filename is "-' then we use stdout as the output.
+  * Automatic support for ZLIB/Compress compressed document is provided
+  * by default if found at compile-time.
+  * TODO: currently if compression is set, the library only support
+  *       writing to a local file.
+  *
+  * Returns the new output or NULL
+  */
+ xmlOutputBufferPtr
+ xmlOutputBufferCreateFilename(const char *URI,
+                               xmlCharEncodingHandlerPtr encoder,
+                               int compression ATTRIBUTE_UNUSED) {
+     if ((xmlOutputBufferCreateFilenameValue)) {
+ 		return xmlOutputBufferCreateFilenameValue(URI, encoder, compression);
+ 	}
+ 	return __xmlOutputBufferCreateFilename(URI, encoder, compression);
  }
  #endif /* LIBXML_OUTPUT_ENABLED */
  
Index: include/libxml/globals.h
===================================================================
RCS file: /cvs/gnome/gnome-xml/include/libxml/globals.h,v
retrieving revision 1.21
diff -c -r1.21 globals.h
*** include/libxml/globals.h	5 Dec 2003 14:57:41 -0000	1.21
--- include/libxml/globals.h	1 Jun 2004 17:29:22 -0000
***************
*** 63,72 ****
--- 63,77 ----
  #undef  xmlRegisterNodeDefaultValue
  #undef  xmlDeregisterNodeDefaultValue
  #undef  xmlLastError
+ #undef  xmlParserInputBufferCreateFilenameValue
+ #undef  xmlOutputBufferCreateFilenameValue
  
  typedef void (*xmlRegisterNodeFunc) (xmlNodePtr node);
  typedef void (*xmlDeregisterNodeFunc) (xmlNodePtr node);
  
+ typedef xmlParserInputBufferPtr (*xmlParserInputBufferCreateFilenameFunc) (const char *URI, xmlCharEncoding enc);
+ typedef xmlOutputBufferPtr (*xmlOutputBufferCreateFilenameFunc) (const char *URI, xmlCharEncodingHandlerPtr encoder, int compression);
+ 
  typedef struct _xmlGlobalState xmlGlobalState;
  typedef xmlGlobalState *xmlGlobalStatePtr;
  struct _xmlGlobalState 
***************
*** 110,115 ****
--- 115,123 ----
  
  	xmlMallocFunc xmlMallocAtomic;
  	xmlError xmlLastError;
+ 
+ 	xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue;
+ 	xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue;
  };
  
  #ifdef __cplusplus
***************
*** 131,136 ****
--- 139,150 ----
  XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func);
  XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func);
  
+ XMLPUBFUN xmlParserInputBufferCreateFilenameFunc XMLCALL xmlParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func);
+ XMLPUBFUN xmlParserInputBufferCreateFilenameFunc XMLCALL xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func);
+ 
+ XMLPUBFUN xmlOutputBufferCreateFilenameFunc XMLCALL xmlOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func);
+ XMLPUBFUN xmlOutputBufferCreateFilenameFunc XMLCALL xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func);
+ 
  /** DOC_DISABLE */
  /*
   * In general the memory allocation entry points are not kept
***************
*** 413,418 ****
--- 427,448 ----
  (*(__xmlDeregisterNodeDefaultValue()))
  #else
  XMLPUBVAR xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue;
+ #endif
+ 
+ XMLPUBFUN xmlParserInputBufferCreateFilenameFunc * XMLCALL __xmlParserInputBufferCreateFilenameValue(void);
+ #ifdef LIBXML_THREAD_ENABLED
+ #define xmlParserInputBufferCreateFilenameValue \
+ (*(__xmlParserInputBufferCreateFilenameValue()))
+ #else
+ XMLPUBVAR xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue;
+ #endif
+ 
+ XMLPUBFUN xmlOutputBufferCreateFilenameFunc * XMLCALL __xmlOutputBufferCreateFilenameValue(void);
+ #ifdef LIBXML_THREAD_ENABLED
+ #define xmlOutputBufferCreateFilenameValue \
+ (*(__xmlOutputBufferCreateFilenameValue()))
+ #else
+ XMLPUBVAR xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue;
  #endif
  
  #ifdef __cplusplus


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]