5 * Copyright (C) 2013 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
32 #include "vpnconnections.h"
34 static void print_connection(char *path, DBusMessageIter *iter)
40 DBusMessageIter entry, val;
42 while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
44 dbus_message_iter_recurse(iter, &entry);
45 dbus_message_iter_get_basic(&entry, &property);
46 if (strcmp(property, "Name") == 0) {
47 dbus_message_iter_next(&entry);
48 dbus_message_iter_recurse(&entry, &val);
49 dbus_message_iter_get_basic(&val, &name);
51 } else if (strcmp(property, "State") == 0) {
52 dbus_message_iter_next(&entry);
53 dbus_message_iter_recurse(&entry, &val);
54 dbus_message_iter_get_basic(&val, &str);
57 if (strcmp(str, "ready") == 0)
59 else if (strcmp(str, "configuration") == 0)
61 else if (strcmp(str, "failure") == 0)
66 dbus_message_iter_next(iter);
69 str = strrchr(path, '/');
75 fprintf(stdout, " %c %-20s %s", state, name, str);
78 void __connmanctl_vpnconnections_list(DBusMessageIter *iter)
80 DBusMessageIter array, entry, dict;
83 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
86 dbus_message_iter_recurse(iter, &array);
88 while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
90 dbus_message_iter_recurse(&array, &entry);
91 if (dbus_message_iter_get_arg_type(&entry)
92 != DBUS_TYPE_OBJECT_PATH)
95 dbus_message_iter_get_basic(&entry, &path);
97 dbus_message_iter_next(&entry);
98 if (dbus_message_iter_get_arg_type(&entry)
100 dbus_message_iter_recurse(&entry, &dict);
101 print_connection(path, &dict);
104 if (dbus_message_iter_has_next(&array))
105 fprintf(stdout, "\n");
107 dbus_message_iter_next(&array);
110 fprintf(stdout, "\n");