summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-06-03 10:59:56 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-06-07 10:08:31 +0300
commitab7294a9b9f13511cac30251970817a30164ac09 (patch)
tree476ac1c617f316237828f28574784d6866ebbfdf /client
parent667f355af16758243941427e2d837f03da213183 (diff)
downloadconnman-ab7294a9b9f13511cac30251970817a30164ac09.tar.gz
connman-ab7294a9b9f13511cac30251970817a30164ac09.tar.bz2
connman-ab7294a9b9f13511cac30251970817a30164ac09.zip
client: Add support for displaying VPN connections
Show a list of VPN connections known to the VPN daemon. Also allow D-Bus path names to start with numbers, as it is fine with the D-Bus library to define such path names. Fix up help command pretty-printing as the VPN command is slightly longer.
Diffstat (limited to 'client')
-rw-r--r--client/commands.c79
1 files changed, 75 insertions, 4 deletions
diff --git a/client/commands.c b/client/commands.c
index 9490bf66..fc56b64d 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -38,6 +38,7 @@
#include "services.h"
#include "commands.h"
#include "agent.h"
+#include "vpnconnections.h"
static DBusConnection *connection;
@@ -73,8 +74,7 @@ static bool check_dbus_name(const char *name)
*/
unsigned int i;
- if (name == NULL || name[0] == '\0' || (name[0] >= '0' &&
- name[0] <= '9'))
+ if (name == NULL || name[0] == '\0')
return false;
for (i = 0; name[i] != '\0'; i++)
@@ -1229,6 +1229,75 @@ static int cmd_agent(char *args[], int num, struct connman_option *options)
return 0;
}
+static int vpnconnections_properties(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ char *path = user_data;
+ char *str;
+ DBusMessageIter dict;
+
+ if (error == NULL) {
+ fprintf(stdout, "%s\n", path);
+
+ dbus_message_iter_recurse(iter, &dict);
+ __connmanctl_dbus_print(&dict, " ", " = ", "\n");
+
+ fprintf(stdout, "\n");
+
+ } else {
+ str = strrchr(path, '/');
+ if (str != NULL)
+ str++;
+ else
+ str = path;
+
+ fprintf(stderr, "Error %s: %s\n", str, error);
+ }
+
+ g_free(user_data);
+
+ return 0;
+}
+
+static int vpnconnections_list(DBusMessageIter *iter, const char *error,
+ void *user_data)
+{
+ if (error == NULL)
+ __connmanctl_vpnconnections_list(iter);
+ else
+ fprintf(stderr, "Error: %s\n", error);
+
+ return 0;
+}
+
+static int cmd_vpnconnections(char *args[], int num,
+ struct connman_option *options)
+{
+ char *vpnconnection_name, *path;
+
+ if (num > 2)
+ return -E2BIG;
+
+ vpnconnection_name = args[1];
+
+ if (vpnconnection_name == NULL)
+ return __connmanctl_dbus_method_call(connection,
+ VPN_SERVICE, VPN_PATH,
+ "net.connman.vpn.Manager", "GetConnections",
+ vpnconnections_list, NULL,
+ DBUS_TYPE_INVALID);
+
+ if (check_dbus_name(vpnconnection_name) == false)
+ return -EINVAL;
+
+ path = g_strdup_printf("/net/connman/vpn/connection/%s",
+ vpnconnection_name);
+ return __connmanctl_dbus_method_call(connection, VPN_SERVICE, path,
+ "net.connman.vpn.Connection", "GetProperties",
+ vpnconnections_properties, path, DBUS_TYPE_INVALID);
+
+}
+
static int cmd_exit(char *args[], int num, struct connman_option *options)
{
return 1;
@@ -1293,6 +1362,8 @@ static const struct {
"Monitor signals from interfaces" },
{ "agent", "on|off", NULL, cmd_agent,
"Agent mode" },
+ {"vpnconnections", "[<connection>]", NULL, cmd_vpnconnections,
+ "Display VPN connections" },
{ "help", NULL, NULL, cmd_help,
"Show help" },
{ "exit", NULL, NULL, cmd_exit,
@@ -1315,7 +1386,7 @@ static int cmd_help(char *args[], int num, struct connman_option *options)
const char *argument = cmd_table[i].argument;
const char *desc = cmd_table[i].desc;
- printf("%-12s%-22s%s\n", cmd != NULL? cmd: "",
+ printf("%-16s%-22s%s\n", cmd != NULL? cmd: "",
argument != NULL? argument: "",
desc != NULL? desc: "");
@@ -1326,7 +1397,7 @@ static int cmd_help(char *args[], int num, struct connman_option *options)
cmd_table[i].options[j].desc != NULL ?
cmd_table[i].options[j].desc: "";
- printf(" --%-12s%s\n",
+ printf(" --%-16s%s\n",
cmd_table[i].options[j].name,
options_desc);
}