xmlIO.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 fonctionnalities 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 fonctionnalities 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 void XMLCALL
  198. xmlRegisterDefaultOutputCallbacks(void);
  199. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  200. xmlAllocOutputBuffer (xmlCharEncodingHandlerPtr encoder);
  201. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  202. xmlOutputBufferCreateFilename (const char *URI,
  203. xmlCharEncodingHandlerPtr encoder,
  204. int compression);
  205. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  206. xmlOutputBufferCreateFile (FILE *file,
  207. xmlCharEncodingHandlerPtr encoder);
  208. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  209. xmlOutputBufferCreateBuffer (xmlBufferPtr buffer,
  210. xmlCharEncodingHandlerPtr encoder);
  211. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  212. xmlOutputBufferCreateFd (int fd,
  213. xmlCharEncodingHandlerPtr encoder);
  214. XMLPUBFUN xmlOutputBufferPtr XMLCALL
  215. xmlOutputBufferCreateIO (xmlOutputWriteCallback iowrite,
  216. xmlOutputCloseCallback ioclose,
  217. void *ioctx,
  218. xmlCharEncodingHandlerPtr encoder);
  219. /* Couple of APIs to get the output without digging into the buffers */
  220. XMLPUBFUN const xmlChar * XMLCALL
  221. xmlOutputBufferGetContent (xmlOutputBufferPtr out);
  222. XMLPUBFUN size_t XMLCALL
  223. xmlOutputBufferGetSize (xmlOutputBufferPtr out);
  224. XMLPUBFUN int XMLCALL
  225. xmlOutputBufferWrite (xmlOutputBufferPtr out,
  226. int len,
  227. const char *buf);
  228. XMLPUBFUN int XMLCALL
  229. xmlOutputBufferWriteString (xmlOutputBufferPtr out,
  230. const char *str);
  231. XMLPUBFUN int XMLCALL
  232. xmlOutputBufferWriteEscape (xmlOutputBufferPtr out,
  233. const xmlChar *str,
  234. xmlCharEncodingOutputFunc escaping);
  235. XMLPUBFUN int XMLCALL
  236. xmlOutputBufferFlush (xmlOutputBufferPtr out);
  237. XMLPUBFUN int XMLCALL
  238. xmlOutputBufferClose (xmlOutputBufferPtr out);
  239. XMLPUBFUN int XMLCALL
  240. xmlRegisterOutputCallbacks (xmlOutputMatchCallback matchFunc,
  241. xmlOutputOpenCallback openFunc,
  242. xmlOutputWriteCallback writeFunc,
  243. xmlOutputCloseCallback closeFunc);
  244. xmlOutputBufferPtr
  245. __xmlOutputBufferCreateFilename(const char *URI,
  246. xmlCharEncodingHandlerPtr encoder,
  247. int compression);
  248. #ifdef LIBXML_HTTP_ENABLED
  249. /* This function only exists if HTTP support built into the library */
  250. XMLPUBFUN void XMLCALL
  251. xmlRegisterHTTPPostCallbacks (void );
  252. #endif /* LIBXML_HTTP_ENABLED */
  253. #endif /* LIBXML_OUTPUT_ENABLED */
  254. XMLPUBFUN xmlParserInputPtr XMLCALL
  255. xmlCheckHTTPInput (xmlParserCtxtPtr ctxt,
  256. xmlParserInputPtr ret);
  257. /*
  258. * A predefined entity loader disabling network accesses
  259. */
  260. XMLPUBFUN xmlParserInputPtr XMLCALL
  261. xmlNoNetExternalEntityLoader (const char *URL,
  262. const char *ID,
  263. xmlParserCtxtPtr ctxt);
  264. /*
  265. * xmlNormalizeWindowsPath is obsolete, don't use it.
  266. * Check xmlCanonicPath in uri.h for a better alternative.
  267. */
  268. XMLPUBFUN xmlChar * XMLCALL
  269. xmlNormalizeWindowsPath (const xmlChar *path);
  270. XMLPUBFUN int XMLCALL
  271. xmlCheckFilename (const char *path);
  272. /**
  273. * Default 'file://' protocol callbacks
  274. */
  275. XMLPUBFUN int XMLCALL
  276. xmlFileMatch (const char *filename);
  277. XMLPUBFUN void * XMLCALL
  278. xmlFileOpen (const char *filename);
  279. XMLPUBFUN int XMLCALL
  280. xmlFileRead (void * context,
  281. char * buffer,
  282. int len);
  283. XMLPUBFUN int XMLCALL
  284. xmlFileClose (void * context);
  285. /**
  286. * Default 'http://' protocol callbacks
  287. */
  288. #ifdef LIBXML_HTTP_ENABLED
  289. XMLPUBFUN int XMLCALL
  290. xmlIOHTTPMatch (const char *filename);
  291. XMLPUBFUN void * XMLCALL
  292. xmlIOHTTPOpen (const char *filename);
  293. #ifdef LIBXML_OUTPUT_ENABLED
  294. XMLPUBFUN void * XMLCALL
  295. xmlIOHTTPOpenW (const char * post_uri,
  296. int compression );
  297. #endif /* LIBXML_OUTPUT_ENABLED */
  298. XMLPUBFUN int XMLCALL
  299. xmlIOHTTPRead (void * context,
  300. char * buffer,
  301. int len);
  302. XMLPUBFUN int XMLCALL
  303. xmlIOHTTPClose (void * context);
  304. #endif /* LIBXML_HTTP_ENABLED */
  305. /**
  306. * Default 'ftp://' protocol callbacks
  307. */
  308. #ifdef LIBXML_FTP_ENABLED
  309. XMLPUBFUN int XMLCALL
  310. xmlIOFTPMatch (const char *filename);
  311. XMLPUBFUN void * XMLCALL
  312. xmlIOFTPOpen (const char *filename);
  313. XMLPUBFUN int XMLCALL
  314. xmlIOFTPRead (void * context,
  315. char * buffer,
  316. int len);
  317. XMLPUBFUN int XMLCALL
  318. xmlIOFTPClose (void * context);
  319. #endif /* LIBXML_FTP_ENABLED */
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #endif /* __XML_IO_H__ */