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 as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
38 #include "technology.h"
39 #include "data_manager.h"
42 static void extract_manager_properties(DBusMessage *message)
44 DBusMessageIter iter, array;
46 dbus_message_iter_init(message, &iter);
47 dbus_message_iter_recurse(&iter, &array);
48 extract_properties(&array);
51 int store_proxy_input(DBusConnection *connection, DBusMessage *message,
52 char *name, int num_args, char *argv[])
56 gchar **servers = NULL;
57 gchar **excludes = NULL;
59 for (i = 0; argv[i] != NULL && strcmp(argv[i], "excludes") != 0 &&
60 strncmp(argv[i], "--", 2) != 0; i++) {
61 servers = g_try_realloc(servers, (i + 1) * sizeof(char *));
62 if (servers == NULL) {
63 fprintf(stderr, "Could not allocate memory for list\n");
66 servers[i] = g_strdup(argv[i]);
67 /* In case the user doesn't enter "excludes" */
68 if (i + 1 == num_args) {
74 for (j = 0; j + (i + 1) != num_args && argv[j + (i + 1)] != NULL &&
75 strncmp(argv[j + i + 1], "--", 2) != 0; j++) {
76 excludes = g_try_realloc(excludes, (j + 1) * sizeof(char *));
77 if (excludes == NULL) {
78 fprintf(stderr, "Could not allocate memory for list\n");
81 excludes[j] = g_strdup(argv[j + (i + 1)]);
85 error = set_proxy_manual(connection, message, name, servers, excludes,
88 for (k = 0; k < j - 1; k++)
92 for (k = 0; k < i - 1; k++)
106 int connect_service(DBusConnection *connection, char *name)
108 DBusMessage *message, *message_connect = NULL;
109 struct service_data service;
111 const char *path_name;
115 message = get_message(connection, "GetServices");
119 path_name = find_service(connection, message, name, &service);
120 if (path_name == NULL) {
125 path = g_strdup_printf("/net/connman/service/%s", path_name);
126 message_connect = dbus_message_new_method_call("net.connman", path,
127 "net.connman.Service",
129 if (message_connect == NULL) {
134 dbus_error_init(&err);
135 dbus_connection_send_with_reply_and_block(connection, message_connect,
138 if (dbus_error_is_set(&err)) {
139 printf("Connection failed; error: '%s'\n", err.message);
144 dbus_connection_send(connection, message_connect, NULL);
145 dbus_connection_flush(connection);
149 dbus_message_unref(message);
150 if (message_connect != NULL)
151 dbus_message_unref(message_connect);
157 int disconnect_service(DBusConnection *connection, char *name)
159 DBusMessage *message, *message_disconnect = NULL;
160 struct service_data service;
162 const char *path_name;
166 message = get_message(connection, "GetServices");
170 path_name = find_service(connection, message, name, &service);
171 if (path_name == NULL) {
176 path = g_strdup_printf("/net/connman/service/%s", path_name);
177 printf("%s\n", path);
178 message_disconnect = dbus_message_new_method_call("net.connman", path,
179 "net.connman.Service",
181 if (message_disconnect == NULL) {
186 dbus_error_init(&err);
187 dbus_connection_send_with_reply_and_block(connection,
191 if (dbus_error_is_set(&err)) {
192 printf("Connection failed; error: '%s'\n", err.message);
197 dbus_connection_send(connection, message_disconnect, NULL);
198 dbus_connection_flush(connection);
202 dbus_message_unref(message);
203 if (message_disconnect != NULL)
204 dbus_message_unref(message_disconnect);
210 int set_manager(DBusConnection *connection, char *key, dbus_bool_t value)
212 DBusMessage *message;
213 DBusMessageIter iter;
215 message = dbus_message_new_method_call("net.connman", "/",
216 "net.connman.Manager",
221 dbus_message_iter_init_append(message, &iter);
222 dbus_property_append_basic(&iter, (const char *) key,
223 DBUS_TYPE_BOOLEAN, &value);
224 dbus_connection_send(connection, message, NULL);
225 dbus_connection_flush(connection);
226 dbus_message_unref(message);
231 /* Call with any given function we want connman to respond to */
232 DBusMessage *get_message(DBusConnection *connection, char *function)
234 DBusMessage *message, *reply;
237 message = dbus_message_new_method_call(CONNMAN_SERVICE,
238 CONNMAN_MANAGER_PATH,
239 CONNMAN_MANAGER_INTERFACE,
244 dbus_error_init(&error);
246 reply = dbus_connection_send_with_reply_and_block(connection,
247 message, -1, &error);
248 if (dbus_error_is_set(&error) == TRUE) {
249 fprintf(stderr, "%s\n", error.message);
250 dbus_error_free(&error);
251 } else if (reply == NULL)
252 fprintf(stderr, "Failed to receive message\n");
254 dbus_message_unref(message);
259 int list_properties(DBusConnection *connection, char *function,
262 DBusMessage *message;
264 message = get_message(connection, function);
268 if (strcmp(function, "GetProperties") == 0)
269 extract_manager_properties(message);
271 else if (strcmp(function, "GetServices") == 0 && service_name != NULL)
272 extract_services(message, service_name);
274 else if (strcmp(function, "GetServices") == 0 && service_name == NULL)
275 get_services(message);
277 else if (strcmp(function, "GetTechnologies") == 0)
278 extract_tech(message);
280 dbus_message_unref(message);