comparison Core/HttpClient.cpp @ 2023:7fe860db9664

rename
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 18 Jun 2016 10:05:47 +0200
parents fefbe71c2272
children 944b255035a0
comparison
equal deleted inserted replaced
2022:fefbe71c2272 2023:7fe860db9664
296 296
297 return code; 297 return code;
298 } 298 }
299 299
300 300
301 static size_t CurlCallback(void *buffer, size_t size, size_t nmemb, void *payload) 301 static size_t CurlBodyCallback(void *buffer, size_t size, size_t nmemb, void *payload)
302 { 302 {
303 std::string& target = *(static_cast<std::string*>(payload)); 303 std::string& target = *(static_cast<std::string*>(payload));
304 304
305 size_t length = size * nmemb; 305 size_t length = size * nmemb;
306 if (length == 0) 306 if (length == 0)
329 { 329 {
330 curl_slist_free_all(pimpl_->defaultPostHeaders_); 330 curl_slist_free_all(pimpl_->defaultPostHeaders_);
331 throw OrthancException(ErrorCode_NotEnoughMemory); 331 throw OrthancException(ErrorCode_NotEnoughMemory);
332 } 332 }
333 333
334 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlCallback)); 334 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEFUNCTION, &CurlBodyCallback));
335 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0)); 335 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HEADER, 0));
336 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1)); 336 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_FOLLOWLOCATION, 1));
337 337
338 // This fixes the "longjmp causes uninitialized stack frame" crash 338 // This fixes the "longjmp causes uninitialized stack frame" crash
339 // that happens on modern Linux versions. 339 // that happens on modern Linux versions.
434 pimpl_->userHeaders_ = NULL; 434 pimpl_->userHeaders_ = NULL;
435 } 435 }
436 } 436 }
437 437
438 438
439 bool HttpClient::Apply(std::string& answer) 439 bool HttpClient::ApplyInternal(std::string& answer)
440 { 440 {
441 answer.clear(); 441 answer.clear();
442 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str())); 442 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_URL, url_.c_str()));
443 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer)); 443 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_WRITEDATA, &answer));
444 444
633 633
634 return success; 634 return success;
635 } 635 }
636 636
637 637
638 bool HttpClient::Apply(std::string& answer)
639 {
640 return ApplyInternal(answer);
641 }
642
643
638 bool HttpClient::Apply(Json::Value& answer) 644 bool HttpClient::Apply(Json::Value& answer)
639 { 645 {
640 std::string s; 646 std::string s;
641 if (Apply(s)) 647 if (Apply(s))
642 { 648 {