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