Merge of validiation cleanups from head.
authorTim Potter <tpot@samba.org>
Mon, 21 Oct 2002 04:21:05 +0000 (04:21 +0000)
committerTim Potter <tpot@samba.org>
Mon, 21 Oct 2002 04:21:05 +0000 (04:21 +0000)
source/python/py_spoolss_drivers_conv.c
source/python/py_spoolss_forms_conv.c
source/python/py_spoolss_ports.c

index 41ff38327e297eccd28eac1f7bde5213909f3451..fd47c0e84da5d502b345c84684569f23f62b603a 100644 (file)
@@ -102,10 +102,16 @@ static PyObject *from_dependentfiles(uint16 *dependentfiles)
        return list;
 }
 
+static uint16 *to_dependentfiles(PyObject *dict)
+{
+       return (uint16 *)"abcd\0";
+}
+
 BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info)
 {
        *dict = from_struct(info, py_DRIVER_INFO_1);
        PyDict_SetItemString(*dict, "level", PyInt_FromLong(1));
+
        return True;
 }
 
@@ -118,6 +124,7 @@ BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info)
 {
        *dict = from_struct(info, py_DRIVER_INFO_2);
        PyDict_SetItemString(*dict, "level", PyInt_FromLong(2));
+
        return True;
 }
 
@@ -129,7 +136,9 @@ BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict)
 BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info)
 {
        *dict = from_struct(info, py_DRIVER_INFO_3);
+
        PyDict_SetItemString(*dict, "level", PyInt_FromLong(3));
+
        PyDict_SetItemString(
                *dict, "dependent_files", 
                from_dependentfiles(info->dependentfiles));
@@ -139,12 +148,29 @@ BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info)
 
 BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict)
 {
-       PyObject *dict_copy = PyDict_Copy(dict);
-       BOOL result;
+       PyObject *obj, *dict_copy = PyDict_Copy(dict);
+       BOOL result = False;
+
+       if (!(obj = PyDict_GetItemString(dict_copy, "dependent_files")) ||
+           !PyList_Check(obj))
+               goto done;
+
+       info->dependentfiles = to_dependentfiles(obj);
+
+       PyDict_DelItemString(dict_copy, "dependent_files");
+
+       if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
+           !PyInt_Check(obj))
+               goto done;
 
        PyDict_DelItemString(dict_copy, "level");
-       result = to_struct(info, dict_copy, py_DRIVER_INFO_3);
 
+       if (!to_struct(info, dict_copy, py_DRIVER_INFO_3))
+           goto done;
+
+       result = True;
+
+done:
        Py_DECREF(dict_copy);
        return result;
 }
index 6ef953cbc9bbfa7430a5d45f12f1514aa288df41..cfeb475b1eb948d08fc488f9203d96de21d66e61 100644 (file)
@@ -57,23 +57,30 @@ BOOL py_to_FORM(FORM *form, PyObject *dict)
 {
        PyObject *obj, *dict_copy = PyDict_Copy(dict);
        char *name;
+       BOOL result = False;
 
-       obj = PyDict_GetItemString(dict, "name");
+       if (!(obj = PyDict_GetItemString(dict_copy, "name")) || 
+           !PyString_Check(obj))
+               goto done;
 
-       if (!obj || !PyString_Check(obj))
-               return False;
+       PyDict_DelItemString(dict_copy, "name");
+
+       if (!(obj = PyDict_GetItemString(dict_copy, "level")) ||
+           !PyInt_Check(obj))
+               goto done;
 
        PyDict_DelItemString(dict_copy, "level");
-       PyDict_DelItemString(dict_copy, "name");
 
-       if (!to_struct(form, dict_copy, py_FORM)) {
-               Py_DECREF(dict_copy);
-               return False;
-       }
+       if (!to_struct(form, dict_copy, py_FORM))
+               goto done;
 
        name = PyString_AsString(obj);
 
        init_unistr2(&form->name, name, strlen(name) + 1);
        
-       return True;
+       result = True;
+
+done:
+       Py_DECREF(dict_copy);
+       return result;
 }
index b5f2102e5e8f3faa8165a240e29d4b2fc199bbb5..fe6d7536d39e85b51de740d4ff0f7b4ca680d8c0 100644 (file)
@@ -26,7 +26,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
 {
        WERROR werror;
        PyObject *result = NULL, *creds = NULL;
-       int level = 1;
+       uint32 level = 1;
        uint32 i, needed, num_ports;
        static char *kwlist[] = {"server", "level", "creds", NULL};
        TALLOC_CTX *mem_ctx = NULL;