xmlIO.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. #ifndef __XML_IO_H__
  13. #define __XML_IO_H__
  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. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * Callback used in the I/O Input API to detect if the current handler
  25. * can provide input functionality for this resource.
  26. *
  27. * @param filename the filename or URI
  28. * @returns 1 if yes and 0 if another Input module should be used
  29. */
  30. typedef int (*xmlInputMatchCallback) (const char *filename);
  31. /**
  32. * Callback used in the I/O Input API to open the resource
  33. *
  34. * @param filename the filename or URI
  35. * @returns an Input context or NULL in case or error
  36. */
  37. typedef void * (*xmlInputOpenCallback) (const char *filename);
  38. /**
  39. * Callback used in the I/O Input API to read the resource
  40. *
  41. * @param context an Input context
  42. * @param buffer the buffer to store data read
  43. * @param len the length of the buffer in bytes
  44. * @returns the number of bytes read or -1 in case of error
  45. */
  46. typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
  47. /**
  48. * Callback used in the I/O Input API to close the resource
  49. *
  50. * @param context an Input context
  51. * @returns 0 or -1 in case of error
  52. */
  53. typedef int (*xmlInputCloseCallback) (void * context);
  54. #ifdef LIBXML_OUTPUT_ENABLED
  55. /**
  56. * Callback used in the I/O Output API to detect if the current handler
  57. * can provide output functionality for this resource.
  58. *
  59. * @param filename the filename or URI
  60. * @returns 1 if yes and 0 if another Output module should be used
  61. */
  62. typedef int (*xmlOutputMatchCallback) (const char *filename);
  63. /**
  64. * Callback used in the I/O Output API to open the resource
  65. *
  66. * @param filename the filename or URI
  67. * @returns an Output context or NULL in case or error
  68. */
  69. typedef void * (*xmlOutputOpenCallback) (const char *filename);
  70. /**
  71. * Callback used in the I/O Output API to write to the resource
  72. *
  73. * @param context an Output context
  74. * @param buffer the buffer of data to write
  75. * @param len the length of the buffer in bytes
  76. * @returns the number of bytes written or -1 in case of error
  77. */
  78. typedef int (*xmlOutputWriteCallback) (void * context, const char * buffer,
  79. int len);
  80. /**
  81. * Callback used in the I/O Output API to close the resource
  82. *
  83. * @param context an Output context
  84. * @returns 0 or -1 in case of error
  85. */
  86. typedef int (*xmlOutputCloseCallback) (void * context);
  87. #endif /* LIBXML_OUTPUT_ENABLED */
  88. /**
  89. * Signature for the function doing the lookup for a suitable input method
  90. * corresponding to an URI.
  91. *
  92. * @param URI the URI to read from
  93. * @param enc the requested source encoding
  94. * @returns the new xmlParserInputBuffer in case of success or NULL if no
  95. * method was found.
  96. */
  97. typedef xmlParserInputBuffer *
  98. (*xmlParserInputBufferCreateFilenameFunc)(const char *URI, xmlCharEncoding enc);
  99. /**
  100. * Signature for the function doing the lookup for a suitable output method
  101. * corresponding to an URI.
  102. *
  103. * @param URI the URI to write to
  104. * @param encoder the requested target encoding
  105. * @param compression compression level
  106. * @returns the new xmlOutputBuffer in case of success or NULL if no
  107. * method was found.
  108. */
  109. typedef xmlOutputBuffer *
  110. (*xmlOutputBufferCreateFilenameFunc)(const char *URI,
  111. xmlCharEncodingHandler *encoder, int compression);
  112. /**
  113. * Parser input buffer
  114. *
  115. * This struct and all related functions should ultimately
  116. * be removed from the public interface.
  117. */
  118. struct _xmlParserInputBuffer {
  119. void* context XML_DEPRECATED_MEMBER;
  120. xmlInputReadCallback readcallback XML_DEPRECATED_MEMBER;
  121. xmlInputCloseCallback closecallback XML_DEPRECATED_MEMBER;
  122. /* I18N conversions to UTF-8 */
  123. xmlCharEncodingHandler *encoder XML_DEPRECATED_MEMBER;
  124. /* Local buffer encoded in UTF-8 */
  125. xmlBuf *buffer XML_DEPRECATED_MEMBER;
  126. /* if encoder != NULL buffer for raw input */
  127. xmlBuf *raw XML_DEPRECATED_MEMBER;
  128. /* -1=unknown, 0=not compressed, 1=compressed */
  129. int compressed XML_DEPRECATED_MEMBER;
  130. int error XML_DEPRECATED_MEMBER;
  131. /* amount consumed from raw */
  132. unsigned long rawconsumed XML_DEPRECATED_MEMBER;
  133. };
  134. #ifdef LIBXML_OUTPUT_ENABLED
  135. /**
  136. * Output buffer
  137. */
  138. struct _xmlOutputBuffer {
  139. void* context;
  140. xmlOutputWriteCallback writecallback;
  141. xmlOutputCloseCallback closecallback;
  142. /* I18N conversions to UTF-8 */
  143. xmlCharEncodingHandler *encoder;
  144. /* Local buffer encoded in UTF-8 or ISOLatin */
  145. xmlBuf *buffer;
  146. /* if encoder != NULL buffer for output */
  147. xmlBuf *conv;
  148. /* total number of byte written */
  149. int written;
  150. int error;
  151. };
  152. #endif /* LIBXML_OUTPUT_ENABLED */
  153. /** @cond ignore */
  154. XML_DEPRECATED
  155. XMLPUBFUN xmlParserInputBufferCreateFilenameFunc *
  156. __xmlParserInputBufferCreateFilenameValue(void);
  157. XML_DEPRECATED
  158. XMLPUBFUN xmlOutputBufferCreateFilenameFunc *
  159. __xmlOutputBufferCreateFilenameValue(void);
  160. #ifndef XML_GLOBALS_NO_REDEFINITION
  161. #define xmlParserInputBufferCreateFilenameValue \
  162. (*__xmlParserInputBufferCreateFilenameValue())
  163. #define xmlOutputBufferCreateFilenameValue \
  164. (*__xmlOutputBufferCreateFilenameValue())
  165. #endif
  166. /** @endcond */
  167. /*
  168. * Interfaces for input
  169. */
  170. XMLPUBFUN void
  171. xmlCleanupInputCallbacks (void);
  172. XMLPUBFUN int
  173. xmlPopInputCallbacks (void);
  174. XMLPUBFUN void
  175. xmlRegisterDefaultInputCallbacks (void);
  176. XMLPUBFUN xmlParserInputBuffer *
  177. xmlAllocParserInputBuffer (xmlCharEncoding enc);
  178. XMLPUBFUN xmlParserInputBuffer *
  179. xmlParserInputBufferCreateFilename (const char *URI,
  180. xmlCharEncoding enc);
  181. XML_DEPRECATED
  182. XMLPUBFUN xmlParserInputBuffer *
  183. xmlParserInputBufferCreateFile (FILE *file,
  184. xmlCharEncoding enc);
  185. XMLPUBFUN xmlParserInputBuffer *
  186. xmlParserInputBufferCreateFd (int fd,
  187. xmlCharEncoding enc);
  188. XMLPUBFUN xmlParserInputBuffer *
  189. xmlParserInputBufferCreateMem (const char *mem, int size,
  190. xmlCharEncoding enc);
  191. XMLPUBFUN xmlParserInputBuffer *
  192. xmlParserInputBufferCreateStatic (const char *mem, int size,
  193. xmlCharEncoding enc);
  194. XMLPUBFUN xmlParserInputBuffer *
  195. xmlParserInputBufferCreateIO (xmlInputReadCallback ioread,
  196. xmlInputCloseCallback ioclose,
  197. void *ioctx,
  198. xmlCharEncoding enc);
  199. XML_DEPRECATED
  200. XMLPUBFUN int
  201. xmlParserInputBufferRead (xmlParserInputBuffer *in,
  202. int len);
  203. XML_DEPRECATED
  204. XMLPUBFUN int
  205. xmlParserInputBufferGrow (xmlParserInputBuffer *in,
  206. int len);
  207. XML_DEPRECATED
  208. XMLPUBFUN int
  209. xmlParserInputBufferPush (xmlParserInputBuffer *in,
  210. int len,
  211. const char *buf);
  212. XMLPUBFUN void
  213. xmlFreeParserInputBuffer (xmlParserInputBuffer *in);
  214. XMLPUBFUN char *
  215. xmlParserGetDirectory (const char *filename);
  216. XMLPUBFUN int
  217. xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
  218. xmlInputOpenCallback openFunc,
  219. xmlInputReadCallback readFunc,
  220. xmlInputCloseCallback closeFunc);
  221. XMLPUBFUN xmlParserInputBuffer *
  222. __xmlParserInputBufferCreateFilename(const char *URI,
  223. xmlCharEncoding enc);
  224. #ifdef LIBXML_OUTPUT_ENABLED
  225. /*
  226. * Interfaces for output
  227. */
  228. XMLPUBFUN void
  229. xmlCleanupOutputCallbacks (void);
  230. XMLPUBFUN int
  231. xmlPopOutputCallbacks (void);
  232. XMLPUBFUN void
  233. xmlRegisterDefaultOutputCallbacks(void);
  234. XMLPUBFUN xmlOutputBuffer *
  235. xmlAllocOutputBuffer (xmlCharEncodingHandler *encoder);
  236. XMLPUBFUN xmlOutputBuffer *
  237. xmlOutputBufferCreateFilename (const char *URI,
  238. xmlCharEncodingHandler *encoder,
  239. int compression);
  240. XMLPUBFUN xmlOutputBuffer *
  241. xmlOutputBufferCreateFile (FILE *file,
  242. xmlCharEncodingHandler *encoder);
  243. XMLPUBFUN xmlOutputBuffer *
  244. xmlOutputBufferCreateBuffer (xmlBuffer *buffer,
  245. xmlCharEncodingHandler *encoder);
  246. XMLPUBFUN xmlOutputBuffer *
  247. xmlOutputBufferCreateFd (int fd,
  248. xmlCharEncodingHandler *encoder);
  249. XMLPUBFUN xmlOutputBuffer *
  250. xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
  251. xmlOutputCloseCallback ioclose,
  252. void *ioctx,
  253. xmlCharEncodingHandler *encoder);
  254. /* Couple of APIs to get the output without digging into the buffers */
  255. XMLPUBFUN const xmlChar *
  256. xmlOutputBufferGetContent (xmlOutputBuffer *out);
  257. XMLPUBFUN size_t
  258. xmlOutputBufferGetSize (xmlOutputBuffer *out);
  259. XMLPUBFUN int
  260. xmlOutputBufferWrite (xmlOutputBuffer *out,
  261. int len,
  262. const char *buf);
  263. XMLPUBFUN int
  264. xmlOutputBufferWriteString (xmlOutputBuffer *out,
  265. const char *str);
  266. XMLPUBFUN int
  267. xmlOutputBufferWriteEscape (xmlOutputBuffer *out,
  268. const xmlChar *str,
  269. xmlCharEncodingOutputFunc escaping);
  270. XMLPUBFUN int
  271. xmlOutputBufferFlush (xmlOutputBuffer *out);
  272. XMLPUBFUN int
  273. xmlOutputBufferClose (xmlOutputBuffer *out);
  274. XMLPUBFUN int
  275. xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
  276. xmlOutputOpenCallback openFunc,
  277. xmlOutputWriteCallback writeFunc,
  278. xmlOutputCloseCallback closeFunc);
  279. XMLPUBFUN xmlOutputBuffer *
  280. __xmlOutputBufferCreateFilename(const char *URI,
  281. xmlCharEncodingHandler *encoder,
  282. int compression);
  283. #endif /* LIBXML_OUTPUT_ENABLED */
  284. XML_DEPRECATED
  285. XMLPUBFUN xmlParserInput *
  286. xmlCheckHTTPInput (xmlParserCtxt *ctxt,
  287. xmlParserInput *ret);
  288. XML_DEPRECATED
  289. XMLPUBFUN xmlParserInput *
  290. xmlNoNetExternalEntityLoader (const char *URL,
  291. const char *ID,
  292. xmlParserCtxt *ctxt);
  293. XML_DEPRECATED
  294. XMLPUBFUN xmlChar *
  295. xmlNormalizeWindowsPath (const xmlChar *path);
  296. XML_DEPRECATED
  297. XMLPUBFUN int
  298. xmlCheckFilename (const char *path);
  299. XML_DEPRECATED
  300. XMLPUBFUN int
  301. xmlFileMatch (const char *filename);
  302. XML_DEPRECATED
  303. XMLPUBFUN void *
  304. xmlFileOpen (const char *filename);
  305. XML_DEPRECATED
  306. XMLPUBFUN int
  307. xmlFileRead (void * context,
  308. char * buffer,
  309. int len);
  310. XML_DEPRECATED
  311. XMLPUBFUN int
  312. xmlFileClose (void * context);
  313. #ifdef LIBXML_HTTP_STUBS_ENABLED
  314. /** @cond IGNORE */
  315. XML_DEPRECATED
  316. XMLPUBFUN int
  317. xmlIOHTTPMatch (const char *filename);
  318. XML_DEPRECATED
  319. XMLPUBFUN void *
  320. xmlIOHTTPOpen (const char *filename);
  321. #ifdef LIBXML_OUTPUT_ENABLED
  322. XML_DEPRECATED
  323. XMLPUBFUN void
  324. xmlRegisterHTTPPostCallbacks (void );
  325. XML_DEPRECATED
  326. XMLPUBFUN void *
  327. xmlIOHTTPOpenW (const char * post_uri,
  328. int compression );
  329. #endif /* LIBXML_OUTPUT_ENABLED */
  330. XML_DEPRECATED
  331. XMLPUBFUN int
  332. xmlIOHTTPRead (void * context,
  333. char * buffer,
  334. int len);
  335. XML_DEPRECATED
  336. XMLPUBFUN int
  337. xmlIOHTTPClose (void * context);
  338. /** @endcond */
  339. #endif /* LIBXML_HTTP_STUBS_ENABLED */
  340. XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
  341. xmlParserInputBufferCreateFilenameDefault(
  342. xmlParserInputBufferCreateFilenameFunc func);
  343. XMLPUBFUN xmlOutputBufferCreateFilenameFunc
  344. xmlOutputBufferCreateFilenameDefault(
  345. xmlOutputBufferCreateFilenameFunc func);
  346. XML_DEPRECATED
  347. XMLPUBFUN xmlOutputBufferCreateFilenameFunc
  348. xmlThrDefOutputBufferCreateFilenameDefault(
  349. xmlOutputBufferCreateFilenameFunc func);
  350. XML_DEPRECATED
  351. XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
  352. xmlThrDefParserInputBufferCreateFilenameDefault(
  353. xmlParserInputBufferCreateFilenameFunc func);
  354. #ifdef __cplusplus
  355. }
  356. #endif
  357. #endif /* __XML_IO_H__ */