summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Houston <stephen@localhost.localdomain>2017-11-29 16:39:53 -0600
committerStephen Houston <stephen@localhost.localdomain>2017-11-29 16:39:53 -0600
commit5736bd5aae339ef5c0f79b441c85abc8a40f459f (patch)
treed7e284f8104866f776d9fce8756ccdec9c27de09
parent113eb906d273dc4b2661efd47af4d21e01560772 (diff)
Track when connections are created and deleted.
-rw-r--r--src/networkmanager.c161
1 files changed, 158 insertions, 3 deletions
diff --git a/src/networkmanager.c b/src/networkmanager.c
index 037a164..55f627a 100644
--- a/src/networkmanager.c
+++ b/src/networkmanager.c
@@ -3,10 +3,16 @@
3#define NETWORKMANAGER_BUS_NAME "org.freedesktop.NetworkManager" 3#define NETWORKMANAGER_BUS_NAME "org.freedesktop.NetworkManager"
4#define NETWORKMANAGER_BUS_PATH "/org/freedesktop/NetworkManager" 4#define NETWORKMANAGER_BUS_PATH "/org/freedesktop/NetworkManager"
5#define NETWORKMANAGER_BUS_INTERFACE NETWORKMANAGER_BUS_NAME 5#define NETWORKMANAGER_BUS_INTERFACE NETWORKMANAGER_BUS_NAME
6
7#define NETWORKMANAGER_CONN_BUS_PATH "/org/freedesktop/NetworkManager/Settings"
8#define NETWORKMANAGER_CONN_BUS_INTERFACE NETWORKMANAGER_BUS_INTERFACE ".Settings"
9
6#define NETWORKMANAGER_AGENT_MANAGER NETWORKMANAGER_BUS_NAME ".AgentManager" 10#define NETWORKMANAGER_AGENT_MANAGER NETWORKMANAGER_BUS_NAME ".AgentManager"
7#define NETWORKMANAGER_AGENT_MANAGER_PATH NETWORKMANAGER_BUS_PATH "/AgentManager" 11#define NETWORKMANAGER_AGENT_MANAGER_PATH NETWORKMANAGER_BUS_PATH "/AgentManager"
12
8#define NETWORKMANAGER_SECRET_AGENT "org.freedesktop.NetworkManager.SecretAgent" 13#define NETWORKMANAGER_SECRET_AGENT "org.freedesktop.NetworkManager.SecretAgent"
9#define NETWORKMANAGER_SECRET_AGENT_PATH "/org/freedesktop/NetworkManager/SecretAgent" 14#define NETWORKMANAGER_SECRET_AGENT_PATH "/org/freedesktop/NetworkManager/SecretAgent"
15
10#define NETWORKMANAGER_AGENT_NAME "org.wireless.networkmanager.agent" 16#define NETWORKMANAGER_AGENT_NAME "org.wireless.networkmanager.agent"
11 17
12#define NETWORKMANAGER_SERVICE_TYPE_ITER(i) \ 18#define NETWORKMANAGER_SERVICE_TYPE_ITER(i) \
@@ -146,9 +152,11 @@ static Eldbus_Pending *pending_getdevices;
146static Eldbus_Pending *pending_getactive; 152static Eldbus_Pending *pending_getactive;
147static Eldbus_Proxy *proxy_manager; 153static Eldbus_Proxy *proxy_manager;
148static Eldbus_Proxy *agent_proxy_manager; 154static Eldbus_Proxy *agent_proxy_manager;
155static Eldbus_Proxy *conn_proxy_manager;
149static Eina_List *pending_technologies; 156static Eina_List *pending_technologies;
150static Eina_List *sig_handlers; 157static Eina_List *sig_handlers;
151static Eldbus_Service_Interface *agent_iface; 158static Eldbus_Service_Interface *agent_iface;
159static int active_connection_type;
152static const char *active_connection; 160static const char *active_connection;
153Eldbus_Connection *dbus_conn; 161Eldbus_Connection *dbus_conn;
154 162
@@ -2182,8 +2190,10 @@ _networkmanager_manager_getactive_conn(void *data EINA_UNUSED, const Eldbus_Mess
2182 if (!ns->path) continue; 2190 if (!ns->path) continue;
2183 if (eina_streq(ns->path, conn_path)) 2191 if (eina_streq(ns->path, conn_path))
2184 { 2192 {
2185 ns->is_active_connection = EINA_TRUE; 2193 active_connection_type = i;
2194 ns->is_active_connection = EINA_TRUE;
2186 _networkmanager_service_state(ns, networkmanager_technology[i].state); 2195 _networkmanager_service_state(ns, networkmanager_technology[i].state);
2196 break;
2187 } 2197 }
2188 } 2198 }
2189 } 2199 }
@@ -2234,6 +2244,7 @@ _networkmanager_manager_getactive(void *data EINA_UNUSED, const Eldbus_Message *
2234 } 2244 }
2235 _networkmanager_update_networks(i); 2245 _networkmanager_update_networks(i);
2236 } 2246 }
2247 active_connection_type = -1;
2237 return; 2248 return;
2238 } 2249 }
2239 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, conn_path); 2250 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, conn_path);
@@ -2354,6 +2365,7 @@ _networkmanager_manager_update_prop(void *data EINA_UNUSED, const void *msg, Eld
2354 } 2365 }
2355 _networkmanager_update_networks(i); 2366 _networkmanager_update_networks(i);
2356 } 2367 }
2368 active_connection_type = -1;
2357 return; 2369 return;
2358 } 2370 }
2359 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, conn_path); 2371 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, conn_path);
@@ -2365,6 +2377,138 @@ _networkmanager_manager_update_prop(void *data EINA_UNUSED, const void *msg, Eld
2365} 2377}
2366 2378
2367static void 2379static void
2380_networkmanager_add_con_addservice(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
2381{
2382 const char *path, *name, *text;
2383 Eldbus_Message_Iter *it, *array;
2384 pending_technologies = eina_list_remove(pending_technologies, pending);
2385 NetworkManager_Technology *nt = data;
2386 NetworkManager_Service *ns;
2387
2388 it = eldbus_message_iter_get(msg);
2389 if (eldbus_message_error_get(msg, &name, &text))
2390 {
2391 ERR("Could not get technology connection %s: %s", name, text);
2392 return;
2393 }
2394 if (!eldbus_message_iter_arguments_get(it, "a{sv}", &array))
2395 {
2396 ERR("Could not get connection settings %p", msg);
2397 return;
2398 }
2399 path = eldbus_pending_path_get(pending);
2400 ns = _networkmanager_service_new(nt->type, nt->state, path, array);
2401 if (ns) ns->device_proxy = nt->proxy;
2402 _networkmanager_update_networks(nt->type);
2403}
2404
2405static void
2406_networkmanager_add_con_getsettings(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending)
2407{
2408 const char *name, *text, *path = data, *main_setting, *setting;
2409 Eldbus_Message_Iter *it, *array, *array2, *array3, *array4, *variant;
2410 pending_technologies = eina_list_remove(pending_technologies, pending);
2411
2412 it = eldbus_message_iter_get(msg);
2413 if (eldbus_message_error_get(msg, &name, &text))
2414 {
2415 ERR("Could not get technology connection %s: %s", name, text);
2416 return;
2417 }
2418 if (!eldbus_message_iter_arguments_get(it, "a{sv}", &array))
2419 {
2420 ERR("Could not get connection settings %p", msg);
2421 return;
2422 }
2423 while (eldbus_message_iter_get_and_next(array, 'e', &array2))
2424 {
2425 if (!eldbus_message_iter_arguments_get(array2, "sa{sv}", &main_setting, &array3))
2426 {
2427 ERR("Could not get technology settings array %p", msg);
2428 return;
2429 }
2430 while (eldbus_message_iter_get_and_next(array3, 'e', &array4))
2431 {
2432 if (!eldbus_message_iter_arguments_get(array4, "sv", &setting, &variant))
2433 {
2434 ERR("Could not get technology settings array %p", msg);
2435 return;
2436 }
2437 if (eina_streq(main_setting, "connection") && eina_streq(setting, "type"))
2438 {
2439 const char *type;
2440 NetworkManager_Technology *nt;
2441
2442 if (!eldbus_message_iter_arguments_get(variant, "s", &type))
2443 {
2444 ERR("Could not parse settings array %p", msg);
2445 continue;
2446 }
2447 if (eina_streq(type, "802-3-ethernet"))
2448 nt = &networkmanager_technology[0];
2449 else if (eina_streq(type, "802-11-wireless"))
2450 nt = &networkmanager_technology[1];
2451 else if (eina_streq(type, "bluetooth"))
2452 nt = &networkmanager_technology[2];
2453 else if (eina_streq(type, "gdm") || eina_streq(type, "cdma"))
2454 nt = &networkmanager_technology[3];
2455 if (nt)
2456 {
2457 Eldbus_Object *obj;
2458 Eldbus_Proxy *proxy;
2459 Eldbus_Pending *pend;
2460 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
2461 proxy = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Settings.Connection");
2462 pend = eldbus_proxy_call(proxy, "GetSettings",
2463 _networkmanager_add_con_addservice, nt, -1, "");
2464 pending_technologies = eina_list_append(pending_technologies, pend);
2465 }
2466 break;
2467 }
2468 }
2469 }
2470 }
2471
2472static void
2473_networkmanager_manager_event_connection_add(void *data EINA_UNUSED, const Eldbus_Message *msg)
2474{
2475 const char *path;
2476 Eldbus_Object *obj;
2477 Eldbus_Proxy *proxy;
2478 Eldbus_Pending *pend;
2479
2480 if (!eldbus_message_arguments_get(msg, "o", &path))
2481 {
2482 ERR("Could not parse connection update %p", msg);
2483 return;
2484 }
2485 obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, path);
2486 proxy = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE ".Settings.Connection");
2487 pend = eldbus_proxy_call(proxy, "GetSettings",
2488 _networkmanager_add_con_getsettings, path, -1, "");
2489 pending_technologies = eina_list_append(pending_technologies, pend);
2490}
2491
2492static void
2493_networkmanager_manager_event_connection_remove(void *data EINA_UNUSED, const Eldbus_Message *msg)
2494{
2495 const char *path;
2496 NetworkManager_Service *ns;
2497 int i;
2498
2499 if (!eldbus_message_arguments_get(msg, "o", &path))
2500 {
2501 ERR("Could not parse property update %p", msg);
2502 return;
2503 }
2504 ns = _networkmanager_service_find_path(path);
2505 EINA_SAFETY_ON_NULL_RETURN(ns);
2506 i = ns->type;
2507 _networkmanager_service_free(ns);
2508 _networkmanager_update_networks(i);
2509}
2510
2511static void
2368_networkmanager_manager_event_property(void *data EINA_UNUSED, const Eldbus_Message *msg) 2512_networkmanager_manager_event_property(void *data EINA_UNUSED, const Eldbus_Message *msg)
2369{ 2513{
2370 Eldbus_Message_Iter *var; 2514 Eldbus_Message_Iter *var;
@@ -2477,9 +2621,11 @@ _networkmanager_manager_agent_register(void *data EINA_UNUSED, const Eldbus_Mess
2477static void 2621static void
2478_networkmanager_start(void) 2622_networkmanager_start(void)
2479{ 2623{
2480 Eldbus_Object *obj, *agent_obj; 2624 Eldbus_Object *obj, *agent_obj, *conn_obj;
2481 int i; 2625 int i;
2482 2626
2627 active_connection_type = -1;
2628
2483 NETWORKMANAGER_SERVICE_TYPE_ITER(i) 2629 NETWORKMANAGER_SERVICE_TYPE_ITER(i)
2484 { 2630 {
2485 networkmanager_technology[i].type = -1; 2631 networkmanager_technology[i].type = -1;
@@ -2491,6 +2637,8 @@ _networkmanager_start(void)
2491 proxy_manager = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE); 2637 proxy_manager = eldbus_proxy_get(obj, NETWORKMANAGER_BUS_INTERFACE);
2492 agent_obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, NETWORKMANAGER_AGENT_MANAGER_PATH); 2638 agent_obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, NETWORKMANAGER_AGENT_MANAGER_PATH);
2493 agent_proxy_manager = eldbus_proxy_get(agent_obj, NETWORKMANAGER_AGENT_MANAGER); 2639 agent_proxy_manager = eldbus_proxy_get(agent_obj, NETWORKMANAGER_AGENT_MANAGER);
2640 conn_obj = eldbus_object_get(dbus_conn, NETWORKMANAGER_BUS_NAME, NETWORKMANAGER_CONN_BUS_PATH);
2641 conn_proxy_manager = eldbus_proxy_get(conn_obj, NETWORKMANAGER_CONN_BUS_INTERFACE);
2494 2642
2495 pending_getproperties_manager = 2643 pending_getproperties_manager =
2496 eldbus_proxy_call(proxy_manager, "state", _networkmanager_manager_getstate, 2644 eldbus_proxy_call(proxy_manager, "state", _networkmanager_manager_getstate,
@@ -2510,7 +2658,12 @@ _networkmanager_start(void)
2510 sig_handlers = eina_list_append(sig_handlers, 2658 sig_handlers = eina_list_append(sig_handlers,
2511 eldbus_proxy_signal_handler_add(proxy_manager, "PropertiesChanged", 2659 eldbus_proxy_signal_handler_add(proxy_manager, "PropertiesChanged",
2512 _networkmanager_manager_event_property, NULL)); 2660 _networkmanager_manager_event_property, NULL));
2513 2661 sig_handlers = eina_list_append(sig_handlers,
2662 eldbus_proxy_signal_handler_add(conn_proxy_manager, "NewConnection",
2663 _networkmanager_manager_event_connection_add, NULL));
2664 sig_handlers = eina_list_append(sig_handlers,
2665 eldbus_proxy_signal_handler_add(conn_proxy_manager, "ConnectionRemoved",
2666 _networkmanager_manager_event_connection_remove, NULL));
2514} 2667}
2515 2668
2516static void 2669static void
@@ -2548,6 +2701,8 @@ _networkmanager_end(void)
2548 pending_getproperties_manager = NULL; 2701 pending_getproperties_manager = NULL;
2549 _eldbus_proxy_del(agent_proxy_manager); 2702 _eldbus_proxy_del(agent_proxy_manager);
2550 agent_proxy_manager = NULL; 2703 agent_proxy_manager = NULL;
2704 _eldbus_proxy_del(conn_proxy_manager);
2705 conn_proxy_manager = NULL;
2551 _eldbus_proxy_del(proxy_manager); 2706 _eldbus_proxy_del(proxy_manager);
2552 proxy_manager = NULL; 2707 proxy_manager = NULL;
2553 eldbus_service_object_unregister(agent_iface); 2708 eldbus_service_object_unregister(agent_iface);