r2295: Convert simple scalar types and policy handles between dcerpc function
authorTim Potter <tpot@samba.org>
Sun, 12 Sep 2004 10:13:24 +0000 (10:13 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:58:40 +0000 (12:58 -0500)
call request and response structures.
(This used to be commit d31d23b944b7e4ef300d75dad5038727e9133af1)

source4/build/pidl/swig.pm
source4/scripting/swig/dcerpc.i

index 59eb493bf2727923d5e0a8bd8179ad1796b3a12b..f03467177e886bc0534a6a3ead005a5d46c82824 100644 (file)
@@ -11,6 +11,98 @@ use Data::Dumper;
 my($res);
 my($name);
 
+sub DebugElement($)
+{
+    my($e) = shift;
+    my($result) = "";
+
+    $result .= "\t// $e->{TYPE} $e->{NAME} ";
+
+    $result .= "(scalar) " 
+       if util::is_scalar_type($e->{TYPE});
+
+    $result .= "pointers=$e->{POINTERS} " 
+       if $e->{POINTERS} > 0;
+
+    my($size_is) = util::has_property($e, "size_is");
+    $result .= "size_is=" . $size_is . " " if $size_is;
+
+    my($length_is) = util::has_property($e, "length_is");
+    $result .= "length_is=" . $length_is . " " if $length_is;
+
+    $result .= "array_len=" . $e->{ARRAY_LEN} . " " if $e->{ARRAY_LEN};
+
+    $result .= "\n";
+
+    return $result;
+}
+
+sub XFromPython($$)
+{
+    my($e) = shift;
+    my($prefix) = shift;
+    my($result) = "";
+
+    # Special cases
+
+    if ($e->{TYPE} eq "policy_handle" && $e->{POINTERS} == 1) {
+       $result .= "\ts->$prefix$e->{NAME} = policy_handle_from_python(obj);";
+       return $result;
+    }
+
+    if (util::is_scalar_type($e->{TYPE})) {
+       if ($e->{POINTERS} == 0) {
+           if ($e->{ARRAY_LEN}) {
+               # pointer to scalar with array len property
+               $result .= DebugElement($e);
+           } else {
+               $result .= "\ts->$prefix$e->{NAME} = $e->{TYPE}_from_python(obj);\n";
+           }
+       } else {
+           # Pointer to scalar
+           $result .= DebugElement($e);
+       }
+    } else {
+       # Non-scalar type
+       $result .= DebugElement($e);
+    }
+
+    return $result;
+}
+
+sub XToPython($$)
+{
+    my($e) = shift;
+    my($prefix) = shift;
+    my($result) = "";
+
+    # Special cases
+
+    if ($e->{TYPE} eq "policy_handle" && $e->{POINTERS} == 1) {
+       $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), policy_handle_to_python(s->$prefix$e->{NAME}));\n";
+       return $result;
+    }
+
+    if (util::is_scalar_type($e->{TYPE})) {
+       if ($e->{POINTERS} == 0) {
+           if ($e->{ARRAY_LEN}) {
+               # pointer to scalar with array len property
+               $result .= DebugElement($e);
+           } else {
+               $result .= "\tPyDict_SetItem(obj, PyString_FromString(\"$e->{NAME}\"), $e->{TYPE}_to_python(s->$prefix$e->{NAME}));\n";
+           }
+       } else {
+           # Pointer to scalar
+           $result .= DebugElement($e);
+       }
+    } else {
+       # Non-scalar type
+       $result .= DebugElement($e);
+    }
+
+    return $result;
+}
+
 sub ParseFunction($)
 {
     my($fn) = shift;
@@ -23,9 +115,7 @@ sub ParseFunction($)
     $res .= "{\n";
 
     foreach my $e (@{$fn->{DATA}}) {
-       if (util::has_property($e, "in")) {
-           $res .= "\t// $e->{TYPE} $e->{NAME}\n";
-       }
+       $res .= XFromPython($e, "in.") if util::has_property($e, "in")
     }
 
     $res .= "\n";
@@ -38,9 +128,7 @@ sub ParseFunction($)
     $res .= "{\n";
 
     foreach my $e (@{$fn->{DATA}}) {
-       if (util::has_property($e, "out")) {
-           $res .= "\t// $e->{TYPE} $e->{NAME}\n";
-       }
+       $res .= XToPython($e, "out.") if util::has_property($e, "out")
     }
 
     $res .= "\n";
@@ -93,7 +181,7 @@ sub ParseStruct($)
     $res .= "{\n";
 
     foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
-       $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+       $res .= XFromPython($e, "");
     }
 
     $res .= "\n";
@@ -106,7 +194,7 @@ sub ParseStruct($)
     $res .= "{\n";
 
     foreach my $e (@{$s->{DATA}{ELEMENTS}}) {
-       $res .= "\t// $e->{TYPE} $e->{NAME}\n";
+       $res .= XToPython($e, "");
     }
 
     $res .= "\n";
index 10dc4721e6880e5d83b24e6833341a9322f3bfaf..fb4870d8192f6ce6919d75dab3ab5916579187b4 100644 (file)
@@ -52,41 +52,81 @@ uint8 uint8_from_python(PyObject *obj)
        return (uint8)PyInt_AsLong(obj);
 }
 
+PyObject *uint8_to_python(uint8 obj)
+{
+       return PyInt_FromLong(obj);
+}
+
 uint16 uint16_from_python(PyObject *obj)
 {
        return (uint16)PyInt_AsLong(obj);
 }
 
+PyObject *uint16_to_python(uint16 obj)
+{
+       return PyInt_FromLong(obj);
+}
+
 uint32 uint32_from_python(PyObject *obj)
 {
        return (uint32)PyInt_AsLong(obj);
 }
 
+PyObject *uint32_to_python(uint32 obj)
+{
+       return PyInt_FromLong(obj);
+}
+
 int64 int64_from_python(PyObject *obj)
 {
        return (int64)PyLong_AsLong(obj);
 }
 
+PyObject *int64_to_python(int64 obj)
+{
+       return PyLong_FromLong(obj);
+}
+
 uint64 uint64_from_python(PyObject *obj)
 {
        return (uint64)PyLong_AsLong(obj);
 }
 
+PyObject *uint64_to_python(uint64 obj)
+{
+       return PyLong_FromLong(obj);
+}
+
 NTTIME NTTIME_from_python(PyObject *obj)
 {
        return (NTTIME)PyLong_AsLong(obj);
 }
 
+PyObject *NTTIME_to_python(NTTIME obj)
+{
+       return PyLong_FromLong(obj);
+}
+
 HYPER_T HYPER_T_from_python(PyObject *obj)
 {
        return (HYPER_T)PyLong_AsLong(obj);
 }
 
+PyObject *HYPER_T_to_python(HYPER_T obj)
+{
+       return PyLong_FromLong(obj);
+}
+
 struct policy_handle *policy_handle_from_python(PyObject *obj)
 {
        return (struct policy_handle *)PyString_AsString(obj);
 }
 
+PyObject *policy_handle_to_python(struct policy_handle *handle)
+{
+       return PyString_FromStringAndSize((char *)handle, sizeof(*handle));
+}
+
 struct security_descriptor *security_descriptor_from_python(PyObject *obj)
 {
        return NULL;