xmlIO.h 10.0 KB

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