1 /*
2 * Python object definition of the libolecf property set stream
3 *
4 * Copyright (C) 2008-2021, Joachim Metz <joachim.metz@gmail.com>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <common.h>
23 #include <types.h>
24
25 #if defined( HAVE_STDLIB_H ) || defined( HAVE_WINAPI )
26 #include <stdlib.h>
27 #endif
28
29 #include "pyolecf_error.h"
30 #include "pyolecf_libcerror.h"
31 #include "pyolecf_libolecf.h"
32 #include "pyolecf_property_set.h"
33 #include "pyolecf_property_set_stream.h"
34 #include "pyolecf_python.h"
35 #include "pyolecf_stream.h"
36 #include "pyolecf_unused.h"
37
38 PyMethodDef pyolecf_property_set_stream_object_methods[] = {
39
40 /* Functions to access the property set stream values */
41
42 { "get_set",
43 (PyCFunction) pyolecf_property_set_stream_get_set,
44 METH_NOARGS,
45 "get_set() -> Object or None\n"
46 "\n"
47 "Retrieves the property set." },
48
49 /* Sentinel */
50 { NULL, NULL, 0, NULL }
51 };
52
53 PyGetSetDef pyolecf_property_set_stream_object_get_set_definitions[] = {
54
55 { "set",
56 (getter) pyolecf_property_set_stream_get_set,
57 (setter) 0,
58 "The property set",
59 NULL },
60
61 /* Sentinel */
62 { NULL, NULL, NULL, NULL, NULL }
63 };
64
65 PyTypeObject pyolecf_property_set_stream_type_object = {
66 PyVarObject_HEAD_INIT( NULL, 0 )
67
68 /* tp_name */
69 "pyolecf.property_set_stream",
70 /* tp_basicsize */
71 sizeof( pyolecf_item_t ),
72 /* tp_itemsize */
73 0,
74 /* tp_dealloc */
75 0,
76 /* tp_print */
77 0,
78 /* tp_getattr */
79 0,
80 /* tp_setattr */
81 0,
82 /* tp_compare */
83 0,
84 /* tp_repr */
85 0,
86 /* tp_as_number */
87 0,
88 /* tp_as_sequence */
89 0,
90 /* tp_as_mapping */
91 0,
92 /* tp_hash */
93 0,
94 /* tp_call */
95 0,
96 /* tp_str */
97 0,
98 /* tp_getattro */
99 0,
100 /* tp_setattro */
101 0,
102 /* tp_as_buffer */
103 0,
104 /* tp_flags */
105 Py_TPFLAGS_DEFAULT,
106 /* tp_doc */
107 "pyolecf propery set stream object (wraps libolecf_item_t type 0x02)",
108 /* tp_traverse */
109 0,
110 /* tp_clear */
111 0,
112 /* tp_richcompare */
113 0,
114 /* tp_weaklistoffset */
115 0,
116 /* tp_iter */
117 0,
118 /* tp_iternext */
119 0,
120 /* tp_methods */
121 pyolecf_property_set_stream_object_methods,
122 /* tp_members */
123 0,
124 /* tp_getset */
125 pyolecf_property_set_stream_object_get_set_definitions,
126 /* tp_base */
127 &pyolecf_stream_type_object,
128 /* tp_dict */
129 0,
130 /* tp_descr_get */
131 0,
132 /* tp_descr_set */
133 0,
134 /* tp_dictoffset */
135 0,
136 /* tp_init */
137 0,
138 /* tp_alloc */
139 0,
140 /* tp_new */
141 0,
142 /* tp_free */
143 0,
144 /* tp_is_gc */
145 0,
146 /* tp_bases */
147 NULL,
148 /* tp_mro */
149 NULL,
150 /* tp_cache */
151 NULL,
152 /* tp_subclasses */
153 NULL,
154 /* tp_weaklist */
155 NULL,
156 /* tp_del */
157 0
158 };
159
160 /* Retrieves the property set
161 * Returns a Python object if successful or NULL on error
162 */
pyolecf_property_set_stream_get_set(pyolecf_item_t * pyolecf_item,PyObject * arguments PYOLECF_ATTRIBUTE_UNUSED)163 PyObject *pyolecf_property_set_stream_get_set(
164 pyolecf_item_t *pyolecf_item,
165 PyObject *arguments PYOLECF_ATTRIBUTE_UNUSED )
166 {
167 libcerror_error_t *error = NULL;
168 libolecf_property_set_t *property_set = NULL;
169 PyObject *property_set_object = NULL;
170 static char *function = "pyolecf_property_set_stream_get_set";
171 int result = 0;
172
173 PYOLECF_UNREFERENCED_PARAMETER( arguments )
174
175 if( pyolecf_item == NULL )
176 {
177 PyErr_Format(
178 PyExc_TypeError,
179 "%s: invalid item.",
180 function );
181
182 return( NULL );
183 }
184 Py_BEGIN_ALLOW_THREADS
185
186 result = libolecf_property_set_stream_get_set(
187 pyolecf_item->item,
188 &property_set,
189 &error );
190
191 Py_END_ALLOW_THREADS
192
193 if( result != 1 )
194 {
195 pyolecf_error_raise(
196 error,
197 PyExc_IOError,
198 "%s: unable to retrieve property set.",
199 function );
200
201 libcerror_error_free(
202 &error );
203
204 goto on_error;
205 }
206 property_set_object = pyolecf_property_set_new(
207 property_set,
208 (PyObject *) pyolecf_item );
209
210 if( property_set_object == NULL )
211 {
212 PyErr_Format(
213 PyExc_MemoryError,
214 "%s: unable to create property set object.",
215 function );
216
217 goto on_error;
218 }
219 return( property_set_object );
220
221 on_error:
222 if( property_set != NULL )
223 {
224 libolecf_property_set_free(
225 &property_set,
226 NULL );
227 }
228 return( NULL );
229 }
230
231