diff --git a/include/cookie.h b/include/cookie.h index f62a3d8..8663f96 100644 --- a/include/cookie.h +++ b/include/cookie.h @@ -37,12 +37,12 @@ namespace curl { */ class cookie { public: - /* + /** * Default constructor. */ - cookie() {} + cookie() = default; /** - * The constructor allow a fast way to build a cookie. + * The overloaded constructor allow a fast way to build a cookie. */ cookie(const std::string&, const std::string&, const cookie_datetime &, const std::string& = "", const std::string& = "", bool = false); diff --git a/include/cookie_date.h b/include/cookie_date.h index 99991f4..952a0eb 100644 --- a/include/cookie_date.h +++ b/include/cookie_date.h @@ -42,12 +42,12 @@ namespace curl { // Leave this alone :) namespace details { // Map months numbers with months short names (cookies likes it short XD) - static const std::map months_names = { + static const std::map monthsNames = { {JANUARY,"Jan"}, {FEBRUARY,"Feb"}, {MARCH,"Mar"}, {APRIL,"Apr"}, {MAY,"May"}, {JUNE,"Jun"}, {JULY,"Jul"},{AUGUST,"Aug"},{SEPTEMBER,"Sep"},{OCTOBER,"Oct"},{NOVEMBER,"Nov"},{DECEMBER,"Dec"} }; // Map week days numbers with days short names (cookies likes it, still, short XD) - static const std::map weekday_names = { + static const std::map weekdayNames = { {MONDAY,"Mon"}, {TUESDAY,"Tue"}, {WEDNESDAY,"Wed"}, {THURSDAY,"Thu"}, {FRIDAY,"Fri"}, {SATURDAY,"Sat"}, {SUNDAY,"Sun"} }; diff --git a/include/cookie_datetime.h b/include/cookie_datetime.h index 813788d..bd64b3d 100644 --- a/include/cookie_datetime.h +++ b/include/cookie_datetime.h @@ -54,11 +54,11 @@ namespace curl { /** * This method returns the time object. */ - const cookie_time get_time() const NOEXCEPT; + cookie_time get_time() const NOEXCEPT; /** * This method returns the date object. */ - const cookie_date get_date() const NOEXCEPT; + cookie_date get_date() const NOEXCEPT; /** * This method returns the cookie_datetime as a string. */ diff --git a/include/cookie_time.h b/include/cookie_time.h index e5223e1..d39a97c 100644 --- a/include/cookie_time.h +++ b/include/cookie_time.h @@ -61,19 +61,19 @@ namespace curl { /** * This method returns the hours. */ - const unsigned int get_hour() const NOEXCEPT; + unsigned int get_hour() const NOEXCEPT; /** * This method returns the minutes. */ - const unsigned int get_minutes() const NOEXCEPT; + unsigned int get_minutes() const NOEXCEPT; /** * This method returns the seconds. */ - const unsigned int get_seconds() const NOEXCEPT; + unsigned int get_seconds() const NOEXCEPT; /** * This method returns the time formatted as h:m:s */ - std::string get_formatted() NOEXCEPT; + std::string get_formatted() const NOEXCEPT; private: /** * The hours. diff --git a/include/curl_cookie.h b/include/curl_cookie.h index 112f896..ec870e3 100644 --- a/include/curl_cookie.h +++ b/include/curl_cookie.h @@ -52,7 +52,7 @@ namespace curl { * If you pass an empty string or a string containing a non existing file's path, * the cookie engine will be initialized, but without reading initial cookies. */ - void set_file(std::string); + void set_file(const std::string&); /** * This method allow you to specify a string that represents a cookie. Such a cookie * can be either a single line in Netscape / Mozilla format or just regular HTTP-style @@ -67,7 +67,7 @@ namespace curl { /** * This method allow you to get all known cookies for a specific domain. */ - const curlcpp_cookies get() const NOEXCEPT; + curlcpp_cookies get() const NOEXCEPT; /** * This method erases all cookies held in memory. */ diff --git a/include/curl_easy.h b/include/curl_easy.h index 1a4b521..9eb575d 100644 --- a/include/curl_easy.h +++ b/include/curl_easy.h @@ -175,10 +175,14 @@ namespace curl { CURLCPP_DEFINE_OPTION(CURLOPT_ERRORBUFFER, char*); /* Function that will be called to store the output (instead of fwrite). The * parameters will use fwrite() syntax, make sure to follow them. */ - CURLCPP_DEFINE_OPTION(CURLOPT_WRITEFUNCTION, size_t(*)(void *ptr, size_t size, size_t nmemb, void *userdata)); + CURLCPP_DEFINE_OPTION(CURLOPT_WRITEFUNCTION, + size_t(*)(void *ptr, size_t size, size_t nmemb, void *userdata)); + /* Function that will be called to read the input (instead of fread). The * parameters will use fread() syntax, make sure to follow them. */ - CURLCPP_DEFINE_OPTION(CURLOPT_READFUNCTION, size_t(*)(void *buffer, size_t size, size_t nitems, void *instream)); + CURLCPP_DEFINE_OPTION(CURLOPT_READFUNCTION, + size_t(*)(void *buffer, size_t size, size_t nitems, void *instream)); + /* Time-out the read operation after this amount of seconds */ CURLCPP_DEFINE_OPTION(CURLOPT_TIMEOUT, long); /* If the CURLOPT_INFILE is used, this can be used to inform libcurl about @@ -383,7 +387,8 @@ namespace curl { /* Function that will be called to store headers (instead of fwrite). The * parameters will use fwrite() syntax, make sure to follow them. */ - CURLCPP_DEFINE_OPTION(CURLOPT_HEADERFUNCTION, size_t(*)(void *buffer, size_t size, size_t nitems, void *userdata)); + CURLCPP_DEFINE_OPTION(CURLOPT_HEADERFUNCTION, + size_t(*)(void *buffer, size_t size, size_t nitems, void *userdata)); /* Set this to force the HTTP request to get back to GET. Only really usable if POST, PUT or a custom request have been used first. @@ -495,7 +500,8 @@ namespace curl { /* Set the ssl context callback function, currently only for OpenSSL ssl_ctx in second argument. The function must be matching the curl_ssl_ctx_callback proto. */ - CURLCPP_DEFINE_OPTION(CURLOPT_SSL_CTX_FUNCTION, CURLcode(*)(CURL *curl, void *ssl_ctx, void *userptr)); + CURLCPP_DEFINE_OPTION(CURLOPT_SSL_CTX_FUNCTION, + CURLcode(*)(CURL *curl, void *ssl_ctx, void *userptr)); /* Set the userdata for the ssl context callback function's third argument */ diff --git a/include/curl_exception.h b/include/curl_exception.h index dc8832c..11e78f8 100644 --- a/include/curl_exception.h +++ b/include/curl_exception.h @@ -102,7 +102,9 @@ namespace curl { // Implementation of print_traceback inline void curl_exception::print_traceback() const { curl_exception::tracebackLocker.lock(); - std::for_each(curl_exception::traceback.begin(),curl_exception::traceback.end(),[](const curlcpp_traceback_object &value) { + std::for_each(curl_exception::traceback.begin(),curl_exception::traceback.end(), + [](const curlcpp_traceback_object &value) { + std::cout<<"ERROR: "< &, const curl_pair &, const curl_pair &); + void add(const curl_pair &, + const curl_pair &, const curl_pair &); /** * Overloaded add method. It adds another curl_pair object to add more * contents to the form contents list. */ - void add(const curl_pair &, const curl_pair &, const curl_pair &); + void add(const curl_pair &, + const curl_pair &, const curl_pair &); /** * Overloaded add method. It adds another curl_pair object to add more * contents to the form contents list. */ - void add(const curl_pair &, const curl_pair &, const curl_pair &); + void add(const curl_pair &, + const curl_pair &, const curl_pair &); /** * Overloaded add method. It adds another curl_pair object to add more * contents to the form contents list. */ - void add(const curl_pair &, const curl_pair &, const curl_pair &, const curl_pair &); + void add(const curl_pair &,const curl_pair &, + const curl_pair &, const curl_pair &); /** * Overloaded add method. Used primarily to pass data via CURLFORM_BUFFERPTR. * E.g. first option is content name, second is buffer name, * third is buffer data pointer, fourth is buffer length. */ - void add(const curl_pair &, const curl_pair &, const curl_pair &, const curl_pair &); + void add(const curl_pair &, const curl_pair &, + const curl_pair &, const curl_pair &); /** * Overloaded add method. This version is primarily used to upload multiple files. * You can pass a vector of filenames to upload them. diff --git a/include/curl_option.h b/include/curl_option.h index 86bfafb..dfe056c 100644 --- a/include/curl_option.h +++ b/include/curl_option.h @@ -27,6 +27,7 @@ #define __curlcpp__curl_option__ #include +#include #include "curl_pair.h" namespace curl { diff --git a/include/curl_pair.h b/include/curl_pair.h index c75dc69..785b549 100644 --- a/include/curl_pair.h +++ b/include/curl_pair.h @@ -110,7 +110,8 @@ namespace curl { * The two parameters constructor gives users a fast way to * build an object of this type. */ - curl_pair(const T option, const std::string &value) : option(option == CURLOPT_POSTFIELDS ? CURLOPT_COPYPOSTFIELDS : option), value(value) {}; + curl_pair(const T option, const std::string &value) : + option(option == CURLOPT_POSTFIELDS ? CURLOPT_COPYPOSTFIELDS : option), value(value) {}; /** * Simple method that returns the first field of the pair. */ diff --git a/include/curl_receiver.h b/include/curl_receiver.h index 5430182..7fb18bc 100644 --- a/include/curl_receiver.h +++ b/include/curl_receiver.h @@ -45,7 +45,7 @@ namespace curl { /** * In this case the destructor does not have to release any resource. */ - ~curl_receiver() {} + ~curl_receiver() = default; /** * The receive method wraps curl_easy_recv function and receives raw * data from the established connection on an easy handler. diff --git a/include/curl_sender.h b/include/curl_sender.h index 65c1fdb..cb9115f 100644 --- a/include/curl_sender.h +++ b/include/curl_sender.h @@ -39,12 +39,12 @@ namespace curl { * The constructor initializes the easy handler and the number of * sent bytes. */ - curl_sender(curl_easy &easy); + explicit curl_sender(curl_easy &easy); /** * This method wraps the curl_easy_send function that sends raw data * on an established connection on an easy handler. */ - void send(const T, const size_t); + void send(T, size_t); /** * Simple getter method that returns sent's current byte number. */ @@ -83,13 +83,13 @@ namespace curl { * The constructor initializes the easy handler and the number of * sent bytes. */ - curl_sender(curl_easy &easy) : _easy(easy), _sent_bytes(0) {} + explicit curl_sender(curl_easy &easy) : _easy(easy), _sent_bytes(0) {} /** * This method wraps the curl_easy_send function that sends raw data * on an established connection on an easy handler, treating strings * as const char pointers. */ - void send(const std::string buffer) { + void send(const std::string& buffer) { const CURLcode code = curl_easy_send(_easy.get_curl(),buffer.c_str(),buffer.length(),&_sent_bytes); if (code != CURLE_OK) { throw curl_easy_exception(code,__FUNCTION__); diff --git a/include/curl_utility.h b/include/curl_utility.h index ad39690..49a7de9 100644 --- a/include/curl_utility.h +++ b/include/curl_utility.h @@ -43,17 +43,17 @@ namespace curl { * online documentation for more information about the datetime * parameter. */ - static time_t get_date(const std::string); + static time_t get_date(const std::string&); private: /** * Build an object of this type have no sense. So let's hide * the constructor. */ - curl_utility() {}; + curl_utility() = default; }; // Implementation of get_date method. - time_t curl_utility::get_date(const std::string format) { + time_t curl_utility::get_date(const std::string& format) { const time_t value = curl_getdate(format.c_str(),nullptr); if (value == -1) { throw curl_exception("*** Error while parsing the date ***",__FUNCTION__); diff --git a/src/cookie_date.cpp b/src/cookie_date.cpp index 3e7d478..3aa23f8 100644 --- a/src/cookie_date.cpp +++ b/src/cookie_date.cpp @@ -9,14 +9,16 @@ using std::out_of_range; using std::ostringstream; // Implementation of constructor with parameters. -curl::cookie_date::cookie_date(const unsigned int week_day, const unsigned int day, const unsigned int month, const unsigned int year) NOEXCEPT { +curl::cookie_date::cookie_date(const unsigned int week_day, const unsigned int day, + const unsigned int month, const unsigned int year) NOEXCEPT { + this->set_week_day(week_day)->set_day(day)->set_month(month)->set_year(year); } // Implementation of set_week_day method. -curl::cookie_date *curl::cookie_date::set_week_day(const unsigned int week_day) NOEXCEPT { +curl::cookie_date *curl::cookie_date::set_week_day(const unsigned int weekDay) NOEXCEPT { try { - this->week_day = details::weekday_names.at(week_day); + this->week_day = details::weekdayNames.at(weekDay); } catch (const out_of_range &exception) { this->week_day = "Mon"; } @@ -24,15 +26,15 @@ curl::cookie_date *curl::cookie_date::set_week_day(const unsigned int week_day) } // Implementation of set_day method. -curl::cookie_date *curl::cookie_date::set_day(const unsigned int day) NOEXCEPT { - this->day = (day < 1 or day > 31) ? 1 : day; +curl::cookie_date *curl::cookie_date::set_day(const unsigned int cookieDay) NOEXCEPT { + this->day = (cookieDay < 1 or cookieDay > 31) ? 1 : cookieDay; return this; } // Implementation of set_month method. -curl::cookie_date *curl::cookie_date::set_month(const unsigned int month) { +curl::cookie_date *curl::cookie_date::set_month(const unsigned int cookieMonth) { try { - this->month = details::months_names.at(month); + this->month = details::monthsNames.at(cookieMonth); } catch (const out_of_range &exception) { this->month = "Jan"; } @@ -40,8 +42,8 @@ curl::cookie_date *curl::cookie_date::set_month(const unsigned int month) { } // Implementation of set_year method. -curl::cookie_date *curl::cookie_date::set_year(const unsigned int year) NOEXCEPT { - this->year = (year < 1970 ) ? 1970 : year; +curl::cookie_date *curl::cookie_date::set_year(const unsigned int cookieYear) NOEXCEPT { + this->year = (cookieYear < 1970 ) ? 1970 : cookieYear; return this; } diff --git a/src/cookie_datetime.cpp b/src/cookie_datetime.cpp index 604eb2c..f84547c 100644 --- a/src/cookie_datetime.cpp +++ b/src/cookie_datetime.cpp @@ -11,24 +11,24 @@ curl::cookie_datetime::cookie_datetime(const cookie_time &time, const cookie_dat } // Implementation of set_time method. -curl::cookie_datetime *curl::cookie_datetime::set_time(const cookie_time &time) NOEXCEPT { - this->time = time; +curl::cookie_datetime *curl::cookie_datetime::set_time(const cookie_time &cookieTime) NOEXCEPT { + this->time = cookieTime; return this; } // Implementation of set_date method. -curl::cookie_datetime *curl::cookie_datetime::set_date(const cookie_date &date) NOEXCEPT { - this->date = date; +curl::cookie_datetime *curl::cookie_datetime::set_date(const cookie_date &cookieDate) NOEXCEPT { + this->date = cookieDate; return this; } // Implementation of get_time method. -const curl::cookie_time curl::cookie_datetime::get_time() const NOEXCEPT { +curl::cookie_time curl::cookie_datetime::get_time() const NOEXCEPT { return this->time; } // Implementation of get_date method. -const curl::cookie_date curl::cookie_datetime::get_date() const NOEXCEPT { +curl::cookie_date curl::cookie_datetime::get_date() const NOEXCEPT { return this->date; } diff --git a/src/cookie_time.cpp b/src/cookie_time.cpp index eb2096a..b39cdb5 100644 --- a/src/cookie_time.cpp +++ b/src/cookie_time.cpp @@ -33,22 +33,22 @@ curl::cookie_time *curl::cookie_time::set_seconds(unsigned int _seconds) NOEXCEP } // Implementation of get_hour method. -const unsigned int curl::cookie_time::get_hour() const NOEXCEPT { +unsigned int curl::cookie_time::get_hour() const NOEXCEPT { return this->hour; } // Implementation of get_minutes method. -const unsigned int curl::cookie_time::get_minutes() const NOEXCEPT { +unsigned int curl::cookie_time::get_minutes() const NOEXCEPT { return this->minutes; } // Implementation of get_seconds method. -const unsigned int curl::cookie_time::get_seconds() const NOEXCEPT { +unsigned int curl::cookie_time::get_seconds() const NOEXCEPT { return this->seconds; } // Implementation of get_formatted method. -std::string curl::cookie_time::get_formatted() NOEXCEPT { +std::string curl::cookie_time::get_formatted() const NOEXCEPT { ostringstream stream; stream<get_hour()<<":"<get_minutes()<<":"<get_seconds()<<" GMT"; return stream.str(); diff --git a/src/curl_cookie.cpp b/src/curl_cookie.cpp index 15a9635..1fde915 100644 --- a/src/curl_cookie.cpp +++ b/src/curl_cookie.cpp @@ -13,13 +13,13 @@ using std::ostringstream; namespace curl { // Implementation of the get method. - const curlcpp_cookies curl_cookie::get() const NOEXCEPT { + curlcpp_cookies curl_cookie::get() const NOEXCEPT { auto info = this->easy.get_info(); return info.get(); } // Implementation of set_cookie_file method. - void curl_cookie::set_file(const string file = "") { + void curl_cookie::set_file(const string& file = "") { this->easy.add(file.c_str()); } diff --git a/src/curl_easy.cpp b/src/curl_easy.cpp index 19cc381..33362e1 100644 --- a/src/curl_easy.cpp +++ b/src/curl_easy.cpp @@ -82,7 +82,9 @@ void curl_easy::perform() { // Implementation of escape method. void curl_easy::escape(string &url) { - std::unique_ptr url_encoded(curl_easy_escape(this->curl, url.c_str(), (int)url.length()), [](char *ptr) { curl_free(ptr); }); + std::unique_ptr url_encoded(curl_easy_escape(this->curl, url.c_str(), (int)url.length()), + [](char *ptr) { curl_free(ptr); }); + if (!url_encoded) { throw curl_easy_exception("Null pointer intercepted", __FUNCTION__); } @@ -91,7 +93,9 @@ void curl_easy::escape(string &url) { // Implementation of unescape method. void curl_easy::unescape(string &url) { - std::unique_ptr url_decoded(curl_easy_unescape(this->curl,url.c_str(),(int)url.length(),nullptr),[](char *ptr) { curl_free(ptr); }); + std::unique_ptr url_decoded(curl_easy_unescape(this->curl,url.c_str(),(int)url.length(), + nullptr),[](char *ptr) { curl_free(ptr); }); + if (url_decoded == nullptr) { throw curl_easy_exception("Null pointer intercepted",__FUNCTION__); } diff --git a/src/curl_exception.cpp b/src/curl_exception.cpp index 72a62c7..7542c02 100644 --- a/src/curl_exception.cpp +++ b/src/curl_exception.cpp @@ -16,7 +16,10 @@ std::mutex curl::curl_exception::tracebackLocker; // Constructor implementation. Every call will push into the calls stack the function name and the error occurred. curl_exception::curl_exception(const std::string &error, const std::string &fun_name) NOEXCEPT { curl_exception::tracebackLocker.lock(); - curl_exception::traceback.insert(curl_exception::traceback.begin(),curlcpp_traceback_object(error,fun_name)); + + curl_exception::traceback.insert( + curl_exception::traceback.begin(),curlcpp_traceback_object(error,fun_name)); + curl_exception::tracebackLocker.unlock(); } diff --git a/src/curl_form.cpp b/src/curl_form.cpp index 686bd4b..481ff3c 100644 --- a/src/curl_form.cpp +++ b/src/curl_form.cpp @@ -36,7 +36,9 @@ curl_form &curl_form::operator=(const curl_form &form) { struct curl_httppost *old_head = form.form_post; while (old_head != nullptr) { if (this->form_post == nullptr) { - this->is_null(this->last_ptr = this->form_post = (struct curl_httppost *)malloc(sizeof(struct curl_httppost))); + this->is_null(this->last_ptr = this->form_post = + (struct curl_httppost *)malloc(sizeof(struct curl_httppost))); + this->copy_ptr(&this->last_ptr,old_head); } else { this->is_null(this->last_ptr->next = (struct curl_httppost *)malloc(sizeof(struct curl_httppost))); @@ -49,7 +51,9 @@ curl_form &curl_form::operator=(const curl_form &form) { } // Implementation of add method. -void curl_form::add(const curl_pair &form_name, const curl_pair &form_content) { +void curl_form::add(const curl_pair &form_name, + const curl_pair &form_content) { + if (curl_formadd(&this->form_post,&this->last_ptr, form_name.first(),form_name.second(), form_content.first(),form_content.second(), diff --git a/src/curl_header.cpp b/src/curl_header.cpp index 1a2da62..1a4534c 100644 --- a/src/curl_header.cpp +++ b/src/curl_header.cpp @@ -22,7 +22,7 @@ curl_header::curl_header() : size(0), headers(nullptr) { // Implementation of the list constructor's initialize method. curl_header::curl_header(initializer_list headers) : size(0), headers(nullptr) { - for_each(headers.begin(),headers.end(),[this](const string header) { + for_each(headers.begin(),headers.end(),[this](const string& header) { this->add(header); }); } diff --git a/src/curl_multi.cpp b/src/curl_multi.cpp index dc191eb..9dd72e7 100644 --- a/src/curl_multi.cpp +++ b/src/curl_multi.cpp @@ -17,9 +17,7 @@ void curl_multi::multi_deleter::operator()(CURLM* ptr) const { curl_multi::curl_multi() : curl_multi(CURL_GLOBAL_ALL) {} -curl_multi::curl_multi(const long flag) - : curl_interface(flag), - curl(curl_multi_init()) { +curl_multi::curl_multi(const long flag) : curl_interface(flag), curl(curl_multi_init()) { if (this->curl == nullptr) { throw curl_multi_exception("Null pointer intercepted", __FUNCTION__); } @@ -27,8 +25,7 @@ curl_multi::curl_multi(const long flag) this->message_queued = 0; } -curl_multi::curl_multi(curl_multi&& other) NOEXCEPT - : curl_interface(std::forward(other)), +curl_multi::curl_multi(curl_multi&& other) NOEXCEPT : curl_interface(std::forward(other)), curl(std::move(other.curl)), active_transfers(other.active_transfers), message_queued(other.message_queued) { @@ -68,7 +65,7 @@ void curl_multi::remove(const curl_easy &easy) { // Implementation of get_info method. vector> curl_multi::get_info() { vector> infos; - CURLMsg *message = nullptr; + CURLMsg *message; while ((message = curl_multi_info_read(this->curl.get(),&this->message_queued))) { infos.push_back(unique_ptr(new curl_multi::curl_message(message))); } @@ -77,7 +74,7 @@ vector> curl_multi::get_info() { // Implementation of overloaded get_info method. unique_ptr curl_multi::get_info(const curl_easy &easy) { - CURLMsg *message = nullptr; + CURLMsg *message; while ((message = curl_multi_info_read(this->curl.get(),&this->message_queued))) { if (message->easy_handle == easy.get_curl()) { unique_ptr ptr{new curl_multi::curl_message(message)}; @@ -90,8 +87,9 @@ unique_ptr curl_multi::get_info(const curl_easy &easy) // Implementation of get_next_finished method. curl_easy* curl_multi::get_next_finished() { CURLMsg *message = curl_multi_info_read(this->curl.get(),&this->message_queued); - if (!message) - return nullptr; + if (!message) { + return nullptr; + } if (message->msg == CURLMSG_DONE) { std::unordered_map::const_iterator it = handles.find(message->easy_handle); if (it != handles.end()) { @@ -103,7 +101,7 @@ curl_easy* curl_multi::get_next_finished() { // Implementation of is_finished method. bool curl_multi::is_finished(const curl_easy &easy) { - CURLMsg *message = nullptr; + CURLMsg *message; while ((message = curl_multi_info_read(this->curl.get(),&this->message_queued))) { if (message->easy_handle == easy.get_curl() and message->msg == CURLMSG_DONE) { return true; @@ -171,6 +169,7 @@ void curl_multi::timeout(long *timeout) { // Implementation of curl_message constructor. curl_multi::curl_message::curl_message(const CURLMsg *msg) : message(msg->msg), whatever(msg->data.whatever), code(msg->data.result) { + // ... nothing to do here ... } diff --git a/test/cookie.cpp b/test/cookie.cpp index 049b031..f2a69c3 100644 --- a/test/cookie.cpp +++ b/test/cookie.cpp @@ -27,9 +27,9 @@ using curl::cookie_datetime; int main() { // Let's declare a stream - ostringstream str; + ostringstream stream; // We are going to put the request's output in the previously declared stream - curl_ios ios(str); + curl_ios ios(stream); // Easy object to handle the connection, url and verbosity level. curl_easy easy(ios); diff --git a/test/custom_request.cpp b/test/custom_request.cpp index aa6b0d9..e49ba93 100644 --- a/test/custom_request.cpp +++ b/test/custom_request.cpp @@ -7,6 +7,9 @@ using curl::curl_easy; using curl::curl_easy_exception; using curl::curlcpp_traceback; +/** + * This example shows how to perform a custom request. + */ int main() { // Let's create an object which will contain a list of headers. curl_header header; @@ -14,14 +17,14 @@ int main() { curl_easy easy; // Add custom headers. - std::string jsonInfo = "{\"username\":\"abc\",\"password\":\"abc\"}"; + std::string jsonInfo = R"({"username":"abc","password":"abc"})"; header.add(jsonInfo); header.add("Content-type: application/json"); // Add the headers to the easy object. easy.add(header.get()); // Your URL. - easy.add("http://yoururl"); + easy.add("http://example.com"); // Custom request. easy.add("PUT"); // You can choose between 1L and 0L (enable verbose video log or disable) diff --git a/test/easy.cpp b/test/easy.cpp index 2e65f30..9e044f4 100644 --- a/test/easy.cpp +++ b/test/easy.cpp @@ -3,7 +3,7 @@ using curl::curl_easy; using curl::curl_easy_exception; -/* +/** * This example shows how to make a simple request with curl. */ int main() { diff --git a/test/easy_info.cpp b/test/easy_info.cpp index da5c7f3..91b91c7 100644 --- a/test/easy_info.cpp +++ b/test/easy_info.cpp @@ -9,16 +9,16 @@ using curl::curl_easy_exception; using curl::curlcpp_traceback; using curl::curl_ios; -/* +/** * This example shows how to use the easy interface and obtain * informations about the current session. */ int main(int argc, const char **argv) { // Let's declare a stream - ostringstream str; + ostringstream stream; // We are going to put the request's output in the previously declared stream - curl_ios ios(str); + curl_ios ios(stream); // Declaration of an easy object curl_easy easy(ios); diff --git a/test/header.cpp b/test/header.cpp index eaed23d..e17ad7b 100644 --- a/test/header.cpp +++ b/test/header.cpp @@ -7,17 +7,16 @@ using curl::curl_easy; using curl::curl_easy_exception; using curl::curlcpp_traceback; -/* +/** * This example shows how to add custom headers to a simple * curl request. */ int main() { - // Let's create an object which will contain a list of headers. - curl_header header; // Easy object to handle the connection. curl_easy easy; - // Add custom headers. + // Let's create an object which will contain a list of headers. + curl_header header; header.add("Accept:"); header.add("Another:yes"); header.add("Host: example.com"); @@ -25,7 +24,7 @@ int main() { // Add the headers to the easy object. easy.add(header.get()); - easy.add("localhost"); + easy.add("http://example.com"); easy.add(1L); try { // Request execution diff --git a/test/recv_header.cpp b/test/recv_header.cpp index ecc4b28..83200e5 100644 --- a/test/recv_header.cpp +++ b/test/recv_header.cpp @@ -6,7 +6,7 @@ using curl::curl_ios; using curl::curl_easy_exception; using std::ostringstream; -/* +/** * This example shows how to split the received headers and body content * into two different streams */ @@ -23,7 +23,7 @@ int main() { // Easy object to handle the connection. curl_easy easy; - // We will the default write function + // We will use the default write function easy.add(header.get_function()); // Specify the stream for headers content.