~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to pyopenchange/mapistore/folder.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   OpenChange MAPI implementation.
 
3
 
 
4
   Python interface to mapistore folder
 
5
 
 
6
   Copyright (C) Julien Kerihuel 2011.
 
7
 
 
8
   This program is free software; you can redistribute it and/or modify
 
9
   it under the terms of the GNU General Public License as published by
 
10
   the Free Software Foundation; either version 3 of the License, or
 
11
   (at your option) any later version.
 
12
   
 
13
   This program is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
   GNU General Public License for more details.
 
17
   
 
18
   You should have received a copy of the GNU General Public License
 
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include <Python.h>
 
23
#include "pyopenchange/mapistore/pymapistore.h"
 
24
#include "gen_ndr/exchange.h"
 
25
 
 
26
static void py_MAPIStoreFolder_dealloc(PyObject *_self)
 
27
{
 
28
        PyMAPIStoreFolderObject *self = (PyMAPIStoreFolderObject *)_self;
 
29
 
 
30
        Py_DECREF(self->context);
 
31
        PyObject_Del(_self);
 
32
}
 
33
 
 
34
static PyObject *py_MAPIStoreFolder_create_folder(PyMAPIStoreFolderObject *self, PyObject *args, PyObject *kwargs)
 
35
{
 
36
        int                     ret;
 
37
        /* PyMAPIStoreFolderObject      *folder; */
 
38
        char                    *kwnames[] = { "name", "description", "foldertype", "flags" };
 
39
        const char              *name;
 
40
        const char              *desc = NULL;
 
41
        uint16_t                foldertype = FOLDER_GENERIC;
 
42
        uint16_t                flags = NONE;
 
43
        uint64_t                fid;
 
44
 
 
45
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|shh", kwnames, &name, &desc, &foldertype, &flags)) {
 
46
                return NULL;
 
47
        }
 
48
 
 
49
        /* Step 1. Check if the folder already exists */
 
50
        ret = mapistore_folder_get_child_fid_by_name(self->context->mstore_ctx,
 
51
                                                     self->context->context_id,
 
52
                                                     self->context->folder_object, 
 
53
                                                     name, &fid);
 
54
        if (ret == MAPISTORE_SUCCESS) {
 
55
                if (flags != OPEN_IF_EXISTS) {
 
56
                        PyErr_MAPIStore_IS_ERR_RAISE(MAPISTORE_ERR_EXIST);
 
57
                        Py_RETURN_NONE;
 
58
                }
 
59
        }
 
60
        
 
61
        /* TODO: Complete the implementation */
 
62
 
 
63
        return Py_None;
 
64
}
 
65
 
 
66
static PyObject *py_MAPIStoreFolder_get_fid(PyMAPIStoreFolderObject *self, void *closure)
 
67
{
 
68
        return PyLong_FromLongLong(self->fid);
 
69
}
 
70
 
 
71
static PyObject *py_MAPIStoreFolder_get_child_count(PyMAPIStoreFolderObject *self, PyObject *args, PyObject *kwargs)
 
72
{
 
73
        uint32_t                        RowCount;
 
74
        enum mapistore_table_type       table_type;
 
75
        char                            *kwnames[] = { "table_type" };
 
76
        int                             retval;
 
77
 
 
78
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwnames, &table_type)) {
 
79
                return NULL;
 
80
        }
 
81
 
 
82
        retval = mapistore_folder_get_child_count(self->context->mstore_ctx, self->context->context_id,
 
83
                                                  (self->folder_object ? self->folder_object : 
 
84
                                                   self->context->folder_object), table_type, &RowCount);
 
85
        if (retval != MAPISTORE_SUCCESS) {
 
86
                return PyInt_FromLong(-1);
 
87
        }
 
88
 
 
89
        return PyInt_FromLong(RowCount);
 
90
}
 
91
 
 
92
static PyMethodDef mapistore_folder_methods[] = {
 
93
        { "create_folder", (PyCFunction)py_MAPIStoreFolder_create_folder, METH_VARARGS|METH_KEYWORDS },
 
94
        { "get_child_count", (PyCFunction)py_MAPIStoreFolder_get_child_count, METH_VARARGS|METH_KEYWORDS },
 
95
        { NULL },
 
96
};
 
97
 
 
98
static PyGetSetDef mapistore_folder_getsetters[] = {
 
99
        { (char *)"fid", (getter)py_MAPIStoreFolder_get_fid, NULL, NULL },
 
100
        { NULL }
 
101
};
 
102
 
 
103
PyTypeObject PyMAPIStoreFolder = {
 
104
        PyObject_HEAD_INIT(NULL) 0,
 
105
        .tp_name = "mapistore folder",
 
106
        .tp_basicsize = sizeof (PyMAPIStoreFolderObject),
 
107
        .tp_methods = mapistore_folder_methods,
 
108
        .tp_getset = mapistore_folder_getsetters,
 
109
        .tp_doc = "mapistore folder object",
 
110
        .tp_dealloc = (destructor)py_MAPIStoreFolder_dealloc,
 
111
        .tp_flags = Py_TPFLAGS_DEFAULT,
 
112
};