1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
/*
*
* OBEX Server
*
* Copyright (C) 2010-2011 Nokia Corporation
*
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <fcntl.h>
#include <inttypes.h>
#include <gobex/gobex.h>
#include <gobex/gobex-apparam.h>
#include "obexd.h"
#include "plugin.h"
#include "log.h"
#include "obex.h"
#include "service.h"
#include "mimetype.h"
#include "filesystem.h"
#include "manager.h"
#include "map_ap.h"
#include "messages.h"
/* Channel number according to bluez doc/assigned-numbers.txt */
#define MAS_CHANNEL 16
#define MAS_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
<record> \
<attribute id=\"0x0001\"> \
<sequence> \
<uuid value=\"0x1132\"/> \
</sequence> \
</attribute> \
\
<attribute id=\"0x0004\"> \
<sequence> \
<sequence> \
<uuid value=\"0x0100\"/> \
</sequence> \
<sequence> \
<uuid value=\"0x0003\"/> \
<uint8 value=\"%u\" name=\"channel\"/> \
</sequence> \
<sequence> \
<uuid value=\"0x0008\"/> \
</sequence> \
</sequence> \
</attribute> \
\
<attribute id=\"0x0009\"> \
<sequence> \
<sequence> \
<uuid value=\"0x1134\"/> \
<uint16 value=\"0x0100\" name=\"version\"/> \
</sequence> \
</sequence> \
</attribute> \
\
<attribute id=\"0x0100\"> \
<text value=\"%s\" name=\"name\"/> \
</attribute> \
\
<attribute id=\"0x0315\"> \
<uint8 value=\"0x00\"/> \
</attribute> \
\
<attribute id=\"0x0316\"> \
<uint8 value=\"0x0F\"/> \
</attribute> \
</record>"
#define XML_DECL "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
/* Building blocks for x-obex/folder-listing */
#define FL_DTD "<!DOCTYPE folder-listing SYSTEM \"obex-folder-listing.dtd\">"
#define FL_BODY_BEGIN "<folder-listing version=\"1.0\">"
#define FL_BODY_EMPTY "<folder-listing version=\"1.0\"/>"
#define FL_PARENT_FOLDER_ELEMENT "<parent-folder/>"
#define FL_FOLDER_ELEMENT "<folder name=\"%s\"/>"
#define FL_BODY_END "</folder-listing>"
#define ML_BODY_BEGIN "<MAP-msg-listing version=\"1.0\">"
#define ML_BODY_END "</MAP-msg-listing>"
struct mas_session {
struct mas_request *request;
void *backend_data;
gboolean finished;
gboolean nth_call;
GString *buffer;
GObexApparam *inparams;
GObexApparam *outparams;
gboolean ap_sent;
};
static const uint8_t MAS_TARGET[TARGET_SIZE] = {
0xbb, 0x58, 0x2b, 0x40, 0x42, 0x0c, 0x11, 0xdb,
0xb0, 0xde, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 };
static int get_params(struct obex_session *os, struct mas_session *mas)
{
const uint8_t *buffer;
ssize_t size;
size = obex_get_apparam(os, &buffer);
if (size < 0)
size = 0;
mas->inparams = g_obex_apparam_decode(buffer, size);
if (mas->inparams == NULL) {
DBG("Error when parsing parameters!");
return -EBADR;
}
return 0;
}
static void reset_request(struct mas_session *mas)
{
if (mas->buffer) {
g_string_free(mas->buffer, TRUE);
mas->buffer = NULL;
}
if (mas->inparams) {
g_obex_apparam_free(mas->inparams);
mas->inparams = NULL;
}
if (mas->outparams) {
g_obex_apparam_free(mas->outparams);
mas->outparams = NULL;
}
mas->nth_call = FALSE;
mas->finished = FALSE;
}
static void mas_clean(struct mas_session *mas)
{
reset_request(mas);
g_free(mas);
}
static void *mas_connect(struct obex_session *os, int *err)
{
struct mas_session *mas;
DBG("");
mas = g_new0(struct mas_session, 1);
*err = messages_connect(&mas->backend_data);
if (*err < 0)
goto failed;
manager_register_session(os);
return mas;
failed:
g_free(mas);
return NULL;
}
static void mas_disconnect(struct obex_session *os, void *user_data)
{
struct mas_session *mas = user_data;
DBG("");
manager_unregister_session(os);
messages_disconnect(mas->backend_data);
mas_clean(mas);
}
static int mas_get(struct obex_session *os, void *user_data)
{
struct mas_session *mas = user_data;
const char *type = obex_get_type(os);
const char *name = obex_get_name(os);
int ret;
DBG("GET: name %s type %s mas %p",
name, type, mas);
if (type == NULL)
return -EBADR;
ret = get_params(os, mas);
if (ret < 0)
goto failed;
ret = obex_get_stream_start(os, name);
if (ret < 0)
goto failed;
return 0;
failed:
reset_request(mas);
return ret;
}
static int mas_put(struct obex_session *os, void *user_data)
{
struct mas_session *mas = user_data;
const char *type = obex_get_type(os);
const char *name = obex_get_name(os);
int ret;
DBG("PUT: name %s type %s mas %p", name, type, mas);
if (type == NULL)
return -EBADR;
ret = get_params(os, mas);
if (ret < 0)
goto failed;
ret = obex_put_stream_start(os, name);
if (ret < 0)
goto failed;
return 0;
failed:
reset_request(mas);
return ret;
}
/* FIXME: Preserve whitespaces */
static void g_string_append_escaped_printf(GString *string,
const gchar *format, ...)
{
va_list ap;
char *escaped;
va_start(ap, format);
escaped = g_markup_vprintf_escaped(format, ap);
g_string_append(string, escaped);
g_free(escaped);
va_end(ap);
}
static const char *yesorno(gboolean a)
{
if (a)
return "yes";
return "no";
}
static void get_messages_listing_cb(void *session, int err, uint16_t size,
gboolean newmsg,
const struct messages_message *entry,
void *user_data)
{
struct mas_session *mas = user_data;
uint16_t max = 1024;
if (err < 0 && err != -EAGAIN) {
obex_object_set_io_flags(mas, G_IO_ERR, err);
return;
}
g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max);
if (max == 0) {
if (!entry)
mas->finished = TRUE;
goto proceed;
}
if (!mas->nth_call) {
g_string_append(mas->buffer, ML_BODY_BEGIN);
mas->nth_call = TRUE;
}
if (!entry) {
g_string_append(mas->buffer, ML_BODY_END);
mas->finished = TRUE;
goto proceed;
}
g_string_append(mas->buffer, "<msg");
g_string_append_escaped_printf(mas->buffer, " handle=\"%s\"",
entry->handle);
if (entry->mask & PMASK_SUBJECT)
g_string_append_escaped_printf(mas->buffer, " subject=\"%s\"",
entry->subject);
if (entry->mask & PMASK_DATETIME)
g_string_append_escaped_printf(mas->buffer, " datetime=\"%s\"",
entry->datetime);
if (entry->mask & PMASK_SENDER_NAME)
g_string_append_escaped_printf(mas->buffer,
" sender_name=\"%s\"",
entry->sender_name);
if (entry->mask & PMASK_SENDER_ADDRESSING)
g_string_append_escaped_printf(mas->buffer,
" sender_addressing=\"%s\"",
entry->sender_addressing);
if (entry->mask & PMASK_REPLYTO_ADDRESSING)
g_string_append_escaped_printf(mas->buffer,
" replyto_addressing=\"%s\"",
entry->replyto_addressing);
if (entry->mask & PMASK_RECIPIENT_NAME)
g_string_append_escaped_printf(mas->buffer,
" recipient_name=\"%s\"",
entry->recipient_name);
if (entry->mask & PMASK_RECIPIENT_ADDRESSING)
g_string_append_escaped_printf(mas->buffer,
" recipient_addressing=\"%s\"",
entry->recipient_addressing);
if (entry->mask & PMASK_TYPE)
g_string_append_escaped_printf(mas->buffer, " type=\"%s\"",
entry->type);
if (entry->mask & PMASK_RECEPTION_STATUS)
g_string_append_escaped_printf(mas->buffer,
" reception_status=\"%s\"",
entry->reception_status);
if (entry->mask & PMASK_SIZE)
g_string_append_escaped_printf(mas->buffer, " size=\"%s\"",
entry->size);
if (entry->mask & PMASK_ATTACHMENT_SIZE)
g_string_append_escaped_printf(mas->buffer,
" attachment_size=\"%s\"",
entry->attachment_size);
if (entry->mask & PMASK_TEXT)
g_string_append_escaped_printf(mas->buffer, " text=\"%s\"",
yesorno(entry->text));
if (entry->mask & PMASK_READ)
g_string_append_escaped_printf(mas->buffer, " read=\"%s\"",
yesorno(entry->read));
if (entry->mask & PMASK_SENT)
g_string_append_escaped_printf(mas->buffer, " sent=\"%s\"",
yesorno(entry->sent));
if (entry->mask & PMASK_PROTECTED)
g_string_append_escaped_printf(mas->buffer, " protected=\"%s\"",
yesorno(entry->protect));
if (entry->mask & PMASK_PRIORITY)
g_string_append_escaped_printf(mas->buffer, " priority=\"%s\"",
yesorno(entry->priority));
g_string_append(mas->buffer, "/>\n");
proceed:
if (!entry) {
mas->outparams = g_obex_apparam_set_uint16(mas->outparams,
MAP_AP_MESSAGESLISTINGSIZE,
size);
mas->outparams = g_obex_apparam_set_uint8(mas->outparams,
MAP_AP_NEWMESSAGE,
newmsg ? 1 : 0);
}
if (err != -EAGAIN)
obex_object_set_io_flags(mas, G_IO_IN, 0);
}
static void get_message_cb(void *session, int err, gboolean fmore,
const char *chunk, void *user_data)
{
struct mas_session *mas = user_data;
DBG("");
if (err < 0 && err != -EAGAIN) {
obex_object_set_io_flags(mas, G_IO_ERR, err);
return;
}
if (!chunk) {
mas->finished = TRUE;
goto proceed;
}
g_string_append(mas->buffer, chunk);
proceed:
if (err != -EAGAIN)
obex_object_set_io_flags(mas, G_IO_IN, 0);
}
static void get_folder_listing_cb(void *session, int err, uint16_t size,
const char *name, void *user_data)
{
struct mas_session *mas = user_data;
uint16_t max = 1024;
if (err < 0 && err != -EAGAIN) {
obex_object_set_io_flags(mas, G_IO_ERR, err);
return;
}
g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max);
if (max == 0) {
if (err != -EAGAIN)
mas->outparams = g_obex_apparam_set_uint16(
mas->outparams,
MAP_AP_FOLDERLISTINGSIZE,
size);
if (!name)
mas->finished = TRUE;
goto proceed;
}
if (!mas->nth_call) {
g_string_append(mas->buffer, XML_DECL);
g_string_append(mas->buffer, FL_DTD);
if (!name) {
g_string_append(mas->buffer, FL_BODY_EMPTY);
mas->finished = TRUE;
goto proceed;
}
g_string_append(mas->buffer, FL_BODY_BEGIN);
mas->nth_call = TRUE;
}
if (!name) {
g_string_append(mas->buffer, FL_BODY_END);
mas->finished = TRUE;
goto proceed;
}
if (g_strcmp0(name, "..") == 0)
g_string_append(mas->buffer, FL_PARENT_FOLDER_ELEMENT);
else
g_string_append_escaped_printf(mas->buffer, FL_FOLDER_ELEMENT,
name);
proceed:
if (err != -EAGAIN)
obex_object_set_io_flags(mas, G_IO_IN, err);
}
static void update_inbox_cb(void *session, int err, void *user_data)
{
struct mas_session *mas = user_data;
DBG("");
mas->finished = TRUE;
if (err < 0)
obex_object_set_io_flags(mas, G_IO_ERR, err);
else
obex_object_set_io_flags(mas, G_IO_OUT, 0);
}
static int mas_setpath(struct obex_session *os, void *user_data)
{
const char *name;
const uint8_t *nonhdr;
struct mas_session *mas = user_data;
if (obex_get_non_header_data(os, &nonhdr) != 2) {
error("Set path failed: flag and constants not found!");
return -EBADR;
}
name = obex_get_name(os);
DBG("SETPATH: name %s nonhdr 0x%x%x", name, nonhdr[0], nonhdr[1]);
if ((nonhdr[0] & 0x02) != 0x02) {
DBG("Error: requested directory creation");
return -EBADR;
}
return messages_set_folder(mas->backend_data, name, nonhdr[0] & 0x01);
}
static void *folder_listing_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err)
{
struct mas_session *mas = driver_data;
/* 1024 is the default when there was no MaxListCount sent */
uint16_t max = 1024;
uint16_t offset = 0;
if (oflag != O_RDONLY) {
*err = -EBADR;
return NULL;
}
DBG("name = %s", name);
g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max);
g_obex_apparam_get_uint16(mas->inparams, MAP_AP_STARTOFFSET, &offset);
*err = messages_get_folder_listing(mas->backend_data, name, max,
offset, get_folder_listing_cb, mas);
mas->buffer = g_string_new("");
if (*err < 0)
return NULL;
else
return mas;
}
static void *msg_listing_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err)
{
struct mas_session *mas = driver_data;
struct messages_filter filter = { 0, };
/* 1024 is the default when there was no MaxListCount sent */
uint16_t max = 1024;
uint16_t offset = 0;
DBG("");
if (oflag != O_RDONLY) {
*err = -EBADR;
return NULL;
}
g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT, &max);
g_obex_apparam_get_uint16(mas->inparams, MAP_AP_STARTOFFSET, &offset);
g_obex_apparam_get_uint32(mas->inparams, MAP_AP_PARAMETERMASK,
&filter.parameter_mask);
g_obex_apparam_get_uint8(mas->inparams, MAP_AP_FILTERMESSAGETYPE,
&filter.type);
filter.period_begin = g_obex_apparam_get_string(mas->inparams,
MAP_AP_FILTERPERIODBEGIN);
filter.period_end = g_obex_apparam_get_string(mas->inparams,
MAP_AP_FILTERPERIODEND);
g_obex_apparam_get_uint8(mas->inparams, MAP_AP_FILTERREADSTATUS,
&filter.read_status);
filter.recipient = g_obex_apparam_get_string(mas->inparams,
MAP_AP_FILTERRECIPIENT);
filter.originator = g_obex_apparam_get_string(mas->inparams,
MAP_AP_FILTERORIGINATOR);
g_obex_apparam_get_uint8(mas->inparams, MAP_AP_FILTERPRIORITY,
&filter.priority);
*err = messages_get_messages_listing(mas->backend_data, name, max,
offset, &filter,
get_messages_listing_cb, mas);
mas->buffer = g_string_new("");
if (*err < 0)
return NULL;
else
return mas;
}
static void *message_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err)
{
struct mas_session *mas = driver_data;
DBG("");
if (oflag != O_RDONLY) {
DBG("Message pushing unsupported");
*err = -ENOSYS;
return NULL;
}
*err = messages_get_message(mas->backend_data, name, 0,
get_message_cb, mas);
mas->buffer = g_string_new("");
if (*err < 0)
return NULL;
else
return mas;
}
static void *message_update_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size,
int *err)
{
struct mas_session *mas = driver_data;
DBG("");
if (oflag != O_WRONLY) {
*err = -EBADR;
return NULL;
}
*err = messages_update_inbox(mas->backend_data, update_inbox_cb, mas);
if (*err < 0)
return NULL;
else
return mas;
}
static ssize_t any_get_next_header(void *object, void *buf, size_t mtu,
uint8_t *hi)
{
struct mas_session *mas = object;
DBG("");
if (mas->buffer->len == 0 && !mas->finished)
return -EAGAIN;
*hi = G_OBEX_HDR_APPARAM;
if (mas->ap_sent)
return 0;
mas->ap_sent = TRUE;
return g_obex_apparam_encode(mas->outparams, buf, mtu);
}
static void *any_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err)
{
DBG("");
*err = -ENOSYS;
return NULL;
}
static ssize_t any_write(void *object, const void *buf, size_t count)
{
DBG("");
return count;
}
static ssize_t any_read(void *obj, void *buf, size_t count)
{
struct mas_session *mas = obj;
ssize_t len;
DBG("");
len = string_read(mas->buffer, buf, count);
if (len == 0 && !mas->finished)
return -EAGAIN;
return len;
}
static int any_close(void *obj)
{
struct mas_session *mas = obj;
DBG("");
if (!mas->finished)
messages_abort(mas->backend_data);
reset_request(mas);
return 0;
}
static struct obex_service_driver mas = {
.name = "Message Access server",
.service = OBEX_MAS,
.channel = MAS_CHANNEL,
.secure = TRUE,
.record = MAS_RECORD,
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.connect = mas_connect,
.get = mas_get,
.put = mas_put,
.setpath = mas_setpath,
.disconnect = mas_disconnect,
};
static struct obex_mime_type_driver mime_map = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = NULL,
.open = any_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver mime_message = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/message",
.open = message_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver mime_folder_listing = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-obex/folder-listing",
.get_next_header = any_get_next_header,
.open = folder_listing_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver mime_msg_listing = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/MAP-msg-listing",
.open = msg_listing_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver mime_notification_registration = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/MAP-NotificationRegistration",
.open = any_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver mime_message_status = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/messageStatus",
.open = any_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver mime_message_update = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/MAP-messageUpdate",
.open = message_update_open,
.close = any_close,
.read = any_read,
.write = any_write,
};
static struct obex_mime_type_driver *map_drivers[] = {
&mime_map,
&mime_message,
&mime_folder_listing,
&mime_msg_listing,
&mime_notification_registration,
&mime_message_status,
&mime_message_update,
NULL
};
static int mas_init(void)
{
int err;
int i;
err = messages_init();
if (err < 0)
return err;
for (i = 0; map_drivers[i] != NULL; ++i) {
err = obex_mime_type_driver_register(map_drivers[i]);
if (err < 0)
goto failed;
}
err = obex_service_driver_register(&mas);
if (err < 0)
goto failed;
return 0;
failed:
for (--i; i >= 0; --i)
obex_mime_type_driver_unregister(map_drivers[i]);
messages_exit();
return err;
}
static void mas_exit(void)
{
int i;
obex_service_driver_unregister(&mas);
for (i = 0; map_drivers[i] != NULL; ++i)
obex_mime_type_driver_unregister(map_drivers[i]);
messages_exit();
}
OBEX_PLUGIN_DEFINE(mas, mas_init, mas_exit)
|