1 #include <Python.h>
2 #include <libxml/tree.h>
3 #include <libxml/parser.h>
4 #include <libxml/parserInternals.h>
5 #include <libxml/catalog.h>
6 #include <libxml/threads.h>
7 #include <libxml/nanoftp.h>
8 #include <libxml/nanohttp.h>
9 #include <libxml/uri.h>
10 #include <libxml/xpath.h>
11 #include <libxml/xpathInternals.h>
12 #include <libxml/debugXML.h>
13 #include <libxml/HTMLparser.h>
14 #include <libxml/HTMLtree.h>
15 #include <libxml/xinclude.h>
16 #include <libxml/xpointer.h>
17 #include <libxml/xmlunicode.h>
18 #include <libxml/xmlregexp.h>
19 #include <libxml/xmlautomata.h>
20 #include <libxml/xmlreader.h>
21 #include <libxml/globals.h>
22 #include <libxml/xmlsave.h>
23 #ifdef LIBXML_SCHEMAS_ENABLED
24 #include <libxml/relaxng.h>
25 #include <libxml/xmlschemas.h>
26 #endif
27
28 /*
29 * for older versions of Python, we don't use PyBytes, but keep PyString
30 * and don't use Capsule but CObjects
31 */
32 #if PY_VERSION_HEX < 0x02070000
33 #ifndef PyBytes_Check
34 #define PyBytes_Check PyString_Check
35 #define PyBytes_Size PyString_Size
36 #define PyBytes_AsString PyString_AsString
37 #define PyBytes_AS_STRING PyString_AS_STRING
38 #define PyBytes_GET_SIZE PyString_GET_SIZE
39 #endif
40 #ifndef PyCapsule_New
41 #define PyCapsule_New PyCObject_FromVoidPtrAndDesc
42 #define PyCapsule_CheckExact PyCObject_Check
43 #define PyCapsule_GetPointer(o, n) PyCObject_GetDesc((o))
44 #endif
45 #endif
46
47 /**
48 * ATTRIBUTE_UNUSED:
49 *
50 * Macro used to signal to GCC unused function parameters
51 * Repeated here since the definition is not available when
52 * compiled outside the libxml2 build tree.
53 */
54 #ifdef __GNUC__
55 #ifdef ATTRIBUTE_UNUSED
56 #undef ATTRIBUTE_UNUSED
57 #endif
58 #ifndef ATTRIBUTE_UNUSED
59 #define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
60 #endif /* ATTRIBUTE_UNUSED */
61 #else
62 #define ATTRIBUTE_UNUSED
63 #endif
64
65 /*
66 * Macros to ignore deprecation warnings
67 */
68 #if defined(__clang__) || \
69 (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
70 #define XML_IGNORE_DEPRECATION_WARNINGS \
71 _Pragma("GCC diagnostic push") \
72 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
73 #elif defined (_MSC_VER) && (_MSC_VER >= 1400)
74 #define XML_IGNORE_DEPRECATION_WARNINGS \
75 __pragma(warning(push)) \
76 __pragma(warning(disable : 4996))
77 #else
78 #define XML_IGNORE_DEPRECATION_WARNINGS
79 #endif
80
81 #define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
82 (((PyxmlNode_Object *)(v))->obj))
83
84 typedef struct {
85 PyObject_HEAD
86 xmlNodePtr obj;
87 } PyxmlNode_Object;
88
89 #define PyxmlXPathContext_Get(v) (((v) == Py_None) ? NULL : \
90 (((PyxmlXPathContext_Object *)(v))->obj))
91
92 typedef struct {
93 PyObject_HEAD
94 xmlXPathContextPtr obj;
95 } PyxmlXPathContext_Object;
96
97 #define PyxmlXPathParserContext_Get(v) (((v) == Py_None) ? NULL : \
98 (((PyxmlXPathParserContext_Object *)(v))->obj))
99
100 typedef struct {
101 PyObject_HEAD
102 xmlXPathParserContextPtr obj;
103 } PyxmlXPathParserContext_Object;
104
105 #define PyparserCtxt_Get(v) (((v) == Py_None) ? NULL : \
106 (((PyparserCtxt_Object *)(v))->obj))
107
108 typedef struct {
109 PyObject_HEAD
110 xmlParserCtxtPtr obj;
111 } PyparserCtxt_Object;
112
113 #define PyValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
114 (((PyValidCtxt_Object *)(v))->obj))
115
116 typedef struct {
117 PyObject_HEAD
118 xmlValidCtxtPtr obj;
119 } PyValidCtxt_Object;
120
121 #define Pycatalog_Get(v) (((v) == Py_None) ? NULL : \
122 (((Pycatalog_Object *)(v))->obj))
123
124 typedef struct {
125 PyObject_HEAD
126 xmlCatalogPtr obj;
127 } Pycatalog_Object;
128
129 #ifdef LIBXML_REGEXP_ENABLED
130 #define PyxmlReg_Get(v) (((v) == Py_None) ? NULL : \
131 (((PyxmlReg_Object *)(v))->obj))
132
133 typedef struct {
134 PyObject_HEAD
135 xmlRegexpPtr obj;
136 } PyxmlReg_Object;
137 #endif /* LIBXML_REGEXP_ENABLED */
138
139 #ifdef LIBXML_READER_ENABLED
140 #define PyxmlTextReader_Get(v) (((v) == Py_None) ? NULL : \
141 (((PyxmlTextReader_Object *)(v))->obj))
142
143 typedef struct {
144 PyObject_HEAD
145 xmlTextReaderPtr obj;
146 } PyxmlTextReader_Object;
147
148 #define PyxmlTextReaderLocator_Get(v) (((v) == Py_None) ? NULL : \
149 (((PyxmlTextReaderLocator_Object *)(v))->obj))
150
151 typedef struct {
152 PyObject_HEAD
153 xmlTextReaderLocatorPtr obj;
154 } PyxmlTextReaderLocator_Object;
155 #endif
156
157 #define PyURI_Get(v) (((v) == Py_None) ? NULL : \
158 (((PyURI_Object *)(v))->obj))
159
160 typedef struct {
161 PyObject_HEAD
162 xmlErrorPtr obj;
163 } PyError_Object;
164
165 #define PyError_Get(v) (((v) == Py_None) ? NULL : \
166 (((PyError_Object *)(v))->obj))
167
168 typedef struct {
169 PyObject_HEAD
170 xmlOutputBufferPtr obj;
171 } PyoutputBuffer_Object;
172
173 #define PyoutputBuffer_Get(v) (((v) == Py_None) ? NULL : \
174 (((PyoutputBuffer_Object *)(v))->obj))
175
176 typedef struct {
177 PyObject_HEAD
178 xmlParserInputBufferPtr obj;
179 } PyinputBuffer_Object;
180
181 #define PyinputBuffer_Get(v) (((v) == Py_None) ? NULL : \
182 (((PyinputBuffer_Object *)(v))->obj))
183
184 typedef struct {
185 PyObject_HEAD
186 xmlURIPtr obj;
187 } PyURI_Object;
188
189 /* FILE * have their own internal representation */
190 #if PY_MAJOR_VERSION >= 3
191 FILE *libxml_PyFileGet(PyObject *f);
192 void libxml_PyFileRelease(FILE *f);
193 #define PyFile_Get(v) (((v) == Py_None) ? NULL : libxml_PyFileGet(v))
194 #define PyFile_Release(f) libxml_PyFileRelease(f)
195 #else
196 #define PyFile_Get(v) (((v) == Py_None) ? NULL : \
197 (PyFile_Check(v) ? (PyFile_AsFile(v)) : stdout))
198 #define PyFile_Release(f)
199 #endif
200
201 #ifdef LIBXML_SCHEMAS_ENABLED
202 typedef struct {
203 PyObject_HEAD
204 xmlRelaxNGPtr obj;
205 } PyrelaxNgSchema_Object;
206
207 #define PyrelaxNgSchema_Get(v) (((v) == Py_None) ? NULL : \
208 (((PyrelaxNgSchema_Object *)(v))->obj))
209
210 typedef struct {
211 PyObject_HEAD
212 xmlRelaxNGParserCtxtPtr obj;
213 } PyrelaxNgParserCtxt_Object;
214
215 #define PyrelaxNgParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
216 (((PyrelaxNgParserCtxt_Object *)(v))->obj))
217
218 typedef struct {
219 PyObject_HEAD
220 xmlRelaxNGValidCtxtPtr obj;
221 } PyrelaxNgValidCtxt_Object;
222
223 #define PyrelaxNgValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
224 (((PyrelaxNgValidCtxt_Object *)(v))->obj))
225
226 typedef struct {
227 PyObject_HEAD
228 xmlSchemaPtr obj;
229 } PySchema_Object;
230
231 #define PySchema_Get(v) (((v) == Py_None) ? NULL : \
232 (((PySchema_Object *)(v))->obj))
233
234 typedef struct {
235 PyObject_HEAD
236 xmlSchemaParserCtxtPtr obj;
237 } PySchemaParserCtxt_Object;
238
239 #define PySchemaParserCtxt_Get(v) (((v) == Py_None) ? NULL : \
240 (((PySchemaParserCtxt_Object *)(v))->obj))
241
242 typedef struct {
243 PyObject_HEAD
244 xmlSchemaValidCtxtPtr obj;
245 } PySchemaValidCtxt_Object;
246
247 #define PySchemaValidCtxt_Get(v) (((v) == Py_None) ? NULL : \
248 (((PySchemaValidCtxt_Object *)(v))->obj))
249
250 #endif /* LIBXML_SCHEMAS_ENABLED */
251
252 PyObject * libxml_intWrap(int val);
253 PyObject * libxml_longWrap(long val);
254 PyObject * libxml_xmlCharPtrWrap(xmlChar *str);
255 PyObject * libxml_constxmlCharPtrWrap(const xmlChar *str);
256 PyObject * libxml_charPtrWrap(char *str);
257 PyObject * libxml_constcharPtrWrap(const char *str);
258 PyObject * libxml_charPtrConstWrap(const char *str);
259 PyObject * libxml_xmlCharPtrConstWrap(const xmlChar *str);
260 PyObject * libxml_xmlDocPtrWrap(xmlDocPtr doc);
261 PyObject * libxml_xmlNodePtrWrap(xmlNodePtr node);
262 PyObject * libxml_xmlAttrPtrWrap(xmlAttrPtr attr);
263 PyObject * libxml_xmlNsPtrWrap(xmlNsPtr ns);
264 PyObject * libxml_xmlAttributePtrWrap(xmlAttributePtr ns);
265 PyObject * libxml_xmlElementPtrWrap(xmlElementPtr ns);
266 PyObject * libxml_doubleWrap(double val);
267 PyObject * libxml_xmlXPathContextPtrWrap(xmlXPathContextPtr ctxt);
268 PyObject * libxml_xmlParserCtxtPtrWrap(xmlParserCtxtPtr ctxt);
269 PyObject * libxml_xmlXPathParserContextPtrWrap(xmlXPathParserContextPtr ctxt);
270 PyObject * libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj);
271 PyObject * libxml_xmlValidCtxtPtrWrap(xmlValidCtxtPtr valid);
272 PyObject * libxml_xmlCatalogPtrWrap(xmlCatalogPtr obj);
273 PyObject * libxml_xmlURIPtrWrap(xmlURIPtr uri);
274 PyObject * libxml_xmlOutputBufferPtrWrap(xmlOutputBufferPtr buffer);
275 PyObject * libxml_xmlParserInputBufferPtrWrap(xmlParserInputBufferPtr buffer);
276 #ifdef LIBXML_REGEXP_ENABLED
277 PyObject * libxml_xmlRegexpPtrWrap(xmlRegexpPtr regexp);
278 #endif /* LIBXML_REGEXP_ENABLED */
279 #ifdef LIBXML_READER_ENABLED
280 PyObject * libxml_xmlTextReaderPtrWrap(xmlTextReaderPtr reader);
281 PyObject * libxml_xmlTextReaderLocatorPtrWrap(xmlTextReaderLocatorPtr locator);
282 #endif
283
284 xmlXPathObjectPtr libxml_xmlXPathObjectPtrConvert(PyObject * obj);
285 #ifdef LIBXML_SCHEMAS_ENABLED
286 PyObject * libxml_xmlRelaxNGPtrWrap(xmlRelaxNGPtr ctxt);
287 PyObject * libxml_xmlRelaxNGParserCtxtPtrWrap(xmlRelaxNGParserCtxtPtr ctxt);
288 PyObject * libxml_xmlRelaxNGValidCtxtPtrWrap(xmlRelaxNGValidCtxtPtr valid);
289 PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
290 PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
291 PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
292 #endif /* LIBXML_SCHEMAS_ENABLED */
293 PyObject * libxml_xmlErrorPtrWrap(const xmlError *error);
294 PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
295 PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
296 PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
297 PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
298
299 int libxml_deprecationWarning(const char *func);