xmlIO.h 12 KB

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