summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorSeonah Moon <seonah1.moon@samsung.com>2018-01-08 13:42:54 +0900
committerSeonah Moon <seonah1.moon@samsung.com>2018-01-08 13:43:31 +0900
commit9362752a471a5c892d679548fbf2828d5fc5684b (patch)
tree83c7d29a28556906938f5c2198d81e2d35f86f92 /client
parent22633ced6225d294ce8483efbf2b39ea0c0c1b65 (diff)
downloadconnman-9362752a471a5c892d679548fbf2828d5fc5684b.tar.gz
connman-9362752a471a5c892d679548fbf2828d5fc5684b.tar.bz2
connman-9362752a471a5c892d679548fbf2828d5fc5684b.zip
Imported Upstream version 1.35upstream/1.35
Change-Id: I174854914d9fd06a813270b57d1f7bc2bac63c6a Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
Diffstat (limited to 'client')
-rw-r--r--client/commands.c341
-rw-r--r--client/dbus_helpers.c8
-rw-r--r--client/input.c6
3 files changed, 340 insertions, 15 deletions
diff --git a/client/commands.c b/client/commands.c
index 9208016b..583095b1 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -46,6 +46,7 @@
static DBusConnection *connection;
static GHashTable *service_hash;
+static GHashTable *vpnconnection_hash;
static GHashTable *peer_hash;
static GHashTable *technology_hash;
static char *session_notify_path;
@@ -265,6 +266,33 @@ static int cmd_state(char *args[], int num, struct connman_option *options)
state_print, NULL, NULL, NULL);
}
+static int clock_print(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ DBusMessageIter entry;
+
+ if (error) {
+ fprintf(stderr, "Error: %s", error);
+ return 0;
+ }
+
+ dbus_message_iter_recurse(iter, &entry);
+ __connmanctl_dbus_print(&entry, " ", " = ", "\n");
+ fprintf(stdout, "\n");
+
+ return 0;
+}
+
+static int cmd_clock(char *args[], int num, struct connman_option *options)
+{
+ if (num > 1)
+ return -E2BIG;
+
+ return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+ CONNMAN_PATH, "net.connman.Clock", "GetProperties",
+ clock_print, NULL, NULL, NULL);
+}
+
static int services_list(DBusMessageIter *iter, const char *error,
void *user_data)
{
@@ -495,8 +523,13 @@ struct tether_properties {
static int tether_update(struct tether_properties *tether)
{
- if (tether->ssid_result == 0 && tether->passphrase_result == 0)
- return tether_set("wifi", tether->set_tethering);
+ int ret;
+
+ if (tether->ssid_result == 0 && tether->passphrase_result == 0) {
+ ret = tether_set("wifi", tether->set_tethering);
+ g_free(tether);
+ return ret;
+ }
if (tether->ssid_result != -EINPROGRESS &&
tether->passphrase_result != -EINPROGRESS) {
@@ -725,6 +758,131 @@ static int cmd_disconnect(char *args[], int num, struct connman_option *options)
disconnect_return, path, NULL, NULL);
}
+struct move_service {
+ char *service;
+ char *target;
+};
+
+static int move_before_return(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ struct move_service *services = user_data;
+ char *service;
+ char *target;
+
+ if (!error) {
+ service = strrchr(services->service, '/');
+ service++;
+ target = strrchr(services->target, '/');
+ target++;
+ fprintf(stdout, "Moved %s before %s\n", service, target);
+ } else
+ fprintf(stderr, "Error %s: %s\n", services->service, error);
+
+ g_free(services->service);
+ g_free(services->target);
+ g_free(user_data);
+
+ return 0;
+}
+
+static void move_before_append_args(DBusMessageIter *iter, void *user_data)
+{
+ char *path = user_data;
+
+ dbus_message_iter_append_basic(iter,
+ DBUS_TYPE_OBJECT_PATH, &path);
+
+ return;
+}
+
+static int cmd_service_move_before(char *args[], int num,
+ struct connman_option *options)
+{
+ const char *iface = "net.connman.Service";
+ struct move_service *services;
+
+ if (num > 3)
+ return -E2BIG;
+
+ if (num < 3)
+ return -EINVAL;
+
+ if (check_dbus_name(args[1]) == false)
+ return -EINVAL;
+
+ services = g_new(struct move_service, 1);
+
+ services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
+ services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
+
+ return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+ services->service, iface, "MoveBefore",
+ move_before_return, services,
+ move_before_append_args,
+ services->target);
+}
+
+static int move_after_return(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ struct move_service *services = user_data;
+ char *service;
+ char *target;
+
+ if (!error) {
+ service = strrchr(services->service, '/');
+ service++;
+ target = strrchr(services->target, '/');
+ target++;
+ fprintf(stdout, "Moved %s after %s\n", service, target);
+ } else
+ fprintf(stderr, "Error %s: %s\n", services->service, error);
+
+ g_free(services->service);
+ g_free(services->target);
+ g_free(user_data);
+
+ return 0;
+}
+
+static void move_after_append_args(DBusMessageIter *iter, void *user_data)
+{
+ char *path = user_data;
+
+ dbus_message_iter_append_basic(iter,
+ DBUS_TYPE_OBJECT_PATH, &path);
+
+ return;
+}
+
+static int cmd_service_move_after(char *args[], int num,
+ struct connman_option *options)
+{
+ const char *iface = "net.connman.Service";
+ struct move_service *services;
+
+ if (num > 3)
+ return -E2BIG;
+
+ if (num < 3)
+ return -EINVAL;
+
+ if (check_dbus_name(args[1]) == false)
+ return -EINVAL;
+
+ services = g_new(struct move_service, 1);
+
+ services->service = g_strdup_printf("/net/connman/service/%s", args[1]);
+ services->target = g_strdup_printf("/net/connman/service/%s", args[2]);
+
+ return __connmanctl_dbus_method_call(connection, CONNMAN_SERVICE,
+ services->service, iface, "MoveAfter",
+ move_after_return, services,
+ move_after_append_args,
+ services->target);
+}
+
static int config_return(DBusMessageIter *iter, const char *error,
void *user_data)
{
@@ -1738,6 +1896,8 @@ static int session_config(char *args[], int num,
int index = 0, res = 0;
struct config_append append;
char c;
+ char *ifname;
+ dbus_bool_t source_ip_rule;
while (index < num && args[index]) {
append.opts = &args[index];
@@ -1764,6 +1924,41 @@ static int session_config(char *args[], int num,
DBUS_TYPE_STRING, &args[index + 1]);
append.values = 2;
break;
+ case 'i':
+ if (index + 1 < num)
+ ifname = args[index + 1];
+ else
+ ifname = "";
+
+ res = __connmanctl_dbus_session_change(connection,
+ session_path, session_config_return,
+ "AllowedInterface", "AllowedInterface",
+ DBUS_TYPE_STRING, &ifname);
+ append.values = 2;
+ break;
+ case 's':
+ if (!args[index + 1]) {
+ res = -EINVAL;
+ break;
+ }
+ switch (parse_boolean(args[index + 1])) {
+ case 1:
+ source_ip_rule = TRUE;
+ break;
+ case 0:
+ source_ip_rule = FALSE;
+ break;
+ default:
+ res = -EINVAL;
+ break;
+ }
+
+ res = __connmanctl_dbus_session_change(connection,
+ session_path, session_config_return,
+ "SourceIPRule", "SourceIPRule",
+ DBUS_TYPE_BOOLEAN, &source_ip_rule);
+ append.values = 2;
+ break;
default:
res = -EINVAL;
@@ -1838,22 +2033,21 @@ static int cmd_exit(char *args[], int num, struct connman_option *options)
return 1;
}
-static char *lookup_service(const char *text, int state)
+static char *lookup_key_from_table(GHashTable *hash, const char *text,
+ int state)
{
static int len = 0;
static GHashTableIter iter;
gpointer key, value;
if (state == 0) {
- g_hash_table_iter_init(&iter, service_hash);
+ g_hash_table_iter_init(&iter, hash);
len = strlen(text);
}
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- const char *service = key;
- if (strncmp(text, service, len) == 0)
- return strdup(service);
- }
+ while (g_hash_table_iter_next(&iter, &key, &value))
+ if (strncmp(text, key, len) == 0)
+ return strdup(key);
return NULL;
}
@@ -1865,7 +2059,7 @@ static char *lookup_service_arg(const char *text, int state)
return NULL;
}
- return lookup_service(text, state);
+ return lookup_key_from_table(service_hash, text, state);
}
static char *lookup_peer(const char *text, int state)
@@ -2009,6 +2203,16 @@ static char *lookup_agent(const char *text, int state)
return lookup_on_off(text, state);
}
+static char *lookup_vpnconnection_arg(const char *text, int state)
+{
+ if (__connmanctl_input_calc_level() > 1) {
+ __connmanctl_input_lookup_end();
+ return NULL;
+ }
+
+ return lookup_key_from_table(vpnconnection_hash, text, state);
+}
+
static struct connman_option service_options[] = {
{"properties", 'p', "[<service>] (obsolete)"},
{ NULL, }
@@ -2042,6 +2246,8 @@ static struct connman_option monitor_options[] = {
static struct connman_option session_options[] = {
{"bearers", 'b', "<technology1> [<technology2> [...]]"},
{"type", 't', "local|internet|any"},
+ {"ifname", 'i', "[<interface_name>]"},
+ {"srciprule", 's', "yes|no"},
{ NULL, }
};
@@ -2087,7 +2293,7 @@ static char *lookup_monitor(const char *text, int state)
static char *lookup_config(const char *text, int state)
{
if (__connmanctl_input_calc_level() < 2)
- return lookup_service(text, state);
+ return lookup_key_from_table(service_hash, text, state);
return lookup_options(config_options, text, state);
}
@@ -2376,6 +2582,8 @@ static const struct {
"Shows if the system is online or offline", NULL },
{ "technologies", NULL, NULL, cmd_technologies,
"Display technologies", NULL },
+ { "clock", NULL, NULL, cmd_clock,
+ "Get System Clock Properties", NULL },
{ "enable", "<technology>|offline", NULL, cmd_enable,
"Enables given technology or offline mode",
lookup_technology_offline },
@@ -2398,14 +2606,20 @@ static const struct {
"Connect a given service or peer", lookup_service_arg },
{ "disconnect", "<service/peer>", NULL, cmd_disconnect,
"Disconnect a given service or peer", lookup_service_arg },
+ { "move-before", "<service> <target service> ", NULL,
+ cmd_service_move_before, "Move <service> before <target service>",
+ lookup_service_arg },
+ { "move-after", "<service> <target service> ", NULL,
+ cmd_service_move_after, "Move <service> after <target service>",
+ lookup_service_arg },
{ "config", "<service>", config_options, cmd_config,
"Set service configuration options", lookup_config },
{ "monitor", "[off]", monitor_options, cmd_monitor,
"Monitor signals from interfaces", lookup_monitor },
{ "agent", "on|off", NULL, cmd_agent,
"Agent mode", lookup_agent },
- {"vpnconnections", "[<connection>]", NULL, cmd_vpnconnections,
- "Display VPN connections", NULL },
+ { "vpnconnections", "[<connection>]", NULL, cmd_vpnconnections,
+ "Display VPN connections", lookup_vpnconnection_arg },
{ "vpnagent", "on|off", NULL, cmd_vpnagent,
"VPN Agent mode", lookup_agent },
{ "session", "on|off|connect|disconnect|config", session_options,
@@ -2609,6 +2823,72 @@ static int populate_service_hash(DBusMessageIter *iter, const char *error,
return 0;
}
+static void add_vpnconnection_id(const char *path)
+{
+ g_hash_table_replace(vpnconnection_hash, g_strdup(path),
+ GINT_TO_POINTER(TRUE));
+}
+
+static void remove_vpnconnection_id(const char *path)
+{
+ g_hash_table_remove(vpnconnection_hash, path);
+}
+
+static void vpnconnection_added(DBusMessageIter *iter)
+{
+ char *path = NULL;
+
+ dbus_message_iter_get_basic(iter, &path);
+ add_vpnconnection_id(get_path(path));
+}
+
+static void vpnconnection_removed(DBusMessageIter *iter)
+{
+ char *path = NULL;
+
+ dbus_message_iter_get_basic(iter, &path);
+ remove_vpnconnection_id(get_path(path));
+}
+
+static void add_vpnconnections(DBusMessageIter *iter)
+{
+ DBusMessageIter array;
+ char *path = NULL;
+
+ while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRUCT) {
+
+ dbus_message_iter_recurse(iter, &array);
+ if (dbus_message_iter_get_arg_type(&array) !=
+ DBUS_TYPE_OBJECT_PATH)
+ return;
+
+ dbus_message_iter_get_basic(&array, &path);
+ add_vpnconnection_id(get_path(path));
+
+ dbus_message_iter_next(iter);
+ }
+}
+
+static int populate_vpnconnection_hash(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ DBusMessageIter array;
+
+ if (error) {
+ fprintf(stderr, "Error getting VPN connections: %s", error);
+ return 0;
+ }
+
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+ return 0;
+
+ dbus_message_iter_recurse(iter, &array);
+
+ add_vpnconnections(&array);
+
+ return 0;
+}
+
static void add_peer_id(const char *path)
{
g_hash_table_replace(peer_hash, g_strdup(path), GINT_TO_POINTER(TRUE));
@@ -2761,6 +3041,20 @@ static DBusHandlerResult monitor_completions_changed(
return handled;
}
+ if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
+ "ConnectionAdded")) {
+ dbus_message_iter_init(message, &iter);
+ vpnconnection_added(&iter);
+ return handled;
+ }
+
+ if (dbus_message_is_signal(message, "net.connman.vpn.Manager",
+ "ConnectionRemoved")) {
+ dbus_message_iter_init(message, &iter);
+ vpnconnection_removed(&iter);
+ return handled;
+ }
+
if (dbus_message_is_signal(message, "net.connman.Manager",
"PeersChanged")) {
dbus_message_iter_init(message, &iter);
@@ -2804,10 +3098,14 @@ void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
if (!dbus_conn) {
g_hash_table_destroy(service_hash);
+ g_hash_table_destroy(vpnconnection_hash);
g_hash_table_destroy(technology_hash);
dbus_bus_remove_match(connection,
"type='signal',interface='net.connman.Manager'", NULL);
+ dbus_bus_remove_match(connection,
+ "type='signal',interface='net.connman.vpn.Manager'",
+ NULL);
dbus_connection_remove_filter(connection,
monitor_completions_changed,
manager_enabled);
@@ -2819,6 +3117,9 @@ void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
service_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
+ vpnconnection_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
+
peer_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
@@ -2831,6 +3132,11 @@ void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
populate_service_hash, NULL, NULL, NULL);
__connmanctl_dbus_method_call(connection,
+ VPN_SERVICE, CONNMAN_PATH,
+ "net.connman.vpn.Manager", "GetConnections",
+ populate_vpnconnection_hash, NULL, NULL, NULL);
+
+ __connmanctl_dbus_method_call(connection,
CONNMAN_SERVICE, CONNMAN_PATH,
"net.connman.Manager", "GetPeers",
populate_peer_hash, NULL, NULL, NULL);
@@ -2848,6 +3154,15 @@ void __connmanctl_monitor_completions(DBusConnection *dbus_conn)
dbus_bus_add_match(connection,
"type='signal',interface='net.connman.Manager'", &err);
+ if (dbus_error_is_set(&err)) {
+ fprintf(stderr, "Error: %s\n", err.message);
+ return;
+ }
+
+ dbus_bus_add_match(connection,
+ "type='signal',interface='net.connman.vpn.Manager'",
+ &err);
+
if (dbus_error_is_set(&err))
fprintf(stderr, "Error: %s\n", err.message);
}
diff --git a/client/dbus_helpers.c b/client/dbus_helpers.c
index d9057463..6ca407d4 100644
--- a/client/dbus_helpers.c
+++ b/client/dbus_helpers.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <errno.h>
+#include <inttypes.h>
#include <glib.h>
#include "input.h"
@@ -38,6 +39,7 @@ void __connmanctl_dbus_print(DBusMessageIter *iter, const char *pre,
dbus_uint16_t u16;
dbus_uint32_t u;
dbus_int32_t i;
+ dbus_uint64_t u64;
double d;
char *str;
@@ -113,6 +115,11 @@ void __connmanctl_dbus_print(DBusMessageIter *iter, const char *pre,
fprintf(stdout, "%d", i);
break;
+ case DBUS_TYPE_UINT64:
+ dbus_message_iter_get_basic(iter, &u64);
+ fprintf(stdout, "%"PRIu64, u64);
+ break;
+
case DBUS_TYPE_DOUBLE:
dbus_message_iter_get_basic(iter, &d);
fprintf(stdout, "%f", d);
@@ -145,6 +152,7 @@ static void dbus_method_reply(DBusPendingCall *call, void *user_data)
__connmanctl_save_rl();
reply = dbus_pending_call_steal_reply(call);
+ dbus_pending_call_unref(call);
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
DBusError err;
diff --git a/client/input.c b/client/input.c
index 97058712..78319ff8 100644
--- a/client/input.c
+++ b/client/input.c
@@ -103,8 +103,9 @@ static void rl_handler(char *input)
}
if (len > 0) {
-
- add_history(input);
+ HIST_ENTRY *previous = history_get(where_history());
+ if(!previous || strcmp(previous->line, input))
+ add_history(input);
err = __connmanctl_commands(connection, trim_args, len);
@@ -114,6 +115,7 @@ static void rl_handler(char *input)
g_strfreev(args);
g_free(trim_args);
+ free(input);
}
static gboolean input_handler(GIOChannel *channel, GIOCondition condition,