From b682bbfc27a05d807155e2947ce3f216a04c28c8 Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Tue, 16 Mar 2021 19:39:00 +0900 Subject: [PATCH] Revert "Remove codes to launch mdnsd" This reverts commit d64465cb8d80c549dbe50fe4dad643c68f4a98c3. --- gtest/gdbus.h | 1 + gtest/network_state.cpp | 21 +++++ gtest/network_state.h | 1 + gtest/unittest.cpp | 20 ++++ include/util.h | 2 + interfaces/netconfig-iface-network-state.xml | 3 + packaging/net-config.spec | 2 +- resources/etc/dbus-1/system.d/net-config.conf | 2 + src/network-state.c | 2 + src/utils/util.c | 91 +++++++++++++++++++ 10 files changed, 144 insertions(+), 1 deletion(-) diff --git a/gtest/gdbus.h b/gtest/gdbus.h index 39c61e7..6008b70 100755 --- a/gtest/gdbus.h +++ b/gtest/gdbus.h @@ -105,6 +105,7 @@ #define CHECK_GET_PRIVILEGE "CheckGetPrivilege" #define CHECK_PROFILE_PRIVILEGE "CheckProfilePrivilege" #define CHECK_INTERNET_Privilege "CheckInternetPrivilege" +#define LAUNCH_MDNS "LaunchMdns" #define DEVICE_POLICY_SET_WIFI "DevicePolicySetWifi" #define DEVICE_POLICY_GET_WIFI "DevicePolicyGetWifi" #define DEVICE_POLICY_SET_WIFI_PROFILE "DevicePolicySetWifiProfile" diff --git a/gtest/network_state.cpp b/gtest/network_state.cpp index c31ece5..4fad5c8 100755 --- a/gtest/network_state.cpp +++ b/gtest/network_state.cpp @@ -105,6 +105,27 @@ error_e NetworkState::EthernetCableState(int *state) return ERROR_NONE; } +error_e NetworkState::LaunchMdns(const char *name) +{ + GVariant *message = NULL; + error_e error = ERROR_NONE; + + message = InvokeMethod(NETCONFIG_SERVICE, + NETCONFIG_NETWORK_PATH, + NETCONFIG_NETWORK_INTERFACE, + LAUNCH_MDNS, + g_variant_new("(s)", name), + &error); + + if (message == NULL) { + GLOGD("Failed to invoke dbus method"); + return error; + } + + g_variant_unref(message); + + return ERROR_NONE; +} error_e NetworkState::DevicePolicySetWifi(int state) { GVariant *message = NULL; diff --git a/gtest/network_state.h b/gtest/network_state.h index 887fb7f..7e33fb2 100755 --- a/gtest/network_state.h +++ b/gtest/network_state.h @@ -28,6 +28,7 @@ public: error_e RemoveRoute(const char *ip, const char *mask, const char *interface, const char *gateway, int family, gboolean *result); error_e EthernetCableState(int *state); + error_e LaunchMdns(const char *name); error_e DevicePolicySetWifi(int state); error_e DevicePolicyGetWifi(int *state); error_e DevicePolicySetWifiProfile(int state); diff --git a/gtest/unittest.cpp b/gtest/unittest.cpp index 356c9da..679b8a8 100755 --- a/gtest/unittest.cpp +++ b/gtest/unittest.cpp @@ -191,6 +191,26 @@ TEST(NetworkState, RemoveRoute_n) EXPECT_NE(ERROR_NONE, ret); } +TEST(NetworkState, LaunchMdns_p) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *name = "gtest"; + + ret = mgr.LaunchMdns(name); + EXPECT_EQ(ERROR_NONE, ret); +} + +TEST(NetworkState, LaunchMdns_n) +{ + error_e ret = ERROR_NONE; + NetworkState mgr; + const char *name = "gtest"; + + ret = mgr.LaunchMdns(name); + EXPECT_EQ(ERROR_NONE, ret); +} + TEST(NetworkState, DevicePolicySetWifi_p1) { error_e ret = ERROR_NONE; diff --git a/include/util.h b/include/util.h index 73f41c5..436f49c 100755 --- a/include/util.h +++ b/include/util.h @@ -86,6 +86,8 @@ int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gi int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family); gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context); +gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context, + gchar *name); gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * data); int netconfig_send_message_to_net_popup(const char *title, diff --git a/interfaces/netconfig-iface-network-state.xml b/interfaces/netconfig-iface-network-state.xml index 5b8b46a..57f7938 100755 --- a/interfaces/netconfig-iface-network-state.xml +++ b/interfaces/netconfig-iface-network-state.xml @@ -23,6 +23,9 @@ + + + diff --git a/packaging/net-config.spec b/packaging/net-config.spec index a16ef7d..4f8059e 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.2.9 +Version: 1.2.8 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf index c651886..2c8fd42 100755 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -18,6 +18,8 @@ + + diff --git a/src/network-state.c b/src/network-state.c index eed90e3..75dea27 100755 --- a/src/network-state.c +++ b/src/network-state.c @@ -1433,6 +1433,8 @@ void state_object_create_and_init(void) G_CALLBACK(handle_preferred_ipv6_address), NULL); g_signal_connect(netconfigstate, "handle-remove-route", G_CALLBACK(handle_remove_route), NULL); + g_signal_connect(netconfigstate, "handle-launch-mdns", + G_CALLBACK(handle_launch_mdns), NULL); g_signal_connect(netconfigstate, "handle-device-policy-set-wifi", G_CALLBACK(handle_device_policy_set_wifi), NULL); g_signal_connect(netconfigstate, "handle-device-policy-get-wifi", diff --git a/src/utils/util.c b/src/utils/util.c index a6d44a5..bf7c4bc 100755 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -58,6 +58,7 @@ #define CONNMAN_WIFI_DEF_IFNAME "DefaultWifiInterface" static gboolean netconfig_device_picker_test = FALSE; +static int mdnsd_ref_count = 0; typedef struct { char *conn_name; int conn_id; @@ -954,6 +955,96 @@ gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context) return TRUE; } +int execute_mdnsd_script(char* op) +{ + const char *path = "/usr/bin/mdnsresponder-server.sh"; + char *const args[] = { "mdnsresponder-server.sh", op, NULL }; + char *const envs[] = { NULL }; + + return netconfig_execute_file(path, args, envs); +} + +static void __dnssd_conn_destroyed_cb(GDBusConnection *conn, + const gchar *Name, const gchar *path, const gchar *interface, + const gchar *sig, GVariant *param, gpointer user_data) +{ + gchar *name = NULL; + gchar *old = NULL; + gchar *new = NULL; + dnssd_conn_destroy_data *data = user_data; + GDBusConnection *connection = NULL; + connection = netdbus_get_connection(); + + if (param == NULL) + return; + + g_variant_get(param, "(sss)", &name, &old, &new); + + if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') { + DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name, + data->conn_id); + mdnsd_ref_count--; + g_dbus_connection_signal_unsubscribe(connection, data->conn_id); + if (mdnsd_ref_count == 0) { + if (execute_mdnsd_script("stop") < 0) + ERR("Failed to stop mdnsresponder daemon"); + } + } + g_free(name); + g_free(old); + g_free(new); + g_free(data->conn_name); + g_free(data); + return; +} + +static void register_dnssd_conn_destroy_signal(gchar *name) +{ + dnssd_conn_destroy_data *data; + GDBusConnection *connection = NULL; + connection = netdbus_get_connection(); + + if (connection == NULL) { + ERR("Failed to get GDbus Connection"); + return; + } + + data = g_try_malloc0(sizeof(dnssd_conn_destroy_data)); + + if (data == NULL) { + ERR("Out of Memory!"); + return; + } + + data->conn_name = g_strdup(name); + + data->conn_id = g_dbus_connection_signal_subscribe(connection, + DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS, + "NameOwnerChanged", NULL, name, + G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb, + data, NULL); + return; +} + +gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context, + gchar *name) +{ + DBG("Launch mdnsresponder daemon"); + + if (execute_mdnsd_script("start") < 0) { + ERR("Failed to launch mdnsresponder daemon"); + netconfig_error_invalid_parameter(context); + return TRUE; + } + + mdnsd_ref_count++; + register_dnssd_conn_destroy_signal(name); + DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count); + + network_complete_launch_mdns(object, context); + return TRUE; +} + gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid) { if (!netconfig_plugin_headed_enabled) -- 2.34.1