1/**
2 * @file
3 *
4 * @brief I/O interfaces used by the parser
5 *
6 * Functions and datatypes for parser input and output.
7 *
8 * @copyright See Copyright for the status of this software.
9 *
10 * @author Daniel Veillard
11 */
12
13#ifndef __XML_IO_H__
14#define __XML_IO_H__
15
16#include <stdio.h>
17#include <libxml/xmlversion.h>
18#include <libxml/encoding.h>
19#define XML_TREE_INTERNALS
20#include <libxml/tree.h>
21#undef XML_TREE_INTERNALS
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/**
28 * Callback used in the I/O Input API to detect if the current handler
29 * can provide input functionality for this resource.
30 *
31 * @param filename the filename or URI
32 * @returns 1 if yes and 0 if another Input module should be used
33 */
34typedef int (*xmlInputMatchCallback) (const char *filename);
35/**
36 * Callback used in the I/O Input API to open the resource
37 *
38 * @param filename the filename or URI
39 * @returns an Input context or NULL in case or error
40 */
41typedef void * (*xmlInputOpenCallback) (const char *filename);
42/**
43 * Callback used in the I/O Input API to read the resource
44 *
45 * @param context an Input context
46 * @param buffer the buffer to store data read
47 * @param len the length of the buffer in bytes
48 * @returns the number of bytes read or -1 in case of error
49 */
50typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
51/**
52 * Callback used in the I/O Input API to close the resource
53 *
54 * @param context an Input context
55 * @returns 0 or -1 in case of error
56 */
57typedef int (*xmlInputCloseCallback) (void * context);
58
59#ifdef LIBXML_OUTPUT_ENABLED
60/**
61 * Callback used in the I/O Output API to detect if the current handler
62 * can provide output functionality for this resource.
63 *
64 * @param filename the filename or URI
65 * @returns 1 if yes and 0 if another Output module should be used
66 */
67typedef int (*xmlOutputMatchCallback) (const char *filename);
68/**
69 * Callback used in the I/O Output API to open the resource
70 *
71 * @param filename the filename or URI
72 * @returns an Output context or NULL in case or error
73 */
74typedef void * (*xmlOutputOpenCallback) (const char *filename);
75/**
76 * Callback used in the I/O Output API to write to the resource
77 *
78 * @param context an Output context
79 * @param buffer the buffer of data to write
80 * @param len the length of the buffer in bytes
81 * @returns the number of bytes written or -1 in case of error
82 */
83typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer,
84 int len);
85/**
86 * Callback used in the I/O Output API to close the resource
87 *
88 * @param context an Output context
89 * @returns 0 or -1 in case of error
90 */
91typedef int (*xmlOutputCloseCallback) (void * context);
92#endif /* LIBXML_OUTPUT_ENABLED */
93
94/**
95 * Signature for the function doing the lookup for a suitable input method
96 * corresponding to an URI.
97 *
98 * @param URI the URI to read from
99 * @param enc the requested source encoding
100 * @returns the new xmlParserInputBuffer in case of success or NULL if no
101 * method was found.
102 */
103typedef xmlParserInputBuffer *
104(*xmlParserInputBufferCreateFilenameFunc)(const char *URI, xmlCharEncoding enc);
105
106/**
107 * Signature for the function doing the lookup for a suitable output method
108 * corresponding to an URI.
109 *
110 * @param URI the URI to write to
111 * @param encoder the requested target encoding
112 * @param compression compression level
113 * @returns the new xmlOutputBuffer in case of success or NULL if no
114 * method was found.
115 */
116typedef xmlOutputBuffer *
117(*xmlOutputBufferCreateFilenameFunc)(const char *URI,
118 xmlCharEncodingHandler *encoder, int compression);
119
120/**
121 * Parser input buffer
122 *
123 * This struct and all related functions should ultimately
124 * be removed from the public interface.
125 */
126struct _xmlParserInputBuffer {
127 void* context XML_DEPRECATED_MEMBER;
128 xmlInputReadCallback readcallback XML_DEPRECATED_MEMBER;
129 xmlInputCloseCallback closecallback XML_DEPRECATED_MEMBER;
130
131 /* I18N conversions to UTF-8 */
132 xmlCharEncodingHandler *encoder XML_DEPRECATED_MEMBER;
133
134 /* Local buffer encoded in UTF-8 */
135 xmlBuf *buffer XML_DEPRECATED_MEMBER;
136 /* if encoder != NULL buffer for raw input */
137 xmlBuf *raw XML_DEPRECATED_MEMBER;
138 /* -1=unknown, 0=not compressed, 1=compressed */
139 int compressed XML_DEPRECATED_MEMBER;
140 int error XML_DEPRECATED_MEMBER;
141 /* amount consumed from raw */
142 unsigned long rawconsumed XML_DEPRECATED_MEMBER;
143};
144
145
146#ifdef LIBXML_OUTPUT_ENABLED
147/**
148 * Output buffer
149 */
150struct _xmlOutputBuffer {
151 void* context;
152 xmlOutputWriteCallback writecallback;
153 xmlOutputCloseCallback closecallback;
154
155 /* I18N conversions to UTF-8 */
156 xmlCharEncodingHandler *encoder;
157
158 /* Local buffer encoded in UTF-8 or ISOLatin */
159 xmlBuf *buffer;
160 /* if encoder != NULL buffer for output */
161 xmlBuf *conv;
162 /* total number of byte written */
163 int written;
164 int error;
165};
166#endif /* LIBXML_OUTPUT_ENABLED */
167
168/** @cond ignore */
169
170XML_DEPRECATED
171XMLPUBFUN xmlParserInputBufferCreateFilenameFunc *
172__xmlParserInputBufferCreateFilenameValue(void);
173XML_DEPRECATED
174XMLPUBFUN xmlOutputBufferCreateFilenameFunc *
175__xmlOutputBufferCreateFilenameValue(void);
176
177#ifndef XML_GLOBALS_NO_REDEFINITION
178 #define xmlParserInputBufferCreateFilenameValue \
179 (*__xmlParserInputBufferCreateFilenameValue())
180 #define xmlOutputBufferCreateFilenameValue \
181 (*__xmlOutputBufferCreateFilenameValue())
182#endif
183
184/** @endcond */
185
186/*
187 * Interfaces for input
188 */
189XMLPUBFUN void
190 xmlCleanupInputCallbacks (void);
191
192XMLPUBFUN int
193 xmlPopInputCallbacks (void);
194
195XMLPUBFUN void
196 xmlRegisterDefaultInputCallbacks (void);
197XMLPUBFUN xmlParserInputBuffer *
198 xmlAllocParserInputBuffer (xmlCharEncoding enc);
199
200XMLPUBFUN xmlParserInputBuffer *
201 xmlParserInputBufferCreateFilename (const char *URI,
202 xmlCharEncoding enc);
203XML_DEPRECATED
204XMLPUBFUN xmlParserInputBuffer *
205 xmlParserInputBufferCreateFile (FILE *file,
206 xmlCharEncoding enc);
207XMLPUBFUN xmlParserInputBuffer *
208 xmlParserInputBufferCreateFd (int fd,
209 xmlCharEncoding enc);
210XMLPUBFUN xmlParserInputBuffer *
211 xmlParserInputBufferCreateMem (const char *mem, int size,
212 xmlCharEncoding enc);
213XMLPUBFUN xmlParserInputBuffer *
214 xmlParserInputBufferCreateStatic (const char *mem, int size,
215 xmlCharEncoding enc);
216XMLPUBFUN xmlParserInputBuffer *
217 xmlParserInputBufferCreateIO (xmlInputReadCallback ioread,
218 xmlInputCloseCallback ioclose,
219 void *ioctx,
220 xmlCharEncoding enc);
221XML_DEPRECATED
222XMLPUBFUN int
223 xmlParserInputBufferRead (xmlParserInputBuffer *in,
224 int len);
225XML_DEPRECATED
226XMLPUBFUN int
227 xmlParserInputBufferGrow (xmlParserInputBuffer *in,
228 int len);
229XML_DEPRECATED
230XMLPUBFUN int
231 xmlParserInputBufferPush (xmlParserInputBuffer *in,
232 int len,
233 const char *buf);
234XMLPUBFUN void
235 xmlFreeParserInputBuffer (xmlParserInputBuffer *in);
236XMLPUBFUN char *
237 xmlParserGetDirectory (const char *filename);
238
239XMLPUBFUN int
240 xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
241 xmlInputOpenCallback openFunc,
242 xmlInputReadCallback readFunc,
243 xmlInputCloseCallback closeFunc);
244
245XMLPUBFUN xmlParserInputBuffer *
246 __xmlParserInputBufferCreateFilename(const char *URI,
247 xmlCharEncoding enc);
248
249#ifdef LIBXML_OUTPUT_ENABLED
250/*
251 * Interfaces for output
252 */
253XMLPUBFUN void
254 xmlCleanupOutputCallbacks (void);
255XMLPUBFUN int
256 xmlPopOutputCallbacks (void);
257XMLPUBFUN void
258 xmlRegisterDefaultOutputCallbacks(void);
259XMLPUBFUN xmlOutputBuffer *
260 xmlAllocOutputBuffer (xmlCharEncodingHandler *encoder);
261
262XMLPUBFUN xmlOutputBuffer *
263 xmlOutputBufferCreateFilename (const char *URI,
264 xmlCharEncodingHandler *encoder,
265 int compression);
266
267XMLPUBFUN xmlOutputBuffer *
268 xmlOutputBufferCreateFile (FILE *file,
269 xmlCharEncodingHandler *encoder);
270
271XMLPUBFUN xmlOutputBuffer *
272 xmlOutputBufferCreateBuffer (xmlBuffer *buffer,
273 xmlCharEncodingHandler *encoder);
274
275XMLPUBFUN xmlOutputBuffer *
276 xmlOutputBufferCreateFd (int fd,
277 xmlCharEncodingHandler *encoder);
278
279XMLPUBFUN xmlOutputBuffer *
280 xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
281 xmlOutputCloseCallback ioclose,
282 void *ioctx,
283 xmlCharEncodingHandler *encoder);
284
285/* Couple of APIs to get the output without digging into the buffers */
286XMLPUBFUN const xmlChar *
287 xmlOutputBufferGetContent (xmlOutputBuffer *out);
288XMLPUBFUN size_t
289 xmlOutputBufferGetSize (xmlOutputBuffer *out);
290
291XMLPUBFUN int
292 xmlOutputBufferWrite (xmlOutputBuffer *out,
293 int len,
294 const char *buf);
295XMLPUBFUN int
296 xmlOutputBufferWriteString (xmlOutputBuffer *out,
297 const char *str);
298XMLPUBFUN int
299 xmlOutputBufferWriteEscape (xmlOutputBuffer *out,
300 const xmlChar *str,
301 xmlCharEncodingOutputFunc escaping);
302
303XMLPUBFUN int
304 xmlOutputBufferFlush (xmlOutputBuffer *out);
305XMLPUBFUN int
306 xmlOutputBufferClose (xmlOutputBuffer *out);
307
308XMLPUBFUN int
309 xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
310 xmlOutputOpenCallback openFunc,
311 xmlOutputWriteCallback writeFunc,
312 xmlOutputCloseCallback closeFunc);
313
314XMLPUBFUN xmlOutputBuffer *
315 __xmlOutputBufferCreateFilename(const char *URI,
316 xmlCharEncodingHandler *encoder,
317 int compression);
318#endif /* LIBXML_OUTPUT_ENABLED */
319
320XML_DEPRECATED
321XMLPUBFUN xmlParserInput *
322 xmlCheckHTTPInput (xmlParserCtxt *ctxt,
323 xmlParserInput *ret);
324
325XML_DEPRECATED
326XMLPUBFUN xmlParserInput *
327 xmlNoNetExternalEntityLoader (const char *URL,
328 const char *ID,
329 xmlParserCtxt *ctxt);
330
331XML_DEPRECATED
332XMLPUBFUN xmlChar *
333 xmlNormalizeWindowsPath (const xmlChar *path);
334
335XML_DEPRECATED
336XMLPUBFUN int
337 xmlCheckFilename (const char *path);
338
339XML_DEPRECATED
340XMLPUBFUN int
341 xmlFileMatch (const char *filename);
342XML_DEPRECATED
343XMLPUBFUN void *
344 xmlFileOpen (const char *filename);
345XML_DEPRECATED
346XMLPUBFUN int
347 xmlFileRead (void * context,
348 char * buffer,
349 int len);
350XML_DEPRECATED
351XMLPUBFUN int
352 xmlFileClose (void * context);
353
354#ifdef LIBXML_HTTP_STUBS_ENABLED
355/** @cond IGNORE */
356XML_DEPRECATED
357XMLPUBFUN int
358 xmlIOHTTPMatch (const char *filename);
359XML_DEPRECATED
360XMLPUBFUN void *
361 xmlIOHTTPOpen (const char *filename);
362#ifdef LIBXML_OUTPUT_ENABLED
363XML_DEPRECATED
364XMLPUBFUN void
365 xmlRegisterHTTPPostCallbacks (void );
366XML_DEPRECATED
367XMLPUBFUN void *
368 xmlIOHTTPOpenW (const char * post_uri,
369 int compression );
370#endif /* LIBXML_OUTPUT_ENABLED */
371XML_DEPRECATED
372XMLPUBFUN int
373 xmlIOHTTPRead (void * context,
374 char * buffer,
375 int len);
376XML_DEPRECATED
377XMLPUBFUN int
378 xmlIOHTTPClose (void * context);
379/** @endcond */
380#endif /* LIBXML_HTTP_STUBS_ENABLED */
381
382XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
383 xmlParserInputBufferCreateFilenameDefault(
384 xmlParserInputBufferCreateFilenameFunc func);
385XMLPUBFUN xmlOutputBufferCreateFilenameFunc
386 xmlOutputBufferCreateFilenameDefault(
387 xmlOutputBufferCreateFilenameFunc func);
388XML_DEPRECATED
389XMLPUBFUN xmlOutputBufferCreateFilenameFunc
390 xmlThrDefOutputBufferCreateFilenameDefault(
391 xmlOutputBufferCreateFilenameFunc func);
392XML_DEPRECATED
393XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
394 xmlThrDefParserInputBufferCreateFilenameDefault(
395 xmlParserInputBufferCreateFilenameFunc func);
396
397#ifdef __cplusplus
398}
399#endif
400
401#endif /* __XML_IO_H__ */
402