Add support for ASP service information 95/86695/2
authorYu Jiung <jiung.yu@samsung.com>
Fri, 2 Sep 2016 10:23:25 +0000 (19:23 +0900)
committerYu Jiung <jiung.yu@samsung.com>
Fri, 2 Sep 2016 10:26:44 +0000 (19:26 +0900)
Change-Id: I02f91f88d1601f664485fc004f9952ef088f803c
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
packaging/wifi-direct-manager.spec
src/wifi-direct-iface.c

index 34e9308..5f05706 100644 (file)
@@ -1,6 +1,6 @@
 Name:          wifi-direct-manager
 Summary:       Wi-Fi Direct manger
-Version:       1.2.200
+Version:       1.2.201
 Release:       1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
index 7a616fe..0112d7c 100644 (file)
@@ -2098,6 +2098,110 @@ failed:
 }
 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
 #if defined(TIZEN_FEATURE_ASP)
+
+static void __g_variant_to_txt_record(GVariant *variant, char **txt_record)
+{
+       GVariantIter *iter = NULL;
+       gchar *key = NULL;
+       GVariant *value = NULL;
+       char *buff = NULL;
+       const char *str = NULL;
+       char *pos = NULL;
+       int txt_length = 0;
+       int key_length = 0;
+       gsize value_length = 0;
+       __WDS_LOG_FUNC_ENTER__;
+
+       DBUS_DEBUG_VARIANT(variant);
+       g_variant_get(variant, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               WDS_LOGD("%s %s", key, g_variant_get_string(value, &value_length));
+               txt_length += strlen(key);
+               str = g_variant_get_string(value, &value_length);
+               txt_length += (int)value_length;
+               txt_length += 2;
+       }
+
+       g_variant_iter_free(iter);
+       if(txt_length == 0) {
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+
+       buff = g_try_malloc0(txt_length);
+       if(buff == NULL) {
+               WDS_LOGE("g_try_malloc0 failed");
+               __WDS_LOG_FUNC_EXIT__;
+               return;
+       }
+       pos = buff;
+       g_variant_get(variant, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+               key_length = strlen(key);
+               str = g_variant_get_string(value, &value_length);
+
+               g_strlcpy(pos, key, key_length + 1);
+               pos+= key_length;
+               pos[0] = '=';
+               pos++;
+
+               g_strlcpy(pos, str, value_length + 1);
+               pos+= (int)value_length;
+               pos[0] = ',';
+               pos++;
+       }
+       buff[txt_length -1] = '\0';
+
+       g_variant_iter_free(iter);
+       *txt_record = buff;
+
+       __WDS_LOG_FUNC_EXIT__;
+       return;
+}
+
+static void __g_variant_to_seek_info(GVariant *variant, char **seek_info)
+{
+       GVariantIter *iter = NULL;
+       gchar *key = NULL;
+       char *buff = NULL;
+       char *pos = NULL;
+       int seek_length = 0;
+       int key_length = 0;
+
+       DBUS_DEBUG_VARIANT(variant);
+       g_variant_get(variant, "as", &iter);
+       while (g_variant_iter_loop(iter, "s", &key)) {
+               seek_length += strlen(key);
+               seek_length += 1;
+       }
+
+       g_variant_iter_free(iter);
+       if(seek_length == 0)
+               return;
+
+       buff = g_try_malloc0(seek_length);
+       if(buff == NULL) {
+               WDS_LOGE("g_try_malloc0 failed");
+               return;
+       }
+       pos = buff;
+       g_variant_get(variant, "as", &iter);
+       while (g_variant_iter_loop(iter, "s", &key)) {
+               key_length = strlen(key);
+
+               g_strlcpy(pos, key, key_length + 1);
+               pos+= key_length;
+               pos[0] = ',';
+               pos++;
+       }
+       buff[seek_length -1] = '\0';
+
+       g_variant_iter_free(iter);
+       *seek_info = buff;
+
+       return;
+}
+
 static void __wfd_manager_asp_iface_handler(const gchar *method_name,
                                               GVariant    *parameters,
                                               GDBusMethodInvocation *invocation)
@@ -2148,7 +2252,7 @@ static void __wfd_manager_asp_iface_handler(const gchar *method_name,
                        else if (!g_strcmp0(key, "service_type"))
                                        g_variant_get(var, "&s", &(service.service_type));
                        else if (!g_strcmp0(key, "service_info"))
-                               g_variant_get(var, "&s", &(service.service_info));
+                               __g_variant_to_txt_record(var, &(service.service_info));
                        else if (!g_strcmp0(key, "rsp_info"))
                                g_variant_get(var, "&s", &(service.rsp_info));
                        else
@@ -2158,10 +2262,12 @@ static void __wfd_manager_asp_iface_handler(const gchar *method_name,
                ret = wfd_oem_advertise_service(manager->oem_ops, &service, replace);
                if (ret < 0) {
                        WDS_LOGE("Failed to add service");
+                       g_free(service.service_info);
                        g_variant_iter_free(iter);
                        ret = WIFI_DIRECT_ERROR_OPERATION_FAILED;
                        goto failed;
                }
+               g_free(service.service_info);
                g_variant_iter_free(iter);
 
                if (manager->local->dev_role == WFD_DEV_ROLE_GO) {
@@ -2231,7 +2337,7 @@ static void __wfd_manager_asp_iface_handler(const gchar *method_name,
                        else if (!g_strcmp0(key, "service_type"))
                                        g_variant_get(var, "&s", &(service.service_type));
                        else if (!g_strcmp0(key, "service_info"))
-                               g_variant_get(var, "&s", &(service.service_info));
+                               __g_variant_to_seek_info(var, &(service.service_info));
                        else
                                ;/* Do Nothing */
                }
@@ -2239,9 +2345,12 @@ static void __wfd_manager_asp_iface_handler(const gchar *method_name,
                ret = wfd_oem_seek_service(manager->oem_ops, &service);
                if (ret < 0) {
                        WDS_LOGE("Failed to seek service");
+                       g_free(service.service_info);
+                       g_variant_iter_free(iter);
                        ret = WIFI_DIRECT_ERROR_OPERATION_FAILED;
                        goto failed;
                }
+               g_free(service.service_info);
                g_variant_iter_free(iter);
 
                WDS_LOGD("search_id [%x]", service.search_id);