Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:14:04

0001 /**
0002  * @file
0003  * 
0004  * @brief I/O interfaces used by the parser
0005  * 
0006  * Functions and datatypes for parser input and output.
0007  *
0008  * @copyright See Copyright for the status of this software.
0009  *
0010  * @author Daniel Veillard
0011  */
0012 
0013 #ifndef __XML_IO_H__
0014 #define __XML_IO_H__
0015 
0016 #include <stdio.h>
0017 #include <libxml/xmlversion.h>
0018 #include <libxml/encoding.h>
0019 #define XML_TREE_INTERNALS
0020 #include <libxml/tree.h>
0021 #undef XML_TREE_INTERNALS
0022 
0023 #ifdef __cplusplus
0024 extern "C" {
0025 #endif
0026 
0027 /**
0028  * Callback used in the I/O Input API to detect if the current handler
0029  * can provide input functionality for this resource.
0030  *
0031  * @param filename  the filename or URI
0032  * @returns 1 if yes and 0 if another Input module should be used
0033  */
0034 typedef int (*xmlInputMatchCallback) (const char *filename);
0035 /**
0036  * Callback used in the I/O Input API to open the resource
0037  *
0038  * @param filename  the filename or URI
0039  * @returns an Input context or NULL in case or error
0040  */
0041 typedef void * (*xmlInputOpenCallback) (const char *filename);
0042 /**
0043  * Callback used in the I/O Input API to read the resource
0044  *
0045  * @param context  an Input context
0046  * @param buffer  the buffer to store data read
0047  * @param len  the length of the buffer in bytes
0048  * @returns the number of bytes read or -1 in case of error
0049  */
0050 typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
0051 /**
0052  * Callback used in the I/O Input API to close the resource
0053  *
0054  * @param context  an Input context
0055  * @returns 0 or -1 in case of error
0056  */
0057 typedef int (*xmlInputCloseCallback) (void * context);
0058 
0059 #ifdef LIBXML_OUTPUT_ENABLED
0060 /**
0061  * Callback used in the I/O Output API to detect if the current handler
0062  * can provide output functionality for this resource.
0063  *
0064  * @param filename  the filename or URI
0065  * @returns 1 if yes and 0 if another Output module should be used
0066  */
0067 typedef int (*xmlOutputMatchCallback) (const char *filename);
0068 /**
0069  * Callback used in the I/O Output API to open the resource
0070  *
0071  * @param filename  the filename or URI
0072  * @returns an Output context or NULL in case or error
0073  */
0074 typedef void * (*xmlOutputOpenCallback) (const char *filename);
0075 /**
0076  * Callback used in the I/O Output API to write to the resource
0077  *
0078  * @param context  an Output context
0079  * @param buffer  the buffer of data to write
0080  * @param len  the length of the buffer in bytes
0081  * @returns the number of bytes written or -1 in case of error
0082  */
0083 typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer,
0084                                        int len);
0085 /**
0086  * Callback used in the I/O Output API to close the resource
0087  *
0088  * @param context  an Output context
0089  * @returns 0 or -1 in case of error
0090  */
0091 typedef int (*xmlOutputCloseCallback) (void * context);
0092 #endif /* LIBXML_OUTPUT_ENABLED */
0093 
0094 /**
0095  * Signature for the function doing the lookup for a suitable input method
0096  * corresponding to an URI.
0097  *
0098  * @param URI  the URI to read from
0099  * @param enc  the requested source encoding
0100  * @returns the new xmlParserInputBuffer in case of success or NULL if no
0101  *         method was found.
0102  */
0103 typedef xmlParserInputBuffer *
0104 (*xmlParserInputBufferCreateFilenameFunc)(const char *URI, xmlCharEncoding enc);
0105 
0106 /**
0107  * Signature for the function doing the lookup for a suitable output method
0108  * corresponding to an URI.
0109  *
0110  * @param URI  the URI to write to
0111  * @param encoder  the requested target encoding
0112  * @param compression  compression level
0113  * @returns the new xmlOutputBuffer in case of success or NULL if no
0114  *         method was found.
0115  */
0116 typedef xmlOutputBuffer *
0117 (*xmlOutputBufferCreateFilenameFunc)(const char *URI,
0118         xmlCharEncodingHandler *encoder, int compression);
0119 
0120 /**
0121  * Parser input buffer
0122  *
0123  * This struct and all related functions should ultimately
0124  * be removed from the public interface.
0125  */
0126 struct _xmlParserInputBuffer {
0127     void*                  context XML_DEPRECATED_MEMBER;
0128     xmlInputReadCallback   readcallback XML_DEPRECATED_MEMBER;
0129     xmlInputCloseCallback  closecallback XML_DEPRECATED_MEMBER;
0130 
0131     /* I18N conversions to UTF-8 */
0132     xmlCharEncodingHandler *encoder XML_DEPRECATED_MEMBER;
0133 
0134     /* Local buffer encoded in UTF-8 */
0135     xmlBuf *buffer XML_DEPRECATED_MEMBER;
0136     /* if encoder != NULL buffer for raw input */
0137     xmlBuf *raw XML_DEPRECATED_MEMBER;
0138     /* -1=unknown, 0=not compressed, 1=compressed */
0139     int compressed XML_DEPRECATED_MEMBER;
0140     int error XML_DEPRECATED_MEMBER;
0141     /* amount consumed from raw */
0142     unsigned long rawconsumed XML_DEPRECATED_MEMBER;
0143 };
0144 
0145 
0146 #ifdef LIBXML_OUTPUT_ENABLED
0147 /**
0148  * Output buffer
0149  */
0150 struct _xmlOutputBuffer {
0151     void*                   context;
0152     xmlOutputWriteCallback  writecallback;
0153     xmlOutputCloseCallback  closecallback;
0154 
0155     /* I18N conversions to UTF-8 */
0156     xmlCharEncodingHandler *encoder;
0157 
0158     /* Local buffer encoded in UTF-8 or ISOLatin */
0159     xmlBuf *buffer;
0160     /* if encoder != NULL buffer for output */
0161     xmlBuf *conv;
0162     /* total number of byte written */
0163     int written;
0164     int error;
0165 };
0166 #endif /* LIBXML_OUTPUT_ENABLED */
0167 
0168 /** @cond ignore */
0169 
0170 XML_DEPRECATED
0171 XMLPUBFUN xmlParserInputBufferCreateFilenameFunc *
0172 __xmlParserInputBufferCreateFilenameValue(void);
0173 XML_DEPRECATED
0174 XMLPUBFUN xmlOutputBufferCreateFilenameFunc *
0175 __xmlOutputBufferCreateFilenameValue(void);
0176 
0177 #ifndef XML_GLOBALS_NO_REDEFINITION
0178   #define xmlParserInputBufferCreateFilenameValue \
0179     (*__xmlParserInputBufferCreateFilenameValue())
0180   #define xmlOutputBufferCreateFilenameValue \
0181     (*__xmlOutputBufferCreateFilenameValue())
0182 #endif
0183 
0184 /** @endcond */
0185 
0186 /*
0187  * Interfaces for input
0188  */
0189 XMLPUBFUN void
0190     xmlCleanupInputCallbacks        (void);
0191 
0192 XMLPUBFUN int
0193     xmlPopInputCallbacks            (void);
0194 
0195 XMLPUBFUN void
0196     xmlRegisterDefaultInputCallbacks    (void);
0197 XMLPUBFUN xmlParserInputBuffer *
0198     xmlAllocParserInputBuffer       (xmlCharEncoding enc);
0199 
0200 XMLPUBFUN xmlParserInputBuffer *
0201     xmlParserInputBufferCreateFilename  (const char *URI,
0202                                                  xmlCharEncoding enc);
0203 XML_DEPRECATED
0204 XMLPUBFUN xmlParserInputBuffer *
0205     xmlParserInputBufferCreateFile      (FILE *file,
0206                                                  xmlCharEncoding enc);
0207 XMLPUBFUN xmlParserInputBuffer *
0208     xmlParserInputBufferCreateFd        (int fd,
0209                                              xmlCharEncoding enc);
0210 XMLPUBFUN xmlParserInputBuffer *
0211     xmlParserInputBufferCreateMem       (const char *mem, int size,
0212                                              xmlCharEncoding enc);
0213 XMLPUBFUN xmlParserInputBuffer *
0214     xmlParserInputBufferCreateStatic    (const char *mem, int size,
0215                                              xmlCharEncoding enc);
0216 XMLPUBFUN xmlParserInputBuffer *
0217     xmlParserInputBufferCreateIO        (xmlInputReadCallback   ioread,
0218                          xmlInputCloseCallback  ioclose,
0219                          void *ioctx,
0220                                              xmlCharEncoding enc);
0221 XML_DEPRECATED
0222 XMLPUBFUN int
0223     xmlParserInputBufferRead        (xmlParserInputBuffer *in,
0224                          int len);
0225 XML_DEPRECATED
0226 XMLPUBFUN int
0227     xmlParserInputBufferGrow        (xmlParserInputBuffer *in,
0228                          int len);
0229 XML_DEPRECATED
0230 XMLPUBFUN int
0231     xmlParserInputBufferPush        (xmlParserInputBuffer *in,
0232                          int len,
0233                          const char *buf);
0234 XMLPUBFUN void
0235     xmlFreeParserInputBuffer        (xmlParserInputBuffer *in);
0236 XMLPUBFUN char *
0237     xmlParserGetDirectory           (const char *filename);
0238 
0239 XMLPUBFUN int
0240     xmlRegisterInputCallbacks       (xmlInputMatchCallback matchFunc,
0241                          xmlInputOpenCallback openFunc,
0242                          xmlInputReadCallback readFunc,
0243                          xmlInputCloseCallback closeFunc);
0244 
0245 XMLPUBFUN xmlParserInputBuffer *
0246     __xmlParserInputBufferCreateFilename(const char *URI,
0247                         xmlCharEncoding enc);
0248 
0249 #ifdef LIBXML_OUTPUT_ENABLED
0250 /*
0251  * Interfaces for output
0252  */
0253 XMLPUBFUN void
0254     xmlCleanupOutputCallbacks       (void);
0255 XMLPUBFUN int
0256     xmlPopOutputCallbacks           (void);
0257 XMLPUBFUN void
0258     xmlRegisterDefaultOutputCallbacks(void);
0259 XMLPUBFUN xmlOutputBuffer *
0260     xmlAllocOutputBuffer        (xmlCharEncodingHandler *encoder);
0261 
0262 XMLPUBFUN xmlOutputBuffer *
0263     xmlOutputBufferCreateFilename   (const char *URI,
0264                      xmlCharEncodingHandler *encoder,
0265                      int compression);
0266 
0267 XMLPUBFUN xmlOutputBuffer *
0268     xmlOutputBufferCreateFile   (FILE *file,
0269                      xmlCharEncodingHandler *encoder);
0270 
0271 XMLPUBFUN xmlOutputBuffer *
0272     xmlOutputBufferCreateBuffer (xmlBuffer *buffer,
0273                      xmlCharEncodingHandler *encoder);
0274 
0275 XMLPUBFUN xmlOutputBuffer *
0276     xmlOutputBufferCreateFd     (int fd,
0277                      xmlCharEncodingHandler *encoder);
0278 
0279 XMLPUBFUN xmlOutputBuffer *
0280     xmlOutputBufferCreateIO     (xmlOutputWriteCallback   iowrite,
0281                      xmlOutputCloseCallback  ioclose,
0282                      void *ioctx,
0283                      xmlCharEncodingHandler *encoder);
0284 
0285 /* Couple of APIs to get the output without digging into the buffers */
0286 XMLPUBFUN const xmlChar *
0287         xmlOutputBufferGetContent       (xmlOutputBuffer *out);
0288 XMLPUBFUN size_t
0289         xmlOutputBufferGetSize          (xmlOutputBuffer *out);
0290 
0291 XMLPUBFUN int
0292     xmlOutputBufferWrite        (xmlOutputBuffer *out,
0293                      int len,
0294                      const char *buf);
0295 XMLPUBFUN int
0296     xmlOutputBufferWriteString  (xmlOutputBuffer *out,
0297                      const char *str);
0298 XMLPUBFUN int
0299     xmlOutputBufferWriteEscape  (xmlOutputBuffer *out,
0300                      const xmlChar *str,
0301                      xmlCharEncodingOutputFunc escaping);
0302 
0303 XMLPUBFUN int
0304     xmlOutputBufferFlush        (xmlOutputBuffer *out);
0305 XMLPUBFUN int
0306     xmlOutputBufferClose        (xmlOutputBuffer *out);
0307 
0308 XMLPUBFUN int
0309     xmlRegisterOutputCallbacks  (xmlOutputMatchCallback matchFunc,
0310                      xmlOutputOpenCallback openFunc,
0311                      xmlOutputWriteCallback writeFunc,
0312                      xmlOutputCloseCallback closeFunc);
0313 
0314 XMLPUBFUN xmlOutputBuffer *
0315     __xmlOutputBufferCreateFilename(const char *URI,
0316                               xmlCharEncodingHandler *encoder,
0317                               int compression);
0318 #endif /* LIBXML_OUTPUT_ENABLED */
0319 
0320 XML_DEPRECATED
0321 XMLPUBFUN xmlParserInput *
0322     xmlCheckHTTPInput       (xmlParserCtxt *ctxt,
0323                      xmlParserInput *ret);
0324 
0325 XML_DEPRECATED
0326 XMLPUBFUN xmlParserInput *
0327     xmlNoNetExternalEntityLoader    (const char *URL,
0328                      const char *ID,
0329                      xmlParserCtxt *ctxt);
0330 
0331 XML_DEPRECATED
0332 XMLPUBFUN xmlChar *
0333     xmlNormalizeWindowsPath     (const xmlChar *path);
0334 
0335 XML_DEPRECATED
0336 XMLPUBFUN int
0337     xmlCheckFilename        (const char *path);
0338 
0339 XML_DEPRECATED
0340 XMLPUBFUN int
0341     xmlFileMatch            (const char *filename);
0342 XML_DEPRECATED
0343 XMLPUBFUN void *
0344     xmlFileOpen         (const char *filename);
0345 XML_DEPRECATED
0346 XMLPUBFUN int
0347     xmlFileRead         (void * context,
0348                      char * buffer,
0349                      int len);
0350 XML_DEPRECATED
0351 XMLPUBFUN int
0352     xmlFileClose            (void * context);
0353 
0354 #ifdef LIBXML_HTTP_STUBS_ENABLED
0355 /** @cond IGNORE */
0356 XML_DEPRECATED
0357 XMLPUBFUN int
0358     xmlIOHTTPMatch          (const char *filename);
0359 XML_DEPRECATED
0360 XMLPUBFUN void *
0361     xmlIOHTTPOpen           (const char *filename);
0362 #ifdef LIBXML_OUTPUT_ENABLED
0363 XML_DEPRECATED
0364 XMLPUBFUN void
0365     xmlRegisterHTTPPostCallbacks    (void );
0366 XML_DEPRECATED
0367 XMLPUBFUN void *
0368     xmlIOHTTPOpenW          (const char * post_uri,
0369                      int   compression );
0370 #endif /* LIBXML_OUTPUT_ENABLED */
0371 XML_DEPRECATED
0372 XMLPUBFUN int
0373     xmlIOHTTPRead           (void * context,
0374                      char * buffer,
0375                      int len);
0376 XML_DEPRECATED
0377 XMLPUBFUN int
0378     xmlIOHTTPClose          (void * context);
0379 /** @endcond */
0380 #endif /* LIBXML_HTTP_STUBS_ENABLED */
0381 
0382 XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
0383     xmlParserInputBufferCreateFilenameDefault(
0384         xmlParserInputBufferCreateFilenameFunc func);
0385 XMLPUBFUN xmlOutputBufferCreateFilenameFunc
0386     xmlOutputBufferCreateFilenameDefault(
0387         xmlOutputBufferCreateFilenameFunc func);
0388 XML_DEPRECATED
0389 XMLPUBFUN xmlOutputBufferCreateFilenameFunc
0390     xmlThrDefOutputBufferCreateFilenameDefault(
0391         xmlOutputBufferCreateFilenameFunc func);
0392 XML_DEPRECATED
0393 XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
0394     xmlThrDefParserInputBufferCreateFilenameDefault(
0395         xmlParserInputBufferCreateFilenameFunc func);
0396 
0397 #ifdef __cplusplus
0398 }
0399 #endif
0400 
0401 #endif /* __XML_IO_H__ */