diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-06-03 13:04:19 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-06-07 10:08:37 +0300 |
commit | 9a048c1e0c1dda4497a0f767f7bf56622012d6d1 (patch) | |
tree | de8fe03b72b7cb9bb24963d5b1c90061f6f84be8 /client | |
parent | ab7294a9b9f13511cac30251970817a30164ac09 (diff) | |
download | connman-9a048c1e0c1dda4497a0f767f7bf56622012d6d1.tar.gz connman-9a048c1e0c1dda4497a0f767f7bf56622012d6d1.tar.bz2 connman-9a048c1e0c1dda4497a0f767f7bf56622012d6d1.zip |
client: Add VPN monitoring support
When adding VPN monitoring capabilities, also clean up the monitor code.
Diffstat (limited to 'client')
-rw-r--r-- | client/commands.c | 122 |
1 files changed, 84 insertions, 38 deletions
diff --git a/client/commands.c b/client/commands.c index fc56b64d..b0fd1fa3 100644 --- a/client/commands.c +++ b/client/commands.c @@ -1043,13 +1043,20 @@ static DBusHandlerResult monitor_changed(DBusConnection *connection, return DBUS_HANDLER_RESULT_HANDLED; } - if (dbus_message_is_signal(message, "net.connman.Manager", - "TechnologyAdded") == TRUE) - path = "TechnologyAdded"; - if (dbus_message_is_signal(message, "net.connman.Manager", + if (dbus_message_is_signal(message, "net.connman.vpn.Manager", + "ConnectionAdded") == TRUE || + dbus_message_is_signal(message, + "net.connman.vpn.Manager", + "ConnectionRemoved") == TRUE) { + interface = "vpn.Manager"; + path = dbus_message_get_member(message); + + } else if (dbus_message_is_signal(message, "net.connman.Manager", + "TechnologyAdded") == TRUE || + dbus_message_is_signal(message, "net.connman.Manager", "TechnologyRemoved") == TRUE) - path = "TechnologyRemoved"; + path = dbus_message_get_member(message); fprintf(stdout, "%-12s %-20s ", interface, path); dbus_message_iter_init(message, &iter); @@ -1062,34 +1069,45 @@ static DBusHandlerResult monitor_changed(DBusConnection *connection, return DBUS_HANDLER_RESULT_HANDLED; } -static bool monitor_s = false; -static bool monitor_t = false; -static bool monitor_m = false; +static struct { + char *interface; + bool enabled; +} monitor[] = { + { "Service", false }, + { "Technology", false }, + { "Manager", false }, + { "vpn.Manager", false }, + { "vpn.Connection", false }, + { NULL, }, +}; static void monitor_add(char *interface) { + bool add_filter = true, found = false; + int i; char *rule; DBusError err; - if (monitor_s == false && monitor_t == false && monitor_m == false) - dbus_connection_add_filter(connection, monitor_changed, - NULL, NULL); + for (i = 0; monitor[i].interface != NULL; i++) { + if (monitor[i].enabled == true) + add_filter = false; - if (g_strcmp0(interface, "Service") == 0) { - if (monitor_s == true) - return; - monitor_s = true; - } else if (g_strcmp0(interface, "Technology") == 0) { - if (monitor_t == true) - return; - monitor_t = true; - } else if (g_strcmp0(interface, "Manager") == 0) { - if (monitor_m == true) - return; - monitor_m = true; - } else + if (g_strcmp0(interface, monitor[i].interface) == 0) { + if (monitor[i].enabled == true) + return; + + monitor[i].enabled = true; + found = true; + } + } + + if (found == false) return; + if (add_filter == true) + dbus_connection_add_filter(connection, monitor_changed, + NULL, NULL); + dbus_error_init(&err); rule = g_strdup_printf("type='signal',interface='net.connman.%s'", interface); @@ -1102,21 +1120,25 @@ static void monitor_add(char *interface) static void monitor_del(char *interface) { + bool del_filter = true, found = false; + int i; char *rule; - if (g_strcmp0(interface, "Service") == 0) { - if (monitor_s == false) - return; - monitor_s = false; - } else if (g_strcmp0(interface, "Technology") == 0) { - if (monitor_t == false) - return; - monitor_t = false; - } else if (g_strcmp0(interface, "Manager") == 0) { - if (monitor_m == false) - return; - monitor_m = false; - } else + + for (i = 0; monitor[i].interface != NULL; i++) { + if (g_strcmp0(interface, monitor[i].interface) == 0) { + if (monitor[i].enabled == false) + return; + + monitor[i].enabled = false; + found = true; + } + + if (monitor[i].enabled == true) + del_filter = false; + } + + if (found == false) return; rule = g_strdup_printf("type='signal',interface='net.connman.%s'", @@ -1124,7 +1146,7 @@ static void monitor_del(char *interface) dbus_bus_remove_match(connection, rule, NULL); g_free(rule); - if (monitor_s == false && monitor_t == false && monitor_m == false) + if (del_filter == true) dbus_connection_remove_filter(connection, monitor_changed, NULL); } @@ -1154,6 +1176,8 @@ static int cmd_monitor(char *args[], int num, struct connman_option *options) monitor_add("Service"); monitor_add("Technology"); monitor_add("Manager"); + monitor_add("vpn.Manager"); + monitor_add("vpn.Connection"); break; case 's': @@ -1177,18 +1201,36 @@ static int cmd_monitor(char *args[], int num, struct connman_option *options) monitor_del("Manager"); break; + case 'M': + if (add == true) + monitor_add("vpn.Manager"); + else + monitor_del("vpn.Manager"); + break; + + case 'C': + if (add == true) + monitor_add("vpn.Connection"); + else + monitor_del("vpn.Connection"); + break; + default: switch(parse_boolean(args[1])) { case 0: monitor_del("Service"); monitor_del("Technology"); monitor_del("Manager"); + monitor_del("vpn.Manager"); + monitor_del("vpn.Connection"); break; case 1: monitor_add("Service"); monitor_add("Technology"); monitor_add("Manager"); + monitor_add("vpn.Manager"); + monitor_add("vpn.Connection"); break; default: @@ -1326,6 +1368,10 @@ static struct connman_option monitor_options[] = { {"services", 's', "[off] Monitor only services"}, {"tech", 'c', "[off] Monitor only technologies"}, {"manager", 'm', "[off] Monitor only manager interface"}, + {"vpnmanager", 'M', "[off] Monitor only VPN manager " + "interface"}, + {"vpnconnection", 'C', "[off] Monitor only VPN " + "connections" }, { NULL, } }; |