Add mapistore folder object skeleton for mapistore python bindings
authorJulien Kerihuel <j.kerihuel@openchange.org>
Wed, 16 Mar 2011 10:03:08 +0000 (10:03 +0000)
committerJulien Kerihuel <j.kerihuel@openchange.org>
Wed, 16 Mar 2011 10:03:08 +0000 (10:03 +0000)
Makefile
pyopenchange/pymapistore.h
pyopenchange/pymapistore_folder.c [new file with mode: 0644]
pyopenchange/pymapistore_module.c

index 9ab78f367420fe768af3ffe8ed045b680afa7a19..af42a148561cbe7eb10596290954b9e27f0fc221 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1545,6 +1545,7 @@ $(pythonscriptdir)/openchange/ocpf.$(SHLIBEXT):   pyopenchange/pyocpf.c                           \
 
 $(pythonscriptdir)/openchange/mapistore.$(SHLIBEXT):   pyopenchange/pymapistore_module.c                               \
                                                        pyopenchange/pymapistore_object.c                               \
+                                                       pyopenchange/pymapistore_folder.c                               \
                                                        mapiproxy/libmapistore.$(SHLIBEXT).$(PACKAGE_VERSION)
        @echo "Linking $@"
        @$(CC) $(WAF_BUILD_INC) $(CFLAGS) $(DSOOPT) $(LDFLAGS) -o $@ $^ `$(PYTHON_CONFIG) --cflags --libs` $(LIBS)
index b2e4e1496ed9e89f5faa6908cb1e43a45cdcdbb9..0dec932885f7ed7e7af99cd221f408fdd7a0cd3a 100644 (file)
@@ -34,6 +34,15 @@ typedef struct {
        struct mapistore_context        *mstore_ctx;
 } PyMAPIStoreObject;
 
+typedef struct {
+       PyObject_HEAD
+       TALLOC_CTX                      *mem_ctx;
+       struct mapistore_context        *mstore_ctx;
+       PyObject                        *parent_object;
+       uint32_t                        context_id;
+       uint64_t                        fid;
+} PyMAPIStoreFolderObject;
+
 typedef struct {
        PyObject_HEAD
        TALLOC_CTX                      *mem_ctx;
@@ -41,6 +50,24 @@ typedef struct {
 } PyMAPIStoreDBObject;
 
 PyAPI_DATA(PyTypeObject)       PyMAPIStore;
+PyAPI_DATA(PyTypeObject)       PyMAPIStoreFolder;
 PyAPI_DATA(PyTypeObject)       PyMAPIStoreDB;
 
+#ifndef __BEGIN_DECLS
+#ifdef __cplusplus
+#define __BEGIN_DECLS          extern "C" {
+#define __END_DECLS            }
+#else
+#define __BEGIN_DECLS
+#define __END_DECLS
+#endif
+#endif
+
+__BEGIN_DECLS
+
+/* These definitions come from pymapistore_folder.c */
+PyObject *pymapistore_folder_new(TALLOC_CTX *, struct mapistore_context *, PyObject *, uint32_t, uint64_t);
+
+__END_DECLS
+
 #endif /* ! __PYMAPISTORE_H_ */
diff --git a/pyopenchange/pymapistore_folder.c b/pyopenchange/pymapistore_folder.c
new file mode 100644 (file)
index 0000000..2db4ef8
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+   OpenChange MAPI implementation.
+
+   Python interface to mapistore folders
+
+   Copyright (C) Julien Kerihuel 2011.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <Python.h>
+#include "pyopenchange/pymapistore.h"
+#include "pyopenchange/pymapi.h"
+
+PyObject *pymapistore_folder_new(TALLOC_CTX *mem_ctx,
+                                struct mapistore_context *mstore_ctx,
+                                PyObject *parent_object,
+                                uint32_t context_id,
+                                uint64_t fid)
+{
+       PyMAPIStoreFolderObject *ret;
+
+       /* Sanity checks */
+       if (!mstore_ctx || !context_id) {
+               PyErr_SetString(PyExc_ValueError, "Invalid parameter");
+               return NULL;
+       }
+
+       ret = PyObject_New(PyMAPIStoreFolderObject, &PyMAPIStoreFolder);
+       if (!ret) {
+               PyErr_SetString(PyExc_MemoryError, "No more memory");
+               return NULL;
+       }
+
+       ret->mem_ctx = mem_ctx;
+       ret->mstore_ctx = mstore_ctx;
+       ret->parent_object = parent_object;
+       ret->context_id = context_id;
+       ret->fid = fid;
+
+       Py_INCREF(ret->parent_object);
+       Py_INCREF(ret);
+
+       return (PyObject *) ret;
+}
+
+static PyObject *py_MAPIStoreFolder_open(PyMAPIStoreFolderObject *self,
+                                        PyObject *args,
+                                        PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_close(PyMAPIStoreFolderObject *self,
+                                         PyObject *args,
+                                         PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_mkdir(PyMAPIStoreFolderObject *self,
+                                         PyObject *args,
+                                         PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_rmdir(PyMAPIStoreFolderObject *self,
+                                         PyObject *args,
+                                         PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_move(PyMAPIStoreFolderObject *self,
+                                        PyObject *args,
+                                        PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_copy(PyMAPIStoreFolderObject *self,
+                                        PyObject *args,
+                                        PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_empty(PyMAPIStoreFolderObject *self,
+                                         PyObject *args,
+                                         PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_setprops(PyMAPIStoreFolderObject *self,
+                                            PyObject *args,
+                                            PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_get_hierarchy_table(PyMAPIStoreFolderObject *self,
+                                                       PyObject *args,
+                                                       PyObject *kwargs)
+{
+       return NULL;
+}
+
+static PyObject *py_MAPIStoreFolder_get_contents_table(PyMAPIStoreFolderObject *self,
+                                                      PyObject *args,
+                                                      PyObject *kwargs)
+{
+       return NULL;
+}
+
+static void pymapistore_folder_dealloc(PyObject *_self)
+{
+       PyMAPIStoreFolderObject *self = (PyMAPIStoreFolderObject *)_self;
+
+       Py_DECREF(self->parent_object);
+       PyObject_Del(_self);
+}
+
+static PyMethodDef pymapistore_folder_methods[] = {
+       /* Folder semantics */
+       { "open", (PyCFunction)py_MAPIStoreFolder_open, METH_KEYWORDS },
+       { "close", (PyCFunction)py_MAPIStoreFolder_close, METH_KEYWORDS },
+       { "mkdir", (PyCFunction)py_MAPIStoreFolder_mkdir, METH_KEYWORDS },
+       { "rmdir", (PyCFunction)py_MAPIStoreFolder_rmdir, METH_KEYWORDS },
+       { "move", (PyCFunction)py_MAPIStoreFolder_move, METH_KEYWORDS },
+       { "copy", (PyCFunction)py_MAPIStoreFolder_copy, METH_KEYWORDS },
+       { "empty", (PyCFunction)py_MAPIStoreFolder_empty, METH_KEYWORDS },
+       /* Properties semantics */
+       { "setprops", (PyCFunction)py_MAPIStoreFolder_setprops, METH_KEYWORDS },
+       /* Table semantics */
+       { "hierarchy_table", (PyCFunction)py_MAPIStoreFolder_get_hierarchy_table, METH_KEYWORDS },
+       { "contents_table", (PyCFunction)py_MAPIStoreFolder_get_contents_table, METH_KEYWORDS },
+       { NULL }
+};
+
+static PyObject *pymapistore_get_folder_identifier(PyMAPIStoreFolderObject *self, void *py_data)
+{
+       return Py_BuildValue("K", self->fid);
+}
+
+static PyGetSetDef pymapistore_folder_getsetters[] = {
+       { "id", (getter)pymapistore_get_folder_identifier, NULL, "Folder identifier", NULL },
+       { NULL }
+};
+
+PyTypeObject PyMAPIStoreFolder = {
+       PyObject_HEAD_INIT(NULL) 0,
+       .tp_name = "Folder",
+       .tp_basicsize = sizeof(PyMAPIStoreFolderObject),
+       .tp_methods = pymapistore_folder_methods,
+       .tp_getset = pymapistore_folder_getsetters,
+       .tp_doc = "MAPIStore Folder",
+       .tp_dealloc = pymapistore_folder_dealloc,
+       .tp_flags = Py_TPFLAGS_DEFAULT
+};
index 796719c645fb94a76b153280dbcc59271cd3683f..8c582211655462d8aae59e75af2c242fab7eee5f 100644 (file)
@@ -85,6 +85,10 @@ void initmapistore(void)
                return;
        }
 
+       if (PyType_Ready(&PyMAPIStoreFolder) < 0) {
+               return;
+       }
+
        m = Py_InitModule3("mapistore", py_mapistore_global_methods,
                           "An interface to OpenChange MAPIStore");
        if (m == NULL) {
@@ -135,4 +139,7 @@ void initmapistore(void)
 
        Py_INCREF(&PyMAPIStore);
        PyModule_AddObject(m, "mapistore", (PyObject *)&PyMAPIStore);
+
+       Py_INCREF((PyObject *)&PyMAPIStoreFolder);
+       PyModule_AddObject(m, "Folder", (PyObject *)&PyMAPIStoreFolder);
 }