Providing setters for netbiosname, firstorg and firstou is messy.
authorJulien Kerihuel <j.kerihuel@openchange.org>
Tue, 25 Jan 2011 22:48:39 +0000 (22:48 +0000)
committerJulien Kerihuel <j.kerihuel@openchange.org>
Tue, 25 Jan 2011 22:48:39 +0000 (22:48 +0000)
If done after provisioning stage, introduce inconsistent entries within
mapistore.ldb database.

This commit replaces getters with parameters to the provision()
function in python bindings code.

Change python test code to reflect this change

pyopenchange/pymapistoredb.c
pyopenchange/tests/mapistoredb_test.py

index 66d9a16c0e855095fbe5e5990bf04239e10f9dcf..1ee3e8d70b9c8d0576518e5f484a15a5d491886f 100644 (file)
@@ -69,8 +69,21 @@ static PyObject *py_MAPIStoreDB_dump_configuration(PyMAPIStoreDBObject *self, Py
        return PyInt_FromLong(0);
 }
 
-static PyObject *py_MAPIStoreDB_provision(PyMAPIStoreDBObject *self, PyObject *args)
+static PyObject *py_MAPIStoreDB_provision(PyMAPIStoreDBObject *self, PyObject *args, PyObject *kwargs)
 {
+       const char              *netbiosname;
+       const char              *firstorg;
+       const char              *firstou;
+       char                    *kwnames[] = { "netbiosname", "firstorg", "firstou", NULL };
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sss", kwnames, &netbiosname, &firstorg, &firstou)) {
+               return NULL;
+       }
+
+       mapistoredb_set_netbiosname(self->mdb_ctx, netbiosname);
+       mapistoredb_set_firstorg(self->mdb_ctx, firstorg);
+       mapistoredb_set_firstou(self->mdb_ctx, firstou);
+
        return PyInt_FromLong(mapistoredb_provision(self->mdb_ctx));
 }
 
@@ -168,29 +181,6 @@ static PyObject *py_MAPIStoreDB_set_mailbox_allocation_range(PyMAPIStoreDBObject
        return PyInt_FromLong(retval);
 }
 
-static int PyMAPIStoreDB_setParameter(PyObject *_self, PyObject *value, void *data)
-{
-       PyMAPIStoreDBObject     *self = (PyMAPIStoreDBObject *) _self;
-       const char              *attr = (const char *) data;
-       const char              *str;
-
-       if (!self->mdb_ctx) return -1;
-
-       if (!PyArg_Parse(value, "s", &str)) {
-               return -1;
-       }
-
-       if (!strcmp(attr, "netbiosname")) {
-               return mapistoredb_set_netbiosname(self->mdb_ctx, str);
-       } else if (!strcmp(attr, "firstorg")) {
-               return mapistoredb_set_firstorg(self->mdb_ctx, str);
-       } else if (!strcmp(attr, "firstou")) {
-               return mapistoredb_set_firstou(self->mdb_ctx, str);
-       }
-
-       return 0;
-}
-
 static PyObject *PyMAPIStoreDB_getParameter(PyObject *_self, void *data)
 {
        PyMAPIStoreDBObject     *self = (PyMAPIStoreDBObject *) _self;
@@ -209,7 +199,7 @@ static PyObject *PyMAPIStoreDB_getParameter(PyObject *_self, void *data)
 
 static PyMethodDef mapistoredb_methods[] = {
        { "dump_configuration", (PyCFunction)py_MAPIStoreDB_dump_configuration, METH_VARARGS },
-       { "provision", (PyCFunction)py_MAPIStoreDB_provision, METH_VARARGS },
+       { "provision", (PyCFunction)py_MAPIStoreDB_provision, METH_KEYWORDS },
        { "get_mapistore_uri", (PyCFunction)py_MAPIStoreDB_get_mapistore_uri, METH_VARARGS },
        { "get_new_fid", (PyCFunction)py_MAPIStoreDB_get_new_fid, METH_VARARGS },
        { "get_new_allocation_range", (PyCFunction)py_MAPIStoreDB_get_new_allocation_range, METH_VARARGS },
@@ -220,11 +210,11 @@ static PyMethodDef mapistoredb_methods[] = {
 
 static PyGetSetDef mapistoredb_getsetters[] = {
        { "netbiosname", (getter)PyMAPIStoreDB_getParameter,
-         (setter)PyMAPIStoreDB_setParameter, "netbiosname", "netbiosname"},
+         (setter)NULL, "netbiosname", "netbiosname"},
        { "firstorg", (getter)PyMAPIStoreDB_getParameter,
-         (setter)PyMAPIStoreDB_setParameter, "firstorg", "firstorg"},
+         (setter)NULL, "firstorg", "firstorg"},
        { "firstou", (getter)PyMAPIStoreDB_getParameter,
-         (setter)PyMAPIStoreDB_setParameter, "firstou", "firstou"},
+         (setter)NULL, "firstou", "firstou"},
        { NULL },
 };
 
index aff60091b1339b80a1bc5cac42b3f1c135b08394..044182d8dd866dac301986abfba75038a5a318aa 100755 (executable)
@@ -21,13 +21,10 @@ def newTitle(title, separator):
 newTitle("[Step 1]. Initializing mapistore database", '=')
 MAPIStoreDB = mapistoredb.mapistoredb("/tmp/mapistoredb")
 
-newTitle("[Step 2]. Modify and dump configuration", '=')
-MAPIStoreDB.netbiosname = "server"
-MAPIStoreDB.firstorg = "OpenChange Project"
-MAPIStoreDB.firstou = "OpenChange Development Unit"
-
-newTitle("[Step 3]. Provisioning mapistore database", '=')
-ret = MAPIStoreDB.provision()
+newTitle("[Step 2]. Provisioning mapistore database", '=')
+ret = MAPIStoreDB.provision(netbiosname = "server",
+                            firstorg = "OpenChange Project",
+                            firstou = "OpenChange Development Unit")
 if (ret == 0):
     print "\t* Provisioning: SUCCESS"
 else:
@@ -35,7 +32,7 @@ else:
 
 MAPIStoreDB.dump_configuration()
 
-newTitle("[Step 4]. Testing API parts", '=')
+newTitle("[Step 3]. Testing API parts", '=')
 
 newTitle("A. Testing NetBIOS name", '-')
 print "* NetBIOS name: %s" %MAPIStoreDB.netbiosname
@@ -47,7 +44,7 @@ newTitle("C. Testing First Organisation", '-')
 print "* First Organisation: %s" %MAPIStoreDB.firstorg
 
 
-newTitle("[Step 5]. Retrieve mapistore URI for fsocpf", '=')
+newTitle("[Step 4]. Retrieve mapistore URI for fsocpf", '=')
 newTitle("*fsocpf:", '=')
 print "\t* Inbox: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_INBOX, "jkerihuel", "fsocpf://")
 print "\t* Calendar: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_CALENDAR, "jkerihuel", "fsocpf://")
@@ -59,12 +56,12 @@ print "\t* Mailbox Root: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_ROO
 print "\t* IPM SUbtree: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_IPM_SUBTREE, "jkerihuel", "mstoredb://")
 print "\t* Inbox: %s" % MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_INBOX, "jkerihuel", "mstoredb://")
 
-newTitle("[Step 6]. Create a new mailbox", '=')
+newTitle("[Step 5]. Create a new mailbox", '=')
 uri = MAPIStoreDB.get_mapistore_uri(mapistoredb.MDB_ROOT_FOLDER, "jkerihuel", "mstoredb://")
 ret = MAPIStoreDB.new_mailbox("jkerihuel", uri)
 print "\t* new_mailbox: ret = %d" % ret
 
-newTitle("[Step 7]. Get and Set a new allocation range to the mailbox ", '=')
+newTitle("[Step 6]. Get and Set a new allocation range to the mailbox ", '=')
 (retval,rstart,rend) = MAPIStoreDB.get_new_allocation_range("jkerihuel", 0x1000)
 if retval == 0:
     print "\t* range start = 0x%.16x" % rstart