Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * xmlIO.h : interface for the I/O interfaces used by the parser |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | c5d6434 | 2001-06-24 12:13:24 +0000 | [diff] [blame] | 6 | * daniel@veillard.com |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 7 | * |
| 8 | * 15 Nov 2000 ht - modified for VMS |
| 9 | */ |
| 10 | |
| 11 | #ifndef __XML_IO_H__ |
| 12 | #define __XML_IO_H__ |
| 13 | |
| 14 | #include <stdio.h> |
Daniel Veillard | 5790537 | 2001-07-31 15:52:17 +0000 | [diff] [blame] | 15 | #if defined(WIN32) && defined(_MSC_VER) |
| 16 | #include <libxml/xmlwin32version.h> |
| 17 | #else |
Daniel Veillard | f012a64 | 2001-07-23 19:10:52 +0000 | [diff] [blame] | 18 | #include <libxml/xmlversion.h> |
Daniel Veillard | 5790537 | 2001-07-31 15:52:17 +0000 | [diff] [blame] | 19 | #endif |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | /* |
| 26 | * Those are the functions and datatypes for the parser input |
| 27 | * I/O structures. |
| 28 | */ |
| 29 | |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 30 | /** |
| 31 | * xmlInputMatchCallback: |
| 32 | * @filename: the filename or URI |
| 33 | * |
| 34 | * Callback used in the I/O Input API to detect if the current handler |
| 35 | * can provide input fonctionnalities for this resource. |
| 36 | * |
| 37 | * Returns 1 if yes and 0 if another Input module should be used |
| 38 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 39 | typedef int (*xmlInputMatchCallback) (char const *filename); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 40 | /** |
| 41 | * xmlInputOpenCallback: |
| 42 | * @filename: the filename or URI |
| 43 | * |
| 44 | * Callback used in the I/O Input API to open the resource |
| 45 | * |
| 46 | * Returns an Input context or NULL in case or error |
| 47 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 48 | typedef void * (*xmlInputOpenCallback) (char const *filename); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 49 | /** |
| 50 | * xmlInputReadCallback: |
| 51 | * @context: an Input context |
| 52 | * @buffer: the buffer to store data read |
| 53 | * @len: the length of the buffer in bytes |
| 54 | * |
| 55 | * Callback used in the I/O Input API to read the resource |
| 56 | * |
| 57 | * Returns the number of bytes read or -1 in case of error |
| 58 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 59 | typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 60 | /** |
| 61 | * xmlInputCloseCallback: |
| 62 | * @context: an Input context |
| 63 | * |
| 64 | * Callback used in the I/O Input API to close the resource |
| 65 | * |
| 66 | * Returns 0 or -1 in case of error |
| 67 | */ |
Daniel Veillard | f012a64 | 2001-07-23 19:10:52 +0000 | [diff] [blame] | 68 | typedef int (*xmlInputCloseCallback) (void * context); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 69 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 70 | /* |
| 71 | * Those are the functions and datatypes for the library output |
| 72 | * I/O structures. |
| 73 | */ |
| 74 | |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 75 | /** |
| 76 | * xmlOutputMatchCallback: |
| 77 | * @filename: the filename or URI |
| 78 | * |
| 79 | * Callback used in the I/O Output API to detect if the current handler |
| 80 | * can provide output fonctionnalities for this resource. |
| 81 | * |
| 82 | * Returns 1 if yes and 0 if another Output module should be used |
| 83 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 84 | typedef int (*xmlOutputMatchCallback) (char const *filename); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 85 | /** |
| 86 | * xmlOutputOpenCallback: |
| 87 | * @filename: the filename or URI |
| 88 | * |
| 89 | * Callback used in the I/O Output API to open the resource |
| 90 | * |
| 91 | * Returns an Output context or NULL in case or error |
| 92 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 93 | typedef void * (*xmlOutputOpenCallback) (char const *filename); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 94 | /** |
| 95 | * xmlOutputWriteCallback: |
| 96 | * @context: an Output context |
| 97 | * @buffer: the buffer of data to write |
| 98 | * @len: the length of the buffer in bytes |
| 99 | * |
| 100 | * Callback used in the I/O Output API to write to the resource |
| 101 | * |
| 102 | * Returns the number of bytes written or -1 in case of error |
| 103 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 104 | typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer, |
| 105 | int len); |
Daniel Veillard | 9d06d30 | 2002-01-22 18:15:52 +0000 | [diff] [blame] | 106 | /** |
| 107 | * xmlOutputCloseCallback: |
| 108 | * @context: an Output context |
| 109 | * |
| 110 | * Callback used in the I/O Output API to close the resource |
| 111 | * |
| 112 | * Returns 0 or -1 in case of error |
| 113 | */ |
Daniel Veillard | f012a64 | 2001-07-23 19:10:52 +0000 | [diff] [blame] | 114 | typedef int (*xmlOutputCloseCallback) (void * context); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 115 | |
Daniel Veillard | a8a89fe | 2002-04-12 21:03:34 +0000 | [diff] [blame^] | 116 | #ifdef __cplusplus |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | #include <libxml/globals.h> |
| 121 | #include <libxml/tree.h> |
| 122 | #include <libxml/parser.h> |
| 123 | #include <libxml/encoding.h> |
| 124 | |
| 125 | #ifdef __cplusplus |
| 126 | extern "C" { |
| 127 | #endif |
| 128 | struct _xmlParserInputBuffer { |
| 129 | void* context; |
| 130 | xmlInputReadCallback readcallback; |
| 131 | xmlInputCloseCallback closecallback; |
| 132 | |
| 133 | xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */ |
| 134 | |
| 135 | xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 */ |
| 136 | xmlBufferPtr raw; /* if encoder != NULL buffer for raw input */ |
| 137 | }; |
| 138 | |
| 139 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 140 | struct _xmlOutputBuffer { |
| 141 | void* context; |
| 142 | xmlOutputWriteCallback writecallback; |
| 143 | xmlOutputCloseCallback closecallback; |
| 144 | |
| 145 | xmlCharEncodingHandlerPtr encoder; /* I18N conversions to UTF-8 */ |
| 146 | |
| 147 | xmlBufferPtr buffer; /* Local buffer encoded in UTF-8 or ISOLatin */ |
| 148 | xmlBufferPtr conv; /* if encoder != NULL buffer for output */ |
| 149 | int written; /* total number of byte written */ |
| 150 | }; |
| 151 | |
| 152 | /* |
| 153 | * Interfaces for input |
| 154 | */ |
Daniel Veillard | acf7ff0 | 2001-10-29 20:21:47 +0000 | [diff] [blame] | 155 | void xmlCleanupInputCallbacks (void); |
| 156 | void xmlCleanupOutputCallbacks (void); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 157 | |
| 158 | void xmlRegisterDefaultInputCallbacks (void); |
| 159 | xmlParserInputBufferPtr |
| 160 | xmlAllocParserInputBuffer (xmlCharEncoding enc); |
| 161 | |
| 162 | #ifdef VMS |
| 163 | xmlParserInputBufferPtr |
| 164 | xmlParserInputBufferCreateFname (const char *URI, |
| 165 | xmlCharEncoding enc); |
| 166 | #define xmlParserInputBufferCreateFilename xmlParserInputBufferCreateFname |
| 167 | #else |
| 168 | xmlParserInputBufferPtr |
| 169 | xmlParserInputBufferCreateFilename (const char *URI, |
| 170 | xmlCharEncoding enc); |
| 171 | #endif |
| 172 | |
| 173 | xmlParserInputBufferPtr |
| 174 | xmlParserInputBufferCreateFile (FILE *file, |
| 175 | xmlCharEncoding enc); |
| 176 | xmlParserInputBufferPtr |
| 177 | xmlParserInputBufferCreateFd (int fd, |
| 178 | xmlCharEncoding enc); |
| 179 | xmlParserInputBufferPtr |
| 180 | xmlParserInputBufferCreateMem (const char *mem, int size, |
| 181 | xmlCharEncoding enc); |
| 182 | xmlParserInputBufferPtr |
| 183 | xmlParserInputBufferCreateIO (xmlInputReadCallback ioread, |
| 184 | xmlInputCloseCallback ioclose, |
| 185 | void *ioctx, |
| 186 | xmlCharEncoding enc); |
| 187 | int xmlParserInputBufferRead (xmlParserInputBufferPtr in, |
| 188 | int len); |
| 189 | int xmlParserInputBufferGrow (xmlParserInputBufferPtr in, |
| 190 | int len); |
| 191 | int xmlParserInputBufferPush (xmlParserInputBufferPtr in, |
| 192 | int len, |
| 193 | const char *buf); |
| 194 | void xmlFreeParserInputBuffer (xmlParserInputBufferPtr in); |
| 195 | char * xmlParserGetDirectory (const char *filename); |
| 196 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 197 | int xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc, |
| 198 | xmlInputOpenCallback openFunc, |
| 199 | xmlInputReadCallback readFunc, |
| 200 | xmlInputCloseCallback closeFunc); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 201 | /* |
| 202 | * Interfaces for output |
| 203 | */ |
| 204 | void xmlRegisterDefaultOutputCallbacks(void); |
| 205 | xmlOutputBufferPtr |
| 206 | xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder); |
| 207 | |
| 208 | xmlOutputBufferPtr |
| 209 | xmlOutputBufferCreateFilename (const char *URI, |
| 210 | xmlCharEncodingHandlerPtr encoder, |
| 211 | int compression); |
| 212 | |
| 213 | xmlOutputBufferPtr |
| 214 | xmlOutputBufferCreateFile (FILE *file, |
| 215 | xmlCharEncodingHandlerPtr encoder); |
| 216 | |
| 217 | xmlOutputBufferPtr |
| 218 | xmlOutputBufferCreateFd (int fd, |
| 219 | xmlCharEncodingHandlerPtr encoder); |
| 220 | |
| 221 | xmlOutputBufferPtr |
| 222 | xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite, |
| 223 | xmlOutputCloseCallback ioclose, |
| 224 | void *ioctx, |
| 225 | xmlCharEncodingHandlerPtr encoder); |
| 226 | |
| 227 | int xmlOutputBufferWrite (xmlOutputBufferPtr out, |
| 228 | int len, |
| 229 | const char *buf); |
| 230 | int xmlOutputBufferWriteString (xmlOutputBufferPtr out, |
| 231 | const char *str); |
| 232 | |
| 233 | int xmlOutputBufferFlush (xmlOutputBufferPtr out); |
| 234 | int xmlOutputBufferClose (xmlOutputBufferPtr out); |
| 235 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 236 | int xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc, |
| 237 | xmlOutputOpenCallback openFunc, |
| 238 | xmlOutputWriteCallback writeFunc, |
| 239 | xmlOutputCloseCallback closeFunc); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 240 | |
Daniel Veillard | f012a64 | 2001-07-23 19:10:52 +0000 | [diff] [blame] | 241 | /* This function only exists if HTTP support built into the library */ |
| 242 | #ifdef LIBXML_HTTP_ENABLED |
| 243 | void * xmlIOHTTPOpenW (const char * post_uri, |
| 244 | int compression ); |
Daniel Veillard | 5d90b6c | 2001-08-22 14:29:45 +0000 | [diff] [blame] | 245 | void xmlRegisterHTTPPostCallbacks (void ); |
Daniel Veillard | f012a64 | 2001-07-23 19:10:52 +0000 | [diff] [blame] | 246 | #endif |
| 247 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 248 | /* |
Daniel Veillard | 8bdb91d | 2001-10-31 17:52:43 +0000 | [diff] [blame] | 249 | * A predefined entity loader disabling network accesses |
| 250 | */ |
| 251 | xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL, |
| 252 | const char *ID, |
| 253 | xmlParserCtxtPtr ctxt); |
| 254 | |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 255 | #ifdef __cplusplus |
| 256 | } |
| 257 | #endif |
| 258 | |
| 259 | #endif /* __XML_IO_H__ */ |