From 6833a8b5d5f079538a2d72f805900a5e00d790ca Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Wed, 27 Mar 2013 13:54:08 +0200 Subject: client: Remove now obsolete functions and files Remove now obsolete files from services. Remove data_manager, dbus and technology .h and .c files. Update Makefile.am accordingly. --- Makefile.am | 10 +- client/commands.c | 7 +- client/data_manager.c | 282 ---------------------------- client/data_manager.h | 45 ----- client/dbus.c | 80 -------- client/dbus.h | 65 ------- client/services.c | 494 -------------------------------------------------- client/services.h | 31 ---- client/technology.c | 188 ------------------- client/technology.h | 40 ---- 10 files changed, 5 insertions(+), 1237 deletions(-) delete mode 100644 client/data_manager.c delete mode 100644 client/data_manager.h delete mode 100644 client/dbus.c delete mode 100644 client/dbus.h delete mode 100644 client/technology.c delete mode 100644 client/technology.h diff --git a/Makefile.am b/Makefile.am index 4bc1e930..4ae08529 100644 --- a/Makefile.am +++ b/Makefile.am @@ -228,14 +228,12 @@ noinst_PROGRAMS += client/connmanctl MANUAL_PAGES += doc/connmanctl.1 -client_connmanctl_SOURCES = $(gdbus_sources) src/connman.h \ +client_connmanctl_SOURCES = $(gdbus_sources) \ client/dbus_helpers.h client/dbus_helpers.c \ - client/dbus.h client/dbus.c \ - client/data_manager.h client/data_manager.c \ client/services.h client/services.c \ - client/technology.h client/technology.c \ - client/commands.h client/commands.c client/main.c \ - client/input.h client/input.c + client/commands.h client/commands.c \ + client/input.h client/input.c \ + client/main.c client_connmanctl_LDADD = @DBUS_LIBS@ @GLIB_LIBS@ -lreadline -ldl endif diff --git a/client/commands.c b/client/commands.c index eb53de59..8f9b7185 100644 --- a/client/commands.c +++ b/client/commands.c @@ -34,16 +34,11 @@ #include #include -#include "services.h" -#include "technology.h" -#include "data_manager.h" - #include "dbus_helpers.h" #include "input.h" +#include "services.h" #include "commands.h" -#define MANDATORY_ARGS 3 - static DBusConnection *connection; static char *ipv4[] = { diff --git a/client/data_manager.c b/client/data_manager.c deleted file mode 100644 index a4ad9394..00000000 --- a/client/data_manager.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * 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 -#endif - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "services.h" -#include "technology.h" -#include "data_manager.h" -#include "dbus.h" - -static void extract_manager_properties(DBusMessage *message) -{ - DBusMessageIter iter, array; - - dbus_message_iter_init(message, &iter); - dbus_message_iter_recurse(&iter, &array); - extract_properties(&array); -} - -int store_proxy_input(DBusConnection *connection, DBusMessage *message, - char *name, int num_args, char *argv[]) -{ - int i, j, k; - int error = 0; - gchar **servers = NULL; - gchar **excludes = NULL; - - for (i = 0; argv[i] != NULL && strcmp(argv[i], "excludes") != 0 && - strncmp(argv[i], "--", 2) != 0; i++) { - servers = g_try_realloc(servers, (i + 1) * sizeof(char *)); - if (servers == NULL) { - fprintf(stderr, "Could not allocate memory for list\n"); - return -ENOMEM; - } - servers[i] = g_strdup(argv[i]); - /* In case the user doesn't enter "excludes" */ - if (i + 1 == num_args) { - i++; - j = 0; - goto free_servers; - } - } - for (j = 0; j + (i + 1) != num_args && argv[j + (i + 1)] != NULL && - strncmp(argv[j + i + 1], "--", 2) != 0; j++) { - excludes = g_try_realloc(excludes, (j + 1) * sizeof(char *)); - if (excludes == NULL) { - fprintf(stderr, "Could not allocate memory for list\n"); - return -ENOMEM; - } - excludes[j] = g_strdup(argv[j + (i + 1)]); - } - -free_servers: - error = set_proxy_manual(connection, message, name, servers, excludes, - i, j); - - for (k = 0; k < j - 1; k++) - g_free(excludes[k]); - g_free(excludes); - - for (k = 0; k < i - 1; k++) - g_free(servers[k]); - g_free(servers); - - if (error < 0) - return error; - - if (i > 0) - i++; - if (j > 0) - j++; - return i + j; -} - -int connect_service(DBusConnection *connection, char *name) -{ - DBusMessage *message, *message_connect = NULL; - char *path = NULL; - const char *path_name; - DBusError err; - int err_ret = 0; - - message = get_message(connection, "GetServices"); - if (message == NULL) - return -ENOMEM; - - path_name = strip_service_path(name); - - path = g_strdup_printf("/net/connman/service/%s", path_name); - message_connect = dbus_message_new_method_call("net.connman", path, - "net.connman.Service", - "Connect"); - if (message_connect == NULL) { - err_ret = -ENOMEM; - goto error; - } - - dbus_error_init(&err); - dbus_connection_send_with_reply_and_block(connection, message_connect, - -1, &err); - - if (dbus_error_is_set(&err)) { - printf("Error '%s': %s\n", path, err.message); - dbus_error_free(&err); - err_ret = -EINVAL; - goto error; - } - - dbus_connection_send(connection, message_connect, NULL); - dbus_connection_flush(connection); - -error: - if (message != NULL) - dbus_message_unref(message); - if (message_connect != NULL) - dbus_message_unref(message_connect); - g_free(path); - - return err_ret; -} - -int disconnect_service(DBusConnection *connection, char *name) -{ - DBusMessage *message, *message_disconnect = NULL; - char *path = NULL; - const char *path_name; - DBusError err; - int err_ret = 0; - - message = get_message(connection, "GetServices"); - if (message == NULL) - return -ENOMEM; - - path_name = strip_service_path(name); - path = g_strdup_printf("/net/connman/service/%s", path_name); - - message_disconnect = dbus_message_new_method_call("net.connman", path, - "net.connman.Service", - "Disconnect"); - if (message_disconnect == NULL) { - err_ret = -ENOMEM; - goto error; - } - - dbus_error_init(&err); - dbus_connection_send_with_reply_and_block(connection, - message_disconnect, - -1, &err); - - if (dbus_error_is_set(&err)) { - printf("Error '%s': %s\n", path, err.message); - dbus_error_free(&err); - err_ret = -EINVAL; - goto error; - } - - dbus_connection_send(connection, message_disconnect, NULL); - dbus_connection_flush(connection); - -error: - if (message != NULL) - dbus_message_unref(message); - if (message_disconnect != NULL) - dbus_message_unref(message_disconnect); - g_free(path); - - return err_ret; -} - -int set_manager(DBusConnection *connection, char *key, dbus_bool_t value) -{ - DBusMessage *message; - DBusMessageIter iter; - DBusError err; - - message = dbus_message_new_method_call("net.connman", "/", - "net.connman.Manager", - "SetProperty"); - if (message == NULL) - return -ENOMEM; - - dbus_message_iter_init_append(message, &iter); - dbus_property_append_basic(&iter, (const char *) key, - DBUS_TYPE_BOOLEAN, &value); - - dbus_error_init(&err); - dbus_connection_send_with_reply_and_block(connection, message, - -1, &err); - if (dbus_error_is_set(&err) == TRUE) { - printf("Error 'net.connman.Manager' %s\n", err.message); - dbus_error_free(&err); - } - - dbus_message_unref(message); - - return 0; -} - -/* Call with any given function we want connman to respond to */ -DBusMessage *get_message(DBusConnection *connection, char *function) -{ - DBusMessage *message, *reply; - DBusError error; - - message = dbus_message_new_method_call(CONNMAN_SERVICE, - CONNMAN_MANAGER_PATH, - CONNMAN_MANAGER_INTERFACE, - function); - if (message == NULL) - return NULL; - - dbus_error_init(&error); - - reply = dbus_connection_send_with_reply_and_block(connection, - message, -1, &error); - if (dbus_error_is_set(&error) == TRUE) { - fprintf(stderr, "%s\n", error.message); - dbus_error_free(&error); - } else if (reply == NULL) - fprintf(stderr, "Failed to receive message\n"); - - dbus_message_unref(message); - - return reply; -} - -int list_properties(DBusConnection *connection, char *function, - char *service_name) -{ - DBusMessage *message; - - message = get_message(connection, function); - if (message == NULL) - return -ENOMEM; - - if (strcmp(function, "GetProperties") == 0) - extract_manager_properties(message); - - else if (strcmp(function, "GetServices") == 0 && service_name != NULL) - extract_services(message, service_name); - - else if (strcmp(function, "GetServices") == 0 && service_name == NULL) - get_services(message); - - else if (strcmp(function, "GetTechnologies") == 0) - extract_tech(message); - - dbus_message_unref(message); - - return 0; -} diff --git a/client/data_manager.h b/client/data_manager.h deleted file mode 100644 index 211eeb39..00000000 --- a/client/data_manager.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * 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 - * - */ - -#include - -#define SIGNAL_LISTEN_TIMEOUT 10 - -struct signal_args { - DBusConnection *connection; - const char *signal_name; -}; - -struct proxy_input { - char *servers; - char *excludes; -}; - -DBusMessage *get_message(DBusConnection *connection, char *function); -int store_proxy_input(DBusConnection *connection, DBusMessage *message, - char *name, int num_args, char *argv[]); -int list_properties(DBusConnection *connection, char *function, - char *service_name); -int connect_service(DBusConnection *connection, char *name); -int disconnect_service(DBusConnection *connection, char *name); -int set_manager(DBusConnection *connection, char *key, dbus_bool_t value); -void listen_for_manager_signal(void *args); diff --git a/client/dbus.c b/client/dbus.c deleted file mode 100644 index 002d858f..00000000 --- a/client/dbus.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * 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 -#endif - -#include - -#include "dbus.h" - -void dbus_property_append_basic(DBusMessageIter *iter, - const char *key, int type, void *val) -{ - DBusMessageIter value; - const char *signature; - - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key); - - switch (type) { - case DBUS_TYPE_BOOLEAN: - signature = DBUS_TYPE_BOOLEAN_AS_STRING; - break; - case DBUS_TYPE_STRING: - signature = DBUS_TYPE_STRING_AS_STRING; - break; - case DBUS_TYPE_BYTE: - signature = DBUS_TYPE_BYTE_AS_STRING; - break; - case DBUS_TYPE_UINT16: - signature = DBUS_TYPE_UINT16_AS_STRING; - break; - case DBUS_TYPE_INT16: - signature = DBUS_TYPE_INT16_AS_STRING; - break; - case DBUS_TYPE_UINT32: - signature = DBUS_TYPE_UINT32_AS_STRING; - break; - case DBUS_TYPE_INT32: - signature = DBUS_TYPE_INT32_AS_STRING; - break; - case DBUS_TYPE_UINT64: - signature = DBUS_TYPE_UINT64_AS_STRING; - break; - case DBUS_TYPE_INT64: - signature = DBUS_TYPE_INT64_AS_STRING; - break; - case DBUS_TYPE_OBJECT_PATH: - signature = DBUS_TYPE_OBJECT_PATH_AS_STRING; - break; - default: - signature = DBUS_TYPE_VARIANT_AS_STRING; - break; - } - - dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, - signature, &value); - dbus_message_iter_append_basic(&value, type, val); - dbus_message_iter_close_container(iter, &value); -} - diff --git a/client/dbus.h b/client/dbus.h deleted file mode 100644 index 3cde017f..00000000 --- a/client/dbus.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * 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 - * - */ - -#include - -#define CONNMAN_SERVICE "net.connman" - -#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" -#define CONNMAN_MANAGER_PATH "/" - -#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" - -void dbus_property_append_basic(DBusMessageIter *iter, - const char *key, int type, void *val); - -static inline void dbus_dict_open(DBusMessageIter *iter, DBusMessageIter *dict) -{ - dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING - DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict); -} - -static inline void dbus_dict_open_variant(DBusMessageIter *iter, - DBusMessageIter *dict) -{ - dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, - DBUS_TYPE_ARRAY_AS_STRING - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING - DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict); -} - -static inline void dbus_array_open(DBusMessageIter *iter, DBusMessageIter *dict) -{ - dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, - DBUS_TYPE_ARRAY_AS_STRING - DBUS_TYPE_STRING_AS_STRING, - dict); -} - -static inline void dbus_dict_close(DBusMessageIter *iter, DBusMessageIter *dict) -{ - dbus_message_iter_close_container(iter, dict); -} - diff --git a/client/services.c b/client/services.c index bdf24da7..b4bc0f65 100644 --- a/client/services.c +++ b/client/services.c @@ -34,7 +34,6 @@ #include #include "services.h" -#include "dbus.h" int parse_boolean(char *arg) { @@ -178,496 +177,3 @@ void __connmanctl_services_list(DBusMessageIter *iter) } } - - -static int append_property_array(DBusMessageIter *iter, char *property, - char **data, int num_args) -{ - DBusMessageIter value, array; - int i = 0; - - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &property); - - dbus_array_open(iter, &value); - dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, - DBUS_TYPE_STRING_AS_STRING, &array); - - while (data[i] != NULL && strncmp(data[i], "--", 2) != 0) { - dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, - &data[i]); - if (num_args > 0 && i == num_args) - break; - i++; - } - - dbus_message_iter_close_container(&value, &array); - dbus_message_iter_close_container(iter, &value); - - return i; -} - -static int append_property_dict(DBusMessageIter *iter, char *property, - char **keys, char **data, int num_args) -{ - int is_ipv6 = 0; - DBusMessageIter value, dict, entry, dict_key; - int i = 0; - unsigned char prefix; - char *property_value; - - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &property); - - /* Top most level is a{sv} */ - dbus_dict_open_variant(iter, &value); - - dbus_dict_open(&value, &dict); - - if (strcmp(property, "IPv6.Configuration") == 0) - is_ipv6 = 1; - - while (keys[i] != NULL && data[i] != NULL - && strncmp(data[i], "--", 2) != 0) { - - if (num_args > 0 && i == num_args) - break; - - dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, - NULL, &entry); - dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, - &keys[i]); - - property_value = data[i]; - - if (is_ipv6 == 1 && g_strcmp0(keys[i], "PrefixLength") == 0) { - prefix = atoi(data[i]); - - dbus_message_iter_open_container(&entry, - DBUS_TYPE_VARIANT, - DBUS_TYPE_BYTE_AS_STRING, - &dict_key); - dbus_message_iter_append_basic(&dict_key, - DBUS_TYPE_BYTE, &prefix); - } else { - if (is_ipv6 == 1 && strcmp(keys[i], "Privacy") == 0) { - switch (parse_boolean(property_value)) { - case 0: - property_value = "disabled"; - break; - case 1: - property_value = "enabled"; - break; - case -1: - if (strcmp(property_value, - "prefered") != 0) - return -EINVAL; - break; - } - } - - dbus_message_iter_open_container(&entry, - DBUS_TYPE_VARIANT, - DBUS_TYPE_STRING_AS_STRING, - &dict_key); - dbus_message_iter_append_basic(&dict_key, - DBUS_TYPE_STRING, - &property_value); - } - - dbus_message_iter_close_container(&entry, &dict_key); - dbus_message_iter_close_container(&dict, &entry); - - i++; - } - /* Close {sv}, then close a{sv} */ - dbus_dict_close(&value, &dict); - dbus_dict_close(iter, &value); - - return i; -} - -void iterate_array(DBusMessageIter *iter) -{ - DBusMessageIter array_item; - dbus_bool_t key_bool; - char *key_str; - - dbus_message_iter_recurse(iter, &array_item); - /* Make sure the entry is not NULL! */ - printf("[ "); - while (dbus_message_iter_get_arg_type(&array_item) != - DBUS_TYPE_INVALID) { - if (dbus_message_iter_get_arg_type(&array_item) == - DBUS_TYPE_STRING) { - dbus_message_iter_get_basic(&array_item, - &key_str); - printf("%s ", key_str); - } else if (dbus_message_iter_get_arg_type(&array_item) == - DBUS_TYPE_BOOLEAN) { - dbus_message_iter_get_basic(&array_item, &key_bool); - printf("%s ", key_bool == TRUE ? "True" - : "False"); - } - dbus_message_iter_next(&array_item); - } - if (dbus_message_iter_get_arg_type(&array_item) == - DBUS_TYPE_INVALID) - printf("] "); -} - -void iterate_dict(DBusMessageIter *dict, char *string, uint16_t key_int) -{ - DBusMessageIter dict_entry, sub_dict_entry; - - printf("{ "); - while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) { - dbus_message_iter_recurse(dict, &dict_entry); - dbus_message_iter_get_basic(&dict_entry, &string); - printf("%s=", string); - dbus_message_iter_next(&dict_entry); - while (dbus_message_iter_get_arg_type(&dict_entry) - != DBUS_TYPE_INVALID) { - dbus_message_iter_recurse(&dict_entry, &sub_dict_entry); - if (dbus_message_iter_get_arg_type(&sub_dict_entry) - == DBUS_TYPE_UINT16) { - dbus_message_iter_get_basic(&sub_dict_entry, - &key_int); - printf("%d ", key_int); - } else if (dbus_message_iter_get_arg_type(&sub_dict_entry) - == DBUS_TYPE_STRING) { - dbus_message_iter_get_basic(&sub_dict_entry, - &string); - printf("%s ", string); - } else if (dbus_message_iter_get_arg_type(&sub_dict_entry) - == DBUS_TYPE_ARRAY) { - iterate_array(&sub_dict_entry); - } - dbus_message_iter_next(&dict_entry); - } - dbus_message_iter_next(dict); - } - printf("}"); -} - -/* Get dictionary info about the current service and store it */ -static void extract_service_properties(DBusMessageIter *dict, - struct service_data *service) -{ - DBusMessageIter entry, value, array_item; - char *key; - char *key_str; - uint16_t key_uint16; - dbus_bool_t key_bool; - - while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) { - dbus_message_iter_recurse(dict, &entry); - dbus_message_iter_get_basic(&entry, &key); - printf("\n %s = ", key); - if (strcmp(key, "Name") == 0 && strlen(key) < 5) - service->name = key; - - dbus_message_iter_next(&entry); - dbus_message_iter_recurse(&entry, &value); - /* Check if entry is a dictionary itself */ - if (strcmp(key, "Ethernet") == 0 || - /* if just strcmp, the .Configuration names don't match - * and they are iterated with iterate_array instead*/ - strncmp(key, "IPv4", 4) == 0 || - strncmp(key, "IPv6", 4) == 0 || - strncmp(key, "Proxy", 5) == 0 || - strcmp(key, "Provider") == 0) { - dbus_message_iter_recurse(&value, &array_item); - iterate_dict(&array_item, key_str, key_uint16); - } else - switch (dbus_message_iter_get_arg_type(&value)) { - case DBUS_TYPE_ARRAY: - iterate_array(&value); - break; - case DBUS_TYPE_BOOLEAN: - dbus_message_iter_get_basic(&value, &key_bool); - printf("%s", key_bool == TRUE ? "True" : "False"); - break; - case DBUS_TYPE_BYTE: - dbus_message_iter_get_basic(&value, &key_uint16); - printf("%d", key_uint16); - break; - case DBUS_TYPE_STRING: - dbus_message_iter_get_basic(&value, &key_str); - printf("%s", key_str); - break; - } - dbus_message_iter_next(dict); - } - printf("\n\n"); -} - -void extract_service_name(DBusMessageIter *dict, struct service_data *service) -{ - DBusMessageIter dict_entry, value; - const char *key; - const char *state; - - while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) { - dbus_message_iter_recurse(dict, &dict_entry); - dbus_message_iter_get_basic(&dict_entry, &key); - if (strcmp(key, "Name") == 0) { - dbus_message_iter_next(&dict_entry); - dbus_message_iter_recurse(&dict_entry, &value); - dbus_message_iter_get_basic(&value, &service->name); - } - if (strcmp(key, "AutoConnect") == 0) { - dbus_message_iter_next(&dict_entry); - dbus_message_iter_recurse(&dict_entry, &value); - dbus_message_iter_get_basic(&value, &service->autoconn); - } - if (strcmp(key, "State") == 0) { - dbus_message_iter_next(&dict_entry); - dbus_message_iter_recurse(&dict_entry, &value); - dbus_message_iter_get_basic(&value, &state); - if (strcmp(state, "ready") == 0) { - service->connected = TRUE; - service->online = FALSE; - } else if (strcmp(state, "online") == 0) { - service->connected = FALSE; - service->online = TRUE; - } else { - service->connected = FALSE; - service->online = FALSE; - } - } - if (strcmp(key, "Favorite") == 0) { - dbus_message_iter_next(&dict_entry); - dbus_message_iter_recurse(&dict_entry, &value); - dbus_message_iter_get_basic(&value, &service->favorite); - } - dbus_message_iter_next(dict); - } -} - -/* Show detailed information about a service */ -void extract_services(DBusMessage *message, char *service_name) -{ - DBusMessageIter iter, array; - - dbus_message_iter_init(message, &iter); - dbus_message_iter_recurse(&iter, &array); - - while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { - DBusMessageIter entry, dict; - struct service_data service; - char *path; - - dbus_message_iter_recurse(&array, &entry); - dbus_message_iter_get_basic(&entry, &path); - - service.path = strip_service_path(path); - if (g_strcmp0(service.path, service_name) == 0) { - printf("[ %s ]\n", service.path); - dbus_message_iter_next(&entry); - dbus_message_iter_recurse(&entry, &dict); - extract_service_properties(&dict, &service); - } - dbus_message_iter_next(&array); - } -} - -/* Support both string names and path names for connecting to services */ -char *strip_service_path(char *service) -{ - char *service_name; - service_name = strrchr(service, '/'); - if (service_name == NULL) - return service; - else - return service_name + 1; -} - -/* Show a simple list of service names only */ -void get_services(DBusMessage *message) -{ - DBusMessageIter iter, array; - - dbus_message_iter_init(message, &iter); - dbus_message_iter_recurse(&iter, &array); - - while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { - DBusMessageIter entry, dict; - struct service_data service; - char *path; - - dbus_message_iter_recurse(&array, &entry); - dbus_message_iter_get_basic(&entry, &path); - - service.path = strip_service_path(path); - dbus_message_iter_next(&entry); - dbus_message_iter_recurse(&entry, &dict); - extract_service_name(&dict, &service); - printf("%-1s%-1s%-1s %-20s { %s }\n", - service.favorite ? "*" : "", - service.autoconn ? "A" : "", - service.online ? "O" : (service.connected ? "R" : ""), - service.name, service.path); - dbus_message_iter_next(&array); - } -} - -int set_proxy_manual(DBusConnection *connection, DBusMessage *message, - char *name, char **servers, char **excludes, - int num_servers, int num_excludes) -{ - DBusMessage *message_send; - DBusMessageIter iter, value, dict, entry, data; - char *path; - const char *path_name; - char *property = "Proxy.Configuration"; - char *method = "Method"; - char *manual = "manual"; - DBusError dbus_error; - - path_name = strip_service_path(name); - if (path_name == NULL) - return -ENXIO; - - path = g_strdup_printf("/net/connman/service/%s", path_name); - message_send = dbus_message_new_method_call("net.connman", path, - "net.connman.Service", - "SetProperty"); - - if (message_send == NULL) { - g_free(path); - return -ENOMEM; - } - - dbus_message_iter_init_append(message_send, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &property); - dbus_dict_open_variant(&iter, &value); - dbus_dict_open(&value, &dict); - dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, - &entry); - dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &method); - dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, - DBUS_TYPE_STRING_AS_STRING, - &data); - dbus_message_iter_append_basic(&data, DBUS_TYPE_STRING, &manual); - dbus_message_iter_close_container(&entry, &data); - dbus_message_iter_close_container(&dict, &entry); - dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, - &entry); - append_property_array(&entry, "Servers", servers, num_servers -1); - dbus_message_iter_close_container(&dict, &entry); - - if (num_excludes != 0) { - dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, - NULL, &entry); - append_property_array(&entry, "Excludes", excludes, - num_excludes -1); - dbus_message_iter_close_container(&dict, &entry); - } - - dbus_message_iter_close_container(&value, &dict); - dbus_message_iter_close_container(&iter, &value); - - dbus_error_init(&dbus_error); - dbus_connection_send_with_reply_and_block(connection, message_send, - -1, &dbus_error); - - if (dbus_error_is_set(&dbus_error) == TRUE) { - printf("Error '%s': %s", path, dbus_error.message); - dbus_error_free(&dbus_error); - } - - dbus_message_unref(message_send); - - g_free(path); - - return num_servers + num_excludes; -} - -int set_service_property(DBusConnection *connection, DBusMessage *message, - char *name, char *property, char **keys, - void *data, int num_args) -{ - int num_props = 1; - DBusMessage *message_send; - DBusMessageIter iter; - char *path; - const char *path_name; - DBusError dbus_error; - - path_name = strip_service_path(name); - if (path_name == NULL) - return -ENXIO; - - path = g_strdup_printf("/net/connman/service/%s", path_name); - message_send = dbus_message_new_method_call("net.connman", path, - "net.connman.Service", - "SetProperty"); - - if (message_send == NULL) { - g_free(path); - return -ENOMEM; - } - - dbus_message_iter_init_append(message_send, &iter); - - if (strcmp(property, "AutoConnect") == 0) - dbus_property_append_basic(&iter, (const char *) property, - DBUS_TYPE_BOOLEAN, data); - else if ((strcmp(property, "Domains.Configuration") == 0) - || (strcmp(property, "Timeservers.Configuration") == 0) - || (strcmp(property, "Nameservers.Configuration") == 0)) - num_props = append_property_array(&iter, property, data, - num_args); - else if ((strcmp(property, "IPv4.Configuration") == 0) - || (strcmp(property, "IPv6.Configuration") == 0) - || (strcmp(property, "Proxy.Configuration") == 0)) - num_props = append_property_dict(&iter, property, keys, data, - num_args); - - if (num_props >= 0) { - dbus_error_init(&dbus_error); - dbus_connection_send_with_reply_and_block(connection, - message_send, -1, &dbus_error); - - if (dbus_error_is_set(&dbus_error) == TRUE) { - printf("Error '%s': %s", path, dbus_error.message); - dbus_error_free(&dbus_error); - } - } - - dbus_message_unref(message_send); - g_free(path); - - return num_props; -} - -int remove_service(DBusConnection *connection, DBusMessage *message, - char *name) -{ - DBusMessage *message_send; - const char *path_name; - char *path; - DBusError err; - - path_name = strip_service_path(name); - path = g_strdup_printf("/net/connman/service/%s", path_name); - message_send = dbus_message_new_method_call(CONNMAN_SERVICE, path, - CONNMAN_SERVICE_INTERFACE, - "Remove"); - if (message_send == NULL) { - g_free(path); - return -ENOMEM; - } - - dbus_error_init(&err); - dbus_connection_send_with_reply_and_block(connection, message_send, - -1, &err); - if (dbus_error_is_set(&err) == TRUE) { - printf("Error '%s' %s\n", path, err.message); - dbus_error_free(&err); - } - - dbus_message_unref(message_send); - g_free(path); - - return 0; -} diff --git a/client/services.h b/client/services.h index 9cec0e9c..f32498bd 100644 --- a/client/services.h +++ b/client/services.h @@ -20,38 +20,7 @@ * */ -#include - #include -struct service_data { - const char *path; - const char *name; - dbus_bool_t autoconn; - dbus_bool_t favorite; - dbus_bool_t connected; - dbus_bool_t online; -}; - int parse_boolean(char *arg); void __connmanctl_services_list(DBusMessageIter *iter); -char *strip_service_path(char *service); -void extract_service_name(DBusMessageIter *dict, struct service_data *service); -int set_service_property(DBusConnection *connection, DBusMessage *message, - char *name, char *property, char **keys, - void *data, int num_args); -int remove_service(DBusConnection *connection, DBusMessage *message, - char *name); -int set_proxy_manual(DBusConnection *connection, DBusMessage *message, - char *name, char **servers, char **excludes, - int num_servers, int num_excludes); - -void extract_services(DBusMessage *message, char *service_name); -void get_services(DBusMessage *message); -void iterate_dict(DBusMessageIter *dict, char *string, uint16_t key_int); -int list_services(DBusConnection *connection, char *function); -int list_services_properties(DBusConnection *connection, char *function, - char *service_name); -int listen_for_service_signal(DBusConnection *connection, char *signal_name, - char *service_name); -void iterate_array(DBusMessageIter *iter); diff --git a/client/technology.c b/client/technology.c deleted file mode 100644 index 3720c4a3..00000000 --- a/client/technology.c +++ /dev/null @@ -1,188 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * 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 -#endif - -#include -#include -#include -#include -#include - -#include - -#include "technology.h" -#include "dbus.h" - -void extract_properties(DBusMessageIter *dict) -{ - while (dbus_message_iter_get_arg_type(dict) == DBUS_TYPE_DICT_ENTRY) { - DBusMessageIter entry, value; - const char *key, *sdata; - dbus_bool_t bdata; - - dbus_message_iter_recurse(dict, &entry); - dbus_message_iter_get_basic(&entry, &key); - printf(" [%s] = ", key); - - dbus_message_iter_next(&entry); - - dbus_message_iter_recurse(&entry, &value); - - if (dbus_message_iter_get_arg_type(&value) == - DBUS_TYPE_BOOLEAN) { - dbus_message_iter_get_basic(&value, &bdata); - printf("%s\n", bdata ? "True" : "False"); - } else if (dbus_message_iter_get_arg_type(&value) == - DBUS_TYPE_STRING) { - dbus_message_iter_get_basic(&value, &sdata); - printf("%s\n", sdata); - } - dbus_message_iter_next(dict); - } -} - -void match_tech_name(DBusMessage *message, char *tech_name, - struct tech_data *tech) -{ - DBusMessageIter iter, array; - - dbus_message_iter_init(message, &iter); - dbus_message_iter_recurse(&iter, &array); - while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { - DBusMessageIter entry; - const char *path; - const char *name; - - dbus_message_iter_recurse(&array, &entry); - dbus_message_iter_get_basic(&entry, &path); - tech->path = g_strdup(path); - name = strrchr(path, '/') + 1; - tech->name = g_strdup(name); - if (g_strcmp0(tech_name, tech->name) == 0) { - break; - } else - dbus_message_iter_next(&array); - } - -} - -void extract_tech(DBusMessage *message) -{ - DBusMessageIter iter, array; - - dbus_message_iter_init(message, &iter); - dbus_message_iter_recurse(&iter, &array); - while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { - DBusMessageIter entry, dict; - - const char *path; - - dbus_message_iter_recurse(&array, &entry); - dbus_message_iter_get_basic(&entry, &path); - - printf("{ %s }\n", path); - - dbus_message_iter_next(&entry); - - dbus_message_iter_recurse(&entry, &dict); - extract_properties(&dict); - - dbus_message_iter_next(&array); - } -} - -int scan_technology(DBusConnection *connection, DBusMessage *message, - char *tech) -{ - DBusMessage *message_send; - struct tech_data technology; - DBusError err; - - match_tech_name(message, tech, &technology); - if (g_strcmp0(tech, technology.name) != 0) { - return -ENXIO; - } - - message_send = dbus_message_new_method_call("net.connman", - technology.path, - "net.connman.Technology", - "Scan"); - if (message_send == NULL) - return -ENOMEM; - - dbus_error_init(&err); - dbus_connection_send_with_reply_and_block(connection, message_send, -1, - &err); - - if (dbus_error_is_set(&err)) { - printf("Error '%s' %s\n", technology.path, err.message); - dbus_error_free(&err); - return -ENXIO; - } - - dbus_message_unref(message_send); - g_free(technology.name); - g_free(technology.path); - - return 0; -} - -int set_technology(DBusConnection *connection, DBusMessage *message, char *key, - char *tech, dbus_bool_t value) -{ - DBusMessage *message_send; - DBusMessageIter iter; - struct tech_data technology; - DBusError err; - - match_tech_name(message, tech, &technology); - if (g_strcmp0(tech, technology.name) != 0) { - return -ENXIO; - } - - message_send = dbus_message_new_method_call("net.connman", - technology.path, - "net.connman.Technology", - "SetProperty"); - if (message_send == NULL) - return -ENOMEM; - - dbus_message_iter_init_append(message_send, &iter); - dbus_property_append_basic(&iter, (const char *) key, - DBUS_TYPE_BOOLEAN, &value); - - dbus_error_init(&err); - dbus_connection_send_with_reply_and_block(connection, message_send, - -1, &err); - if (dbus_error_is_set(&err) == TRUE) { - printf("Error '%s' %s\n", technology.path, err.message); - dbus_error_free(&err); - } - - g_free(technology.name); - g_free(technology.path); - - return 0; -} diff --git a/client/technology.h b/client/technology.h deleted file mode 100644 index 75d1a848..00000000 --- a/client/technology.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Connection Manager - * - * Copyright (C) 2012 Intel Corporation. All rights reserved. - * - * 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 - * - */ - -#include - -struct tech_data { - char *path; - char *name; - dbus_bool_t powered; - dbus_bool_t connected; -}; - -void extract_properties(DBusMessageIter *dict); -void match_tech_name(DBusMessage *message, char *tech_name, - struct tech_data *tech); -void extract_tech(DBusMessage *message); -int list_tech(DBusConnection *connection, char *function); -int set_technology(DBusConnection *connection, DBusMessage *message, char *key, - char *tech, dbus_bool_t value); -int scan_technology(DBusConnection *connection, DBusMessage *message, - char *tech); -- cgit v1.2.3