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 XML_DEPRECATED 220 XMLPUBFUN xmlParserInputBufferPtr 221 xmlParserInputBufferCreateStatic (const char *mem, int size, 222 xmlCharEncoding enc); 223 XMLPUBFUN xmlParserInputBufferPtr 224 xmlParserInputBufferCreateIO (xmlInputReadCallback ioread, 225 xmlInputCloseCallback ioclose, 226 void *ioctx, 227 xmlCharEncoding enc); 228 XMLPUBFUN int 229 xmlParserInputBufferRead (xmlParserInputBufferPtr in, 230 int len); 231 XMLPUBFUN int 232 xmlParserInputBufferGrow (xmlParserInputBufferPtr in, 233 int len); 234 XMLPUBFUN int 235 xmlParserInputBufferPush (xmlParserInputBufferPtr in, 236 int len, 237 const char *buf); 238 XMLPUBFUN void 239 xmlFreeParserInputBuffer (xmlParserInputBufferPtr in); 240 XMLPUBFUN char * 241 xmlParserGetDirectory (const char *filename); 242 243 XMLPUBFUN int 244 xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc, 245 xmlInputOpenCallback openFunc, 246 xmlInputReadCallback readFunc, 247 xmlInputCloseCallback closeFunc); 248 249 xmlParserInputBufferPtr 250 __xmlParserInputBufferCreateFilename(const char *URI, 251 xmlCharEncoding enc); 252 253 #ifdef LIBXML_OUTPUT_ENABLED 254 /* 255 * Interfaces for output 256 */ 257 XMLPUBFUN void 258 xmlCleanupOutputCallbacks (void); 259 XMLPUBFUN int 260 xmlPopOutputCallbacks (void); 261 XMLPUBFUN void 262 xmlRegisterDefaultOutputCallbacks(void); 263 XMLPUBFUN xmlOutputBufferPtr 264 xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder); 265 266 XMLPUBFUN xmlOutputBufferPtr 267 xmlOutputBufferCreateFilename (const char *URI, 268 xmlCharEncodingHandlerPtr encoder, 269 int compression); 270 271 XMLPUBFUN xmlOutputBufferPtr 272 xmlOutputBufferCreateFile (FILE *file, 273 xmlCharEncodingHandlerPtr encoder); 274 275 XMLPUBFUN xmlOutputBufferPtr 276 xmlOutputBufferCreateBuffer (xmlBufferPtr buffer, 277 xmlCharEncodingHandlerPtr encoder); 278 279 XMLPUBFUN xmlOutputBufferPtr 280 xmlOutputBufferCreateFd (int fd, 281 xmlCharEncodingHandlerPtr encoder); 282 283 XMLPUBFUN xmlOutputBufferPtr 284 xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite, 285 xmlOutputCloseCallback ioclose, 286 void *ioctx, 287 xmlCharEncodingHandlerPtr encoder); 288 289 /* Couple of APIs to get the output without digging into the buffers */ 290 XMLPUBFUN const xmlChar * 291 xmlOutputBufferGetContent (xmlOutputBufferPtr out); 292 XMLPUBFUN size_t 293 xmlOutputBufferGetSize (xmlOutputBufferPtr out); 294 295 XMLPUBFUN int 296 xmlOutputBufferWrite (xmlOutputBufferPtr out, 297 int len, 298 const char *buf); 299 XMLPUBFUN int 300 xmlOutputBufferWriteString (xmlOutputBufferPtr out, 301 const char *str); 302 XMLPUBFUN int 303 xmlOutputBufferWriteEscape (xmlOutputBufferPtr out, 304 const xmlChar *str, 305 xmlCharEncodingOutputFunc escaping); 306 307 XMLPUBFUN int 308 xmlOutputBufferFlush (xmlOutputBufferPtr out); 309 XMLPUBFUN int 310 xmlOutputBufferClose (xmlOutputBufferPtr out); 311 312 XMLPUBFUN int 313 xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc, 314 xmlOutputOpenCallback openFunc, 315 xmlOutputWriteCallback writeFunc, 316 xmlOutputCloseCallback closeFunc); 317 318 xmlOutputBufferPtr 319 __xmlOutputBufferCreateFilename(const char *URI, 320 xmlCharEncodingHandlerPtr encoder, 321 int compression); 322 323 #ifdef LIBXML_HTTP_ENABLED 324 /* This function only exists if HTTP support built into the library */ 325 XMLPUBFUN void 326 xmlRegisterHTTPPostCallbacks (void ); 327 #endif /* LIBXML_HTTP_ENABLED */ 328 329 #endif /* LIBXML_OUTPUT_ENABLED */ 330 331 XMLPUBFUN xmlParserInputPtr 332 xmlCheckHTTPInput (xmlParserCtxtPtr ctxt, 333 xmlParserInputPtr ret); 334 335 /* 336 * A predefined entity loader disabling network accesses 337 */ 338 XMLPUBFUN xmlParserInputPtr 339 xmlNoNetExternalEntityLoader (const char *URL, 340 const char *ID, 341 xmlParserCtxtPtr ctxt); 342 343 /* 344 * xmlNormalizeWindowsPath is obsolete, don't use it. 345 * Check xmlCanonicPath in uri.h for a better alternative. 346 */ 347 XMLPUBFUN xmlChar * 348 xmlNormalizeWindowsPath (const xmlChar *path); 349 350 XMLPUBFUN int 351 xmlCheckFilename (const char *path); 352 /** 353 * Default 'file://' protocol callbacks 354 */ 355 XMLPUBFUN int 356 xmlFileMatch (const char *filename); 357 XMLPUBFUN void * 358 xmlFileOpen (const char *filename); 359 XMLPUBFUN int 360 xmlFileRead (void * context, 361 char * buffer, 362 int len); 363 XMLPUBFUN int 364 xmlFileClose (void * context); 365 366 /** 367 * Default 'http://' protocol callbacks 368 */ 369 #ifdef LIBXML_HTTP_ENABLED 370 XMLPUBFUN int 371 xmlIOHTTPMatch (const char *filename); 372 XMLPUBFUN void * 373 xmlIOHTTPOpen (const char *filename); 374 #ifdef LIBXML_OUTPUT_ENABLED 375 XMLPUBFUN void * 376 xmlIOHTTPOpenW (const char * post_uri, 377 int compression ); 378 #endif /* LIBXML_OUTPUT_ENABLED */ 379 XMLPUBFUN int 380 xmlIOHTTPRead (void * context, 381 char * buffer, 382 int len); 383 XMLPUBFUN int 384 xmlIOHTTPClose (void * context); 385 #endif /* LIBXML_HTTP_ENABLED */ 386 387 /** 388 * Default 'ftp://' protocol callbacks 389 */ 390 #if defined(LIBXML_FTP_ENABLED) 391 XMLPUBFUN int 392 xmlIOFTPMatch (const char *filename); 393 XMLPUBFUN void * 394 xmlIOFTPOpen (const char *filename); 395 XMLPUBFUN int 396 xmlIOFTPRead (void * context, 397 char * buffer, 398 int len); 399 XMLPUBFUN int 400 xmlIOFTPClose (void * context); 401 #endif /* defined(LIBXML_FTP_ENABLED) */ 402 403 XMLPUBFUN xmlParserInputBufferCreateFilenameFunc 404 xmlParserInputBufferCreateFilenameDefault( 405 xmlParserInputBufferCreateFilenameFunc func); 406 XMLPUBFUN xmlOutputBufferCreateFilenameFunc 407 xmlOutputBufferCreateFilenameDefault( 408 xmlOutputBufferCreateFilenameFunc func); 409 XMLPUBFUN xmlOutputBufferCreateFilenameFunc 410 xmlThrDefOutputBufferCreateFilenameDefault( 411 xmlOutputBufferCreateFilenameFunc func); 412 XMLPUBFUN xmlParserInputBufferCreateFilenameFunc 413 xmlThrDefParserInputBufferCreateFilenameDefault( 414 xmlParserInputBufferCreateFilenameFunc func); 415 416 #ifdef __cplusplus 417 } 418 #endif 419 420 #endif /* __XML_IO_H__ */ 421