xmlIO.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 (XMLCALL *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 * (XMLCALL *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 (XMLCALL *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 (XMLCALL *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 (XMLCALL *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 * (XMLCALL *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 (XMLCALL *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 (XMLCALL *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 XMLCALL
  142. xmlCleanupInputCallbacks (void);
  143. XMLPUBFUN int XMLCALL
  144. xmlPopInputCallbacks (void);
  145. XMLPUBFUN void XMLCALL
  146. xmlRegisterDefaultInputCallbacks (void);
  147. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  148. xmlAllocParserInputBuffer (xmlCharEncoding enc);
  149. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  150. xmlParserInputBufferCreateFilename (const char *URI,
  151. xmlCharEncoding enc);
  152. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  153. xmlParserInputBufferCreateFile (FILE *file,
  154. xmlCharEncoding enc);
  155. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  156. xmlParserInputBufferCreateFd (int fd,
  157. xmlCharEncoding enc);
  158. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  159. xmlParserInputBufferCreateMem (const char *mem, int size,
  160. xmlCharEncoding enc);
  161. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  162. xmlParserInputBufferCreateStatic (const char *mem, int size,
  163. xmlCharEncoding enc);
  164. XMLPUBFUN xmlParserInputBufferPtr XMLCALL
  165. xmlParserInputBufferCreateIO (xmlInputReadCallback ioread,
  166. xmlInputCloseCallback ioclose,
  167. void *ioctx,
  168. xmlCharEncoding enc);
  169. XMLPUBFUN int XMLCALL
  170. xmlParserInputBufferRead (xmlParserInputBufferPtr in,
  171. int len);
  172. XMLPUBFUN int XMLCALL
  173. xmlParserInputBufferGrow (xmlParserInputBufferPtr in,
  174. int len);
  175. XMLPUBFUN int XMLCALL
  176. xmlParserInputBufferPush (xmlParserInputBufferPtr in,
  177. int len,
  178. const char *buf);
  179. XMLPUBFUN void XMLCALL
  180. xmlFreeParserInputBuffer (xmlParserInputBufferPtr in);
  181. XMLPUBFUN char * XMLCALL
  182. xmlParserGetDirectory (const char *filename);
  183. XMLPUBFUN int XMLCALL
  184. xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
  185. xmlInputOpenCallback openFunc,
  186. xmlInputReadCallback readFunc,
  187. xmlInputCloseCallback closeFunc);
  188. xmlParserInputBufferPtr
  189. __xmlParserInputBufferCreateFilename(const char *URI,
  190. xmlCharEncoding enc);
  191. #ifdef LIBXML_OUTPUT_ENABLED
  192. /*
  193. * Interfaces for output
  194. */
  195. XMLPUBFUN void XMLCALL
  196. xmlCleanupOutputCallbacks (void);
  197. XMLPUBFUN int XMLCALL
  198. xmlPopOutputCallbacks (void);
  199. XMLPUBFUN void XMLCALL
  200. xmlRegisterDefaultOutputCallbacks(void);
  201. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  202. xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder);
  203. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  204. xmlOutputBufferCreateFilename (const char *URI,
  205. xmlCharEncodingHandlerPtr encoder,
  206. int compression);
  207. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  208. xmlOutputBufferCreateFile (FILE *file,
  209. xmlCharEncodingHandlerPtr encoder);
  210. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  211. xmlOutputBufferCreateBuffer (xmlBufferPtr buffer,
  212. xmlCharEncodingHandlerPtr encoder);
  213. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  214. xmlOutputBufferCreateFd (int fd,
  215. xmlCharEncodingHandlerPtr encoder);
  216. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  217. xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
  218. xmlOutputCloseCallback ioclose,
  219. void *ioctx,
  220. xmlCharEncodingHandlerPtr encoder);
  221. /* Couple of APIs to get the output without digging into the buffers */
  222. XMLPUBFUN const xmlChar * XMLCALL
  223. xmlOutputBufferGetContent (xmlOutputBufferPtr out);
  224. XMLPUBFUN size_t XMLCALL
  225. xmlOutputBufferGetSize (xmlOutputBufferPtr out);
  226. XMLPUBFUN int XMLCALL
  227. xmlOutputBufferWrite (xmlOutputBufferPtr out,
  228. int len,
  229. const char *buf);
  230. XMLPUBFUN int XMLCALL
  231. xmlOutputBufferWriteString (xmlOutputBufferPtr out,
  232. const char *str);
  233. XMLPUBFUN int XMLCALL
  234. xmlOutputBufferWriteEscape (xmlOutputBufferPtr out,
  235. const xmlChar *str,
  236. xmlCharEncodingOutputFunc escaping);
  237. XMLPUBFUN int XMLCALL
  238. xmlOutputBufferFlush (xmlOutputBufferPtr out);
  239. XMLPUBFUN int XMLCALL
  240. xmlOutputBufferClose (xmlOutputBufferPtr out);
  241. XMLPUBFUN int XMLCALL
  242. xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
  243. xmlOutputOpenCallback openFunc,
  244. xmlOutputWriteCallback writeFunc,
  245. xmlOutputCloseCallback closeFunc);
  246. xmlOutputBufferPtr
  247. __xmlOutputBufferCreateFilename(const char *URI,
  248. xmlCharEncodingHandlerPtr encoder,
  249. int compression);
  250. #ifdef LIBXML_HTTP_ENABLED
  251. /* This function only exists if HTTP support built into the library */
  252. XMLPUBFUN void XMLCALL
  253. xmlRegisterHTTPPostCallbacks (void );
  254. #endif /* LIBXML_HTTP_ENABLED */
  255. #endif /* LIBXML_OUTPUT_ENABLED */
  256. XMLPUBFUN xmlParserInputPtr XMLCALL
  257. xmlCheckHTTPInput (xmlParserCtxtPtr ctxt,
  258. xmlParserInputPtr ret);
  259. /*
  260. * A predefined entity loader disabling network accesses
  261. */
  262. XMLPUBFUN xmlParserInputPtr XMLCALL
  263. xmlNoNetExternalEntityLoader (const char *URL,
  264. const char *ID,
  265. xmlParserCtxtPtr ctxt);
  266. /*
  267. * xmlNormalizeWindowsPath is obsolete, don't use it.
  268. * Check xmlCanonicPath in uri.h for a better alternative.
  269. */
  270. XMLPUBFUN xmlChar * XMLCALL
  271. xmlNormalizeWindowsPath (const xmlChar *path);
  272. XMLPUBFUN int XMLCALL
  273. xmlCheckFilename (const char *path);
  274. /**
  275. * Default 'file://' protocol callbacks
  276. */
  277. XMLPUBFUN int XMLCALL
  278. xmlFileMatch (const char *filename);
  279. XMLPUBFUN void * XMLCALL
  280. xmlFileOpen (const char *filename);
  281. XMLPUBFUN int XMLCALL
  282. xmlFileRead (void * context,
  283. char * buffer,
  284. int len);
  285. XMLPUBFUN int XMLCALL
  286. xmlFileClose (void * context);
  287. /**
  288. * Default 'http://' protocol callbacks
  289. */
  290. #ifdef LIBXML_HTTP_ENABLED
  291. XMLPUBFUN int XMLCALL
  292. xmlIOHTTPMatch (const char *filename);
  293. XMLPUBFUN void * XMLCALL
  294. xmlIOHTTPOpen (const char *filename);
  295. #ifdef LIBXML_OUTPUT_ENABLED
  296. XMLPUBFUN void * XMLCALL
  297. xmlIOHTTPOpenW (const char * post_uri,
  298. int compression );
  299. #endif /* LIBXML_OUTPUT_ENABLED */
  300. XMLPUBFUN int XMLCALL
  301. xmlIOHTTPRead (void * context,
  302. char * buffer,
  303. int len);
  304. XMLPUBFUN int XMLCALL
  305. xmlIOHTTPClose (void * context);
  306. #endif /* LIBXML_HTTP_ENABLED */
  307. /**
  308. * Default 'ftp://' protocol callbacks
  309. */
  310. #ifdef LIBXML_FTP_ENABLED
  311. XMLPUBFUN int XMLCALL
  312. xmlIOFTPMatch (const char *filename);
  313. XMLPUBFUN void * XMLCALL
  314. xmlIOFTPOpen (const char *filename);
  315. XMLPUBFUN int XMLCALL
  316. xmlIOFTPRead (void * context,
  317. char * buffer,
  318. int len);
  319. XMLPUBFUN int XMLCALL
  320. xmlIOFTPClose (void * context);
  321. #endif /* LIBXML_FTP_ENABLED */
  322. #ifdef __cplusplus
  323. }
  324. #endif
  325. #endif /* __XML_IO_H__ */