X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fo1%2Fves%2FHttpClient.cpp;h=7aed15f80b090bc5a372802209c63a00cbc159bb;hb=6dc8a4c17da24847b3a3aee91b37151f77a8a5bc;hp=4fc675cb77464540b84ac78ec2956891d9dcaa66;hpb=788e4f7e2d55fbfa67a986d9b21791aaaa4e4f2a;p=o-du%2Fl2.git diff --git a/src/o1/ves/HttpClient.cpp b/src/o1/ves/HttpClient.cpp index 4fc675cb7..7aed15f80 100644 --- a/src/o1/ves/HttpClient.cpp +++ b/src/o1/ves/HttpClient.cpp @@ -24,9 +24,9 @@ #include "HttpClient.hpp" /* Overloaded constructor */ -HttpClient::HttpClient(string ip, string port, string username, \ - string password): mServerIp(ip), mServerPort(port), \ - mServerUsername(username), mServerPassword(password) +HttpClient::HttpClient(string url, string username, string password): + mUrl(url), mServerUsername(username), + mServerPassword(password) { } @@ -89,30 +89,28 @@ bool HttpClient::prepareHttpHeader(struct curl_slist *header, CURL *curl) if(!setUserPassword(curl)) { - O1_LOG("O1 VES : unable to set user:password \n"); + O1_LOG("\nO1 HttpClient : unable to set user:password"); curl_slist_free_all(header); } setCurlOptions(curl); header = curl_slist_append(header, "Content-Type: application/json"); if(!header) { - O1_LOG("O1 VES : curl_slist_append failed\n"); - curl_easy_cleanup(curl); - return false; + O1_LOG("\nO1 HttpClient : curl_slist_append failed"); + curl_easy_cleanup(curl); + return false; } - header = curl_slist_append(header, "Accept: application/json"); - if(!header) { - O1_LOG("O1 VES : curl_slist_append failed\n"); - curl_easy_cleanup(curl); - return false; - } - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); - if(!createUrl(curl)) - { - O1_LOG("O1 VES : could not create URL\n"); - return false; - } + header = curl_slist_append(header, "Accept: application/json"); + if(!header) { + O1_LOG("\nO1 HttpClient : curl_slist_append failed"); + curl_easy_cleanup(curl); + return false; + } + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); + + curl_easy_setopt(curl, CURLOPT_URL, mUrl.c_str()); + return true; } @@ -142,7 +140,7 @@ bool HttpClient::setUserPassword(CURL *curl) if((mServerUsername.c_str()) && (mServerPassword.c_str())) { asprintf(&credentials, "%s:%s", mServerUsername.c_str(), mServerPassword.c_str()); if(credentials == 0) { - O1_LOG("O1 VES : credentials is blank\n"); + O1_LOG("\nO1 HttpClient : Credential is blank"); curl_easy_cleanup(curl); return false; } @@ -155,41 +153,6 @@ bool HttpClient::setUserPassword(CURL *curl) return true; } -/******************************************************************* - * - * @brief creates and set URL into the curl header - * - * @details - * - * Function : createUrl - * - * Functionality: - * - creates URL string and set into the curl - * - * - * @params[in] pointer to curl - * @return true : success - * false : failure - ******************************************************************/ - - -bool HttpClient::createUrl(CURL *curl) -{ - //make the url format -- https://10.0.2.132:8443/eventListener/v7 - - std::ostringstream oss; - if((mServerIp.c_str()) && (mServerPort.c_str())) { - oss <<"https://"<res, mem->size + realsize + 1); if(ptr == NULL) { - O1_LOG("O1 VES : realloc failed"); + O1_LOG("\nO1 HttpClient : realloc failed"); return 0; }