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

« back to all changes in this revision

Viewing changes to pymapi/session.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
 
   Copyright (C) Jelmer Vernooij <jelmer@openchange.org> 2008.
5
 
 
6
 
   This program is free software; you can redistribute it and/or modify
7
 
   it under the terms of the GNU General Public License as published by
8
 
   the Free Software Foundation; either version 3 of the License, or
9
 
   (at your option) any later version.
10
 
   
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
   
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include "pymapi/pymapi.h"
21
 
 
22
 
typedef struct {
23
 
        PyObject_HEAD   
24
 
        struct mapi_session *session;
25
 
} PyMapiSessionObject;
26
 
 
27
 
static PyObject *py_session_create(PyTypeObject *type, PyObject *args, PyObject *kwargs)
28
 
{
29
 
        enum MAPISTATUS retval;
30
 
        char *kwnames[] = { "profname", "password", "provider" };
31
 
        char *profname, *password;
32
 
        uint32_t provider = 0;
33
 
        struct mapi_session *session;
34
 
 
35
 
        if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss|i", kwnames, 
36
 
                                                                                &profname, &password, &provider))
37
 
                return NULL;
38
 
 
39
 
        retval = MapiLogonProvider(&session, profname, password, provider);
40
 
        if (!retval) {
41
 
                PyErr_SetMAPISTATUS(retval);
42
 
                return NULL;
43
 
        }
44
 
        return PyMapiSession_FromMapiSession(session);
45
 
}
46
 
 
47
 
PyObject *PyMapiSession_FromMapiSession(struct mapi_session *session)
48
 
{
49
 
        PyMapiSessionObject *ret;
50
 
        ret = PyObject_New(PyMapiSessionObject, &PyMapiSessionType);
51
 
        ret->session = session;
52
 
        return (PyObject *)ret;
53
 
}
54
 
 
55
 
static PyObject *py_session_login(PyObject *args, PyObject *kwargs)
56
 
{
57
 
        /* FIXME */
58
 
        return NULL;
59
 
}
60
 
 
61
 
static PyObject *py_open_msg_store(PyObject *self, PyObject *args)
62
 
{
63
 
        PyObject *py_mapi_object;
64
 
        PyMapiSessionObject *self_session = (PyMapiSessionObject *)self;
65
 
        mapi_object_t *obj;
66
 
        enum MAPISTATUS retval;
67
 
 
68
 
        if (!PyArg_ParseTuple(args, "O", &py_mapi_object))
69
 
                return NULL;
70
 
 
71
 
        obj = PyMapiObject_GetMapiObject(py_mapi_object);
72
 
        if (obj == NULL) {
73
 
                PyErr_SetString(PyExc_TypeError, "Expected MAPI Object");
74
 
                return NULL;
75
 
        }
76
 
 
77
 
        retval = OpenMsgStore(self_session->session, obj);
78
 
        if (!retval) {
79
 
                PyErr_SetMAPISTATUS(retval);
80
 
                return NULL;
81
 
        }
82
 
 
83
 
        return Py_None;
84
 
}
85
 
 
86
 
static PyObject *py_open_user_mailbox(PyObject *self, PyObject *args)
87
 
{
88
 
        PyObject *py_mapi_object;
89
 
        PyMapiSessionObject *self_session = (PyMapiSessionObject *)self;
90
 
        mapi_object_t *obj;
91
 
        enum MAPISTATUS retval;
92
 
        char *username;
93
 
 
94
 
        if (!PyArg_ParseTuple(args, "sO", &username, &py_mapi_object))
95
 
                return NULL;
96
 
 
97
 
        obj = PyMapiObject_GetMapiObject(py_mapi_object);
98
 
        if (obj == NULL) {
99
 
                PyErr_SetString(PyExc_TypeError, "Expected MAPI Object");
100
 
                return NULL;
101
 
        }
102
 
 
103
 
        retval = OpenUserMailbox(self_session->session, username, obj);
104
 
        if (!retval) {
105
 
                PyErr_SetMAPISTATUS(retval);
106
 
                return NULL;
107
 
        }
108
 
 
109
 
        return Py_None;
110
 
}
111
 
 
112
 
static PyObject *py_open_public_folder(PyObject *self, PyObject *args)
113
 
{
114
 
        PyObject *py_mapi_object;
115
 
        PyMapiSessionObject *self_session = (PyMapiSessionObject *)self;
116
 
        mapi_object_t *obj;
117
 
        enum MAPISTATUS retval;
118
 
 
119
 
        if (!PyArg_ParseTuple(args, "O", &py_mapi_object))
120
 
                return NULL;
121
 
 
122
 
        obj = PyMapiObject_GetMapiObject(py_mapi_object);
123
 
        if (obj == NULL) {
124
 
                PyErr_SetString(PyExc_TypeError, "Expected MAPI Object");
125
 
                return NULL;
126
 
        }
127
 
 
128
 
        retval = OpenPublicFolder(self_session->session, obj);
129
 
        if (!retval) {
130
 
                PyErr_SetMAPISTATUS(retval);
131
 
                return NULL;
132
 
        }
133
 
 
134
 
        return Py_None;
135
 
}
136
 
 
137
 
static PyObject *py_unsubscribe(PyMapiSessionObject *self, PyObject *args)
138
 
{
139
 
        uint32_t ulConnection;
140
 
        enum MAPISTATUS status;
141
 
        
142
 
        if (!PyArg_ParseTuple(args, "i", &ulConnection))
143
 
                return NULL;
144
 
 
145
 
        status = Unsubscribe(self->session, ulConnection);
146
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
147
 
 
148
 
        return Py_None;
149
 
}
150
 
 
151
 
static PyMethodDef session_methods[] = {
152
 
        { "login", (PyCFunction) py_session_login, METH_VARARGS|METH_KEYWORDS },
153
 
        { "open_msg_store", (PyCFunction) py_open_msg_store, METH_VARARGS,
154
 
                "S.open_msg_store(object)\n\n"
155
 
                "This function opens the main message store. This allows access to "
156
 
                "the normal user folders."
157
 
        },
158
 
        { "open_user_mailbox", (PyCFunction) py_open_user_mailbox, METH_VARARGS,
159
 
                "S.open_user_mailbox(username, object)\n\n"
160
 
                "Open another users mailbox."
161
 
        },
162
 
        { "open_public_folder", (PyCFunction) py_open_public_folder, METH_VARARGS,
163
 
                "S.open_public_folder(object)\n\n"
164
 
                "This function opens the public folder store. This allows access to "
165
 
                "the public folders."
166
 
        },
167
 
        { "unsubscribe", (PyCFunction) py_unsubscribe, METH_VARARGS,
168
 
                "S.Unsubscribe(int) -> None"
169
 
        },
170
 
        { NULL },
171
 
};
172
 
 
173
 
static PyGetSetDef session_getsetters[] = {
174
 
        { "default_profile_path", NULL, NULL },
175
 
        { "profile_name", NULL, NULL },
176
 
        { "message_store", NULL, NULL },
177
 
        { NULL }
178
 
};
179
 
 
180
 
PyTypeObject PyMapiSessionType = {
181
 
        PyObject_HEAD_INIT(NULL) 0,
182
 
        .tp_name = "Session",
183
 
        .tp_basicsize = sizeof(PyMapiSessionObject),
184
 
        .tp_methods = session_methods,
185
 
        .tp_getset = session_getsetters,
186
 
        .tp_doc = "MAPI Session",
187
 
        .tp_new = py_session_create,
188
 
        .tp_flags = Py_TPFLAGS_DEFAULT,
189
 
};
190