libsmbconf: Document smbconf_get_share().
[Samba.git] / source4 / lib / com / pycom.c
blob3323ca645e680948ff84b988cbff02c972909412
1 /*
2 Unix SMB/CIFS implementation.
3 Python bindings for COM library.
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
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.
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.
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/>.
20 #include <Python.h>
21 #include "includes.h"
22 #include "lib/com/com.h"
23 #include "librpc/ndr/libndr.h"
24 #include "libcli/util/pyerrors.h"
26 static struct com_context *py_com_ctx = NULL; /* FIXME: evil global */
28 static PyObject *py_get_class_object(PyObject *self, PyObject *args)
30 char *s_clsid, *s_iid;
31 struct GUID clsid, iid;
32 struct IUnknown *object;
33 NTSTATUS status;
34 WERROR error;
36 if (!PyArg_ParseTuple(args, "ss", &s_clsid, &s_iid))
37 return NULL;
39 status = GUID_from_string(s_clsid, &clsid);
40 if (!NT_STATUS_IS_OK(status)) {
41 PyErr_FromNTSTATUS(status);
42 return NULL;
45 status = GUID_from_string(s_iid, &iid);
46 if (!NT_STATUS_IS_OK(status)) {
47 PyErr_FromNTSTATUS(status);
48 return NULL;
51 error = com_get_class_object(py_com_ctx, &clsid, &iid, &object);
52 if (!W_ERROR_IS_OK(error)) {
53 PyErr_FromWERROR(error);
54 return NULL;
57 /* FIXME: Magic, integrate with stubs generated by pidl. */
59 Py_RETURN_NONE;
62 static struct PyMethodDef com_methods[] = {
63 { "get_class_object", (PyCFunction)py_get_class_object, METH_VARARGS, "S.get_class_object(clsid, iid) -> instance" },
64 { NULL },
67 void initcom(void)
69 PyObject *m;
70 WERROR error;
72 error = com_init_ctx(&py_com_ctx, NULL);
73 if (!W_ERROR_IS_OK(error)) {
74 PyErr_FromWERROR(error);
75 return;
78 m = Py_InitModule3("com", com_methods, "Simple COM implementation");
79 if (m == NULL)
80 return;