-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwrap_objs.c
177 lines (144 loc) · 4.16 KB
/
wrap_objs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* $Id$
*
* PyXMLSec - Python bindings for XML Security library (XMLSec)
*
* Copyright (C) 2003-2013 Easter-eggs, Valery Febvre
* http://pyxmlsec.labs.libre-entreprise.org
*
* Author: Valery Febvre <[email protected]>
*
* This is free software; see COPYING file in the source
* distribution for preciese wording.
*/
#include "wrap_objs.h"
/*****************************************************************************/
/* Functions to wrap Python objects -> C objects */
/*****************************************************************************/
xmlChar **PythonStringList_get(PyObject *list_obj) {
int i;
xmlChar **list = NULL;
if (list_obj == Py_None) return NULL;
/* convert Python list into a NULL terminated C list */
list = (xmlChar **) xmlMalloc ((PyList_Size(list_obj)+1)*sizeof (xmlChar *));
for (i=0; i<PyList_Size(list_obj); i++)
list[i] = (xmlChar *)PyString_AsString(PyList_GetItem(list_obj, i));
list[i] = NULL;
return list;
}
/*****************************************************************************/
/* Functions to wrap C objects -> Python objects */
/*****************************************************************************/
PyObject *wrap_int(int val) {
return (Py_BuildValue("i", val));
}
PyObject *wrap_charPtr(char *str) {
PyObject *ret;
if (str == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyString_FromString(str);
/* deallocation */
free (str);
return (ret);
}
PyObject *wrap_charPtrConst(const char *str) {
PyObject *ret;
if (str == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyString_FromString(str);
return (ret);
}
/*****************************************************************************/
/* Functions to wrap LibXML objects -> Python objects */
/*****************************************************************************/
PyObject *wrap_xmlCharPtr(xmlChar *str) {
PyObject *ret;
if (str == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyString_FromString((char *) str);
/* deallocation */
xmlFree(str);
return (ret);
}
PyObject *wrap_xmlCharPtrConst(const xmlChar *str) {
PyObject *ret;
if (str == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyString_FromString((char *) str);
return (ret);
}
PyObject *wrap_xmlDocPtr(xmlDocPtr doc) {
PyObject *ret;
if (doc == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) doc, (char *) "xmlDocPtr", NULL);
return (ret);
}
PyObject *wrap_xmlNodePtr(xmlNodePtr node) {
PyObject *ret;
if (node == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) node, (char *) "xmlNodePtr", NULL);
return (ret);
}
PyObject *wrap_xmlNodeSetPtr(xmlNodeSetPtr nset) {
PyObject *ret;
if (nset == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) nset, (char *) "xmlNodeSetPtr", NULL);
return (ret);
}
PyObject *wrap_xmlOutputBufferPtr(xmlOutputBufferPtr buf) {
PyObject *ret;
if (buf == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCObject_FromVoidPtrAndDesc((void *) buf,
(char *) "xmlOutputBufferPtr", NULL);
return (ret);
}
/*****************************************************************************/
/* Functions to wrap XMLSec objects -> Python objects */
/*****************************************************************************/
PyObject *wrap_xmlSecPtr(xmlSecPtr ptr) {
PyObject *ret;
if (ptr == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = (PyCObject_FromVoidPtr((void *) ptr, NULL));
return (ret);
}
PyObject *wrap_xmlSecBytePtr(xmlSecByte *str) {
PyObject *ret;
if (str == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyString_FromString((char *) str);
xmlFree(str);
return (ret);
}
PyObject *wrap_xmlSecBytePtrConst(const xmlSecByte *str) {
PyObject *ret;
if (str == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyString_FromString((char *) str);
return (ret);
}