blob: 0ccaeafce4b268355af45e853d310daeb2fa47e8 [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
Daniel Veillardbe586972003-11-18 20:56:51 +00002 * Summary: interface for the I/O interfaces used by the parser
3 * Description: interface for the I/O interfaces used by the parser
Owen Taylor3473f882001-02-23 17:55:21 +00004 *
Daniel Veillardbe586972003-11-18 20:56:51 +00005 * Copy: See Copyright for the status of this software.
Owen Taylor3473f882001-02-23 17:55:21 +00006 *
Daniel Veillardbe586972003-11-18 20:56:51 +00007 * Author: Daniel Veillard
Owen Taylor3473f882001-02-23 17:55:21 +00008 */
9
10#ifndef __XML_IO_H__
11#define __XML_IO_H__
12
13#include <stdio.h>
Daniel Veillardf012a642001-07-23 19:10:52 +000014#include <libxml/xmlversion.h>
Owen Taylor3473f882001-02-23 17:55:21 +000015
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/*
21 * Those are the functions and datatypes for the parser input
22 * I/O structures.
23 */
24
Daniel Veillard9d06d302002-01-22 18:15:52 +000025/**
26 * xmlInputMatchCallback:
27 * @filename: the filename or URI
28 *
29 * Callback used in the I/O Input API to detect if the current handler
30 * can provide input fonctionnalities for this resource.
31 *
32 * Returns 1 if yes and 0 if another Input module should be used
33 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000034typedef int (XMLCALL *xmlInputMatchCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000035/**
36 * xmlInputOpenCallback:
37 * @filename: the filename or URI
38 *
39 * Callback used in the I/O Input API to open the resource
40 *
41 * Returns an Input context or NULL in case or error
42 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000043typedef void * (XMLCALL *xmlInputOpenCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000044/**
45 * xmlInputReadCallback:
46 * @context: an Input context
47 * @buffer: the buffer to store data read
48 * @len: the length of the buffer in bytes
49 *
50 * Callback used in the I/O Input API to read the resource
51 *
52 * Returns the number of bytes read or -1 in case of error
53 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000054typedef int (XMLCALL *xmlInputReadCallback) (void * context, char * buffer, int len);
Daniel Veillard9d06d302002-01-22 18:15:52 +000055/**
56 * xmlInputCloseCallback:
57 * @context: an Input context
58 *
59 * Callback used in the I/O Input API to close the resource
60 *
61 * Returns 0 or -1 in case of error
62 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000063typedef int (XMLCALL *xmlInputCloseCallback) (void * context);
Owen Taylor3473f882001-02-23 17:55:21 +000064
Daniel Veillarda9cce9c2003-09-29 13:20:24 +000065#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +000066/*
67 * Those are the functions and datatypes for the library output
68 * I/O structures.
69 */
70
Daniel Veillard9d06d302002-01-22 18:15:52 +000071/**
72 * xmlOutputMatchCallback:
73 * @filename: the filename or URI
74 *
75 * Callback used in the I/O Output API to detect if the current handler
76 * can provide output fonctionnalities for this resource.
77 *
78 * Returns 1 if yes and 0 if another Output module should be used
79 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000080typedef int (XMLCALL *xmlOutputMatchCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000081/**
82 * xmlOutputOpenCallback:
83 * @filename: the filename or URI
84 *
85 * Callback used in the I/O Output API to open the resource
86 *
87 * Returns an Output context or NULL in case or error
88 */
Daniel Veillardffa3c742005-07-21 13:24:09 +000089typedef void * (XMLCALL *xmlOutputOpenCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000090/**
91 * xmlOutputWriteCallback:
92 * @context: an Output context
93 * @buffer: the buffer of data to write
94 * @len: the length of the buffer in bytes
95 *
96 * Callback used in the I/O Output API to write to the resource
97 *
98 * Returns the number of bytes written or -1 in case of error
99 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000100typedef int (XMLCALL *xmlOutputWriteCallback) (void * context, const char * buffer,
Owen Taylor3473f882001-02-23 17:55:21 +0000101 int len);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000102/**
103 * xmlOutputCloseCallback:
104 * @context: an Output context
105 *
106 * Callback used in the I/O Output API to close the resource
107 *
108 * Returns 0 or -1 in case of error
109 */
Daniel Veillardffa3c742005-07-21 13:24:09 +0000110typedef int (XMLCALL *xmlOutputCloseCallback) (void * context);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000111#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000112
Daniel Veillarda8a89fe2002-04-12 21:03:34 +0000113#ifdef __cplusplus
114}
115#endif
116
117#include <libxml/globals.h>
118#include <libxml/tree.h>
119#include <libxml/parser.h>
120#include <libxml/encoding.h>
121
122#ifdef __cplusplus
123extern "C" {
124#endif
125struct _xmlParserInputBuffer {
126 void* context;
127 xmlInputReadCallback readcallback;
128 xmlInputCloseCallback closecallback;
129
130 xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
131
Daniel Veillard65c7d3b2012-07-16 14:13:58 +0800132 xmlBufPtr buffer; /* Local buffer encoded in UTF-8 */
133 xmlBufPtr raw; /* if encoder != NULL buffer for raw input */
William M. Brackc07329e2003-09-08 01:57:30 +0000134 int compressed; /* -1=unknown, 0=not compressed, 1=compressed */
Daniel Veillard97bf4d02003-10-08 18:58:28 +0000135 int error;
Daniel Veillard36711902004-02-11 13:25:26 +0000136 unsigned long rawconsumed;/* amount consumed from raw */
Daniel Veillarda8a89fe2002-04-12 21:03:34 +0000137};
138
139
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000140#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000141struct _xmlOutputBuffer {
142 void* context;
143 xmlOutputWriteCallback writecallback;
144 xmlOutputCloseCallback closecallback;
145
146 xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
147
Daniel Veillard65c7d3b2012-07-16 14:13:58 +0800148 xmlBufPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */
149 xmlBufPtr conv; /* if encoder != NULL buffer for output */
Owen Taylor3473f882001-02-23 17:55:21 +0000150 int written; /* total number of byte written */
Daniel Veillard97bf4d02003-10-08 18:58:28 +0000151 int error;
Owen Taylor3473f882001-02-23 17:55:21 +0000152};
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000153#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000154
155/*
156 * Interfaces for input
157 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000158XMLPUBFUN void XMLCALL
159 xmlCleanupInputCallbacks (void);
Owen Taylor3473f882001-02-23 17:55:21 +0000160
Daniel Veillardaecc0dc2004-05-08 02:32:07 +0000161XMLPUBFUN int XMLCALL
162 xmlPopInputCallbacks (void);
163
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000164XMLPUBFUN void XMLCALL
165 xmlRegisterDefaultInputCallbacks (void);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000166XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000167 xmlAllocParserInputBuffer (xmlCharEncoding enc);
168
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000169XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000170 xmlParserInputBufferCreateFilename (const char *URI,
171 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000172XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000173 xmlParserInputBufferCreateFile (FILE *file,
174 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000175XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000176 xmlParserInputBufferCreateFd (int fd,
177 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000178XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000179 xmlParserInputBufferCreateMem (const char *mem, int size,
180 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000181XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Daniel Veillard53350552003-09-18 13:35:51 +0000182 xmlParserInputBufferCreateStatic (const char *mem, int size,
183 xmlCharEncoding enc);
184XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000185 xmlParserInputBufferCreateIO (xmlInputReadCallback ioread,
186 xmlInputCloseCallback ioclose,
187 void *ioctx,
188 xmlCharEncoding enc);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000189XMLPUBFUN int XMLCALL
190 xmlParserInputBufferRead (xmlParserInputBufferPtr in,
Owen Taylor3473f882001-02-23 17:55:21 +0000191 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000192XMLPUBFUN int XMLCALL
193 xmlParserInputBufferGrow (xmlParserInputBufferPtr in,
Owen Taylor3473f882001-02-23 17:55:21 +0000194 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000195XMLPUBFUN int XMLCALL
196 xmlParserInputBufferPush (xmlParserInputBufferPtr in,
Owen Taylor3473f882001-02-23 17:55:21 +0000197 int len,
198 const char *buf);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000199XMLPUBFUN void XMLCALL
200 xmlFreeParserInputBuffer (xmlParserInputBufferPtr in);
201XMLPUBFUN char * XMLCALL
202 xmlParserGetDirectory (const char *filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000203
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000204XMLPUBFUN int XMLCALL
205 xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000206 xmlInputOpenCallback openFunc,
207 xmlInputReadCallback readFunc,
208 xmlInputCloseCallback closeFunc);
Daniel Veillard1b243b42004-06-08 10:16:42 +0000209
Daniel Veillard1b243b42004-06-08 10:16:42 +0000210xmlParserInputBufferPtr
211 __xmlParserInputBufferCreateFilename(const char *URI,
212 xmlCharEncoding enc);
213
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000214#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000215/*
216 * Interfaces for output
217 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000218XMLPUBFUN void XMLCALL
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000219 xmlCleanupOutputCallbacks (void);
220XMLPUBFUN void XMLCALL
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000221 xmlRegisterDefaultOutputCallbacks(void);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000222XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000223 xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder);
224
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000225XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000226 xmlOutputBufferCreateFilename (const char *URI,
227 xmlCharEncodingHandlerPtr encoder,
228 int compression);
229
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000230XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000231 xmlOutputBufferCreateFile (FILE *file,
232 xmlCharEncodingHandlerPtr encoder);
233
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000234XMLPUBFUN xmlOutputBufferPtr XMLCALL
Daniel Veillard9a00fd22005-11-09 08:56:26 +0000235 xmlOutputBufferCreateBuffer (xmlBufferPtr buffer,
236 xmlCharEncodingHandlerPtr encoder);
237
238XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000239 xmlOutputBufferCreateFd (int fd,
240 xmlCharEncodingHandlerPtr encoder);
241
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000242XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000243 xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
244 xmlOutputCloseCallback ioclose,
245 void *ioctx,
246 xmlCharEncodingHandlerPtr encoder);
247
Daniel Veillarde258ade2012-08-06 11:16:30 +0800248/* Couple of APIs to get the output without digging into the buffers */
249XMLPUBFUN const xmlChar * XMLCALL
250 xmlOutputBufferGetContent (xmlOutputBufferPtr out);
251XMLPUBFUN size_t XMLCALL
252 xmlOutputBufferGetSize (xmlOutputBufferPtr out);
253
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000254XMLPUBFUN int XMLCALL
255 xmlOutputBufferWrite (xmlOutputBufferPtr out,
Owen Taylor3473f882001-02-23 17:55:21 +0000256 int len,
257 const char *buf);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000258XMLPUBFUN int XMLCALL
259 xmlOutputBufferWriteString (xmlOutputBufferPtr out,
Owen Taylor3473f882001-02-23 17:55:21 +0000260 const char *str);
Daniel Veillard5d1a4d82004-05-13 14:31:25 +0000261XMLPUBFUN int XMLCALL
262 xmlOutputBufferWriteEscape (xmlOutputBufferPtr out,
Daniel Veillardee8960b2004-05-14 03:25:14 +0000263 const xmlChar *str,
264 xmlCharEncodingOutputFunc escaping);
Owen Taylor3473f882001-02-23 17:55:21 +0000265
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000266XMLPUBFUN int XMLCALL
267 xmlOutputBufferFlush (xmlOutputBufferPtr out);
268XMLPUBFUN int XMLCALL
269 xmlOutputBufferClose (xmlOutputBufferPtr out);
Owen Taylor3473f882001-02-23 17:55:21 +0000270
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000271XMLPUBFUN int XMLCALL
272 xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000273 xmlOutputOpenCallback openFunc,
274 xmlOutputWriteCallback writeFunc,
275 xmlOutputCloseCallback closeFunc);
Daniel Veillard1b243b42004-06-08 10:16:42 +0000276
277xmlOutputBufferPtr
278 __xmlOutputBufferCreateFilename(const char *URI,
279 xmlCharEncodingHandlerPtr encoder,
280 int compression);
Owen Taylor3473f882001-02-23 17:55:21 +0000281
Daniel Veillardf012a642001-07-23 19:10:52 +0000282#ifdef LIBXML_HTTP_ENABLED
William M. Brack21e4ef22005-01-02 09:53:13 +0000283/* This function only exists if HTTP support built into the library */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000284XMLPUBFUN void XMLCALL
285 xmlRegisterHTTPPostCallbacks (void );
William M. Brack21e4ef22005-01-02 09:53:13 +0000286#endif /* LIBXML_HTTP_ENABLED */
287
288#endif /* LIBXML_OUTPUT_ENABLED */
289
Daniel Veillarda840b692003-10-19 13:35:37 +0000290XMLPUBFUN xmlParserInputPtr XMLCALL
291 xmlCheckHTTPInput (xmlParserCtxtPtr ctxt,
292 xmlParserInputPtr ret);
Daniel Veillardf012a642001-07-23 19:10:52 +0000293
Owen Taylor3473f882001-02-23 17:55:21 +0000294/*
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000295 * A predefined entity loader disabling network accesses
296 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000297XMLPUBFUN xmlParserInputPtr XMLCALL
298 xmlNoNetExternalEntityLoader (const char *URL,
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000299 const char *ID,
300 xmlParserCtxtPtr ctxt);
301
Igor Zlatkovic5f9fada2003-02-19 14:51:00 +0000302/*
303 * xmlNormalizeWindowsPath is obsolete, don't use it.
304 * Check xmlCanonicPath in uri.h for a better alternative.
305 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000306XMLPUBFUN xmlChar * XMLCALL
307 xmlNormalizeWindowsPath (const xmlChar *path);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000308
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000309XMLPUBFUN int XMLCALL
310 xmlCheckFilename (const char *path);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000311/**
312 * Default 'file://' protocol callbacks
313 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000314XMLPUBFUN int XMLCALL
315 xmlFileMatch (const char *filename);
316XMLPUBFUN void * XMLCALL
317 xmlFileOpen (const char *filename);
318XMLPUBFUN int XMLCALL
319 xmlFileRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000320 char * buffer,
321 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000322XMLPUBFUN int XMLCALL
323 xmlFileClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000324
325/**
326 * Default 'http://' protocol callbacks
327 */
328#ifdef LIBXML_HTTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000329XMLPUBFUN int XMLCALL
330 xmlIOHTTPMatch (const char *filename);
331XMLPUBFUN void * XMLCALL
332 xmlIOHTTPOpen (const char *filename);
William M. Brack21e4ef22005-01-02 09:53:13 +0000333#ifdef LIBXML_OUTPUT_ENABLED
334XMLPUBFUN void * XMLCALL
335 xmlIOHTTPOpenW (const char * post_uri,
336 int compression );
337#endif /* LIBXML_OUTPUT_ENABLED */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000338XMLPUBFUN int XMLCALL
339 xmlIOHTTPRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000340 char * buffer,
341 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000342XMLPUBFUN int XMLCALL
343 xmlIOHTTPClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000344#endif /* LIBXML_HTTP_ENABLED */
345
346/**
347 * Default 'ftp://' protocol callbacks
348 */
349#ifdef LIBXML_FTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000350XMLPUBFUN int XMLCALL
351 xmlIOFTPMatch (const char *filename);
352XMLPUBFUN void * XMLCALL
353 xmlIOFTPOpen (const char *filename);
354XMLPUBFUN int XMLCALL
355 xmlIOFTPRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000356 char * buffer,
357 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000358XMLPUBFUN int XMLCALL
359 xmlIOFTPClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000360#endif /* LIBXML_FTP_ENABLED */
361
Owen Taylor3473f882001-02-23 17:55:21 +0000362#ifdef __cplusplus
363}
364#endif
365
366#endif /* __XML_IO_H__ */