Skip to content

Commit

Permalink
Updated source file implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Feb 16, 2025
1 parent e75b5a2 commit c40192d
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 56 deletions.
73 changes: 41 additions & 32 deletions src/quoneq/ftp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include <quoneq/ftp.hpp>
#include <quoneq/net.hpp>

#include <curl/curl.h>
#include <fstream>
Expand Down Expand Up @@ -235,10 +236,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::upload(
CURLOPT_INFILESIZE_LARGE,
static_cast<curl_off_t>(fileSize)
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down Expand Up @@ -290,10 +292,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::download_file(
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_file_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down Expand Up @@ -337,10 +340,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::read(
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down Expand Up @@ -375,10 +379,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::remove(

curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

std::string path = quoneq_ftp_client::extract_ftp_path(ftp_url);
std::string deleCmd = "DELE " + path;
Expand Down Expand Up @@ -430,10 +435,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::list(
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down Expand Up @@ -526,10 +532,11 @@ bool quoneq_ftp_client::exists(

curl_easy_setopt(curl, CURLOPT_URL, ftp_url.c_str());
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down Expand Up @@ -627,10 +634,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::file_info(
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down Expand Up @@ -671,10 +679,11 @@ std::unique_ptr<quoneq_ftp_response> quoneq_ftp_client::folder_info(
CURLOPT_WRITEFUNCTION,
quoneq_ftp_client::write_callback
);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!username.empty())
curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());
Expand Down
37 changes: 21 additions & 16 deletions src/quoneq/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include <quoneq/http.hpp>
#include <quoneq/net.hpp>

#include <chrono>
#include <fstream>
Expand Down Expand Up @@ -147,10 +148,11 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::get(
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, quoneq_http_client::header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, response.get());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

struct curl_slist* curl_headers = quoneq_http_client::prepare_headers(headers);
if(curl_headers)
Expand Down Expand Up @@ -214,10 +216,11 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::post(
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, quoneq_http_client::header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, response.get());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

curl_mime* mime = curl_mime_init(curl);
for(const auto& field : form) {
Expand Down Expand Up @@ -301,10 +304,11 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::ping(

curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!proxy.empty())
curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
Expand Down Expand Up @@ -369,10 +373,11 @@ std::unique_ptr<quoneq_http_response> quoneq_http_client::download_file(
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, quoneq_http_client::header_callback);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, response.get());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

struct curl_slist* header_list = quoneq_http_client::prepare_headers(headers);
if(header_list)
Expand Down
20 changes: 20 additions & 0 deletions src/quoneq/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,30 @@

#include <curl/curl.h>

std::string quoneq_net::cacert_path = "";

void quoneq_net::init() {
curl_global_init(CURL_GLOBAL_DEFAULT);
}

void quoneq_net::cleanup() {
curl_global_cleanup();
}

void quoneq_net::set_ca_cert(std::string path) {
quoneq_net::cacert_path = path;
}

std::string quoneq_net::get_ca_cert() {
char* cacert_path = nullptr;
CURL *curl = curl_easy_init();

if(!curl)
return quoneq_net::cacert_path;

curl_easy_getinfo(curl, CURLINFO_CAINFO, &cacert_path);
if((cacert_path != NULL) && (cacert_path[0] == '\0'))
return cacert_path;

return quoneq_net::cacert_path;
}
19 changes: 11 additions & 8 deletions src/quoneq/telnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* THE SOFTWARE.
*/

#include <quoneq/net.hpp>
#include <quoneq/telnet.hpp>

#include <curl/curl.h>
Expand Down Expand Up @@ -62,10 +63,11 @@ std::unique_ptr<quoneq_telnet_response> quoneq_telnet_client::command(
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!proxy.empty())
curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
Expand Down Expand Up @@ -192,10 +194,11 @@ std::unique_ptr<quoneq_telnet_response> quoneq_telnet_client::exec_with_options(
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\Windows\\System32\\cacert.pem");
#endif
curl_easy_setopt(
curl,
CURLOPT_CAINFO,
quoneq_net::get_ca_cert().c_str()
);

if(!proxy.empty())
curl_easy_setopt(curl, CURLOPT_PROXY, proxy.c_str());
Expand Down

0 comments on commit c40192d

Please sign in to comment.