(root)/
libxml2-2.12.3/
include/
libxml/
xmlIO.h
       1  /*
       2   * Summary: interface for the I/O interfaces used by the parser
       3   * Description: interface for the I/O interfaces used by the parser
       4   *
       5   * Copy: See Copyright for the status of this software.
       6   *
       7   * Author: Daniel Veillard
       8   */
       9  
      10  #ifndef __XML_IO_H__
      11  #define __XML_IO_H__
      12  
      13  #include <stdio.h>
      14  #include <libxml/xmlversion.h>
      15  #include <libxml/encoding.h>
      16  #define XML_TREE_INTERNALS
      17  #include <libxml/tree.h>
      18  #undef XML_TREE_INTERNALS
      19  
      20  #ifdef __cplusplus
      21  extern "C" {
      22  #endif
      23  
      24  /*
      25   * Those are the functions and datatypes for the parser input
      26   * I/O structures.
      27   */
      28  
      29  /**
      30   * xmlInputMatchCallback:
      31   * @filename: the filename or URI
      32   *
      33   * Callback used in the I/O Input API to detect if the current handler
      34   * can provide input functionality for this resource.
      35   *
      36   * Returns 1 if yes and 0 if another Input module should be used
      37   */
      38  typedef int (*xmlInputMatchCallback) (char const *filename);
      39  /**
      40   * xmlInputOpenCallback:
      41   * @filename: the filename or URI
      42   *
      43   * Callback used in the I/O Input API to open the resource
      44   *
      45   * Returns an Input context or NULL in case or error
      46   */
      47  typedef void * (*xmlInputOpenCallback) (char const *filename);
      48  /**
      49   * xmlInputReadCallback:
      50   * @context:  an Input context
      51   * @buffer:  the buffer to store data read
      52   * @len:  the length of the buffer in bytes
      53   *
      54   * Callback used in the I/O Input API to read the resource
      55   *
      56   * Returns the number of bytes read or -1 in case of error
      57   */
      58  typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
      59  /**
      60   * xmlInputCloseCallback:
      61   * @context:  an Input context
      62   *
      63   * Callback used in the I/O Input API to close the resource
      64   *
      65   * Returns 0 or -1 in case of error
      66   */
      67  typedef int (*xmlInputCloseCallback) (void * context);
      68  
      69  #ifdef LIBXML_OUTPUT_ENABLED
      70  /*
      71   * Those are the functions and datatypes for the library output
      72   * I/O structures.
      73   */
      74  
      75  /**
      76   * xmlOutputMatchCallback:
      77   * @filename: the filename or URI
      78   *
      79   * Callback used in the I/O Output API to detect if the current handler
      80   * can provide output functionality for this resource.
      81   *
      82   * Returns 1 if yes and 0 if another Output module should be used
      83   */
      84  typedef int (*xmlOutputMatchCallback) (char const *filename);
      85  /**
      86   * xmlOutputOpenCallback:
      87   * @filename: the filename or URI
      88   *
      89   * Callback used in the I/O Output API to open the resource
      90   *
      91   * Returns an Output context or NULL in case or error
      92   */
      93  typedef void * (*xmlOutputOpenCallback) (char const *filename);
      94  /**
      95   * xmlOutputWriteCallback:
      96   * @context:  an Output context
      97   * @buffer:  the buffer of data to write
      98   * @len:  the length of the buffer in bytes
      99   *
     100   * Callback used in the I/O Output API to write to the resource
     101   *
     102   * Returns the number of bytes written or -1 in case of error
     103   */
     104  typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer,
     105                                         int len);
     106  /**
     107   * xmlOutputCloseCallback:
     108   * @context:  an Output context
     109   *
     110   * Callback used in the I/O Output API to close the resource
     111   *
     112   * Returns 0 or -1 in case of error
     113   */
     114  typedef int (*xmlOutputCloseCallback) (void * context);
     115  #endif /* LIBXML_OUTPUT_ENABLED */
     116  
     117  /**
     118   * xmlParserInputBufferCreateFilenameFunc:
     119   * @URI: the URI to read from
     120   * @enc: the requested source encoding
     121   *
     122   * Signature for the function doing the lookup for a suitable input method
     123   * corresponding to an URI.
     124   *
     125   * Returns the new xmlParserInputBufferPtr in case of success or NULL if no
     126   *         method was found.
     127   */
     128  typedef xmlParserInputBufferPtr
     129  (*xmlParserInputBufferCreateFilenameFunc)(const char *URI, xmlCharEncoding enc);
     130  
     131  /**
     132   * xmlOutputBufferCreateFilenameFunc:
     133   * @URI: the URI to write to
     134   * @enc: the requested target encoding
     135   *
     136   * Signature for the function doing the lookup for a suitable output method
     137   * corresponding to an URI.
     138   *
     139   * Returns the new xmlOutputBufferPtr in case of success or NULL if no
     140   *         method was found.
     141   */
     142  typedef xmlOutputBufferPtr
     143  (*xmlOutputBufferCreateFilenameFunc)(const char *URI,
     144          xmlCharEncodingHandlerPtr encoder, int compression);
     145  
     146  struct _xmlParserInputBuffer {
     147      void*                  context;
     148      xmlInputReadCallback   readcallback;
     149      xmlInputCloseCallback  closecallback;
     150  
     151      xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
     152  
     153      xmlBufPtr buffer;    /* Local buffer encoded in UTF-8 */
     154      xmlBufPtr raw;       /* if encoder != NULL buffer for raw input */
     155      int	compressed;	    /* -1=unknown, 0=not compressed, 1=compressed */
     156      int error;
     157      unsigned long rawconsumed;/* amount consumed from raw */
     158  };
     159  
     160  
     161  #ifdef LIBXML_OUTPUT_ENABLED
     162  struct _xmlOutputBuffer {
     163      void*                   context;
     164      xmlOutputWriteCallback  writecallback;
     165      xmlOutputCloseCallback  closecallback;
     166  
     167      xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
     168  
     169      xmlBufPtr buffer;    /* Local buffer encoded in UTF-8 or ISOLatin */
     170      xmlBufPtr conv;      /* if encoder != NULL buffer for output */
     171      int written;            /* total number of byte written */
     172      int error;
     173  };
     174  #endif /* LIBXML_OUTPUT_ENABLED */
     175  
     176  /** DOC_DISABLE */
     177  #define XML_GLOBALS_IO \
     178    XML_OP(xmlParserInputBufferCreateFilenameValue, \
     179             xmlParserInputBufferCreateFilenameFunc, XML_DEPRECATED) \
     180    XML_OP(xmlOutputBufferCreateFilenameValue, \
     181             xmlOutputBufferCreateFilenameFunc, XML_DEPRECATED)
     182  
     183  #define XML_OP XML_DECLARE_GLOBAL
     184  XML_GLOBALS_IO
     185  #undef XML_OP
     186  
     187  #if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION)
     188    #define xmlParserInputBufferCreateFilenameValue \
     189      XML_GLOBAL_MACRO(xmlParserInputBufferCreateFilenameValue)
     190    #define xmlOutputBufferCreateFilenameValue \
     191      XML_GLOBAL_MACRO(xmlOutputBufferCreateFilenameValue)
     192  #endif
     193  /** DOC_ENABLE */
     194  
     195  /*
     196   * Interfaces for input
     197   */
     198  XMLPUBFUN void
     199  	xmlCleanupInputCallbacks		(void);
     200  
     201  XMLPUBFUN int
     202  	xmlPopInputCallbacks			(void);
     203  
     204  XMLPUBFUN void
     205  	xmlRegisterDefaultInputCallbacks	(void);
     206  XMLPUBFUN xmlParserInputBufferPtr
     207  	xmlAllocParserInputBuffer		(xmlCharEncoding enc);
     208  
     209  XMLPUBFUN xmlParserInputBufferPtr
     210  	xmlParserInputBufferCreateFilename	(const char *URI,
     211                                                   xmlCharEncoding enc);
     212  XMLPUBFUN xmlParserInputBufferPtr
     213  	xmlParserInputBufferCreateFile		(FILE *file,
     214                                                   xmlCharEncoding enc);
     215  XMLPUBFUN xmlParserInputBufferPtr
     216  	xmlParserInputBufferCreateFd		(int fd,
     217  	                                         xmlCharEncoding enc);
     218  XMLPUBFUN xmlParserInputBufferPtr
     219  	xmlParserInputBufferCreateMem		(const char *mem, int size,
     220  	                                         xmlCharEncoding enc);
     221  XML_DEPRECATED
     222  XMLPUBFUN xmlParserInputBufferPtr
     223  	xmlParserInputBufferCreateStatic	(const char *mem, int size,
     224  	                                         xmlCharEncoding enc);
     225  XMLPUBFUN xmlParserInputBufferPtr
     226  	xmlParserInputBufferCreateIO		(xmlInputReadCallback   ioread,
     227  						 xmlInputCloseCallback  ioclose,
     228  						 void *ioctx,
     229  	                                         xmlCharEncoding enc);
     230  XMLPUBFUN int
     231  	xmlParserInputBufferRead		(xmlParserInputBufferPtr in,
     232  						 int len);
     233  XMLPUBFUN int
     234  	xmlParserInputBufferGrow		(xmlParserInputBufferPtr in,
     235  						 int len);
     236  XMLPUBFUN int
     237  	xmlParserInputBufferPush		(xmlParserInputBufferPtr in,
     238  						 int len,
     239  						 const char *buf);
     240  XMLPUBFUN void
     241  	xmlFreeParserInputBuffer		(xmlParserInputBufferPtr in);
     242  XMLPUBFUN char *
     243  	xmlParserGetDirectory			(const char *filename);
     244  
     245  XMLPUBFUN int
     246  	xmlRegisterInputCallbacks		(xmlInputMatchCallback matchFunc,
     247  						 xmlInputOpenCallback openFunc,
     248  						 xmlInputReadCallback readFunc,
     249  						 xmlInputCloseCallback closeFunc);
     250  
     251  xmlParserInputBufferPtr
     252  	__xmlParserInputBufferCreateFilename(const char *URI,
     253  						xmlCharEncoding enc);
     254  
     255  #ifdef LIBXML_OUTPUT_ENABLED
     256  /*
     257   * Interfaces for output
     258   */
     259  XMLPUBFUN void
     260  	xmlCleanupOutputCallbacks		(void);
     261  XMLPUBFUN int
     262  	xmlPopOutputCallbacks			(void);
     263  XMLPUBFUN void
     264  	xmlRegisterDefaultOutputCallbacks(void);
     265  XMLPUBFUN xmlOutputBufferPtr
     266  	xmlAllocOutputBuffer		(xmlCharEncodingHandlerPtr encoder);
     267  
     268  XMLPUBFUN xmlOutputBufferPtr
     269  	xmlOutputBufferCreateFilename	(const char *URI,
     270  					 xmlCharEncodingHandlerPtr encoder,
     271  					 int compression);
     272  
     273  XMLPUBFUN xmlOutputBufferPtr
     274  	xmlOutputBufferCreateFile	(FILE *file,
     275  					 xmlCharEncodingHandlerPtr encoder);
     276  
     277  XMLPUBFUN xmlOutputBufferPtr
     278  	xmlOutputBufferCreateBuffer	(xmlBufferPtr buffer,
     279  					 xmlCharEncodingHandlerPtr encoder);
     280  
     281  XMLPUBFUN xmlOutputBufferPtr
     282  	xmlOutputBufferCreateFd		(int fd,
     283  					 xmlCharEncodingHandlerPtr encoder);
     284  
     285  XMLPUBFUN xmlOutputBufferPtr
     286  	xmlOutputBufferCreateIO		(xmlOutputWriteCallback   iowrite,
     287  					 xmlOutputCloseCallback  ioclose,
     288  					 void *ioctx,
     289  					 xmlCharEncodingHandlerPtr encoder);
     290  
     291  /* Couple of APIs to get the output without digging into the buffers */
     292  XMLPUBFUN const xmlChar *
     293          xmlOutputBufferGetContent       (xmlOutputBufferPtr out);
     294  XMLPUBFUN size_t
     295          xmlOutputBufferGetSize          (xmlOutputBufferPtr out);
     296  
     297  XMLPUBFUN int
     298  	xmlOutputBufferWrite		(xmlOutputBufferPtr out,
     299  					 int len,
     300  					 const char *buf);
     301  XMLPUBFUN int
     302  	xmlOutputBufferWriteString	(xmlOutputBufferPtr out,
     303  					 const char *str);
     304  XMLPUBFUN int
     305  	xmlOutputBufferWriteEscape	(xmlOutputBufferPtr out,
     306  					 const xmlChar *str,
     307  					 xmlCharEncodingOutputFunc escaping);
     308  
     309  XMLPUBFUN int
     310  	xmlOutputBufferFlush		(xmlOutputBufferPtr out);
     311  XMLPUBFUN int
     312  	xmlOutputBufferClose		(xmlOutputBufferPtr out);
     313  
     314  XMLPUBFUN int
     315  	xmlRegisterOutputCallbacks	(xmlOutputMatchCallback matchFunc,
     316  					 xmlOutputOpenCallback openFunc,
     317  					 xmlOutputWriteCallback writeFunc,
     318  					 xmlOutputCloseCallback closeFunc);
     319  
     320  xmlOutputBufferPtr
     321  	__xmlOutputBufferCreateFilename(const char *URI,
     322                                xmlCharEncodingHandlerPtr encoder,
     323                                int compression);
     324  
     325  #ifdef LIBXML_HTTP_ENABLED
     326  /*  This function only exists if HTTP support built into the library  */
     327  XMLPUBFUN void
     328  	xmlRegisterHTTPPostCallbacks	(void );
     329  #endif /* LIBXML_HTTP_ENABLED */
     330  
     331  #endif /* LIBXML_OUTPUT_ENABLED */
     332  
     333  XMLPUBFUN xmlParserInputPtr
     334  	xmlCheckHTTPInput		(xmlParserCtxtPtr ctxt,
     335  					 xmlParserInputPtr ret);
     336  
     337  /*
     338   * A predefined entity loader disabling network accesses
     339   */
     340  XMLPUBFUN xmlParserInputPtr
     341  	xmlNoNetExternalEntityLoader	(const char *URL,
     342  					 const char *ID,
     343  					 xmlParserCtxtPtr ctxt);
     344  
     345  /*
     346   * xmlNormalizeWindowsPath is obsolete, don't use it.
     347   * Check xmlCanonicPath in uri.h for a better alternative.
     348   */
     349  XMLPUBFUN xmlChar *
     350  	xmlNormalizeWindowsPath		(const xmlChar *path);
     351  
     352  XMLPUBFUN int
     353  	xmlCheckFilename		(const char *path);
     354  /**
     355   * Default 'file://' protocol callbacks
     356   */
     357  XMLPUBFUN int
     358  	xmlFileMatch			(const char *filename);
     359  XMLPUBFUN void *
     360  	xmlFileOpen			(const char *filename);
     361  XMLPUBFUN int
     362  	xmlFileRead			(void * context,
     363  					 char * buffer,
     364  					 int len);
     365  XMLPUBFUN int
     366  	xmlFileClose			(void * context);
     367  
     368  /**
     369   * Default 'http://' protocol callbacks
     370   */
     371  #ifdef LIBXML_HTTP_ENABLED
     372  XMLPUBFUN int
     373  	xmlIOHTTPMatch			(const char *filename);
     374  XMLPUBFUN void *
     375  	xmlIOHTTPOpen			(const char *filename);
     376  #ifdef LIBXML_OUTPUT_ENABLED
     377  XMLPUBFUN void *
     378  	xmlIOHTTPOpenW			(const char * post_uri,
     379  					 int   compression );
     380  #endif /* LIBXML_OUTPUT_ENABLED */
     381  XMLPUBFUN int
     382  	xmlIOHTTPRead			(void * context,
     383  					 char * buffer,
     384  					 int len);
     385  XMLPUBFUN int
     386  	xmlIOHTTPClose			(void * context);
     387  #endif /* LIBXML_HTTP_ENABLED */
     388  
     389  /**
     390   * Default 'ftp://' protocol callbacks
     391   */
     392  #if defined(LIBXML_FTP_ENABLED)
     393  XMLPUBFUN int
     394  	xmlIOFTPMatch			(const char *filename);
     395  XMLPUBFUN void *
     396  	xmlIOFTPOpen			(const char *filename);
     397  XMLPUBFUN int
     398  	xmlIOFTPRead			(void * context,
     399  					 char * buffer,
     400  					 int len);
     401  XMLPUBFUN int
     402  	xmlIOFTPClose			(void * context);
     403  #endif /* defined(LIBXML_FTP_ENABLED) */
     404  
     405  XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
     406  	xmlParserInputBufferCreateFilenameDefault(
     407  		xmlParserInputBufferCreateFilenameFunc func);
     408  XMLPUBFUN xmlOutputBufferCreateFilenameFunc
     409  	xmlOutputBufferCreateFilenameDefault(
     410  		xmlOutputBufferCreateFilenameFunc func);
     411  XMLPUBFUN xmlOutputBufferCreateFilenameFunc
     412  	xmlThrDefOutputBufferCreateFilenameDefault(
     413  		xmlOutputBufferCreateFilenameFunc func);
     414  XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
     415  	xmlThrDefParserInputBufferCreateFilenameDefault(
     416  		xmlParserInputBufferCreateFilenameFunc func);
     417  
     418  #ifdef __cplusplus
     419  }
     420  #endif
     421  
     422  #endif /* __XML_IO_H__ */