blob: 8aad7a66acba261e09a9c24e2656b26c94c62728 [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 */
Owen Taylor3473f882001-02-23 17:55:21 +000034typedef int (*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 */
Owen Taylor3473f882001-02-23 17:55:21 +000043typedef void * (*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 */
Owen Taylor3473f882001-02-23 17:55:21 +000054typedef int (*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 Veillardf012a642001-07-23 19:10:52 +000063typedef int (*xmlInputCloseCallback) (void * context);
Owen Taylor3473f882001-02-23 17:55:21 +000064
Daniel Veillard1b243b42004-06-08 10:16:42 +000065typedef xmlParserInputBufferPtr (*xmlParserInputBufferCreateFilenameFunc) (const char *URI, xmlCharEncoding enc);
66typedef xmlOutputBufferPtr (*xmlOutputBufferCreateFilenameFunc) (const char *URI, xmlCharEncodingHandlerPtr encoder, int compression);
67
Daniel Veillarda9cce9c2003-09-29 13:20:24 +000068#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +000069/*
70 * Those are the functions and datatypes for the library output
71 * I/O structures.
72 */
73
Daniel Veillard9d06d302002-01-22 18:15:52 +000074/**
75 * xmlOutputMatchCallback:
76 * @filename: the filename or URI
77 *
78 * Callback used in the I/O Output API to detect if the current handler
79 * can provide output fonctionnalities for this resource.
80 *
81 * Returns 1 if yes and 0 if another Output module should be used
82 */
Owen Taylor3473f882001-02-23 17:55:21 +000083typedef int (*xmlOutputMatchCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000084/**
85 * xmlOutputOpenCallback:
86 * @filename: the filename or URI
87 *
88 * Callback used in the I/O Output API to open the resource
89 *
90 * Returns an Output context or NULL in case or error
91 */
Owen Taylor3473f882001-02-23 17:55:21 +000092typedef void * (*xmlOutputOpenCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000093/**
94 * xmlOutputWriteCallback:
95 * @context: an Output context
96 * @buffer: the buffer of data to write
97 * @len: the length of the buffer in bytes
98 *
99 * Callback used in the I/O Output API to write to the resource
100 *
101 * Returns the number of bytes written or -1 in case of error
102 */
Owen Taylor3473f882001-02-23 17:55:21 +0000103typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer,
104 int len);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000105/**
106 * xmlOutputCloseCallback:
107 * @context: an Output context
108 *
109 * Callback used in the I/O Output API to close the resource
110 *
111 * Returns 0 or -1 in case of error
112 */
Daniel Veillardf012a642001-07-23 19:10:52 +0000113typedef int (*xmlOutputCloseCallback) (void * context);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000114#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000115
Daniel Veillarda8a89fe2002-04-12 21:03:34 +0000116#ifdef __cplusplus
117}
118#endif
119
120#include <libxml/globals.h>
121#include <libxml/tree.h>
122#include <libxml/parser.h>
123#include <libxml/encoding.h>
124
125#ifdef __cplusplus
126extern "C" {
127#endif
128struct _xmlParserInputBuffer {
129 void* context;
130 xmlInputReadCallback readcallback;
131 xmlInputCloseCallback closecallback;
132
133 xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
134
135 xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 */
136 xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */
William M. Brackc07329e2003-09-08 01:57:30 +0000137 int compressed; /* -1=unknown, 0=not compressed, 1=compressed */
Daniel Veillard97bf4d02003-10-08 18:58:28 +0000138 int error;
Daniel Veillard36711902004-02-11 13:25:26 +0000139 unsigned long rawconsumed;/* amount consumed from raw */
Daniel Veillarda8a89fe2002-04-12 21:03:34 +0000140};
141
142
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000143#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000144struct _xmlOutputBuffer {
145 void* context;
146 xmlOutputWriteCallback writecallback;
147 xmlOutputCloseCallback closecallback;
148
149 xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
150
151 xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */
152 xmlBufferPtr conv; /* if encoder != NULL buffer for output */
153 int written; /* total number of byte written */
Daniel Veillard97bf4d02003-10-08 18:58:28 +0000154 int error;
Owen Taylor3473f882001-02-23 17:55:21 +0000155};
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000156#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000157
158/*
159 * Interfaces for input
160 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000161XMLPUBFUN void XMLCALL
162 xmlCleanupInputCallbacks (void);
Owen Taylor3473f882001-02-23 17:55:21 +0000163
Daniel Veillardaecc0dc2004-05-08 02:32:07 +0000164XMLPUBFUN int XMLCALL
165 xmlPopInputCallbacks (void);
166
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000167XMLPUBFUN void XMLCALL
168 xmlRegisterDefaultInputCallbacks (void);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000169XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000170 xmlAllocParserInputBuffer (xmlCharEncoding enc);
171
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000172XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000173 xmlParserInputBufferCreateFilename (const char *URI,
174 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000175XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000176 xmlParserInputBufferCreateFile (FILE *file,
177 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000178XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000179 xmlParserInputBufferCreateFd (int fd,
180 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000181XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000182 xmlParserInputBufferCreateMem (const char *mem, int size,
183 xmlCharEncoding enc);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000184XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Daniel Veillard53350552003-09-18 13:35:51 +0000185 xmlParserInputBufferCreateStatic (const char *mem, int size,
186 xmlCharEncoding enc);
187XMLPUBFUN xmlParserInputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000188 xmlParserInputBufferCreateIO (xmlInputReadCallback ioread,
189 xmlInputCloseCallback ioclose,
190 void *ioctx,
191 xmlCharEncoding enc);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000192XMLPUBFUN int XMLCALL
193 xmlParserInputBufferRead (xmlParserInputBufferPtr in,
Owen Taylor3473f882001-02-23 17:55:21 +0000194 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000195XMLPUBFUN int XMLCALL
196 xmlParserInputBufferGrow (xmlParserInputBufferPtr in,
Owen Taylor3473f882001-02-23 17:55:21 +0000197 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000198XMLPUBFUN int XMLCALL
199 xmlParserInputBufferPush (xmlParserInputBufferPtr in,
Owen Taylor3473f882001-02-23 17:55:21 +0000200 int len,
201 const char *buf);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000202XMLPUBFUN void XMLCALL
203 xmlFreeParserInputBuffer (xmlParserInputBufferPtr in);
204XMLPUBFUN char * XMLCALL
205 xmlParserGetDirectory (const char *filename);
Owen Taylor3473f882001-02-23 17:55:21 +0000206
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000207XMLPUBFUN int XMLCALL
208 xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000209 xmlInputOpenCallback openFunc,
210 xmlInputReadCallback readFunc,
211 xmlInputCloseCallback closeFunc);
Daniel Veillard1b243b42004-06-08 10:16:42 +0000212
213XMLPUBFUN xmlParserInputBufferCreateFilenameFunc XMLCALL
214 xmlParserInputBufferCreateFilenameDefault (xmlParserInputBufferCreateFilenameFunc func);
215XMLPUBFUN xmlOutputBufferCreateFilenameFunc XMLCALL
216 xmlOutputBufferCreateFilenameDefault (xmlOutputBufferCreateFilenameFunc func);
217
218xmlParserInputBufferPtr
219 __xmlParserInputBufferCreateFilename(const char *URI,
220 xmlCharEncoding enc);
221
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000222#ifdef LIBXML_OUTPUT_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000223/*
224 * Interfaces for output
225 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000226XMLPUBFUN void XMLCALL
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000227 xmlCleanupOutputCallbacks (void);
228XMLPUBFUN void XMLCALL
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000229 xmlRegisterDefaultOutputCallbacks(void);
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000230XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000231 xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder);
232
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000233XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000234 xmlOutputBufferCreateFilename (const char *URI,
235 xmlCharEncodingHandlerPtr encoder,
236 int compression);
237
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000238XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000239 xmlOutputBufferCreateFile (FILE *file,
240 xmlCharEncodingHandlerPtr encoder);
241
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000242XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000243 xmlOutputBufferCreateFd (int fd,
244 xmlCharEncodingHandlerPtr encoder);
245
Igor Zlatkovic76874e42003-08-25 09:05:12 +0000246XMLPUBFUN xmlOutputBufferPtr XMLCALL
Owen Taylor3473f882001-02-23 17:55:21 +0000247 xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
248 xmlOutputCloseCallback ioclose,
249 void *ioctx,
250 xmlCharEncodingHandlerPtr encoder);
251
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000252XMLPUBFUN int XMLCALL
253 xmlOutputBufferWrite (xmlOutputBufferPtr out,
Owen Taylor3473f882001-02-23 17:55:21 +0000254 int len,
255 const char *buf);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000256XMLPUBFUN int XMLCALL
257 xmlOutputBufferWriteString (xmlOutputBufferPtr out,
Owen Taylor3473f882001-02-23 17:55:21 +0000258 const char *str);
Daniel Veillard5d1a4d82004-05-13 14:31:25 +0000259XMLPUBFUN int XMLCALL
260 xmlOutputBufferWriteEscape (xmlOutputBufferPtr out,
Daniel Veillardee8960b2004-05-14 03:25:14 +0000261 const xmlChar *str,
262 xmlCharEncodingOutputFunc escaping);
Owen Taylor3473f882001-02-23 17:55:21 +0000263
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000264XMLPUBFUN int XMLCALL
265 xmlOutputBufferFlush (xmlOutputBufferPtr out);
266XMLPUBFUN int XMLCALL
267 xmlOutputBufferClose (xmlOutputBufferPtr out);
Owen Taylor3473f882001-02-23 17:55:21 +0000268
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000269XMLPUBFUN int XMLCALL
270 xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000271 xmlOutputOpenCallback openFunc,
272 xmlOutputWriteCallback writeFunc,
273 xmlOutputCloseCallback closeFunc);
Daniel Veillard1b243b42004-06-08 10:16:42 +0000274
275xmlOutputBufferPtr
276 __xmlOutputBufferCreateFilename(const char *URI,
277 xmlCharEncodingHandlerPtr encoder,
278 int compression);
Daniel Veillarda9cce9c2003-09-29 13:20:24 +0000279#endif /* LIBXML_OUTPUT_ENABLED */
Owen Taylor3473f882001-02-23 17:55:21 +0000280
Daniel Veillardf012a642001-07-23 19:10:52 +0000281/* This function only exists if HTTP support built into the library */
282#ifdef LIBXML_HTTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000283XMLPUBFUN void * XMLCALL
284 xmlIOHTTPOpenW (const char * post_uri,
Daniel Veillardf012a642001-07-23 19:10:52 +0000285 int compression );
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000286XMLPUBFUN void XMLCALL
287 xmlRegisterHTTPPostCallbacks (void );
Daniel Veillardf012a642001-07-23 19:10:52 +0000288#endif
Daniel Veillarda840b692003-10-19 13:35:37 +0000289XMLPUBFUN xmlParserInputPtr XMLCALL
290 xmlCheckHTTPInput (xmlParserCtxtPtr ctxt,
291 xmlParserInputPtr ret);
Daniel Veillardf012a642001-07-23 19:10:52 +0000292
Owen Taylor3473f882001-02-23 17:55:21 +0000293/*
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000294 * A predefined entity loader disabling network accesses
295 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000296XMLPUBFUN xmlParserInputPtr XMLCALL
297 xmlNoNetExternalEntityLoader (const char *URL,
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000298 const char *ID,
299 xmlParserCtxtPtr ctxt);
300
Igor Zlatkovic5f9fada2003-02-19 14:51:00 +0000301/*
302 * xmlNormalizeWindowsPath is obsolete, don't use it.
303 * Check xmlCanonicPath in uri.h for a better alternative.
304 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000305XMLPUBFUN xmlChar * XMLCALL
306 xmlNormalizeWindowsPath (const xmlChar *path);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000307
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000308XMLPUBFUN int XMLCALL
309 xmlCheckFilename (const char *path);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000310/**
311 * Default 'file://' protocol callbacks
312 */
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000313XMLPUBFUN int XMLCALL
314 xmlFileMatch (const char *filename);
315XMLPUBFUN void * XMLCALL
316 xmlFileOpen (const char *filename);
317XMLPUBFUN int XMLCALL
318 xmlFileRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000319 char * buffer,
320 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000321XMLPUBFUN int XMLCALL
322 xmlFileClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000323
324/**
325 * Default 'http://' protocol callbacks
326 */
327#ifdef LIBXML_HTTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000328XMLPUBFUN int XMLCALL
329 xmlIOHTTPMatch (const char *filename);
330XMLPUBFUN void * XMLCALL
331 xmlIOHTTPOpen (const char *filename);
332XMLPUBFUN int XMLCALL
333 xmlIOHTTPRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000334 char * buffer,
335 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000336XMLPUBFUN int XMLCALL
337 xmlIOHTTPClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000338#endif /* LIBXML_HTTP_ENABLED */
339
340/**
341 * Default 'ftp://' protocol callbacks
342 */
343#ifdef LIBXML_FTP_ENABLED
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000344XMLPUBFUN int XMLCALL
345 xmlIOFTPMatch (const char *filename);
346XMLPUBFUN void * XMLCALL
347 xmlIOFTPOpen (const char *filename);
348XMLPUBFUN int XMLCALL
349 xmlIOFTPRead (void * context,
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000350 char * buffer,
351 int len);
Igor Zlatkovicaa3cfbd2003-08-27 08:59:58 +0000352XMLPUBFUN int XMLCALL
353 xmlIOFTPClose (void * context);
Aleksey Sanin5aac8b82002-05-01 18:32:28 +0000354#endif /* LIBXML_FTP_ENABLED */
355
Owen Taylor3473f882001-02-23 17:55:21 +0000356#ifdef __cplusplus
357}
358#endif
359
360#endif /* __XML_IO_H__ */