blob: a633c5c99358223a0a2f33bfdb37733a31bc40ca [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * xmlIO.h : interface for the I/O interfaces used by the parser
3 *
4 * See Copyright for the status of this software.
5 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00006 * daniel@veillard.com
Owen Taylor3473f882001-02-23 17:55:21 +00007 *
8 * 15 Nov 2000 ht - modified for VMS
9 */
10
11#ifndef __XML_IO_H__
12#define __XML_IO_H__
13
14#include <stdio.h>
Daniel Veillard57905372001-07-31 15:52:17 +000015#if defined(WIN32) && defined(_MSC_VER)
16#include <libxml/xmlwin32version.h>
17#else
Daniel Veillardf012a642001-07-23 19:10:52 +000018#include <libxml/xmlversion.h>
Daniel Veillard57905372001-07-31 15:52:17 +000019#endif
Owen Taylor3473f882001-02-23 17:55:21 +000020
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/*
26 * Those are the functions and datatypes for the parser input
27 * I/O structures.
28 */
29
Daniel Veillard9d06d302002-01-22 18:15:52 +000030/**
31 * xmlInputMatchCallback:
32 * @filename: the filename or URI
33 *
34 * Callback used in the I/O Input API to detect if the current handler
35 * can provide input fonctionnalities for this resource.
36 *
37 * Returns 1 if yes and 0 if another Input module should be used
38 */
Owen Taylor3473f882001-02-23 17:55:21 +000039typedef int (*xmlInputMatchCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000040/**
41 * xmlInputOpenCallback:
42 * @filename: the filename or URI
43 *
44 * Callback used in the I/O Input API to open the resource
45 *
46 * Returns an Input context or NULL in case or error
47 */
Owen Taylor3473f882001-02-23 17:55:21 +000048typedef void * (*xmlInputOpenCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000049/**
50 * xmlInputReadCallback:
51 * @context: an Input context
52 * @buffer: the buffer to store data read
53 * @len: the length of the buffer in bytes
54 *
55 * Callback used in the I/O Input API to read the resource
56 *
57 * Returns the number of bytes read or -1 in case of error
58 */
Owen Taylor3473f882001-02-23 17:55:21 +000059typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
Daniel Veillard9d06d302002-01-22 18:15:52 +000060/**
61 * xmlInputCloseCallback:
62 * @context: an Input context
63 *
64 * Callback used in the I/O Input API to close the resource
65 *
66 * Returns 0 or -1 in case of error
67 */
Daniel Veillardf012a642001-07-23 19:10:52 +000068typedef int (*xmlInputCloseCallback) (void * context);
Owen Taylor3473f882001-02-23 17:55:21 +000069
Owen Taylor3473f882001-02-23 17:55:21 +000070/*
71 * Those are the functions and datatypes for the library output
72 * I/O structures.
73 */
74
Daniel Veillard9d06d302002-01-22 18:15:52 +000075/**
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 fonctionnalities for this resource.
81 *
82 * Returns 1 if yes and 0 if another Output module should be used
83 */
Owen Taylor3473f882001-02-23 17:55:21 +000084typedef int (*xmlOutputMatchCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000085/**
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 */
Owen Taylor3473f882001-02-23 17:55:21 +000093typedef void * (*xmlOutputOpenCallback) (char const *filename);
Daniel Veillard9d06d302002-01-22 18:15:52 +000094/**
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 */
Owen Taylor3473f882001-02-23 17:55:21 +0000104typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer,
105 int len);
Daniel Veillard9d06d302002-01-22 18:15:52 +0000106/**
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 */
Daniel Veillardf012a642001-07-23 19:10:52 +0000114typedef int (*xmlOutputCloseCallback) (void * context);
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 */
137};
138
139
Owen Taylor3473f882001-02-23 17:55:21 +0000140struct _xmlOutputBuffer {
141 void* context;
142 xmlOutputWriteCallback writecallback;
143 xmlOutputCloseCallback closecallback;
144
145 xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */
146
147 xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */
148 xmlBufferPtr conv; /* if encoder != NULL buffer for output */
149 int written; /* total number of byte written */
150};
151
152/*
153 * Interfaces for input
154 */
Daniel Veillardacf7ff02001-10-29 20:21:47 +0000155void xmlCleanupInputCallbacks (void);
156void xmlCleanupOutputCallbacks (void);
Owen Taylor3473f882001-02-23 17:55:21 +0000157
158void xmlRegisterDefaultInputCallbacks (void);
159xmlParserInputBufferPtr
160 xmlAllocParserInputBuffer (xmlCharEncoding enc);
161
162#ifdef VMS
163xmlParserInputBufferPtr
164 xmlParserInputBufferCreateFname (const char *URI,
165 xmlCharEncoding enc);
166#define xmlParserInputBufferCreateFilename xmlParserInputBufferCreateFname
167#else
168xmlParserInputBufferPtr
169 xmlParserInputBufferCreateFilename (const char *URI,
170 xmlCharEncoding enc);
171#endif
172
173xmlParserInputBufferPtr
174 xmlParserInputBufferCreateFile (FILE *file,
175 xmlCharEncoding enc);
176xmlParserInputBufferPtr
177 xmlParserInputBufferCreateFd (int fd,
178 xmlCharEncoding enc);
179xmlParserInputBufferPtr
180 xmlParserInputBufferCreateMem (const char *mem, int size,
181 xmlCharEncoding enc);
182xmlParserInputBufferPtr
183 xmlParserInputBufferCreateIO (xmlInputReadCallback ioread,
184 xmlInputCloseCallback ioclose,
185 void *ioctx,
186 xmlCharEncoding enc);
187int xmlParserInputBufferRead (xmlParserInputBufferPtr in,
188 int len);
189int xmlParserInputBufferGrow (xmlParserInputBufferPtr in,
190 int len);
191int xmlParserInputBufferPush (xmlParserInputBufferPtr in,
192 int len,
193 const char *buf);
194void xmlFreeParserInputBuffer (xmlParserInputBufferPtr in);
195char * xmlParserGetDirectory (const char *filename);
196
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000197int xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
198 xmlInputOpenCallback openFunc,
199 xmlInputReadCallback readFunc,
200 xmlInputCloseCallback closeFunc);
Owen Taylor3473f882001-02-23 17:55:21 +0000201/*
202 * Interfaces for output
203 */
204void xmlRegisterDefaultOutputCallbacks(void);
205xmlOutputBufferPtr
206 xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder);
207
208xmlOutputBufferPtr
209 xmlOutputBufferCreateFilename (const char *URI,
210 xmlCharEncodingHandlerPtr encoder,
211 int compression);
212
213xmlOutputBufferPtr
214 xmlOutputBufferCreateFile (FILE *file,
215 xmlCharEncodingHandlerPtr encoder);
216
217xmlOutputBufferPtr
218 xmlOutputBufferCreateFd (int fd,
219 xmlCharEncodingHandlerPtr encoder);
220
221xmlOutputBufferPtr
222 xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
223 xmlOutputCloseCallback ioclose,
224 void *ioctx,
225 xmlCharEncodingHandlerPtr encoder);
226
227int xmlOutputBufferWrite (xmlOutputBufferPtr out,
228 int len,
229 const char *buf);
230int xmlOutputBufferWriteString (xmlOutputBufferPtr out,
231 const char *str);
232
233int xmlOutputBufferFlush (xmlOutputBufferPtr out);
234int xmlOutputBufferClose (xmlOutputBufferPtr out);
235
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000236int xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
237 xmlOutputOpenCallback openFunc,
238 xmlOutputWriteCallback writeFunc,
239 xmlOutputCloseCallback closeFunc);
Owen Taylor3473f882001-02-23 17:55:21 +0000240
Daniel Veillardf012a642001-07-23 19:10:52 +0000241/* This function only exists if HTTP support built into the library */
242#ifdef LIBXML_HTTP_ENABLED
243void * xmlIOHTTPOpenW (const char * post_uri,
244 int compression );
Daniel Veillard5d90b6c2001-08-22 14:29:45 +0000245void xmlRegisterHTTPPostCallbacks (void );
Daniel Veillardf012a642001-07-23 19:10:52 +0000246#endif
247
Owen Taylor3473f882001-02-23 17:55:21 +0000248/*
Daniel Veillard8bdb91d2001-10-31 17:52:43 +0000249 * A predefined entity loader disabling network accesses
250 */
251xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL,
252 const char *ID,
253 xmlParserCtxtPtr ctxt);
254
Owen Taylor3473f882001-02-23 17:55:21 +0000255#ifdef __cplusplus
256}
257#endif
258
259#endif /* __XML_IO_H__ */