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