5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <connman/log.h>
30 #include <connman/agent.h>
32 #include "../src/connman.h"
35 #include "connman/vpn-dbus.h"
37 static int vpn_connect_count;
38 static DBusConnection *connection;
40 static DBusMessage *create(DBusConnection *conn, DBusMessage *msg, void *data)
46 err = __vpn_provider_create(msg);
48 if (err == -EINPROGRESS) {
49 connman_error("Invalid return code (%d) "
54 return __connman_error_failed(msg, -err);
60 static DBusMessage *remove(DBusConnection *conn, DBusMessage *msg, void *data)
65 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
68 DBG("conn %p path %s", conn, path);
70 err = __vpn_provider_remove(path);
72 return __connman_error_failed(msg, -err);
74 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
77 static DBusMessage *get_connections(DBusConnection *conn, DBusMessage *msg,
84 reply = __vpn_provider_get_connections(msg);
86 return __connman_error_failed(msg, -EINVAL);
88 __vpn_provider_check_connections();
93 static DBusMessage *register_agent(DBusConnection *conn,
94 DBusMessage *msg, void *data)
96 const char *sender, *path;
101 sender = dbus_message_get_sender(msg);
103 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
106 err = connman_agent_register(sender, path);
108 return __connman_error_failed(msg, -err);
110 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
113 static DBusMessage *unregister_agent(DBusConnection *conn,
114 DBusMessage *msg, void *data)
116 const char *sender, *path;
119 DBG("conn %p", conn);
121 sender = dbus_message_get_sender(msg);
123 dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
126 err = connman_agent_unregister(sender, path);
128 return __connman_error_failed(msg, -err);
130 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
133 static const GDBusMethodTable manager_methods[] = {
134 { GDBUS_ASYNC_METHOD("Create",
135 GDBUS_ARGS({ "properties", "a{sv}" }),
136 GDBUS_ARGS({ "path", "o" }),
138 { GDBUS_ASYNC_METHOD("Remove",
139 GDBUS_ARGS({ "identifier", "o" }), NULL,
141 { GDBUS_METHOD("GetConnections", NULL,
142 GDBUS_ARGS({ "connections", "a(oa{sv})" }),
144 { GDBUS_METHOD("RegisterAgent",
145 GDBUS_ARGS({ "path", "o" }), NULL,
147 { GDBUS_METHOD("UnregisterAgent",
148 GDBUS_ARGS({ "path", "o" }), NULL,
153 static const GDBusSignalTable manager_signals[] = {
154 { GDBUS_SIGNAL("ConnectionAdded",
155 GDBUS_ARGS({ "identifier", "o" },
156 { "properties", "a{sv}" })) },
157 { GDBUS_SIGNAL("ConnectionRemoved",
158 GDBUS_ARGS({ "identifier", "o" })) },
162 int __vpn_manager_init(void)
166 connection = connman_dbus_get_connection();
167 if (connection == NULL)
170 g_dbus_register_interface(connection, VPN_MANAGER_PATH,
171 VPN_MANAGER_INTERFACE,
173 manager_signals, NULL, NULL, NULL);
175 vpn_connect_count = 0;
180 void __vpn_manager_cleanup(void)
184 if (connection == NULL)
187 g_dbus_unregister_interface(connection, VPN_MANAGER_PATH,
188 VPN_MANAGER_INTERFACE);
190 dbus_connection_unref(connection);