obexd-test package is needed for testing
[profile/ivi/obexd.git] / src / transport.c
1 /*
2  *
3  *  OBEX Server
4  *
5  *  Copyright (C) 2007-2010  Marcel Holtmann <marcel@holtmann.org>
6  *
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 2 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, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <stdint.h>
32 #include <stdlib.h>
33
34 #include <glib.h>
35
36 #include "obex.h"
37 #include "server.h"
38 #include "transport.h"
39 #include "log.h"
40
41 static GSList *drivers = NULL;
42
43 static struct obex_transport_driver *obex_transport_driver_find(
44                                                         const char *name)
45 {
46         GSList *l;
47
48         for (l = drivers; l; l = l->next) {
49                 struct obex_transport_driver *driver = l->data;
50
51                 if (g_strcmp0(name, driver->name) == 0)
52                         return driver;
53         }
54
55         return NULL;
56 }
57
58 GSList *obex_transport_driver_list(void)
59 {
60         return drivers;
61 }
62
63 int obex_transport_driver_register(struct obex_transport_driver *driver)
64 {
65         if (!driver) {
66                 error("Invalid driver");
67                 return -EINVAL;
68         }
69
70         if (obex_transport_driver_find(driver->name) != NULL) {
71                 error("Permission denied: transport %s already registered",
72                         driver->name);
73                 return -EPERM;
74         }
75
76         DBG("driver %p transport %s registered", driver, driver->name);
77
78         drivers = g_slist_prepend(drivers, driver);
79
80         return 0;
81 }
82
83 void obex_transport_driver_unregister(struct obex_transport_driver *driver)
84 {
85         if (!g_slist_find(drivers, driver)) {
86                 error("Unable to unregister: No such driver %p", driver);
87                 return;
88         }
89
90         DBG("driver %p transport %s unregistered", driver, driver->name);
91
92         drivers = g_slist_remove(drivers, driver);
93 }