xmlIO.h 12 KB

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