5 * Copyright (C) 2010-2011 Nokia Corporation
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 2 of the License, or
11 * (at your option) any later version.
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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 /* Those are used by backend to notify transport plugin which properties did it
30 #define PMASK_SUBJECT 0x0001
31 #define PMASK_DATETIME 0x0002
32 #define PMASK_SENDER_NAME 0x0004
33 #define PMASK_SENDER_ADDRESSING 0x0008
34 #define PMASK_RECIPIENT_NAME 0x0010
35 #define PMASK_RECIPIENT_ADDRESSING 0x0020
36 #define PMASK_TYPE 0x0040
37 #define PMASK_SIZE 0x0080
38 #define PMASK_RECEPTION_STATUS 0x0100
39 #define PMASK_TEXT 0x0200
40 #define PMASK_ATTACHMENT_SIZE 0x0400
41 #define PMASK_PRIORITY 0x0800
42 #define PMASK_READ 0x1000
43 #define PMASK_SENT 0x2000
44 #define PMASK_PROTECTED 0x4000
45 #define PMASK_REPLYTO_ADDRESSING 0x8000
47 /* This one is used in a response to GetMessagesListing. Use PMASK_* values to
48 * notify the plugin which members are actually set. Backend shall not omit
49 * properties required by MAP specification (subject, datetime,
50 * recipient_addressing, type, size, reception_status, attachment_size) unless
51 * ordered by PARAMETERMASK. Boolean values should be probably
52 * always sent (need checking). Handle is mandatory. Plugin will filter out any
53 * properties that were not wanted by MCE.
55 * Handle shall be set to hexadecimal representation with upper-case letters. No
56 * prefix shall be appended and without no zeros. This corresponds to PTS
57 * behaviour described in comments to the MAP specification.
59 * The rest of char * fields shall be set according to the MAP specification
62 struct messages_message {
68 char *sender_addressing;
69 char *replyto_addressing;
71 char *recipient_addressing;
73 char *reception_status;
75 char *attachment_size;
83 /* Type of message event to be delivered to MNS server */
84 enum messages_event_type {
96 /* Data for sending MNS notification. Handle shall be formatted as described in
99 struct messages_event {
100 enum messages_event_type type;
108 /* parameter_mask: |-ed PMASK_* values
109 * See MAP specification for the rest.
111 struct messages_filter {
112 uint32_t parameter_mask;
123 /* To store Application parameters.
124 * See MAP specification for the details.
125 * filter - Parameters on which we filter the message list to be sent.
126 * maxlistcount - Maximum number of Messages or folders to be sent,
127 * if not mentioned it is 1024.
128 * offset - Offset from where the list is to be sent, if not mentioned it is 0.
129 * attachment - Indicates if any attachment i.e. ON or OFF.
130 * transparent -To tell MSE that no copy shall me kept in Sent folder.
131 * retry -To indicate if successive attempts to be made, incase network is not
133 * newmessage -To indicate unread messages in message listing.
134 * notification_status -Indicates Incoming message notification On/Off.
135 * mas_instance -Indicate corresponding 'MASInstanceID', as only one MNS
136 * connection can be made with an MSE.
137 * folderlisting_size -Used in response if the value of maxlistcount is 0.
138 * messagelisting_size -Used in response if the value of maxlistcount is 0.
139 * subject_length -Maximum length of the Subject in Messages-Listing.
140 * fraction_request -Used only if the message is fractioned.
141 * fraction_delivery -Used only if fraction_request is present in Get Message
143 * charset - Determines trans-coding of the text i.e. "Native" or "UTF-8".
144 * status_indicator - Indicates which status information is to be modified
145 * i.e. "readStatus" or "deletedStatus".
146 * status_value - Indicates value to status_indicator i.e. "yes" or "no".
147 * msetime -To report the local time of MSE and its UTC Offset.
149 struct apparam_field {
150 struct messages_filter *filter;
151 uint16_t maxlistcount;
157 uint8_t notification_status;
158 uint8_t mas_instance;
159 uint16_t folderlisting_size;
160 uint16_t messagelisting_size;
161 uint8_t subject_length;
163 uint8_t fraction_request;
164 uint8_t fraction_delivery;
165 uint8_t status_indicator;
166 uint8_t status_value;
171 /* This is called once after server starts.
173 * Returns value less than zero if error. This will prevent MAP plugin from
176 int messages_init(void);
178 /* This gets called right before server finishes
180 void messages_exit(void);
182 /* Starts a new MAP session.
184 * session: variable to store pointer to backend session data. This one shall be
185 * passed to all in-session calls.
187 * If session start succeeded, backend shall return 0. Otherwise the error value
188 * will be sent as a response to OBEX connect.
190 int messages_connect(void **session);
192 /* Closes a MAP session.
194 * This call should free buffer reserved by messages_connect.
196 void messages_disconnect(void *session);
198 /******************************************************************************
201 * All functions requiring callbacks have to call them asynchronously.
202 * 'user_data' is for passing arbitrary user data.
204 * Functions for GetMessagesListing, GetFolder listing and GetMessage call their
205 * callbacks multiple times - one for each listing entry or message body chunk.
206 * To indicate the end of operation backend must call callback with the data
207 * pointer parameter set to NULL.
209 * If err == -EAGAIN the transport * plugin does not wake IO.
211 * Keep in mind that application parameters has to be send first. Therefore the
212 * first time err == 0 and thus sending is started, callback will use provided
213 * parameters (e.g. size in case of folder listing) to build applications
214 * parameters header used in response. In any other case those parameters will
217 * If err != 0 && err != -EAGAIN, the operation is finished immediately and err
218 * value is used to set the error code in OBEX response.
219 ******************************************************************************/
221 /* Registers for messaging events notifications.
223 * session: Backend session.
224 * send_event: Function that will be called to indicate a new event.
226 * To unregister currently registered notifications, call this with send_event
229 int messages_set_notification_registration(void *session,
230 void (*send_event)(void *session,
231 const struct messages_event *event, void *user_data),
234 /* Changes current directory.
236 * session: Backend session.
237 * name: Subdirectory to go to. If empty or null and cdup is false, go to the
239 * cdup: If true, go up one level first.
241 int messages_set_folder(void *session, const char *name, gboolean cdup);
243 /* Retrieves subdirectories listing from a current directory.
245 * session: Backend session.
246 * name: Optional subdirectory name (not strictly required by MAP).
247 * max: Maximum number of entries to retrieve.
248 * offset: Offset of the first entry.
249 * size: Total size of listing to be returned.
251 * Callback shall be called for every entry of the listing. 'name' is the
254 typedef void (*messages_folder_listing_cb)(void *session, int err,
255 uint16_t size, const char *name, void *user_data);
257 int messages_get_folder_listing(void *session, const char *name, uint16_t max,
259 messages_folder_listing_cb callback,
262 /* Retrieves messages listing from a current directory.
264 * session: Backend session.
265 * name: Optional subdirectory name.
266 * max: Maximum number of entries to retrieve.
267 * filter: Filter to apply on returned message listing.
268 * size: Total size of listing to be returned.
269 * newmsg: Indicates presence of unread messages.
271 * Callback shall be called for every entry of the listing, giving message data
274 typedef void (*messages_get_messages_listing_cb)(void *session, int err,
275 uint16_t size, gboolean newmsg,
276 const struct messages_message *message,
279 int messages_get_messages_listing(void *session, const char *name,
280 uint16_t max, uint16_t offset,
281 const struct messages_filter *filter,
282 messages_get_messages_listing_cb callback,
285 #define MESSAGES_ATTACHMENT (1 << 0)
286 #define MESSAGES_UTF8 (1 << 1)
287 #define MESSAGES_FRACTION (1 << 2)
288 #define MESSAGES_NEXT (1 << 3)
290 /* Retrieves bMessage object (see MAP specification, ch. 3.1.3) of a given
293 * session: Backend session.
294 * handle: Handle of the message to retrieve.
295 * flags: or-ed mask of following:
296 * MESSAGES_ATTACHMENT: Selects whether or not attachments (if any) are to
298 * MESSAGES_UTF8: If true, convert message to utf-8. Otherwise use native
300 * MESSAGES_FRACTION: If true, deliver fractioned message.
301 * MESSAGES_NEXT: If fraction is true this indicates whether to retrieve
304 * fmore: Indicates whether next fraction is available.
305 * chunk: chunk of bMessage body
307 * Callback allows for returning bMessage in chunks.
309 typedef void (*messages_get_message_cb)(void *session, int err, gboolean fmore,
310 const char *chunk, void *user_data);
312 int messages_get_message(void *session, const char *handle,
314 messages_get_message_cb callback,
317 /* Informs Message Server to Update Inbox via network.
319 * session: Backend session.
320 * user_data: User data if any to be sent.
321 * Callback shall be called for every update inbox request recieved from MCE.
323 typedef void (*messages_update_inbox_cb)(void *session, int err,
326 int messages_update_inbox(void *session, messages_update_inbox_cb callback,
330 /* Informs Message Server to modify status of the message.
332 * session: Backend session.
333 * handle: Unique identifier to the message.
334 * indicator: To indicate which status information is to be modified,
335 * "readStatus" or "deleteStatus".
336 * value: To indicate the value of the indicator
337 * read/unread for "readstatus" and deleted/undeleted for "deleteStatus".
338 * Callback shall be called for every message status update request
340 * user_data: User data if any to be sent.
342 typedef void (*messages_set_message_status_cb)(void *session, int err,
345 int messages_set_message_status(void *session, const char *handle,
346 int indicator, int value,
347 messages_set_message_status_cb callback,
351 /* Aborts currently pending request.
353 * session: Backend session.
355 void messages_abort(void *session);