Fixed self discovery problem 30/91130/2
authorkmook <kmook.choi@samsung.com>
Thu, 6 Oct 2016 04:00:04 +0000 (13:00 +0900)
committerkmook <kmook.choi@samsung.com>
Thu, 6 Oct 2016 10:08:36 +0000 (19:08 +0900)
Change-Id: I1e85a52e0e5ccd63cc9b41f2c87a1dea1a753a39
Signed-off-by: kmook <kmook.choi@samsung.com>
msf_tizen_client/include/Service.h
msf_tizen_client/src/Service.cpp

index 41940ac..84c05fa 100755 (executable)
@@ -55,7 +55,6 @@ class Service
        string name = "";
        string type = "";
        string uri = "";
-       static string curl_data;
        typedef std::map<std::string, std::string> map_type;
        static Service local_service;
        void *result_ptr;
@@ -68,7 +67,6 @@ class Service
 public:
        Service();
        Service(string, string, string, string, string);
-       static ServiceInfo serviceval;
        static Result_Base *Resulturi;
        Result_Base *Resultdevice;
 
index fb17fe3..8291b20 100755 (executable)
@@ -31,7 +31,6 @@ string Service::TYPE_PROPERTY       = "md";
 string Service::ENDPOINT_PROPERTY   = "se";
 
 Result_Base *Service::Resulturi = NULL;
-ServiceInfo Service::serviceval;
 
 Service Service::local_service;
 
@@ -39,8 +38,6 @@ bool Service::success_get_id = false;
 string Service::remote_device_id = "";
 std::map<std::string, std::string> Service::dev_id_map;
 
-string Service::curl_data = "";
-
 Service::Service()
 {
        //Resulturi = NULL;
@@ -254,6 +251,7 @@ int Service::curl_service_calling(string uri, long timeout, void *dev_result_ptr
        struct curl_slist *headers = NULL;
        headers = curl_slist_append(headers, "Accept: application/json");
        headers = curl_slist_append(headers, "Content-Type: application/json");
+       char* read_data = NULL;
 
        curl = curl_easy_init();
        if (curl) {
@@ -263,17 +261,20 @@ int Service::curl_service_calling(string uri, long timeout, void *dev_result_ptr
                curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, timeout);
 
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Service::createdata);
+               curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&read_data);
                curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
 
                res = curl_easy_perform(curl);
 
-               if (res != CURLE_OK) {
-                       MSF_DBG("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
-                       createdata_process("", dev_result_ptr);
-               } else {
-                       createdata_process(curl_data, dev_result_ptr);
-                       curl_data.clear();
-               }
+        if ((res != CURLE_OK) || (read_data == NULL)) {
+            MSF_DBG("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+            createdata_process("", dev_result_ptr);
+            if (read_data)
+                free(read_data);
+        } else {
+            createdata_process(string(read_data), dev_result_ptr);
+            free(read_data);
+        }
 
                curl_easy_cleanup(curl);
        }
@@ -283,13 +284,15 @@ int Service::curl_service_calling(string uri, long timeout, void *dev_result_ptr
 
 size_t Service::createdata(char *buf, size_t size, size_t nmemb, void *up)
 {
-       if (buf != NULL) {
-               curl_data.append(buf, size*nmemb);
-       } else {
-               MSF_DBG("createdata() buf is null");
-       }
-
-       return size*nmemb;
+    char** read_data = (char**)up;
+    *read_data = (char*)calloc(size*nmemb + 1, sizeof(char));
+    if ((buf != NULL) && (*read_data != NULL)) {
+        memcpy(*read_data, buf, size*nmemb);
+    } else {
+        MSF_DBG("createdata() buf is null");
+    }
+
+    return size*nmemb;
 }
 
 void Service::createdata_process(string data, void *dev_result_ptr)
@@ -315,10 +318,12 @@ int Service::json_parse_service(const char *in, void *ptr)
                MSF_DBG("json_parsing error");
        }
 
+       ServiceInfo serviceval;
        JsonObject *root = json_node_get_object(json_parser_get_root(parser));
 
        if (json_object_has_member(root, "id")) {
                serviceval.infoId = json_object_get_string_member(root, "id");
+               MSF_DBG("id:%s", serviceval.infoId.c_str());
        }
 
        if (json_object_has_member(root, "version")) {