Initial commit of Admission Control xAPP and E2AP/X2AP definitions
[ric-app/admin.git] / src / curl / curl_interface.cc
1 #include "curl_interface.hpp"
2 curl_interface::curl_interface(std::string curl_collector_url):_curl_url(curl_collector_url){};
3                                                             
4
5 bool curl_interface::post_metrics(std::string & data){
6
7   CURL *curl = curl_easy_init();
8   CURLcode result;
9   bool res = false;
10  
11   if(curl) {
12     struct curl_slist *headers = NULL;
13     headers = curl_slist_append(headers, "Content-Type:application/json");
14     
15     /* point to ves collector */
16     curl_easy_setopt(curl, CURLOPT_URL, _curl_url.c_str());
17
18     /* Set header */
19     curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
20     
21     /* size of the POST data */
22     curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
23     
24     /* pass in a pointer to the data - libcurl will not copy */
25     curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
26  
27     result = curl_easy_perform(curl);
28     if (result != CURLE_OK){
29       _error.assign(curl_easy_strerror(result));
30     }
31     else{
32         res = true;
33     }
34
35     curl_easy_cleanup(curl);
36     curl_free(headers);
37   }
38   else{
39     _error.assign("Could not instantiate curl handle !");
40   }
41
42   return res;
43 }
44
45
46 std::string curl_interface::getError(void) const{
47   return _error;
48 }