Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix needed while build with curl 7.83 #144

Merged
merged 2 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ else()

find_package(CURL ${CURL_MIN_VERSION} REQUIRED)

target_include_directories(curlcpp PUBLIC ${CURL_INCLUDE_DIRS})
target_link_libraries(curlcpp PUBLIC ${CURL_LIBRARIES})
if(TARGET CURL::libcurl)
target_link_libraries(curlcpp PUBLIC CURL::libcurl)
else()
target_include_directories(curlcpp PUBLIC ${CURL_INCLUDE_DIRS})
target_link_libraries(curlcpp PUBLIC ${CURL_LIBRARIES})
endif()
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down
93 changes: 50 additions & 43 deletions src/curl_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,63 @@
#include "curl_exception.h"
#include <algorithm>

using std::string;
using std::initializer_list;
using std::for_each;
using std::initializer_list;
using std::string;

using curl::curl_header;
using curl::curl_exception;


// Implementation of constructor.
curl_header::curl_header() : size(0), headers(nullptr) {
// ... nothing to do here ...
}
namespace curl
{
// Implementation of constructor.
curl_header::curl_header() : size(0), headers(nullptr)
{
// ... nothing to do here ...
}

// Implementation of the list constructor's initialize method.
curl_header::curl_header(initializer_list<string> headers) : size(0), headers(nullptr) {
for_each(headers.begin(),headers.end(),[this](const string& header) {
this->add(header);
});
}
// Implementation of the list constructor's initialize method.
curl_header::curl_header(initializer_list<string> headers) : size(0), headers(nullptr)
{
for_each(headers.begin(), headers.end(), [this](const string &header)
{ this->add(header); });
}

/**
* Implementation of assignment operator. The object has just been created, so its members have just
* been loaded in memory, so we need to give a valid value to them (in this case just to "headers").
*/
curl_header &curl_header::operator=(const curl_header &header) {
if (this == &header) {
/**
* Implementation of assignment operator. The object has just been created, so its members have just
* been loaded in memory, so we need to give a valid value to them (in this case just to "headers").
*/
curl_header &curl_header::operator=(const curl_header &header)
{
if (this == &header)
{
return *this;
}
curl_slist_free_all(this->headers);
struct curl_slist *tmp_ptr = header.headers;
while (tmp_ptr != nullptr)
{
this->add(tmp_ptr->data);
tmp_ptr = tmp_ptr->next;
}
return *this;
}
curl_slist_free_all(this->headers);
struct curl_slist *tmp_ptr = header.headers;
while (tmp_ptr != nullptr) {
this->add(tmp_ptr->data);
tmp_ptr = tmp_ptr->next;
}
return *this;
}

// Implementation of destructor.
curl_header::~curl_header() NOEXCEPT {
if (this->headers != nullptr) {
curl_slist_free_all(this->headers);
this->headers = nullptr;
// Implementation of destructor.
curl_header::~curl_header() NOEXCEPT
{
if (this->headers != nullptr)
{
curl_slist_free_all(this->headers);
this->headers = nullptr;
}
}
}

// Implementation of add overloaded method.
void curl_header::add(const string& header) {
this->headers = curl_slist_append(this->headers,header.c_str());
if (this->headers == nullptr) {
throw curl_exception("Null pointer exception",__FUNCTION__);
// Implementation of add overloaded method.
void curl_header::add(const string &header)
{
this->headers = curl_slist_append(this->headers, header.c_str());
if (this->headers == nullptr)
{
throw curl_exception("Null pointer exception", __FUNCTION__);
}
++this->size;
}
++this->size;
}
}
1 change: 0 additions & 1 deletion test/cookie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using std::ostringstream;

using curl::cookie;
using curl::curl_header;
using curl::curl_easy;
using curl::curl_easy_exception;
using curl::curl_cookie;
Expand Down
3 changes: 1 addition & 2 deletions test/custom_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "curl_form.h"
#include "curl_header.h"

using curl::curl_header;
using curl::curl_easy;
using curl::curl_easy_exception;
using curl::curlcpp_traceback;
Expand All @@ -12,7 +11,7 @@ using curl::curlcpp_traceback;
*/
int main() {
// Let's create an object which will contain a list of headers.
curl_header header;
curl::curl_header header;
// Easy object to handle the connection.
curl_easy easy;

Expand Down
3 changes: 1 addition & 2 deletions test/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "curl_form.h"
#include "curl_header.h"

using curl::curl_header;
using curl::curl_easy;
using curl::curl_easy_exception;
using curl::curlcpp_traceback;
Expand All @@ -16,7 +15,7 @@ int main() {
curl_easy easy;

// Let's create an object which will contain a list of headers.
curl_header header;
curl::curl_header header;
header.add("Accept:");
header.add("Another:yes");
header.add("Host: example.com");
Expand Down