From: kmook Date: Thu, 6 Oct 2016 04:00:04 +0000 (+0900) Subject: Fixed self discovery problem X-Git-Tag: accepted/tizen/3.0/common/20161114.105717~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54db36b5c5e8534cf07b45e9346c5e98fc6a6c6c;p=platform%2Fcore%2Fconvergence%2Fd2d-conv-manager.git Fixed self discovery problem Change-Id: I1e85a52e0e5ccd63cc9b41f2c87a1dea1a753a39 Signed-off-by: kmook --- diff --git a/msf_tizen_client/include/Service.h b/msf_tizen_client/include/Service.h index 41940ac..84c05fa 100755 --- a/msf_tizen_client/include/Service.h +++ b/msf_tizen_client/include/Service.h @@ -55,7 +55,6 @@ class Service string name = ""; string type = ""; string uri = ""; - static string curl_data; typedef std::map 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; diff --git a/msf_tizen_client/src/Service.cpp b/msf_tizen_client/src/Service.cpp index fb17fe3..8291b20 100755 --- a/msf_tizen_client/src/Service.cpp +++ b/msf_tizen_client/src/Service.cpp @@ -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 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")) {