summaryrefslogtreecommitdiff
path: root/source4/librpc
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-04-21 11:14:11 +0200
committerAndrew Bartlett <abartlet@samba.org>2009-04-21 11:14:11 +0200
commit1856b999c88e0e460fbf713b459d5d367db999f2 (patch)
treebb84c9ac764c35f21eb0d238382d8862dd50f90d /source4/librpc
parent4c32978d973093903a5372a6f358275184bbcab2 (diff)
downloadsamba-1856b999c88e0e460fbf713b459d5d367db999f2.tar.gz
samba-1856b999c88e0e460fbf713b459d5d367db999f2.tar.bz2
samba-1856b999c88e0e460fbf713b459d5d367db999f2.zip
python/rpc: Add custom GUID.__str__, GUID.__repr__, GUID.__init__ and GUID.__cmp__.
Diffstat (limited to 'source4/librpc')
-rw-r--r--source4/librpc/ndr/py_misc.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/source4/librpc/ndr/py_misc.c b/source4/librpc/ndr/py_misc.c
new file mode 100644
index 0000000000..4e25566148
--- /dev/null
+++ b/source4/librpc/ndr/py_misc.c
@@ -0,0 +1,92 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
+
+ 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 3 of the License, or
+ (at your option) any later version.
+
+ 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, see <http://www.gnu.org/licenses/>.
+*/
+#include <Python.h>
+#include "librpc/gen_ndr/misc.h"
+
+#ifndef Py_RETURN_NONE
+#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
+#endif
+
+static int py_GUID_cmp(PyObject *py_self, PyObject *py_other)
+{
+ int ret;
+ struct GUID *self = py_talloc_get_ptr(py_self), *other;
+ other = py_talloc_get_ptr(py_other);
+ if (other == NULL)
+ return -1;
+
+ ret = GUID_compare(self, other);
+ if (ret < 0) {
+ return -1;
+ } else if (ret > 0) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+static PyObject *py_GUID_str(PyObject *py_self)
+{
+ struct GUID *self = py_talloc_get_ptr(py_self);
+ char *str = GUID_string(NULL, self);
+ PyObject *ret = PyString_FromString(str);
+ talloc_free(str);
+ return ret;
+}
+
+static PyObject *py_GUID_repr(PyObject *py_self)
+{
+ struct GUID *self = py_talloc_get_ptr(py_self);
+ char *str = GUID_string(NULL, self);
+ PyObject *ret = PyString_FromFormat("GUID('%s')", str);
+ talloc_free(str);
+ return ret;
+}
+
+static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ char *str = NULL;
+ NTSTATUS status;
+ struct GUID *guid = py_talloc_get_ptr(self);
+ const char *kwnames[] = { "str", NULL };
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", discard_const_p(char *, kwnames), &str))
+ return -1;
+
+ if (str != NULL) {
+ status = GUID_from_string(str, guid);
+ if (!NT_STATUS_IS_OK(status)) {
+ PyErr_SetNTSTATUS(status);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static void py_GUID_patch(PyTypeObject *type)
+{
+ type->tp_init = py_GUID_init;
+ type->tp_str = py_GUID_str;
+ type->tp_repr = py_GUID_repr;
+ type->tp_compare = py_GUID_cmp;
+}
+
+#define PY_GUID_PATCH py_GUID_patch
+