Line data Source code
1 : /* 2 : Unix SMB/CIFS implementation. 3 : Samba utility functions 4 : 5 : Copyright (C) Catalyst IT 2017 6 : 7 : This program is free software; you can redistribute it and/or modify 8 : it under the terms of the GNU General Public License as published by 9 : the Free Software Foundation; either version 3 of the License, or 10 : (at your option) any later version. 11 : 12 : This program is distributed in the hope that it will be useful, 13 : but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : GNU General Public License for more details. 16 : 17 : You should have received a copy of the GNU General Public License 18 : along with this program. If not, see <http://www.gnu.org/licenses/>. 19 : */ 20 : #include "lib/replace/system/python.h" 21 : #include "librpc/gen_ndr/lsa.h" 22 : 23 1980 : static PyObject *py_lsa_String_str(PyObject *py_self) 24 : { 25 1980 : struct lsa_String *self = pytalloc_get_ptr(py_self); 26 1980 : PyObject *ret = NULL; 27 1980 : if (self->string == NULL) { 28 1 : const char *empty = ""; 29 1 : ret = PyUnicode_FromString(empty); 30 : } else { 31 1979 : ret = PyUnicode_FromString(self->string); 32 : } 33 1980 : return ret; 34 : } 35 : 36 37 : static PyObject *py_lsa_String_repr(PyObject *py_self) 37 : { 38 37 : struct lsa_String *self = pytalloc_get_ptr(py_self); 39 37 : PyObject *ret = NULL; 40 37 : if (self->string == NULL) { 41 1 : const char *empty = "lsaString(None)"; 42 1 : ret = PyUnicode_FromString(empty); 43 : } else { 44 36 : ret = PyUnicode_FromFormat("lsaString('%s')", self->string); 45 : } 46 37 : return ret; 47 : } 48 : 49 386 : static int py_lsa_String_init(PyObject *self, PyObject *args, PyObject *kwargs) 50 : { 51 386 : struct lsa_String *string = pytalloc_get_ptr(self); 52 386 : const char *str = NULL; 53 386 : const char *kwnames[] = { "str", NULL }; 54 : 55 386 : if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", discard_const_p(char *, kwnames), &str)) 56 0 : return -1; 57 : 58 386 : string->string = talloc_strdup(string, str); 59 : 60 386 : if (str != NULL && string->string == NULL) { 61 0 : PyErr_NoMemory(); 62 0 : return -1; 63 : } 64 : 65 379 : return 0; 66 : } 67 : 68 : 69 7646 : static void py_lsa_String_patch(PyTypeObject *type) 70 : { 71 7646 : type->tp_init = py_lsa_String_init; 72 7646 : type->tp_str = py_lsa_String_str; 73 7646 : type->tp_repr = py_lsa_String_repr; 74 7453 : } 75 : 76 : #define PY_STRING_PATCH py_lsa_String_patch 77 :