| 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 |
| 24 | extern "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 | */ |
| 34 | typedef 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 | */ |
| 41 | typedef 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 | */ |
| 50 | typedef 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 | */ |
| 57 | typedef 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 | */ |
| 67 | typedef 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 | */ |
| 74 | typedef 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 | */ |
| 83 | typedef 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 | */ |
| 91 | typedef 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 | */ |
| 103 | typedef 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 | */ |
| 116 | typedef 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 | */ |
| 126 | struct _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 | */ |
| 150 | struct _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 | |
| 170 | XML_DEPRECATED |
| 171 | XMLPUBFUN xmlParserInputBufferCreateFilenameFunc * |
| 172 | __xmlParserInputBufferCreateFilenameValue(void); |
| 173 | XML_DEPRECATED |
| 174 | XMLPUBFUN 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 | */ |
| 189 | XMLPUBFUN void |
| 190 | xmlCleanupInputCallbacks (void); |
| 191 | |
| 192 | XMLPUBFUN int |
| 193 | xmlPopInputCallbacks (void); |
| 194 | |
| 195 | XMLPUBFUN void |
| 196 | xmlRegisterDefaultInputCallbacks (void); |
| 197 | XMLPUBFUN xmlParserInputBuffer * |
| 198 | xmlAllocParserInputBuffer (xmlCharEncoding enc); |
| 199 | |
| 200 | XMLPUBFUN xmlParserInputBuffer * |
| 201 | xmlParserInputBufferCreateFilename (const char *URI, |
| 202 | xmlCharEncoding enc); |
| 203 | XML_DEPRECATED |
| 204 | XMLPUBFUN xmlParserInputBuffer * |
| 205 | xmlParserInputBufferCreateFile (FILE *file, |
| 206 | xmlCharEncoding enc); |
| 207 | XMLPUBFUN xmlParserInputBuffer * |
| 208 | xmlParserInputBufferCreateFd (int fd, |
| 209 | xmlCharEncoding enc); |
| 210 | XMLPUBFUN xmlParserInputBuffer * |
| 211 | xmlParserInputBufferCreateMem (const char *mem, int size, |
| 212 | xmlCharEncoding enc); |
| 213 | XMLPUBFUN xmlParserInputBuffer * |
| 214 | xmlParserInputBufferCreateStatic (const char *mem, int size, |
| 215 | xmlCharEncoding enc); |
| 216 | XMLPUBFUN xmlParserInputBuffer * |
| 217 | xmlParserInputBufferCreateIO (xmlInputReadCallback ioread, |
| 218 | xmlInputCloseCallback ioclose, |
| 219 | void *ioctx, |
| 220 | xmlCharEncoding enc); |
| 221 | XML_DEPRECATED |
| 222 | XMLPUBFUN int |
| 223 | xmlParserInputBufferRead (xmlParserInputBuffer *in, |
| 224 | int len); |
| 225 | XML_DEPRECATED |
| 226 | XMLPUBFUN int |
| 227 | xmlParserInputBufferGrow (xmlParserInputBuffer *in, |
| 228 | int len); |
| 229 | XML_DEPRECATED |
| 230 | XMLPUBFUN int |
| 231 | xmlParserInputBufferPush (xmlParserInputBuffer *in, |
| 232 | int len, |
| 233 | const char *buf); |
| 234 | XMLPUBFUN void |
| 235 | xmlFreeParserInputBuffer (xmlParserInputBuffer *in); |
| 236 | XMLPUBFUN char * |
| 237 | xmlParserGetDirectory (const char *filename); |
| 238 | |
| 239 | XMLPUBFUN int |
| 240 | xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc, |
| 241 | xmlInputOpenCallback openFunc, |
| 242 | xmlInputReadCallback readFunc, |
| 243 | xmlInputCloseCallback closeFunc); |
| 244 | |
| 245 | XMLPUBFUN xmlParserInputBuffer * |
| 246 | __xmlParserInputBufferCreateFilename(const char *URI, |
| 247 | xmlCharEncoding enc); |
| 248 | |
| 249 | #ifdef LIBXML_OUTPUT_ENABLED |
| 250 | /* |
| 251 | * Interfaces for output |
| 252 | */ |
| 253 | XMLPUBFUN void |
| 254 | xmlCleanupOutputCallbacks (void); |
| 255 | XMLPUBFUN int |
| 256 | xmlPopOutputCallbacks (void); |
| 257 | XMLPUBFUN void |
| 258 | xmlRegisterDefaultOutputCallbacks(void); |
| 259 | XMLPUBFUN xmlOutputBuffer * |
| 260 | xmlAllocOutputBuffer (xmlCharEncodingHandler *encoder); |
| 261 | |
| 262 | XMLPUBFUN xmlOutputBuffer * |
| 263 | xmlOutputBufferCreateFilename (const char *URI, |
| 264 | xmlCharEncodingHandler *encoder, |
| 265 | int compression); |
| 266 | |
| 267 | XMLPUBFUN xmlOutputBuffer * |
| 268 | xmlOutputBufferCreateFile (FILE *file, |
| 269 | xmlCharEncodingHandler *encoder); |
| 270 | |
| 271 | XMLPUBFUN xmlOutputBuffer * |
| 272 | xmlOutputBufferCreateBuffer (xmlBuffer *buffer, |
| 273 | xmlCharEncodingHandler *encoder); |
| 274 | |
| 275 | XMLPUBFUN xmlOutputBuffer * |
| 276 | xmlOutputBufferCreateFd (int fd, |
| 277 | xmlCharEncodingHandler *encoder); |
| 278 | |
| 279 | XMLPUBFUN 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 */ |
| 286 | XMLPUBFUN const xmlChar * |
| 287 | xmlOutputBufferGetContent (xmlOutputBuffer *out); |
| 288 | XMLPUBFUN size_t |
| 289 | xmlOutputBufferGetSize (xmlOutputBuffer *out); |
| 290 | |
| 291 | XMLPUBFUN int |
| 292 | xmlOutputBufferWrite (xmlOutputBuffer *out, |
| 293 | int len, |
| 294 | const char *buf); |
| 295 | XMLPUBFUN int |
| 296 | xmlOutputBufferWriteString (xmlOutputBuffer *out, |
| 297 | const char *str); |
| 298 | XMLPUBFUN int |
| 299 | xmlOutputBufferWriteEscape (xmlOutputBuffer *out, |
| 300 | const xmlChar *str, |
| 301 | xmlCharEncodingOutputFunc escaping); |
| 302 | |
| 303 | XMLPUBFUN int |
| 304 | xmlOutputBufferFlush (xmlOutputBuffer *out); |
| 305 | XMLPUBFUN int |
| 306 | xmlOutputBufferClose (xmlOutputBuffer *out); |
| 307 | |
| 308 | XMLPUBFUN int |
| 309 | xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc, |
| 310 | xmlOutputOpenCallback openFunc, |
| 311 | xmlOutputWriteCallback writeFunc, |
| 312 | xmlOutputCloseCallback closeFunc); |
| 313 | |
| 314 | XMLPUBFUN xmlOutputBuffer * |
| 315 | __xmlOutputBufferCreateFilename(const char *URI, |
| 316 | xmlCharEncodingHandler *encoder, |
| 317 | int compression); |
| 318 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 319 | |
| 320 | XML_DEPRECATED |
| 321 | XMLPUBFUN xmlParserInput * |
| 322 | xmlCheckHTTPInput (xmlParserCtxt *ctxt, |
| 323 | xmlParserInput *ret); |
| 324 | |
| 325 | XML_DEPRECATED |
| 326 | XMLPUBFUN xmlParserInput * |
| 327 | xmlNoNetExternalEntityLoader (const char *URL, |
| 328 | const char *ID, |
| 329 | xmlParserCtxt *ctxt); |
| 330 | |
| 331 | XML_DEPRECATED |
| 332 | XMLPUBFUN xmlChar * |
| 333 | xmlNormalizeWindowsPath (const xmlChar *path); |
| 334 | |
| 335 | XML_DEPRECATED |
| 336 | XMLPUBFUN int |
| 337 | xmlCheckFilename (const char *path); |
| 338 | |
| 339 | XML_DEPRECATED |
| 340 | XMLPUBFUN int |
| 341 | xmlFileMatch (const char *filename); |
| 342 | XML_DEPRECATED |
| 343 | XMLPUBFUN void * |
| 344 | xmlFileOpen (const char *filename); |
| 345 | XML_DEPRECATED |
| 346 | XMLPUBFUN int |
| 347 | xmlFileRead (void * context, |
| 348 | char * buffer, |
| 349 | int len); |
| 350 | XML_DEPRECATED |
| 351 | XMLPUBFUN int |
| 352 | xmlFileClose (void * context); |
| 353 | |
| 354 | #ifdef LIBXML_HTTP_STUBS_ENABLED |
| 355 | /** @cond IGNORE */ |
| 356 | XML_DEPRECATED |
| 357 | XMLPUBFUN int |
| 358 | xmlIOHTTPMatch (const char *filename); |
| 359 | XML_DEPRECATED |
| 360 | XMLPUBFUN void * |
| 361 | xmlIOHTTPOpen (const char *filename); |
| 362 | #ifdef LIBXML_OUTPUT_ENABLED |
| 363 | XML_DEPRECATED |
| 364 | XMLPUBFUN void |
| 365 | xmlRegisterHTTPPostCallbacks (void ); |
| 366 | XML_DEPRECATED |
| 367 | XMLPUBFUN void * |
| 368 | xmlIOHTTPOpenW (const char * post_uri, |
| 369 | int compression ); |
| 370 | #endif /* LIBXML_OUTPUT_ENABLED */ |
| 371 | XML_DEPRECATED |
| 372 | XMLPUBFUN int |
| 373 | xmlIOHTTPRead (void * context, |
| 374 | char * buffer, |
| 375 | int len); |
| 376 | XML_DEPRECATED |
| 377 | XMLPUBFUN int |
| 378 | xmlIOHTTPClose (void * context); |
| 379 | /** @endcond */ |
| 380 | #endif /* LIBXML_HTTP_STUBS_ENABLED */ |
| 381 | |
| 382 | XMLPUBFUN xmlParserInputBufferCreateFilenameFunc |
| 383 | xmlParserInputBufferCreateFilenameDefault( |
| 384 | xmlParserInputBufferCreateFilenameFunc func); |
| 385 | XMLPUBFUN xmlOutputBufferCreateFilenameFunc |
| 386 | xmlOutputBufferCreateFilenameDefault( |
| 387 | xmlOutputBufferCreateFilenameFunc func); |
| 388 | XML_DEPRECATED |
| 389 | XMLPUBFUN xmlOutputBufferCreateFilenameFunc |
| 390 | xmlThrDefOutputBufferCreateFilenameDefault( |
| 391 | xmlOutputBufferCreateFilenameFunc func); |
| 392 | XML_DEPRECATED |
| 393 | XMLPUBFUN xmlParserInputBufferCreateFilenameFunc |
| 394 | xmlThrDefParserInputBufferCreateFilenameDefault( |
| 395 | xmlParserInputBufferCreateFilenameFunc func); |
| 396 | |
| 397 | #ifdef __cplusplus |
| 398 | } |
| 399 | #endif |
| 400 | |
| 401 | #endif /* __XML_IO_H__ */ |
| 402 | |