X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffiled%2Fpythonfd.c;h=ab15c6b9ada0a8320784f8c82d8c02f4ce02c0e1;hb=72863eb7569fa014b05e8f98aac32d773825b51c;hp=22008eebac8648da64f8a5ac14eddf3a641870d5;hpb=ee7264d0897b1720b53779062938a6abc404007b;p=bacula%2Fbacula diff --git a/bacula/src/filed/pythonfd.c b/bacula/src/filed/pythonfd.c index 22008eebac..ab15c6b9ad 100644 --- a/bacula/src/filed/pythonfd.c +++ b/bacula/src/filed/pythonfd.c @@ -1,31 +1,38 @@ /* - * - * Bacula interface to Python for the File Daemon - * - * Kern Sibbald, March MMV - * - * Version $Id$ - * - */ + Bacula® - The Network Backup Solution -/* - Copyright (C) 2005-2006 Kern Sibbald + Copyright (C) 2005-2008 Free Software Foundation Europe e.V. - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version three of the GNU Affero General Public + License as published by the Free Software Foundation and included + in the file LICENSE. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + You should have received a copy of the GNU Affero General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * + * Bacula interface to Python for the File Daemon + * + * Kern Sibbald, March MMV + * + * Version $Id$ + * */ #include "bacula.h" @@ -35,16 +42,7 @@ #undef _POSIX_C_SOURCE #include -/* External function pointers to be set */ -extern bool (*python_set_prog)(JCR *jcr, const char *prog); -extern int (*python_open)(BFILE *bfd, const char *fname, int flags, mode_t mode); -extern int (*python_close)(BFILE *bfd); -extern ssize_t (*python_read)(BFILE *bfd, void *buf, size_t count); - - -extern JCR *get_jcr_from_PyObject(PyObject *self); -extern PyObject *find_method(PyObject *eventsObject, PyObject *method, - const char *name); +#include /* Forward referenced functions */ static PyObject *set_job_events(PyObject *self, PyObject *arg); @@ -57,33 +55,27 @@ PyMethodDef JobMethods[] = { }; -bool my_python_set_prog(JCR *jcr, const char *prog); -int my_python_open(BFILE *bfd, const char *fname, int flags, mode_t mode); -int my_python_close(BFILE *bfd); -ssize_t my_python_read(BFILE *bfd, void *buf, size_t count); - - struct s_vars { const char *name; - char *fmt; + const char *fmt; }; /* Read-only variables */ static struct s_vars getvars[] = { - { N_("FDName"), "s"}, /* 0 */ - { N_("Level"), "s"}, /* 1 */ - { N_("Type"), "s"}, /* 2 */ - { N_("JobId"), "i"}, /* 3 */ - { N_("Client"), "s"}, /* 4 */ - { N_("JobName"), "s"}, /* 5 */ - { N_("JobStatus"), "s"}, /* 6 */ + { NT_("FDName"), "s"}, /* 0 */ + { NT_("Level"), "s"}, /* 1 */ + { NT_("Type"), "s"}, /* 2 */ + { NT_("JobId"), "i"}, /* 3 */ + { NT_("Client"), "s"}, /* 4 */ + { NT_("JobName"), "s"}, /* 5 */ + { NT_("JobStatus"), "s"}, /* 6 */ { NULL, NULL} }; /* Writable variables */ static struct s_vars setvars[] = { - { N_("JobReport"), "s"}, + { NT_("JobReport"), "s"}, { NULL, NULL} }; @@ -114,21 +106,21 @@ PyObject *job_getattr(PyObject *self, char *attrname) } switch (i) { case 0: /* FD's name */ - return Py_BuildValue(getvars[i].fmt, my_name); + return Py_BuildValue((char *)getvars[i].fmt, my_name); case 1: /* level */ - return Py_BuildValue(getvars[i].fmt, job_level_to_str(jcr->JobLevel)); + return Py_BuildValue((char *)getvars[i].fmt, job_level_to_str(jcr->getJobLevel())); case 2: /* type */ - return Py_BuildValue(getvars[i].fmt, job_type_to_str(jcr->JobType)); + return Py_BuildValue((char *)getvars[i].fmt, job_type_to_str(jcr->getJobType())); case 3: /* JobId */ - return Py_BuildValue(getvars[i].fmt, jcr->JobId); + return Py_BuildValue((char *)getvars[i].fmt, jcr->JobId); case 4: /* Client */ - return Py_BuildValue(getvars[i].fmt, jcr->client_name); + return Py_BuildValue((char *)getvars[i].fmt, jcr->client_name); case 5: /* JobName */ - return Py_BuildValue(getvars[i].fmt, jcr->Job); + return Py_BuildValue((char *)getvars[i].fmt, jcr->Job); case 6: /* JobStatus */ buf[1] = 0; buf[0] = jcr->JobStatus; - return Py_BuildValue(getvars[i].fmt, buf); + return Py_BuildValue((char *)getvars[i].fmt, buf); } bsnprintf(errmsg, sizeof(errmsg), _("Attribute %s not found."), attrname); bail_out: @@ -171,7 +163,7 @@ int job_setattr(PyObject *self, char *attrname, PyObject *value) } /* Get argument value ***FIXME*** handle other formats */ if (setvars[i].fmt != NULL) { - if (!PyArg_Parse(value, setvars[i].fmt, &strval)) { + if (!PyArg_Parse(value, (char *)setvars[i].fmt, &strval)) { PyErr_SetString(PyExc_TypeError, _("Read-only attribute")); return -1; } @@ -194,7 +186,7 @@ static PyObject *job_write(PyObject *self, PyObject *args) char *text = NULL; if (!PyArg_ParseTuple(args, "s:write", &text)) { - Dmsg0(000, "Parse tuple error in job_write\n"); + Pmsg0(000, "Parse tuple error in job_write\n"); return NULL; } if (text) { @@ -212,7 +204,7 @@ static PyObject *set_job_events(PyObject *self, PyObject *arg) Dmsg0(100, "In set_job_events.\n"); if (!PyArg_ParseTuple(arg, "O", &eObject)) { - Dmsg0(000, "Parse error looking for Object argument\n"); + Pmsg0(000, "Parse error looking for Object argument\n"); return NULL; } jcr = get_jcr_from_PyObject(self); @@ -224,12 +216,6 @@ static PyObject *set_job_events(PyObject *self, PyObject *arg) Py_INCREF(eObject); jcr->Python_events = (void *)eObject; /* set new events */ - /* Set function pointers to call here */ - python_set_prog = my_python_set_prog; - python_open = my_python_open; - python_close = my_python_close; - python_read = my_python_read; - Py_INCREF(Py_None); return Py_None; } @@ -247,7 +233,8 @@ int generate_job_event(JCR *jcr, const char *event) return 0; } - PyEval_AcquireLock(); + lock_python(); +// PyEval_AcquireLock(); method = find_method(events, method, event); if (!method) { @@ -255,12 +242,12 @@ int generate_job_event(JCR *jcr, const char *event) } bstrncpy(jcr->event, event, sizeof(jcr->event)); - result = PyObject_CallFunction(method, "O", Job); + result = PyObject_CallFunction(method, (char *)"O", Job); jcr->event[0] = 0; /* no event in progress */ if (result == NULL) { if (PyErr_Occurred()) { PyErr_Print(); - Dmsg1(000, "Error in Python method %s\n", event); + Pmsg1(000, "Error in Python method %s\n", event); } } else { stat = 1; @@ -268,50 +255,12 @@ int generate_job_event(JCR *jcr, const char *event) Py_XDECREF(result); bail_out: - PyEval_ReleaseLock(); + unlock_python(); +// PyEval_ReleaseLock(); return stat; } -bool my_python_set_prog(JCR *jcr, const char *prog) -{ - PyObject *events = (PyObject *)jcr->Python_events; - BFILE *bfd = &jcr->ff->bfd; - char method[MAX_NAME_LENGTH]; - - if (!events) { - return false; - } - bstrncpy(method, prog, sizeof(method)); - bstrncat(method, "_", sizeof(method)); - bstrncat(method, "open", sizeof(method)); - bfd->pio.fo = find_method(events, bfd->pio.fo, method); - bstrncpy(method, prog, sizeof(method)); - bstrncat(method, "_", sizeof(method)); - bstrncat(method, "read", sizeof(method)); - bfd->pio.fr = find_method(events, bfd->pio.fr, method); - bstrncpy(method, prog, sizeof(method)); - bstrncat(method, "_", sizeof(method)); - bstrncat(method, "close", sizeof(method)); - bfd->pio.fc = find_method(events, bfd->pio.fc, method); - return bfd->pio.fo && bfd->pio.fr && bfd->pio.fc; -} - -int my_python_open(BFILE *bfd, const char *fname, int flags, mode_t mode) -{ - return -1; -} - -int my_python_close(BFILE *bfd) -{ - return 0; -} - -ssize_t my_python_read(BFILE *bfd, void *buf, size_t count) -{ - return -1; -} - #else /* Dummy if Python not configured */