mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
pidl:Samba4/Python: add an optional 'allow_remaining' argument to __ndr_unpack__() hooks
Thanks to Amitay Isaacs <amitay@gmail.com> for the help with this. metze
This commit is contained in:
parent
12cb6cd44a
commit
1be5e58958
@ -271,21 +271,44 @@ sub PythonStruct($$$$$$)
|
||||
$self->pidl("}");
|
||||
$self->pidl("");
|
||||
|
||||
$self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args)");
|
||||
$self->pidl("static PyObject *py_$name\_ndr_unpack(PyObject *py_obj, PyObject *args, PyObject *kwargs)");
|
||||
$self->pidl("{");
|
||||
$self->indent;
|
||||
$self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);");
|
||||
$self->pidl("DATA_BLOB blob;");
|
||||
$self->pidl("int blob_length = 0;");
|
||||
$self->pidl("enum ndr_err_code err;");
|
||||
$self->pidl("if (!PyArg_ParseTuple(args, \"s#:__ndr_unpack__\", &blob.data, &blob_length)) {");
|
||||
$self->pidl("const char * const kwnames[] = { \"data_blob\", \"allow_remaining\", NULL };");
|
||||
$self->pidl("PyObject *allow_remaining_obj = NULL;");
|
||||
$self->pidl("bool allow_remaining = false;");
|
||||
$self->pidl("");
|
||||
$self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|O:__ndr_unpack__\",");
|
||||
$self->indent;
|
||||
$self->pidl("discard_const_p(char *, kwnames),");
|
||||
$self->pidl("&blob.data, &blob_length,");
|
||||
$self->pidl("&allow_remaining_obj)) {");
|
||||
$self->deindent;
|
||||
$self->indent;
|
||||
$self->pidl("return NULL;");
|
||||
$self->deindent;
|
||||
$self->pidl("}");
|
||||
$self->pidl("blob.length = blob_length;");
|
||||
$self->pidl("");
|
||||
$self->pidl("if (allow_remaining_obj && PyObject_IsTrue(allow_remaining_obj)) {");
|
||||
$self->indent;
|
||||
$self->pidl("allow_remaining = true;");
|
||||
$self->deindent;
|
||||
$self->pidl("}");
|
||||
$self->pidl("");
|
||||
$self->pidl("if (allow_remaining) {");
|
||||
$self->indent;
|
||||
$self->pidl("err = ndr_pull_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
|
||||
$self->deindent;
|
||||
$self->pidl("} else {");
|
||||
$self->indent;
|
||||
$self->pidl("err = ndr_pull_struct_blob_all(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_pull_flags_fn_t)ndr_pull_$name);");
|
||||
$self->deindent;
|
||||
$self->pidl("}");
|
||||
$self->pidl("if (err != NDR_ERR_SUCCESS) {");
|
||||
$self->indent;
|
||||
$self->pidl("PyErr_SetNdrError(err);");
|
||||
@ -318,7 +341,7 @@ sub PythonStruct($$$$$$)
|
||||
$self->pidl("static PyMethodDef $py_methods\[] = {");
|
||||
$self->indent;
|
||||
$self->pidl("{ \"__ndr_pack__\", (PyCFunction)py_$name\_ndr_pack, METH_NOARGS, \"S.ndr_pack(object) -> blob\\nNDR pack\" },");
|
||||
$self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS, \"S.ndr_unpack(class, blob) -> None\\nNDR unpack\" },");
|
||||
$self->pidl("{ \"__ndr_unpack__\", (PyCFunction)py_$name\_ndr_unpack, METH_VARARGS|METH_KEYWORDS, \"S.ndr_unpack(class, blob, allow_remaining=False) -> None\\nNDR unpack\" },");
|
||||
$self->pidl("{ \"__ndr_print__\", (PyCFunction)py_$name\_ndr_print, METH_VARARGS, \"S.ndr_print(object) -> None\\nNDR print\" },");
|
||||
$self->pidl("{ NULL, NULL, 0, NULL }");
|
||||
$self->deindent;
|
||||
|
Loading…
Reference in New Issue
Block a user