[connman] Added Tizen Wi-Fi Mesh
[platform/upstream/connman.git] / client / vpnconnections.c
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2013  Intel Corporation. All rights reserved.
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <string.h>
29
30 #include <glib.h>
31
32 #include "vpnconnections.h"
33
34 static void print_connection(char *path, DBusMessageIter *iter)
35 {
36         char *name = "";
37         char state = ' ';
38         char *str;
39         char *property;
40         DBusMessageIter entry, val;
41
42         while (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_INVALID) {
43
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);
50
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);
55
56                         if (str) {
57                                 if (strcmp(str, "ready") == 0)
58                                         state = 'R';
59                                 else if (strcmp(str, "configuration") == 0)
60                                         state = 'C';
61                                 else if (strcmp(str, "failure") == 0)
62                                         state = 'F';
63                         }
64                 }
65
66                 dbus_message_iter_next(iter);
67         }
68
69         str = strrchr(path, '/');
70         if (str)
71                 str++;
72         else
73                 str = path;
74
75         fprintf(stdout, "  %c %-20s %s", state, name, str);
76 }
77
78 void __connmanctl_vpnconnections_list(DBusMessageIter *iter)
79 {
80         DBusMessageIter array, entry, dict;
81         char *path = NULL;
82
83         if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
84                 return;
85
86         dbus_message_iter_recurse(iter, &array);
87
88         while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) {
89
90                 dbus_message_iter_recurse(&array, &entry);
91                 if (dbus_message_iter_get_arg_type(&entry)
92                                 != DBUS_TYPE_OBJECT_PATH)
93                         return;
94
95                 dbus_message_iter_get_basic(&entry, &path);
96
97                 dbus_message_iter_next(&entry);
98                 if (dbus_message_iter_get_arg_type(&entry)
99                                 == DBUS_TYPE_ARRAY) {
100                         dbus_message_iter_recurse(&entry, &dict);
101                         print_connection(path, &dict);
102                 }
103
104                 if (dbus_message_iter_has_next(&array))
105                         fprintf(stdout, "\n");
106
107                 dbus_message_iter_next(&array);
108         }
109
110         fprintf(stdout, "\n");
111 }