1/* 2 Unix SMB/CIFS implementation. 3 Python bindings for COM library. 4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18*/ 19 20#include "includes.h" 21#include <Python.h> 22#include "lib/com/com.h" 23#include "librpc/ndr/libndr.h" 24#include "libcli/util/pyerrors.h" 25 26#ifndef Py_RETURN_NONE 27#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 28#endif 29 30static struct com_context *py_com_ctx = NULL; /* FIXME: evil global */ 31 32static PyObject *py_get_class_object(PyObject *self, PyObject *args) 33{ 34 char *s_clsid, *s_iid; 35 struct GUID clsid, iid; 36 struct IUnknown *object; 37 NTSTATUS status; 38 WERROR error; 39 40 if (!PyArg_ParseTuple(args, "ss", &s_clsid, &s_iid)) 41 return NULL; 42 43 status = GUID_from_string(s_clsid, &clsid); 44 if (!NT_STATUS_IS_OK(status)) { 45 PyErr_FromNTSTATUS(status); 46 return NULL; 47 } 48 49 status = GUID_from_string(s_iid, &iid); 50 if (!NT_STATUS_IS_OK(status)) { 51 PyErr_FromNTSTATUS(status); 52 return NULL; 53 } 54 55 error = com_get_class_object(py_com_ctx, &clsid, &iid, &object); 56 if (!W_ERROR_IS_OK(error)) { 57 PyErr_FromWERROR(error); 58 return NULL; 59 } 60 61 /* FIXME: Magic, integrate with stubs generated by pidl. */ 62 63 Py_RETURN_NONE; 64} 65 66static struct PyMethodDef com_methods[] = { 67 { "get_class_object", (PyCFunction)py_get_class_object, METH_VARARGS, "S.get_class_object(clsid, iid) -> instance" }, 68 { NULL }, 69}; 70 71void initcom(void) 72{ 73 PyObject *m; 74 WERROR error; 75 76 error = com_init_ctx(&py_com_ctx, NULL); 77 if (!W_ERROR_IS_OK(error)) { 78 PyErr_FromWERROR(error); 79 return; 80 } 81 82 m = Py_InitModule3("com", com_methods, "Simple COM implementation"); 83 if (m == NULL) 84 return; 85} 86