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