1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2013-2014 Planets Communications B.V.
5    Copyright (C) 2013-2016 Bareos GmbH & Co. KG
6 
7    This program is Free Software; you can modify it under the terms of
8    version three of the GNU Affero General Public License as published by the Free
9    Software Foundation, which is listed in the file LICENSE.
10 
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14    Affero General Public License for more details.
15 
16    You should have received a copy of the GNU Affero General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA.
20 */
21 /**
22  * @file
23  * This defines the Python types in C++ and the callbacks from Python we support.
24  */
25 
26 #ifndef BAREOS_PLUGINS_FILED_PYTHON_FD_H_
27 #define BAREOS_PLUGINS_FILED_PYTHON_FD_H_ 1
28 
29 #include "structmember.h"
30 
31 namespace filedaemon {
32 
33 /**
34  * This defines the arguments that the plugin parser understands.
35  */
36 enum plugin_argument_type {
37    argument_none,
38    argument_module_path,
39    argument_module_name
40 };
41 
42 struct plugin_argument {
43    const char *name;
44    enum plugin_argument_type type;
45 };
46 
47 static plugin_argument plugin_arguments[] = {
48    { "module_path", argument_module_path },
49    { "module_name", argument_module_name },
50    { NULL, argument_none }
51 };
52 
53 /**
54  * Python structures mapping C++ ones.
55  */
56 
57 /**
58  * This packet is used for the restore objects.
59  * It is passed to the plugin when restoring the object.
60  */
61 typedef struct {
62    PyObject_HEAD
63    PyObject *object_name;            /* Object name */
64    PyObject *object;                 /* Restore object data to restore */
65    char *plugin_name;                /* Plugin name */
66    int32_t object_type;              /* FT_xx for this file */
67    int32_t object_len;               /* restore object length */
68    int32_t object_full_len;          /* restore object uncompressed length */
69    int32_t object_index;             /* restore object index */
70    int32_t object_compression;       /* set to compression type */
71    int32_t stream;                   /* attribute stream id */
72    uint32_t JobId;                   /* JobId object came from */
73 } PyRestoreObject;
74 
75 /**
76  * Forward declarations of type specific functions.
77  */
78 static void PyRestoreObject_dealloc(PyRestoreObject *self);
79 static int PyRestoreObject_init(PyRestoreObject *self, PyObject *args, PyObject *kwds);
80 static PyObject *PyRestoreObject_repr(PyRestoreObject *self);
81 
82 static PyMethodDef PyRestoreObject_methods[] = {
83    { NULL }                           /* Sentinel */
84 };
85 
86 static PyMemberDef PyRestoreObject_members[] = {
87    { (char *)"object_name", T_OBJECT, offsetof(PyRestoreObject, object_name), 0, (char *)"Object Name" },
88    { (char *)"object", T_OBJECT, offsetof(PyRestoreObject, object), 0, (char *)"Object Content" },
89    { (char *)"plugin_name", T_STRING, offsetof(PyRestoreObject, plugin_name), 0, (char *)"Plugin Name" },
90    { (char *)"object_type", T_INT, offsetof(PyRestoreObject, object_type), 0, (char *)"Object Type" },
91    { (char *)"object_len", T_INT, offsetof(PyRestoreObject, object_len), 0, (char *)"Object Length" },
92    { (char *)"object_full_len", T_INT, offsetof(PyRestoreObject, object_full_len), 0, (char *)"Object Full Length" },
93    { (char *)"object_index", T_INT, offsetof(PyRestoreObject, object_index), 0, (char *)"Object Index" },
94    { (char *)"object_compression", T_INT, offsetof(PyRestoreObject, object_compression), 0, (char *)"Object Compression" },
95    { (char *)"stream", T_INT, offsetof(PyRestoreObject, stream), 0, (char *)"Attribute Stream" },
96    { (char *)"jobid", T_UINT, offsetof(PyRestoreObject, JobId), 0, (char *)"Jobid" },
97    { NULL }
98 };
99 
100 static PyTypeObject PyRestoreObjectType = {
101    PyVarObject_HEAD_INIT(NULL, 0)
102    "restore_object",                  /* tp_name */
103    sizeof(PyRestoreObject),           /* tp_basicsize */
104    0,                                 /* tp_itemsize */
105    (destructor)PyRestoreObject_dealloc, /* tp_dealloc */
106    0,                                 /* tp_print */
107    0,                                 /* tp_getattr */
108    0,                                 /* tp_setattr */
109    0,                                 /* tp_compare */
110    (reprfunc)PyRestoreObject_repr,    /* tp_repr */
111    0,                                 /* tp_as_number */
112    0,                                 /* tp_as_sequence */
113    0,                                 /* tp_as_mapping */
114    0,                                 /* tp_hash */
115    0,                                 /* tp_call */
116    0,                                 /* tp_str */
117    0,                                 /* tp_getattro */
118    0,                                 /* tp_setattro */
119    0,                                 /* tp_as_buffer */
120    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
121    "io_pkt object",                   /* tp_doc */
122    0,                                 /* tp_traverse */
123    0,                                 /* tp_clear */
124    0,                                 /* tp_richcompare */
125    0,                                 /* tp_weaklistoffset */
126    0,                                 /* tp_iter */
127    0,                                 /* tp_iternext */
128    PyRestoreObject_methods,           /* tp_methods */
129    PyRestoreObject_members,           /* tp_members */
130    0,                                 /* tp_getset */
131    0,                                 /* tp_base */
132    0,                                 /* tp_dict */
133    0,                                 /* tp_descr_get */
134    0,                                 /* tp_descr_set */
135    0,                                 /* tp_dictoffset */
136    (initproc)PyRestoreObject_init,    /* tp_init */
137    0,                                 /* tp_alloc */
138    0,                                 /* tp_new */
139 };
140 
141 /**
142  * The PyStatPacket type
143  */
144 typedef struct {
145    PyObject_HEAD
146    uint32_t dev;
147    uint64_t ino;
148    uint16_t mode;
149    int16_t nlink;
150    uint32_t uid;
151    uint32_t gid;
152    uint32_t rdev;
153    uint64_t size;
154    time_t atime;
155    time_t mtime;
156    time_t ctime;
157    uint32_t blksize;
158    uint64_t blocks;
159 } PyStatPacket;
160 
161 /**
162  * Forward declarations of type specific functions.
163  */
164 static void PyStatPacket_dealloc(PyStatPacket *self);
165 static int PyStatPacket_init(PyStatPacket *self, PyObject *args, PyObject *kwds);
166 static PyObject *PyStatPacket_repr(PyStatPacket *self);
167 
168 static PyMethodDef PyStatPacket_methods[] = {
169    { NULL }                           /* Sentinel */
170 };
171 
172 static PyMemberDef PyStatPacket_members[] = {
173    { (char *)"dev", T_UINT, offsetof(PyStatPacket, dev), 0, (char *)"Device" },
174    { (char *)"ino", T_ULONGLONG, offsetof(PyStatPacket, ino), 0, (char *)"Inode number" },
175    { (char *)"mode", T_USHORT, offsetof(PyStatPacket, mode), 0, (char *)"Mode" },
176    { (char *)"nlink", T_USHORT, offsetof(PyStatPacket, nlink), 0, (char *)"Number of hardlinks" },
177    { (char *)"uid", T_UINT, offsetof(PyStatPacket, uid), 0, (char *)"User Id" },
178    { (char *)"gid", T_UINT, offsetof(PyStatPacket, gid), 0, (char *)"Group Id" },
179    { (char *)"rdev", T_UINT, offsetof(PyStatPacket, rdev), 0, (char *)"Rdev" },
180    { (char *)"size", T_ULONGLONG, offsetof(PyStatPacket, size), 0, (char *)"Size" },
181    { (char *)"atime", T_UINT, offsetof(PyStatPacket, atime), 0, (char *)"Access Time" },
182    { (char *)"mtime", T_UINT, offsetof(PyStatPacket, mtime), 0, (char *)"Modification Time" },
183    { (char *)"ctime", T_UINT, offsetof(PyStatPacket, ctime), 0, (char *)"Change Time" },
184    { (char *)"blksize", T_UINT, offsetof(PyStatPacket, blksize), 0, (char *)"Blocksize" },
185    { (char *)"blocks", T_ULONGLONG, offsetof(PyStatPacket, blocks), 0, (char *)"Blocks" },
186    { NULL }
187 };
188 
189 static PyTypeObject PyStatPacketType = {
190    PyVarObject_HEAD_INIT(NULL, 0)
191    "stat_pkt",                        /* tp_name */
192    sizeof(PyStatPacket),              /* tp_basicsize */
193    0,                                 /* tp_itemsize */
194    (destructor)PyStatPacket_dealloc,  /* tp_dealloc */
195    0,                                 /* tp_print */
196    0,                                 /* tp_getattr */
197    0,                                 /* tp_setattr */
198    0,                                 /* tp_compare */
199    (reprfunc)PyStatPacket_repr,       /* tp_repr */
200    0,                                 /* tp_as_number */
201    0,                                 /* tp_as_sequence */
202    0,                                 /* tp_as_mapping */
203    0,                                 /* tp_hash */
204    0,                                 /* tp_call */
205    0,                                 /* tp_str */
206    0,                                 /* tp_getattro */
207    0,                                 /* tp_setattro */
208    0,                                 /* tp_as_buffer */
209    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
210    "io_pkt object",                   /* tp_doc */
211    0,                                 /* tp_traverse */
212    0,                                 /* tp_clear */
213    0,                                 /* tp_richcompare */
214    0,                                 /* tp_weaklistoffset */
215    0,                                 /* tp_iter */
216    0,                                 /* tp_iternext */
217    PyStatPacket_methods,              /* tp_methods */
218    PyStatPacket_members,              /* tp_members */
219    0,                                 /* tp_getset */
220    0,                                 /* tp_base */
221    0,                                 /* tp_dict */
222    0,                                 /* tp_descr_get */
223    0,                                 /* tp_descr_set */
224    0,                                 /* tp_dictoffset */
225    (initproc)PyStatPacket_init,       /* tp_init */
226    0,                                 /* tp_alloc */
227    0,                                 /* tp_new */
228 };
229 
230 /**
231  * The PySavePacket type
232  */
233 typedef struct {
234    PyObject_HEAD
235    PyObject *fname;                   /* Full path and filename */
236    PyObject *link;                    /* Link name if any */
237    PyObject *statp;                   /* System stat() packet for file */
238    int32_t type;                      /* FT_xx for this file */
239    PyObject *flags;                   /* Bareos internal flags */
240    bool no_read;                      /* During the save, the file should not be saved */
241    bool portable;                     /* set if data format is portable */
242    bool accurate_found;               /* Found in accurate list (valid after CheckChanges()) */
243    char *cmd;                         /* Command */
244    time_t save_time;                  /* Start of incremental time */
245    uint32_t delta_seq;                /* Delta sequence number */
246    PyObject *object_name;             /* Object name to create */
247    PyObject *object;                  /* Restore object data to save */
248    int32_t object_len;                /* Restore object length */
249    int32_t object_index;              /* Restore object index */
250 } PySavePacket;
251 
252 /**
253  * Forward declarations of type specific functions.
254  */
255 static void PySavePacket_dealloc(PySavePacket *self);
256 static int PySavePacket_init(PySavePacket *self, PyObject *args, PyObject *kwds);
257 static PyObject *PySavePacket_repr(PySavePacket *self);
258 
259 static PyMethodDef PySavePacket_methods[] = {
260    { NULL }                           /* Sentinel */
261 };
262 
263 static PyMemberDef PySavePacket_members[] = {
264    { (char *)"fname", T_OBJECT, offsetof(PySavePacket, fname), 0, (char *)"Filename" },
265    { (char *)"link", T_OBJECT, offsetof(PySavePacket, link), 0, (char *)"Linkname" },
266    { (char *)"statp", T_OBJECT, offsetof(PySavePacket, statp), 0, (char *)"Stat Packet" },
267    { (char *)"type", T_INT, offsetof(PySavePacket, type), 0, (char *)"Type" },
268    { (char *)"flags", T_OBJECT, offsetof(PySavePacket, flags), 0, (char *)"Flags" },
269    { (char *)"no_read", T_BOOL, offsetof(PySavePacket, no_read), 0, (char *)"No Read" },
270    { (char *)"portable", T_BOOL, offsetof(PySavePacket, portable), 0, (char *)"Portable" },
271    { (char *)"accurate_found", T_BOOL, offsetof(PySavePacket, accurate_found), 0, (char *)"Accurate Found" },
272    { (char *)"cmd", T_STRING, offsetof(PySavePacket, cmd), 0, (char *)"Command" },
273    { (char *)"save_time", T_UINT, offsetof(PySavePacket, save_time), 0, (char *)"Save Time" },
274    { (char *)"delta_seq", T_UINT, offsetof(PySavePacket, delta_seq), 0, (char *)"Delta Sequence" },
275    { (char *)"object_name", T_OBJECT, offsetof(PySavePacket, object_name), 0, (char *)"Restore Object Name" },
276    { (char *)"object", T_OBJECT, offsetof(PySavePacket, object), 0, (char *)"Restore ObjectName" },
277    { (char *)"object_len", T_INT, offsetof(PySavePacket, object_len), 0, (char *)"Restore ObjectLen" },
278    { (char *)"object_index", T_INT, offsetof(PySavePacket, object_index), 0, (char *)"Restore ObjectIndex" },
279    { NULL }
280 };
281 
282 static PyTypeObject PySavePacketType = {
283    PyVarObject_HEAD_INIT(NULL, 0)
284    "save_pkt",                        /* tp_name */
285    sizeof(PySavePacket),              /* tp_basicsize */
286    0,                                 /* tp_itemsize */
287    (destructor)PySavePacket_dealloc,  /* tp_dealloc */
288    0,                                 /* tp_print */
289    0,                                 /* tp_getattr */
290    0,                                 /* tp_setattr */
291    0,                                 /* tp_compare */
292    (reprfunc)PySavePacket_repr,       /* tp_repr */
293    0,                                 /* tp_as_number */
294    0,                                 /* tp_as_sequence */
295    0,                                 /* tp_as_mapping */
296    0,                                 /* tp_hash */
297    0,                                 /* tp_call */
298    0,                                 /* tp_str */
299    0,                                 /* tp_getattro */
300    0,                                 /* tp_setattro */
301    0,                                 /* tp_as_buffer */
302    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
303    "save_pkt object",                 /* tp_doc */
304    0,                                 /* tp_traverse */
305    0,                                 /* tp_clear */
306    0,                                 /* tp_richcompare */
307    0,                                 /* tp_weaklistoffset */
308    0,                                 /* tp_iter */
309    0,                                 /* tp_iternext */
310    PySavePacket_methods,              /* tp_methods */
311    PySavePacket_members,              /* tp_members */
312    0,                                 /* tp_getset */
313    0,                                 /* tp_base */
314    0,                                 /* tp_dict */
315    0,                                 /* tp_descr_get */
316    0,                                 /* tp_descr_set */
317    0,                                 /* tp_dictoffset */
318    (initproc)PySavePacket_init,       /* tp_init */
319    0,                                 /* tp_alloc */
320    0,                                 /* tp_new */
321 };
322 
323 /**
324  * The PyRestorePacket type
325  */
326 typedef struct {
327    PyObject_HEAD
328    int32_t stream;                    /* Attribute stream id */
329    int32_t data_stream;               /* Id of data stream to follow */
330    int32_t type;                      /* File type FT */
331    int32_t file_index;                /* File index */
332    int32_t LinkFI;                    /* File index to data if hard link */
333    uint32_t uid;                      /* Userid */
334    PyObject *statp;                   /* Decoded stat packet */
335    const char *attrEx;                /* Extended attributes if any */
336    const char *ofname;                /* Output filename */
337    const char *olname;                /* Output link name */
338    const char *where;                 /* Where */
339    const char *RegexWhere;            /* Regex where */
340    int replace;                       /* Replace flag */
341    int create_status;                 /* Status from createFile() */
342 } PyRestorePacket;
343 
344 /**
345  * Forward declarations of type specific functions.
346  */
347 static void PyRestorePacket_dealloc(PyRestorePacket *self);
348 static int PyRestorePacket_init(PyRestorePacket *self, PyObject *args, PyObject *kwds);
349 static PyObject *PyRestorePacket_repr(PyRestorePacket *self);
350 
351 static PyMethodDef PyRestorePacket_methods[] = {
352    { NULL }                           /* Sentinel */
353 };
354 
355 static PyMemberDef PyRestorePacket_members[] = {
356    { (char *)"stream", T_INT, offsetof(PyRestorePacket, stream), 0, (char *)"Attribute stream id" },
357    { (char *)"data_stream", T_INT, offsetof(PyRestorePacket, data_stream), 0, (char *)"Id of data stream to follow" },
358    { (char *)"type", T_INT, offsetof(PyRestorePacket, type), 0, (char *)"File type FT" },
359    { (char *)"file_index", T_INT, offsetof(PyRestorePacket, file_index), 0, (char *)"File index" },
360    { (char *)"linkFI", T_INT, offsetof(PyRestorePacket, LinkFI), 0, (char *)"File index to data if hard link" },
361    { (char *)"uid", T_UINT, offsetof(PyRestorePacket, uid), 0, (char *)"User Id" },
362    { (char *)"statp", T_OBJECT, offsetof(PyRestorePacket, statp), 0, (char *)"Stat Packet" },
363    { (char *)"attrEX", T_STRING, offsetof(PyRestorePacket, attrEx), 0, (char *)"Extended attributes" },
364    { (char *)"ofname", T_STRING, offsetof(PyRestorePacket, ofname), 0, (char *)"Output filename" },
365    { (char *)"olname", T_STRING, offsetof(PyRestorePacket, olname), 0, (char *)"Output link name" },
366    { (char *)"where", T_STRING, offsetof(PyRestorePacket, where), 0, (char *)"Where" },
367    { (char *)"regexwhere", T_STRING, offsetof(PyRestorePacket, RegexWhere), 0, (char *)"Regex where" },
368    { (char *)"replace", T_INT, offsetof(PyRestorePacket, replace), 0, (char *)"Replace flag" },
369    { (char *)"create_status", T_INT, offsetof(PyRestorePacket, create_status), 0, (char *)"Status from createFile()" },
370    { NULL }
371 };
372 
373 static PyTypeObject PyRestorePacketType = {
374    PyVarObject_HEAD_INIT(NULL, 0)
375    "restore_pkt",                     /* tp_name */
376    sizeof(PyRestorePacket),           /* tp_basicsize */
377    0,                                 /* tp_itemsize */
378    (destructor)PyRestorePacket_dealloc, /* tp_dealloc */
379    0,                                 /* tp_print */
380    0,                                 /* tp_getattr */
381    0,                                 /* tp_setattr */
382    0,                                 /* tp_compare */
383    (reprfunc)PyRestorePacket_repr,    /* tp_repr */
384    0,                                 /* tp_as_number */
385    0,                                 /* tp_as_sequence */
386    0,                                 /* tp_as_mapping */
387    0,                                 /* tp_hash */
388    0,                                 /* tp_call */
389    0,                                 /* tp_str */
390    0,                                 /* tp_getattro */
391    0,                                 /* tp_setattro */
392    0,                                 /* tp_as_buffer */
393    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
394    "restore_pkt object",              /* tp_doc */
395    0,                                 /* tp_traverse */
396    0,                                 /* tp_clear */
397    0,                                 /* tp_richcompare */
398    0,                                 /* tp_weaklistoffset */
399    0,                                 /* tp_iter */
400    0,                                 /* tp_iternext */
401    PyRestorePacket_methods,           /* tp_methods */
402    PyRestorePacket_members,           /* tp_members */
403    0,                                 /* tp_getset */
404    0,                                 /* tp_base */
405    0,                                 /* tp_dict */
406    0,                                 /* tp_descr_get */
407    0,                                 /* tp_descr_set */
408    0,                                 /* tp_dictoffset */
409    (initproc)PyRestorePacket_init,    /* tp_init */
410    0,                                 /* tp_alloc */
411    0,                                 /* tp_new */
412 };
413 
414 /**
415  * The PyIOPacket type
416  */
417 typedef struct {
418    PyObject_HEAD
419    uint16_t func;                     /* Function code */
420    int32_t count;                     /* Read/Write count */
421    int32_t flags;                     /* Open flags */
422    int32_t mode;                      /* Permissions for created files */
423    PyObject *buf;                     /* Read/Write buffer */
424    const char *fname;                 /* Open filename */
425    int32_t status;                    /* Return status */
426    int32_t io_errno;                  /* Errno code */
427    int32_t lerror;                    /* Win32 error code */
428    int32_t whence;                    /* Lseek argument */
429    int64_t offset;                    /* Lseek argument */
430    bool win32;                        /* Win32 GetLastError returned */
431 } PyIoPacket;
432 
433 /**
434  * Forward declarations of type specific functions.
435  */
436 static void PyIoPacket_dealloc(PyIoPacket *self);
437 static int PyIoPacket_init(PyIoPacket *self, PyObject *args, PyObject *kwds);
438 static PyObject *PyIoPacket_repr(PyIoPacket *self);
439 
440 static PyMethodDef PyIoPacket_methods[] = {
441    { NULL }                           /* Sentinel */
442 };
443 
444 static PyMemberDef PyIoPacket_members[] = {
445    { (char *)"func", T_USHORT, offsetof(PyIoPacket, func), 0, (char *)"Function code" },
446    { (char *)"count", T_INT, offsetof(PyIoPacket, count), 0, (char *)"Read/write count" },
447    { (char *)"flags", T_INT, offsetof(PyIoPacket, flags), 0, (char *)"Open flags" },
448    { (char *)"mode", T_INT, offsetof(PyIoPacket, mode), 0, (char *)"Permissions for created files" },
449    { (char *)"buf", T_OBJECT, offsetof(PyIoPacket, buf), 0, (char *)"Read/write buffer" },
450    { (char *)"fname", T_STRING, offsetof(PyIoPacket, fname), 0, (char *)"Open filename" },
451    { (char *)"status", T_INT, offsetof(PyIoPacket, status), 0, (char *)"Return status" },
452    { (char *)"io_errno", T_INT, offsetof(PyIoPacket, io_errno), 0, (char *)"Errno code" },
453    { (char *)"lerror", T_INT, offsetof(PyIoPacket, lerror), 0, (char *)"Win32 error code" },
454    { (char *)"whence", T_INT, offsetof(PyIoPacket, whence), 0, (char *)"Lseek argument" },
455    { (char *)"offset", T_LONGLONG, offsetof(PyIoPacket, offset), 0, (char *)"Lseek argument" },
456    { (char *)"win32", T_BOOL, offsetof(PyIoPacket, win32), 0, (char *)"Win32 GetLastError returned" },
457    { NULL }
458 };
459 
460 static PyTypeObject PyIoPacketType = {
461    PyVarObject_HEAD_INIT(NULL, 0)
462    "io_pkt",                          /* tp_name */
463    sizeof(PyIoPacket),                /* tp_basicsize */
464    0,                                 /* tp_itemsize */
465    (destructor)PyIoPacket_dealloc,    /* tp_dealloc */
466    0,                                 /* tp_print */
467    0,                                 /* tp_getattr */
468    0,                                 /* tp_setattr */
469    0,                                 /* tp_compare */
470    (reprfunc)PyIoPacket_repr,         /* tp_repr */
471    0,                                 /* tp_as_number */
472    0,                                 /* tp_as_sequence */
473    0,                                 /* tp_as_mapping */
474    0,                                 /* tp_hash */
475    0,                                 /* tp_call */
476    0,                                 /* tp_str */
477    0,                                 /* tp_getattro */
478    0,                                 /* tp_setattro */
479    0,                                 /* tp_as_buffer */
480    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
481    "io_pkt object",                   /* tp_doc */
482    0,                                 /* tp_traverse */
483    0,                                 /* tp_clear */
484    0,                                 /* tp_richcompare */
485    0,                                 /* tp_weaklistoffset */
486    0,                                 /* tp_iter */
487    0,                                 /* tp_iternext */
488    PyIoPacket_methods,                /* tp_methods */
489    PyIoPacket_members,                /* tp_members */
490    0,                                 /* tp_getset */
491    0,                                 /* tp_base */
492    0,                                 /* tp_dict */
493    0,                                 /* tp_descr_get */
494    0,                                 /* tp_descr_set */
495    0,                                 /* tp_dictoffset */
496    (initproc)PyIoPacket_init,         /* tp_init */
497    0,                                 /* tp_alloc */
498    0,                                 /* tp_new */
499 };
500 
501 /**
502  * The PyAclPacket type
503  */
504 typedef struct {
505    PyObject_HEAD
506    const char *fname;                 /* Filename */
507    PyObject *content;                 /* ACL content */
508 } PyAclPacket;
509 
510 /**
511  * Forward declarations of type specific functions.
512  */
513 static void PyAclPacket_dealloc(PyAclPacket *self);
514 static int PyAclPacket_init(PyAclPacket *self, PyObject *args, PyObject *kwds);
515 static PyObject *PyAclPacket_repr(PyAclPacket *self);
516 
517 static PyMethodDef PyAclPacket_methods[] = {
518    { NULL }                           /* Sentinel */
519 };
520 
521 static PyMemberDef PyAclPacket_members[] = {
522    { (char *)"fname", T_STRING, offsetof(PyAclPacket, fname), 0, (char *)"Filename" },
523    { (char *)"content", T_OBJECT, offsetof(PyAclPacket, content), 0, (char *)"ACL content buffer" },
524    { NULL }
525 };
526 
527 static PyTypeObject PyAclPacketType = {
528    PyVarObject_HEAD_INIT(NULL, 0)
529    "acl_pkt",                         /* tp_name */
530    sizeof(PyAclPacket),               /* tp_basicsize */
531    0,                                 /* tp_itemsize */
532    (destructor)PyAclPacket_dealloc,   /* tp_dealloc */
533    0,                                 /* tp_print */
534    0,                                 /* tp_getattr */
535    0,                                 /* tp_setattr */
536    0,                                 /* tp_compare */
537    (reprfunc)PyAclPacket_repr,        /* tp_repr */
538    0,                                 /* tp_as_number */
539    0,                                 /* tp_as_sequence */
540    0,                                 /* tp_as_mapping */
541    0,                                 /* tp_hash */
542    0,                                 /* tp_call */
543    0,                                 /* tp_str */
544    0,                                 /* tp_getattro */
545    0,                                 /* tp_setattro */
546    0,                                 /* tp_as_buffer */
547    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
548    "acl_pkt object",                  /* tp_doc */
549    0,                                 /* tp_traverse */
550    0,                                 /* tp_clear */
551    0,                                 /* tp_richcompare */
552    0,                                 /* tp_weaklistoffset */
553    0,                                 /* tp_iter */
554    0,                                 /* tp_iternext */
555    PyAclPacket_methods,               /* tp_methods */
556    PyAclPacket_members,               /* tp_members */
557    0,                                 /* tp_getset */
558    0,                                 /* tp_base */
559    0,                                 /* tp_dict */
560    0,                                 /* tp_descr_get */
561    0,                                 /* tp_descr_set */
562    0,                                 /* tp_dictoffset */
563    (initproc)PyAclPacket_init,        /* tp_init */
564    0,                                 /* tp_alloc */
565    0,                                 /* tp_new */
566 };
567 
568 /**
569  * The PyXattrPacket type
570  */
571 typedef struct {
572    PyObject_HEAD
573    const char *fname;                 /* Filename */
574    PyObject *name;                    /* XATTR name */
575    PyObject *value;                   /* XATTR value */
576 } PyXattrPacket;
577 
578 /**
579  * Forward declarations of type specific functions.
580  */
581 static void PyXattrPacket_dealloc(PyXattrPacket *self);
582 static int PyXattrPacket_init(PyXattrPacket *self, PyObject *args, PyObject *kwds);
583 static PyObject *PyXattrPacket_repr(PyXattrPacket *self);
584 
585 static PyMethodDef PyXattrPacket_methods[] = {
586    { NULL }                           /* Sentinel */
587 };
588 
589 static PyMemberDef PyXattrPacket_members[] = {
590    { (char *)"fname", T_STRING, offsetof(PyXattrPacket, fname), 0, (char *)"Filename" },
591    { (char *)"name", T_OBJECT, offsetof(PyXattrPacket, name), 0, (char *)"XATTR name buffer" },
592    { (char *)"value", T_OBJECT, offsetof(PyXattrPacket, value), 0, (char *)"XATTR value buffer" },
593    { NULL }
594 };
595 
596 static PyTypeObject PyXattrPacketType = {
597    PyVarObject_HEAD_INIT(NULL, 0)
598    "xattr_pkt",                       /* tp_name */
599    sizeof(PyXattrPacket),             /* tp_basicsize */
600    0,                                 /* tp_itemsize */
601    (destructor)PyXattrPacket_dealloc, /* tp_dealloc */
602    0,                                 /* tp_print */
603    0,                                 /* tp_getattr */
604    0,                                 /* tp_setattr */
605    0,                                 /* tp_compare */
606    (reprfunc)PyXattrPacket_repr,      /* tp_repr */
607    0,                                 /* tp_as_number */
608    0,                                 /* tp_as_sequence */
609    0,                                 /* tp_as_mapping */
610    0,                                 /* tp_hash */
611    0,                                 /* tp_call */
612    0,                                 /* tp_str */
613    0,                                 /* tp_getattro */
614    0,                                 /* tp_setattro */
615    0,                                 /* tp_as_buffer */
616    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags*/
617    "xattr_pkt object",                /* tp_doc */
618    0,                                 /* tp_traverse */
619    0,                                 /* tp_clear */
620    0,                                 /* tp_richcompare */
621    0,                                 /* tp_weaklistoffset */
622    0,                                 /* tp_iter */
623    0,                                 /* tp_iternext */
624    PyXattrPacket_methods,             /* tp_methods */
625    PyXattrPacket_members,             /* tp_members */
626    0,                                 /* tp_getset */
627    0,                                 /* tp_base */
628    0,                                 /* tp_dict */
629    0,                                 /* tp_descr_get */
630    0,                                 /* tp_descr_set */
631    0,                                 /* tp_dictoffset */
632    (initproc)PyXattrPacket_init,      /* tp_init */
633    0,                                 /* tp_alloc */
634    0,                                 /* tp_new */
635 };
636 
637 /**
638  * Callback methods from Python.
639  */
640 static PyObject *PyBareosGetValue(PyObject *self, PyObject *args);
641 static PyObject *PyBareosSetValue(PyObject *self, PyObject *args);
642 static PyObject *PyBareosDebugMessage(PyObject *self, PyObject *args);
643 static PyObject *PyBareosJobMessage(PyObject *self, PyObject *args);
644 static PyObject *PyBareosRegisterEvents(PyObject *self, PyObject *args);
645 static PyObject *PyBareosUnRegisterEvents(PyObject *self, PyObject *args);
646 static PyObject *PyBareosGetInstanceCount(PyObject *self, PyObject *args);
647 static PyObject *PyBareosAddExclude(PyObject *self, PyObject *args);
648 static PyObject *PyBareosAddInclude(PyObject *self, PyObject *args);
649 static PyObject *PyBareosAddOptions(PyObject *self, PyObject *args);
650 static PyObject *PyBareosAddRegex(PyObject *self, PyObject *args);
651 static PyObject *PyBareosAddWild(PyObject *self, PyObject *args);
652 static PyObject *PyBareosNewOptions(PyObject *self, PyObject *args);
653 static PyObject *PyBareosNewInclude(PyObject *self, PyObject *args);
654 static PyObject *PyBareosNewPreInclude(PyObject *self, PyObject *args);
655 static PyObject *PyBareosCheckChanges(PyObject *self, PyObject *args);
656 static PyObject *PyBareosAcceptFile(PyObject *self, PyObject *args);
657 static PyObject *PyBareosSetSeenBitmap(PyObject *self, PyObject *args);
658 static PyObject *PyBareosClearSeenBitmap(PyObject *self, PyObject *args);
659 
660 static PyMethodDef BareosFDMethods[] = {
661    { "GetValue", PyBareosGetValue, METH_VARARGS, "Get a Plugin value" },
662    { "SetValue", PyBareosSetValue, METH_VARARGS, "Set a Plugin value" },
663    { "DebugMessage", PyBareosDebugMessage, METH_VARARGS, "Print a Debug message" },
664    { "JobMessage", PyBareosJobMessage, METH_VARARGS, "Print a Job message" },
665    { "RegisterEvents", PyBareosRegisterEvents, METH_VARARGS, "Register Plugin Events" },
666    { "UnRegisterEvents", PyBareosUnRegisterEvents, METH_VARARGS, "Unregister Plugin Events" },
667    { "GetInstanceCount", PyBareosGetInstanceCount, METH_VARARGS, "Get number of instances of current plugin" },
668    { "AddExclude", PyBareosAddExclude, METH_VARARGS, "Add Exclude pattern" },
669    { "AddInclude", PyBareosAddInclude, METH_VARARGS, "Add Include pattern" },
670    { "AddOptions", PyBareosAddOptions, METH_VARARGS, "Add Include options" },
671    { "AddRegex", PyBareosAddRegex, METH_VARARGS, "Add regex" },
672    { "AddWild", PyBareosAddWild, METH_VARARGS, "Add wildcard" },
673    { "NewOptions", PyBareosNewOptions, METH_VARARGS, "Add new option block" },
674    { "NewInclude", PyBareosNewInclude, METH_VARARGS, "Add new include block" },
675    { "NewPreInclude", PyBareosNewPreInclude, METH_VARARGS, "Add new pre include block" },
676    { "CheckChanges", PyBareosCheckChanges, METH_VARARGS, "Check if a file have to be backuped using Accurate code" },
677    { "AcceptFile", PyBareosAcceptFile, METH_VARARGS, "Check if a file would be saved using current Include/Exclude code" },
678    { "SetSeenBitmap", PyBareosSetSeenBitmap, METH_VARARGS, "Set bit in the Accurate Seen bitmap" },
679    { "ClearSeenBitmap", PyBareosClearSeenBitmap, METH_VARARGS, "Clear bit in the Accurate Seen bitmap" },
680    { NULL, NULL, 0, NULL }
681 };
682 
683 } /* namespace filedaemon */
684 #endif /* BAREOS_PLUGINS_FILED_PYTHON_FD_H_ */
685