blob: e67b6e5580e8bfc9149524232a2b990ea58d717b [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
132 xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 */
133 xmlBufferPtr 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
148 xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */
149 xmlBufferPtr conv; /* if encoder != NULL buffer for output */
150 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
Owen Taylor3473f882001-02-23 17:55:21 +0000235 xmlOutputBufferCreateFd (int fd,
236 xmlCharEncodingHandlerPtr encoder);
237
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000238XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000239 xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
240 xmlOutputCloseCallback ioclose,
241 void *ioctx,
242 xmlCharEncodingHandlerPtr encoder);
243
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000244XMLPUBFUN int XMLCALL
245 xmlOutputBufferWrite (xmlOutputBufferPtr out,
Owen Taylor3473f882001-02-23 17:55:21 +0000246 int len,
247 const char *buf);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000248XMLPUBFUN int XMLCALL
249 xmlOutputBufferWriteString (xmlOutputBufferPtr out,
Owen Taylor3473f882001-02-23 17:55:21 +0000250 const char *str);
Daniel Veillard5d1a4d82004-05-13 14:31:25 +0000251XMLPUBFUN int XMLCALL
252 xmlOutputBufferWriteEscape (xmlOutputBufferPtr out,
Daniel Veillardee8960b2004-05-14 03:25:14 +0000253 const xmlChar *str,
254 xmlCharEncodingOutputFunc escaping);
Owen Taylor3473f882001-02-23 17:55:21 +0000255
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000256XMLPUBFUN int XMLCALL
257 xmlOutputBufferFlush (xmlOutputBufferPtr out);
258XMLPUBFUN int XMLCALL
259 xmlOutputBufferClose (xmlOutputBufferPtr out);
Owen Taylor3473f882001-02-23 17:55:21 +0000260
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000261XMLPUBFUN int XMLCALL
262 xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000263 xmlOutputOpenCallback openFunc,
264 xmlOutputWriteCallback writeFunc,
265 xmlOutputCloseCallback closeFunc);
Daniel Veillard1b243b42004-06-08 10:16:42 +0000266
267xmlOutputBufferPtr
268 __xmlOutputBufferCreateFilename(const char *URI,
269 xmlCharEncodingHandlerPtr encoder,
270 int compression);
Owen Taylor3473f882001-02-23 17:55:21 +0000271
Daniel Veillardf012a642001-07-23 19:10:52 +0000272#ifdef LIBXML_HTTP_ENABLED
William M. Brack21e4ef22005-01-02 09:53:13 +0000273/* This function only exists if HTTP support built into the library */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000274XMLPUBFUN void XMLCALL
275 xmlRegisterHTTPPostCallbacks (void );
William M. Brack21e4ef22005-01-02 09:53:13 +0000276#endif /* LIBXML_HTTP_ENABLED */
277
278#endif /* LIBXML_OUTPUT_ENABLED */
279
Daniel Veillarda840b692003-10-19 13:35:37 +0000280XMLPUBFUN xmlParserInputPtr XMLCALL
281 xmlCheckHTTPInput (xmlParserCtxtPtr ctxt,
282 xmlParserInputPtr ret);
Daniel Veillardf012a642001-07-23 19:10:52 +0000283
Owen Taylor3473f882001-02-23 17:55:21 +0000284/*
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000285 * A predefined entity loader disabling network accesses
286 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000287XMLPUBFUN xmlParserInputPtr XMLCALL
288 xmlNoNetExternalEntityLoader (const char *URL,
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000289 const char *ID,
290 xmlParserCtxtPtr ctxt);
291
Igor Zlatkovic5f9fada2003-02-19 14:51:00 +0000292/*
293 * xmlNormalizeWindowsPath is obsolete, don't use it.
294 * Check xmlCanonicPath in uri.h for a better alternative.
295 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000296XMLPUBFUN xmlChar * XMLCALL
297 xmlNormalizeWindowsPath (const xmlChar *path);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000298
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000299XMLPUBFUN int XMLCALL
300 xmlCheckFilename (const char *path);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000301/**
302 * Default 'file://' protocol callbacks
303 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000304XMLPUBFUN int XMLCALL
305 xmlFileMatch (const char *filename);
306XMLPUBFUN void * XMLCALL
307 xmlFileOpen (const char *filename);
308XMLPUBFUN int XMLCALL
309 xmlFileRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000310 char * buffer,
311 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000312XMLPUBFUN int XMLCALL
313 xmlFileClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000314
315/**
316 * Default 'http://' protocol callbacks
317 */
318#ifdef LIBXML_HTTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000319XMLPUBFUN int XMLCALL
320 xmlIOHTTPMatch (const char *filename);
321XMLPUBFUN void * XMLCALL
322 xmlIOHTTPOpen (const char *filename);
William M. Brack21e4ef22005-01-02 09:53:13 +0000323#ifdef LIBXML_OUTPUT_ENABLED
324XMLPUBFUN void * XMLCALL
325 xmlIOHTTPOpenW (const char * post_uri,
326 int compression );
327#endif /* LIBXML_OUTPUT_ENABLED */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000328XMLPUBFUN int XMLCALL
329 xmlIOHTTPRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000330 char * buffer,
331 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000332XMLPUBFUN int XMLCALL
333 xmlIOHTTPClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000334#endif /* LIBXML_HTTP_ENABLED */
335
336/**
337 * Default 'ftp://' protocol callbacks
338 */
339#ifdef LIBXML_FTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000340XMLPUBFUN int XMLCALL
341 xmlIOFTPMatch (const char *filename);
342XMLPUBFUN void * XMLCALL
343 xmlIOFTPOpen (const char *filename);
344XMLPUBFUN int XMLCALL
345 xmlIOFTPRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000346 char * buffer,
347 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000348XMLPUBFUN int XMLCALL
349 xmlIOFTPClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000350#endif /* LIBXML_FTP_ENABLED */
351
Owen Taylor3473f882001-02-23 17:55:21 +0000352#ifdef __cplusplus
353}
354#endif
355
356#endif /* __XML_IO_H__ */