From 5c6c5cab350fdbec20b053c188acfabffb4d5222 Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Thu, 7 Apr 2016 13:42:10 +0900 Subject: [PATCH] ADD method for launching mdnsresponder Change-Id: I19445e439bb028661af53be17c5ab137c2db4a2d Signed-off-by: cheoleun --- include/util.h | 3 + interfaces/netconfig-iface-network-state.xml | 3 + packaging/net-config.spec | 2 +- resources/etc/dbus-1/system.d/net-config.conf | 3 + src/network-state.c | 6 ++ src/utils/util.c | 64 +++++++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) mode change 100755 => 100644 include/util.h mode change 100755 => 100644 interfaces/netconfig-iface-network-state.xml mode change 100755 => 100644 resources/etc/dbus-1/system.d/net-config.conf mode change 100755 => 100644 src/network-state.c mode change 100755 => 100644 src/utils/util.c diff --git a/include/util.h b/include/util.h old mode 100755 new mode 100644 index 188aae8..e43ec96 --- a/include/util.h +++ b/include/util.h @@ -72,6 +72,9 @@ 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); +gboolean handle_ref_mdns(Network *object, GDBusMethodInvocation *context); +gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context); 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 old mode 100755 new mode 100644 index e070a59..31860f8 --- a/interfaces/netconfig-iface-network-state.xml +++ b/interfaces/netconfig-iface-network-state.xml @@ -22,5 +22,8 @@ + + + \ No newline at end of file diff --git a/packaging/net-config.spec b/packaging/net-config.spec index a9298fc..7c45efd 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.1.64 +Version: 1.1.65 Release: 2 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 old mode 100755 new mode 100644 index f7e997f..ad238e8 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -11,6 +11,9 @@ + + + diff --git a/src/network-state.c b/src/network-state.c old mode 100755 new mode 100644 index 5180cd2..cfba8d9 --- a/src/network-state.c +++ b/src/network-state.c @@ -1054,6 +1054,12 @@ void state_object_create_and_init(void) G_CALLBACK(handle_ethernet_cable_state), 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-ref-mdns", + G_CALLBACK(handle_ref_mdns), NULL); + g_signal_connect(netconfigstate, "handle-unref-mdns", + G_CALLBACK(handle_unref_mdns), NULL); if (!g_dbus_interface_skeleton_export(interface_network, connection, NETCONFIG_NETWORK_STATE_PATH, NULL)) { diff --git a/src/utils/util.c b/src/utils/util.c old mode 100755 new mode 100644 index 612e7d1..e339c29 --- a/src/utils/util.c +++ b/src/utils/util.c @@ -50,6 +50,7 @@ #define MAC_ADDRESS_MAX_LEN 18 static gboolean netconfig_device_picker_test = FALSE; +static int mdnsd_ref_count = 0; GKeyFile *netconfig_keyfile_load(const char *pathname) { @@ -764,6 +765,7 @@ gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context) netconfig_error_wifi_direct_failed(context); return FALSE; } + wifi_complete_launch_direct(wifi, context); return TRUE; #else @@ -772,6 +774,68 @@ gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context) #endif } +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); +} + +gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context) +{ + DBG("Launch mdnsresponder daemon"); + + if (mdnsd_ref_count != 0) { + ERR("Invalid access"); + netconfig_error_invalid_parameter(context); + return FALSE; + } + + if (execute_mdnsd_script("start") < 0) { + ERR("Failed to launch mdnsresponder daemon"); + netconfig_error_invalid_parameter(context); + return FALSE; + } + + network_complete_launch_mdns(object, context); + return TRUE; +} + +gboolean handle_ref_mdns(Network *object, GDBusMethodInvocation *context) +{ + mdnsd_ref_count++; + + DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count); + network_complete_ref_mdns(object, context); + return TRUE; +} + +gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context) +{ + DBG("Unef mdnsresponder daemon"); + + if (mdnsd_ref_count <= 0) { + ERR("Invalid access"); + netconfig_error_invalid_parameter(context); + return FALSE; + } + + mdnsd_ref_count--; + + DBG("Unref mdnsresponder daemon. ref count: %d", mdnsd_ref_count); + if (mdnsd_ref_count == 0) { + if (execute_mdnsd_script("stop") < 0) { + ERR("Failed to stop mdnsresponder daemon"); + netconfig_error_invalid_parameter(context); + return FALSE; + } + } + + network_complete_unref_mdns(object, context); + return TRUE; +} + gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid) { int ret = 0; -- 2.34.1