Skip to content

Commit

Permalink
General fixing, checked nullpointer reported in #122
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephP91 committed Jun 30, 2019
1 parent c89b28d commit 0c2f06d
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 164 deletions.
20 changes: 11 additions & 9 deletions include/cookie.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ namespace curl {
/**
* The 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 = "", const bool = false);
cookie(const std::string&, const std::string&, const cookie_datetime &,
const std::string& = "", const std::string& = "", bool = false);
/**
* This constructor overloades the previous one.
*/
cookie(const char *, const char *, const cookie_datetime &, const char * = "", const char * = "", const bool = false);
cookie(const char *, const char *, const cookie_datetime &, const char * = "",
const char * = "", bool = false);
/**
* This method allows to specify the cookie name.
*/
cookie *set_name(const std::string);
cookie *set_name(const std::string&);
/**
* This method overloads the previous one allowing to specify a const char *
* instead of a string.
Expand All @@ -61,15 +63,15 @@ namespace curl {
/**
* This method allows to specify the cookie value.
*/
cookie *set_value(const std::string);
cookie *set_value(const std::string&);
/**
* This method allows to specify the cookie value,
*/
cookie *set_value(const char *);
/**
* This method allows to specify the cookie path.
*/
cookie *set_path(const std::string) NOEXCEPT;
cookie *set_path(const std::string&) NOEXCEPT;
/**
* This method overloads the previous one allowing to specify a const char *
* instead of a string.
Expand All @@ -78,7 +80,7 @@ namespace curl {
/**
* This method allows to specify the cookie domain.
*/
cookie *set_domain(const std::string) NOEXCEPT;
cookie *set_domain(const std::string&) NOEXCEPT;
/**
* This method overloads the previous one allowing to specify a const char *
* instead of a string.
Expand All @@ -87,17 +89,17 @@ namespace curl {
/**
* This method allows to specify the cookie security.
*/
cookie *set_secure(const bool) NOEXCEPT;
cookie *set_secure(bool) NOEXCEPT;
/**
* This method overloads the previous one allowing to specify an integer instead
* of a bool.
*/
cookie *set_secure(const unsigned int);
cookie *set_secure(unsigned int);
/**
* This method overloads the previous one allowing to specify a string to indicate
* whether the cookie is secure (with "secure" keyword) or not (empty string).
*/
cookie *set_secure(const std::string) NOEXCEPT;
cookie *set_secure(const std::string&) NOEXCEPT;
/**
* This method overloads the previous one allowing to specify a string to indicate
* whether the cookie is secure (with "secure" keyword) or not (empty string).
Expand Down
10 changes: 5 additions & 5 deletions include/cookie_date.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,27 @@ namespace curl {
/**
* Constructor with parameters, which gives a fast way to build a cookie_date object.
*/
cookie_date(const unsigned int, const unsigned int, const unsigned int, const unsigned int) NOEXCEPT;
cookie_date(unsigned int, unsigned int, unsigned int, unsigned int) NOEXCEPT;
/**
* This method allows to specify the week dayname for the date. If the day is less or equal
* than zero or greater than 7, 1 will be choosen
*/
cookie_date *set_week_day(const unsigned int) NOEXCEPT;
cookie_date *set_week_day(unsigned int) NOEXCEPT;
/**
* This method allows to specify a day for the date. If the day is less than zero or
* greater than 31, 1 will be choosen.
*/
cookie_date *set_day(const unsigned int) NOEXCEPT;
cookie_date *set_day(unsigned int) NOEXCEPT;
/**
* This method allows to specify a month for the date. If the month is not supported,
* January will be choosen.
*/
cookie_date *set_month(const unsigned int);
cookie_date *set_month(unsigned int);
/**
* This method allows to specify a year for the date. If year is less than 1970, 1970 will
* be choosen.
*/
cookie_date *set_year(const unsigned int) NOEXCEPT;
cookie_date *set_year(unsigned int) NOEXCEPT;
/**
* This method returns the week day name
*/
Expand Down
2 changes: 1 addition & 1 deletion include/cookie_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace curl {
/**
* Default constructor.
*/
cookie_datetime() {}
cookie_datetime() = default;
/**
* The constructor with parameters allows to specify a time and a date for cookie expiration.
*/
Expand Down
8 changes: 4 additions & 4 deletions include/cookie_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ namespace curl {
/**
* The constructor with parameters allows to initialize attributes with custom values.
*/
cookie_time(const unsigned int, const unsigned int, const unsigned int);
cookie_time(unsigned int, unsigned int, unsigned int);
/**
* This method allows to specify the hours.
*/
cookie_time *set_hour(const unsigned int) NOEXCEPT;
cookie_time *set_hour(unsigned int) NOEXCEPT;
/**
* This method allows to specify the minutes.
*/
cookie_time *set_minutes(const unsigned int) NOEXCEPT;
cookie_time *set_minutes(unsigned int) NOEXCEPT;
/**
* This method allows to specify the seconds.
*/
cookie_time *set_seconds(const unsigned int) NOEXCEPT;
cookie_time *set_seconds(unsigned int) NOEXCEPT;
/**
* This method returns the hours.
*/
Expand Down
12 changes: 2 additions & 10 deletions include/curl_cookie.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ namespace curl {
/**
* This constructor allow you to specify a curl_easy object.
*/
curl_cookie(curl_easy &easy) : easy(easy) {}
explicit curl_cookie(curl_easy &easy) : easy(easy) {}
/**
* This method allow you to set the cookie file from where to read initial cookies.
* 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(const std::string);
void set_file(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
Expand All @@ -64,14 +64,6 @@ namespace curl {
* This method overloads the one previously declared allowing to specify a vector of cookies.
*/
void set(const std::vector<curl::cookie> &);
/**
* This method allow you to specify a file where libcurl will write every internal
* known-stored cookie when the curl_easy destructor will be called. If no cookies
* are known, no file will be created. Using this option also enables cookies for
* this session, so if you for example follow a location it will make matching cookies
* get sent accordingly.
*/
void set_jar_file(const std::string) NOEXCEPT;
/**
* This method allow you to get all known cookies for a specific domain.
*/
Expand Down
12 changes: 6 additions & 6 deletions include/curl_easy.h
Original file line number Diff line number Diff line change
Expand Up @@ -978,12 +978,12 @@ namespace curl {
* This overloaded constructor allows users to specify a flag
* used to initialize libcurl environment.
*/
explicit curl_easy(const long);
explicit curl_easy(long);
/**
* This overloaded constructor specifies the environment
* initialization flags and an output stream for the libcurl output.
*/
template<class T> curl_easy(const long, curl_ios<T> &);
template<class T> curl_easy(long, curl_ios<T> &);
/**
* Copy constructor to handle pointer copy. Internally, it uses
* a function which duplicates the easy handler.
Expand All @@ -993,7 +993,7 @@ namespace curl {
* Move constructor that moves an easy handler from an istance to
* another.
*/
curl_easy(curl_easy &&);
curl_easy(curl_easy &&) NOEXCEPT;
/**
* Assignment operator used to perform assignment between objects
* of this class.
Expand All @@ -1007,7 +1007,7 @@ namespace curl {
/**
* The destructor will perform cleanup operations.
*/
~curl_easy() NOEXCEPT;
~curl_easy() NOEXCEPT override;
/**
* Allows users to specify an option for the current easy handler,
* using a curl_pair object.
Expand All @@ -1018,7 +1018,7 @@ namespace curl {
* easy handler. In this way, you can specify any iterable data
* structure.
*/
template<typename Iterator> void add(Iterator, const Iterator);
template<typename Iterator> void add(Iterator, Iterator);
/**
* Allows users to specify an option for the current easy handler,
* specify an option statically and enforce its corresponding type.
Expand All @@ -1028,7 +1028,7 @@ namespace curl {
* Using this function, you can explicitly pause a running connection,
* and you can resume a previously paused connection.
*/
void pause(const int);
void pause(int);
/**
* This function converts the given input string to an URL encoded
* string and returns a newly allocated string.
Expand Down
9 changes: 6 additions & 3 deletions include/curl_easy_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace curl {
*/
template<typename T> class curl_easy_info {
public:
curl_easy_info(T pointer) : _pointer(pointer) {}
explicit curl_easy_info(T pointer) : _pointer(pointer) {}

T get() const {
return _pointer;
}
Expand All @@ -49,7 +50,8 @@ namespace curl {
*/
template<> class curl_easy_info<char *> {
public:
curl_easy_info(char *pointer) : _pointer(pointer) {}
explicit curl_easy_info(char *pointer) : _pointer(pointer) {}

std::string get() const {
if (_pointer == nullptr) {
return std::string("");
Expand All @@ -65,7 +67,8 @@ namespace curl {
*/
template<> class curl_easy_info<struct curl_slist *> {
public:
curl_easy_info(struct curl_slist *pointer) : _pointer(pointer) {}
explicit curl_easy_info(struct curl_slist *pointer) : _pointer(pointer) {}

~curl_easy_info() {
if (_pointer != nullptr) {
curl_slist_free_all(_pointer);
Expand Down
8 changes: 4 additions & 4 deletions include/curl_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ namespace curl {
/**
* This constructor is used to build the error.
*/
curl_exception(const std::string&, const std::string&);
curl_exception(const std::string&, const std::string&) NOEXCEPT;
/**
* The copy constructor allows to copy the object in a thread safe way.
*/
curl_exception(const curl_exception &);
curl_exception(const curl_exception &) NOEXCEPT;
/**
* The assignment operator allows to assign the object to another object in
* a thread safe way.
*/
curl_exception & operator=(curl_exception &);
curl_exception & operator=(curl_exception const&);
/**
* The destructor, in this case, doesn't do anything.
*/
~curl_exception() NOEXCEPT;
~curl_exception() NOEXCEPT override;
using std::exception::what;
/**
* Returns the vector of errors.
Expand Down
2 changes: 1 addition & 1 deletion include/curl_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace curl {
* Overloaded constructor that initializes curl environment
* with user specified flag.
*/
explicit curl_global(const long);
explicit curl_global(long);

/**
* Copying disabled to follow RAII idiom.
Expand Down
6 changes: 3 additions & 3 deletions include/curl_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ namespace curl {
/**
* This method allows users to add a header as string.
*/
void add(const std::string);
void add(const std::string&);
/**
* This method allows users to add headers specifying an iterable
* data structure containing the headers to add.
*/
template<typename Iterator> void add(Iterator, const Iterator);
template<typename Iterator> void add(Iterator, Iterator);
/**
* Simple getter method that returns the pointer to the headers
* list.
Expand All @@ -89,7 +89,7 @@ namespace curl {
}

// Implementation of copy constructor.
inline curl_header::curl_header(const curl_header &header) : headers(nullptr) {
inline curl_header::curl_header(const curl_header &header) : headers(nullptr), size(0) {
*this = header;
}

Expand Down
7 changes: 5 additions & 2 deletions include/curl_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace curl {
* Overloaded constructor that allows users to specify the
* libcurl version.
*/
explicit curl_info(const CURLversion);
explicit curl_info(CURLversion);
/**
* Returns a string that shows what host information that this
* libcurl was built for.
Expand Down Expand Up @@ -114,7 +114,10 @@ namespace curl {

// Implementation of get_ssl_version.
inline std::string curl_info::get_ssl_version() const NOEXCEPT {
return std::string(this->version->ssl_version);
if (this->version->ssl_version == nullptr) {
return std::string("");
}
return std::string(this->version->ssl_version);
}

// Implementation of get_libz_version.
Expand Down
28 changes: 11 additions & 17 deletions include/curl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace curl {
* Overloaded constructor that initializes curl environment
* with user specified flag.
*/
explicit curl_interface(const long);
explicit curl_interface(long);
/**
* The virtual destructor will provide an easy and clean
* way to deallocate resources, closing curl environment
Expand All @@ -59,20 +59,15 @@ namespace curl {
* This struct is used for initializing curl only once
* it is implemented as a singleton pattern
*/
struct global_initialisator {
explicit global_initialisator(const long);
~global_initialisator();
struct global_initializer {
explicit global_initializer(long);
~global_initializer();
};

/**
* The singleton instance
* the singleton initialization, constructing a global_initializer.
*/
static global_initialisator instance;

/**
* the singleton initialization, constructing a global_initialisator.
*/
static void init(const long flag);
static void init(long flag);
};

// Implementation of constructor.
Expand All @@ -86,24 +81,23 @@ namespace curl {
}

// Implementation of the virtual destructor.
template<class T> curl_interface<T>::~curl_interface() {
}
template<class T> curl_interface<T>::~curl_interface() = default;

// Implementation of the static initialization function
template<class T> void curl_interface<T>::init(const long flag) {
static global_initialisator _instance {flag};
static global_initializer _instance {flag};
}

// Implementation of the singleton initalizator
template<class T> curl_interface<T>::global_initialisator::global_initialisator(const long flag) {
// Implementation of the singleton initializer
template<class T> curl_interface<T>::global_initializer::global_initializer(const long flag) {
const CURLcode code = curl_global_init(flag);
if (code != CURLE_OK) {
throw curl_easy_exception(code,__FUNCTION__);
}
}

// Implementation of the singleton destructor
template<class T> curl_interface<T>::global_initialisator::~global_initialisator() {
template<class T> curl_interface<T>::global_initializer::~global_initializer() {
curl_global_cleanup();
}
}
Expand Down
Loading

1 comment on commit 0c2f06d

@JosephP91
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.