21 #include <curl/curl.h>
23 #include "netSrvCurl.h"
26 CurlObject::CurlObject(std::string url,
char *data)
31 char errbuf[CURL_ERROR_SIZE];
34 curl_handle = curl_easy_init();
37 LOG_ERR(
"curl failed in init");
40 LOG_DBG(
"curl url is %s", url.c_str());
41 res=curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
43 LOG_ERR(
"curl failed with curl error %d",res);
46 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
47 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, strlen(data));
50 curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errbuf);
52 res=curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, &CurlObject::curlwritefunc);
54 LOG_ERR(
"curl failed with curl error %d ", res);
55 res=curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &curlDataBuffer);
57 LOG_ERR(
"curl failed with curl error %d", res);
58 res=curl_easy_perform(curl_handle);
61 LOG_ERR(
"curl failed with curl error %d ",res);
63 size_t len = strlen(errbuf);
64 fprintf(stderr,
"\nlibcurl: (%d) ", res);
66 fprintf(stderr,
"%s%s", errbuf,
67 ((errbuf[len - 1] !=
'\n') ?
"\n" :
""));
69 fprintf(stderr,
"%s\n", curl_easy_strerror(res));
72 curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
74 LOG_ERR(
"curl failed with http error %ld",http_code);
76 m_httpcode = http_code;
77 curl_easy_cleanup(curl_handle);
81 int CurlObject::curlwritefunc(
char *data,
size_t size,
size_t nmemb, std::string *buffer) {
84 buffer->append(data, size * nmemb);
85 result = size * nmemb;
89 LOG_ERR(
"curl buffer NULL");
95 gchar* CurlObject::getCurlData() {
96 LOG_DBG(
"Authservice url output %s ",curlDataBuffer.c_str());
97 return g_strdup(curlDataBuffer.c_str());
100 long CurlObject::gethttpcode()
105 CurlObject::~CurlObject()