upgrade obexd to 0.47
[profile/ivi/obexd.git] / client / driver.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 <string.h>
29 #include <errno.h>
30 #include <glib.h>
31 #include <gdbus.h>
32
33 #include "transfer.h"
34 #include "session.h"
35 #include "driver.h"
36 #include "log.h"
37
38 static GSList *drivers = NULL;
39
40 struct obc_driver *obc_driver_find(const char *pattern)
41 {
42         GSList *l;
43
44         for (l = drivers; l; l = l->next) {
45                 struct obc_driver *driver = l->data;
46
47                 if (strcasecmp(pattern, driver->service) == 0)
48                         return driver;
49
50                 if (strcasecmp(pattern, driver->uuid) == 0)
51                         return driver;
52         }
53
54         return NULL;
55 }
56
57 int obc_driver_register(struct obc_driver *driver)
58 {
59         if (!driver) {
60                 error("Invalid driver");
61                 return -EINVAL;
62         }
63
64         if (obc_driver_find(driver->service)) {
65                 error("Permission denied: service %s already registered",
66                         driver->service);
67                 return -EPERM;
68         }
69
70         DBG("driver %p service %s registered", driver, driver->service);
71
72         drivers = g_slist_append(drivers, driver);
73
74         return 0;
75 }
76
77 void obc_driver_unregister(struct obc_driver *driver)
78 {
79         if (!g_slist_find(drivers, driver)) {
80                 error("Unable to unregister: No such driver %p", driver);
81                 return;
82         }
83
84         DBG("driver %p service %s unregistered", driver, driver->service);
85
86         drivers = g_slist_remove(drivers, driver);
87 }