r3001: Expose unmarshalling functions for structures marked "public" in the
authorTim Potter <tpot@samba.org>
Sat, 16 Oct 2004 00:19:33 +0000 (00:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:59:56 +0000 (12:59 -0500)
idl.  This allows us to pass a buffer of bytes returned from a spoolss
call and convert it to a Python dictionary.  Works for enumprinters level
1!
(This used to be commit 4bc497a2994b12845a46b2d19f60bb81c9869fc9)

source4/build/pidl/swig.pm
source4/scripting/swig/dcerpc.i
source4/scripting/swig/torture/spoolss.py

index cdfe90450dab27fea1b94ad517b27bdf10ff09e8..b75891df17440b8ec233e38e94315b1a4cd9ca7b 100644 (file)
@@ -351,8 +351,6 @@ sub ParseFunction($)
 
     $result .= "\tresultobj = temp;\n\n";
 
-       
-
     $result .= "\tif (NT_STATUS_IS_ERR(result)) {\n";
     $result .= "\t\tset_ntstatus_exception(NT_STATUS_V(result));\n";
     $result .= "\t\tgoto fail;\n";
@@ -466,19 +464,30 @@ sub ParseStruct($)
 
     # Generate function to convert DATA_BLOB to Python dict
 
-    if (util::has_property($s, "public")) {
-       $result .= "/* Convert DATA_BLOB to python dict of struct $s->{NAME} */\n\n";
-
-       $result .= "NTSTATUS DATA_BLOB_to_python_$s->{NAME}(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, PyObject **obj)\n";
+    if (util::has_property($s->{DATA}, "public")) {
+       $result .= "/* Convert a Python string to a struct $s->{NAME} python dict */\n\n";
+       $result .= "NTSTATUS unmarshall_$s->{NAME}(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct $s->{NAME} *s)\n";
        $result .= "{\n";
-       $result .= "\tstruct $s->{NAME} s;\n";
-       $result .= "\tNTSTATUS result = ndr_pull_struct_blob(blob, mem_ctx, &s, ndr_pull_$s->{NAME});\n\n";
-       $result .= "\treturn NT_STATUS_OK;\n";
-       $result .= "}\n";
+       $result .= "\treturn ndr_pull_struct_blob(blob, mem_ctx, s, ndr_pull_$s->{NAME});\n";
+       $result .= "}\n\n";
     }
 
     $result .= "\n%}\n\n";    
 
+    if (util::has_property($s->{DATA}, "public")) {
+
+       $result .= "%typemap(in, numinputs=0) struct $s->{NAME} *EMPTY (struct $s->{NAME} *temp_$s->{NAME}) {\n";
+       $result .= "\t\$1 = &temp_$s->{NAME};\n";
+       $result .= "}\n\n";
+
+       $result .= "%typemap(argout) struct $s->{NAME} * {\n";
+       $result .= "\tTALLOC_CTX *mem_ctx = talloc_init(\"typemap(argout) $s->{NAME}\");\n\n";
+       $result .= "\tresultobj = $s->{NAME}_ptr_to_python(mem_ctx, \$1);\n";
+       $result .= "}\n\n";
+
+       $result .= "NTSTATUS unmarshall_$s->{NAME}(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct $s->{NAME} *EMPTY);\n\n";
+    }
+
     return $result;
 }
 
@@ -595,8 +604,22 @@ sub ParseUnion($)
 
     $result .= "}\n\n";
 
+    # Generate function to convert DATA_BLOB to Python dict
+
+    if (util::has_property($u->{DATA}, "public")) {
+       $result .= "/* Convert a Python string to a struct $u->{NAME} python dict */\n\n";
+       $result .= "NTSTATUS unmarshall_$u->{NAME}(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, union $u->{NAME} *u)\n";
+       $result .= "{\n";
+       $result .= "\treturn NT_STATUS_OK;\n";
+       $result .= "}\n\n";
+    }
+
     $result .= "\n%}\n\n";    
 
+    if (util::has_property($u->{DATA}, "public")) {
+       $result .= "NTSTATUS unmarshall_$u->{NAME}(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, union $u->{NAME} *EMPTY);\n\n";
+    }
+
     return $result;
 }
 
index ab53a1dc51e727a1d472fd0985a23e5520056887..1222d54766d85ca30ddd5df7ac0772cc9f261e8b 100644 (file)
@@ -346,6 +346,12 @@ NTSTATUS dcerpc_pipe_connect(struct dcerpc_pipe **OUT,
                              const char *username,
                              const char *password);
 
+%typemap(in) DATA_BLOB * (DATA_BLOB temp_data_blob) {
+       temp_data_blob.data = PyString_AsString($input);
+       temp_data_blob.length = PyString_Size($input);
+       $1 = &temp_data_blob;
+}
+
 %include "librpc/gen_ndr/misc.i"
 %include "librpc/gen_ndr/lsa.i"
 %include "librpc/gen_ndr/samr.i"
index 78d573a7cd0f64854ecff7c5d91a03eaeee1ec3f..e29178a0b602e37b50bb0f2cd73c3bd0a29ef59a 100644 (file)
@@ -11,7 +11,7 @@ def test_EnumPrinters(pipe):
 
     result = dcerpc.spoolss_EnumPrinters(pipe, r)
 
-    print result
+    print dcerpc.unmarshall_spoolss_PrinterInfo1(result['buffer'])
 
 def runtests(binding, domain, username, password):