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 <Python.h>
|
---|
21 | #include "includes.h"
|
---|
22 | #include "lib/com/com.h"
|
---|
23 | #include "librpc/ndr/libndr.h"
|
---|
24 | #include "libcli/util/pyerrors.h"
|
---|
25 |
|
---|
26 | void initcom(void);
|
---|
27 |
|
---|
28 | static struct com_context *py_com_ctx = NULL; /* FIXME: evil global */
|
---|
29 |
|
---|
30 | static PyObject *py_get_class_object(PyObject *self, PyObject *args)
|
---|
31 | {
|
---|
32 | char *s_clsid, *s_iid;
|
---|
33 | struct GUID clsid, iid;
|
---|
34 | struct IUnknown *object;
|
---|
35 | NTSTATUS status;
|
---|
36 | WERROR error;
|
---|
37 |
|
---|
38 | if (!PyArg_ParseTuple(args, "ss", &s_clsid, &s_iid))
|
---|
39 | return NULL;
|
---|
40 |
|
---|
41 | status = GUID_from_string(s_clsid, &clsid);
|
---|
42 | if (!NT_STATUS_IS_OK(status)) {
|
---|
43 | PyErr_FromNTSTATUS(status);
|
---|
44 | return NULL;
|
---|
45 | }
|
---|
46 |
|
---|
47 | status = GUID_from_string(s_iid, &iid);
|
---|
48 | if (!NT_STATUS_IS_OK(status)) {
|
---|
49 | PyErr_FromNTSTATUS(status);
|
---|
50 | return NULL;
|
---|
51 | }
|
---|
52 |
|
---|
53 | error = com_get_class_object(py_com_ctx, &clsid, &iid, &object);
|
---|
54 | if (!W_ERROR_IS_OK(error)) {
|
---|
55 | PyErr_FromWERROR(error);
|
---|
56 | return NULL;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /* FIXME: Magic, integrate with stubs generated by pidl. */
|
---|
60 |
|
---|
61 | Py_RETURN_NONE;
|
---|
62 | }
|
---|
63 |
|
---|
64 | static struct PyMethodDef com_methods[] = {
|
---|
65 | { "get_class_object", (PyCFunction)py_get_class_object, METH_VARARGS, "S.get_class_object(clsid, iid) -> instance" },
|
---|
66 | { NULL },
|
---|
67 | };
|
---|
68 |
|
---|
69 | void initcom(void)
|
---|
70 | {
|
---|
71 | PyObject *m;
|
---|
72 | WERROR error;
|
---|
73 |
|
---|
74 | error = com_init_ctx(&py_com_ctx, NULL);
|
---|
75 | if (!W_ERROR_IS_OK(error)) {
|
---|
76 | PyErr_FromWERROR(error);
|
---|
77 | return;
|
---|
78 | }
|
---|
79 |
|
---|
80 | m = Py_InitModule3("com", com_methods, "Simple COM implementation");
|
---|
81 | if (m == NULL)
|
---|
82 | return;
|
---|
83 | }
|
---|