prepare for a http client
This commit is contained in:
+1
-2
@@ -7,8 +7,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
|
||||
|
||||
include_directories(
|
||||
source
|
||||
source/web
|
||||
source/webdav
|
||||
source/pugixml
|
||||
)
|
||||
|
||||
@@ -20,6 +18,7 @@ add_executable(ezremote_client
|
||||
source/web/request.cpp
|
||||
source/web/urn.cpp
|
||||
source/webdav/client.cpp
|
||||
source/http/client.cpp
|
||||
source/actions.cpp
|
||||
source/config.cpp
|
||||
source/fs.cpp
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@
|
||||
#include "lang.h"
|
||||
#include "actions.h"
|
||||
#include "installer.h"
|
||||
#include "request.hpp"
|
||||
#include "urn.hpp"
|
||||
#include "web/request.hpp"
|
||||
#include "web/urn.hpp"
|
||||
#include "rtc.h"
|
||||
#include "ftpclient.h"
|
||||
#include "smbclient.h"
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
#include <http/client.hpp>
|
||||
#include "web/callback.hpp"
|
||||
#include "web/fsinfo.hpp"
|
||||
#include "web/header.hpp"
|
||||
#include "web/pugiext.hpp"
|
||||
#include "web/request.hpp"
|
||||
#include "web/urn.hpp"
|
||||
#include "util.h"
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
|
||||
namespace HTTP
|
||||
{
|
||||
using Web::Data;
|
||||
using Web::Header;
|
||||
using Web::Request;
|
||||
using Web::Urn::Path;
|
||||
|
||||
using progress_funptr = int (*)(void *context, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
|
||||
|
||||
static size_t header_callback(char *buffer, size_t size, size_t nitems, void *userdata)
|
||||
{
|
||||
std::string header(reinterpret_cast<char *>(buffer), size * nitems);
|
||||
dict_t *headers = (dict_t *)userdata;
|
||||
size_t seperator = header.find_first_of(":");
|
||||
|
||||
if (seperator != std::string::npos)
|
||||
{
|
||||
std::string key = header.substr(0, seperator);
|
||||
key = Util::Trim(key, " ");
|
||||
key = Util::ToLower(key);
|
||||
std::string value = header.substr(seperator + 1);
|
||||
value = Util::Trim(value, " ");
|
||||
headers->erase(key);
|
||||
headers->insert(std::make_pair(key, value));
|
||||
}
|
||||
|
||||
return (size * nitems);
|
||||
}
|
||||
|
||||
Client::Client(const dict_t &options)
|
||||
{
|
||||
this->username = get(options, "username");
|
||||
this->password = get(options, "password");
|
||||
this->proxy_hostname = get(options, "proxy_hostname");
|
||||
this->proxy_username = get(options, "proxy_username");
|
||||
this->proxy_password = get(options, "proxy_password");
|
||||
this->cert_path = get(options, "cert_path");
|
||||
this->key_path = get(options, "key_path");
|
||||
}
|
||||
|
||||
dict_t Client::options()
|
||||
{
|
||||
return dict_t{
|
||||
{"username", this->username},
|
||||
{"password", this->password},
|
||||
{"proxy_hostname", this->proxy_hostname},
|
||||
{"proxy_username", this->proxy_username},
|
||||
{"proxy_password", this->proxy_password},
|
||||
{"cert_path", this->cert_path},
|
||||
{"key_path", this->key_path},
|
||||
};
|
||||
}
|
||||
|
||||
bool Client::Head(const std::string &url, dict_t *request_headers, Response &response)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Client::Get(const std::string &url, dict_t *request_headers, Response &Response)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Client::Delete(const std::string &url, void *post_data, dict_t *request_headers, Response &Response)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Client::Post(const std::string &url, void *post_data, dict_t *request_headers, Response &Response)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Client::Patch(const std::string &url, void *post_data, dict_t *request_headers, Response &Response)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Client::Put(const std::string &url, void *post_data, dict_t *request_headers, Response &Response)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Client::download(const std::string &url, const std::string &local_file,
|
||||
progress_data_t progress_data, progress_t progress)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef HTTP_CLIENT_HPP
|
||||
#define HTTP_CLIENT_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <curl/curl.h>
|
||||
#include "web/callback.hpp"
|
||||
|
||||
namespace HTTP
|
||||
{
|
||||
using progress_data_t = void *;
|
||||
|
||||
using progress_t = int(void *context,
|
||||
curl_off_t dltotal,
|
||||
curl_off_t dlnow,
|
||||
curl_off_t ultotal,
|
||||
curl_off_t ulnow);
|
||||
|
||||
using callback_t = std::function<void(bool)>;
|
||||
using dict_t = std::map<std::string, std::string>;
|
||||
|
||||
auto inline get(const dict_t &options, const std::string &&name) -> std::string
|
||||
{
|
||||
auto it = options.find(name);
|
||||
if (it == options.end())
|
||||
return "";
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
struct Response
|
||||
{
|
||||
int err;
|
||||
int status_code;
|
||||
Web::Data body;
|
||||
dict_t headers;
|
||||
};
|
||||
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
Client(const dict_t &options);
|
||||
bool Head(const std::string &url, dict_t *request_headers, Response &response);
|
||||
bool Get(const std::string &url, dict_t *request_headers, Response &Response);
|
||||
bool Delete(const std::string &url, void *post_data, dict_t *request_headers, Response &Response);
|
||||
bool Post(const std::string &url, void *post_data, dict_t *request_headers, Response &Response);
|
||||
bool Patch(const std::string &url, void *post_data, dict_t *request_headers, Response &Response);
|
||||
bool Put(const std::string &url, void *post_data, dict_t *request_headers, Response &Response);
|
||||
bool download(const std::string &url, const std::string &local_file,
|
||||
progress_data_t progress_data = nullptr, progress_t progress = nullptr);
|
||||
dict_t options();
|
||||
|
||||
private:
|
||||
std::string username;
|
||||
std::string password;
|
||||
|
||||
std::string proxy_hostname;
|
||||
std::string proxy_username;
|
||||
std::string proxy_password;
|
||||
|
||||
std::string cert_path;
|
||||
std::string key_path;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <orbis/AppInstUtil.h>
|
||||
#include <orbis/UserService.h>
|
||||
#include <curl/curl.h>
|
||||
#include <request.hpp>
|
||||
#include <urn.hpp>
|
||||
#include <web/request.hpp>
|
||||
#include <web/urn.hpp>
|
||||
#include "installer.h"
|
||||
#include "util.h"
|
||||
#include "config.h"
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#include <client.hpp>
|
||||
#include <webdav/client.hpp>
|
||||
|
||||
#include "callback.hpp"
|
||||
#include "fsinfo.hpp"
|
||||
#include "header.hpp"
|
||||
#include "pugiext.hpp"
|
||||
#include "request.hpp"
|
||||
#include "urn.hpp"
|
||||
#include "web/callback.hpp"
|
||||
#include "web/fsinfo.hpp"
|
||||
#include "web/header.hpp"
|
||||
#include "web/pugiext.hpp"
|
||||
#include "web/request.hpp"
|
||||
#include "web/urn.hpp"
|
||||
#include "util.h"
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ namespace Windows
|
||||
BeginGroupPanel(title, ImVec2(1905, 100));
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
|
||||
char id[256];
|
||||
std::string hidden_password = std::string("xxxxxxx");
|
||||
std::string hidden_password = (strlen(remote_settings->password) > 0)? std::string("*******") : "";
|
||||
ImVec2 pos;
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 4);
|
||||
|
||||
Reference in New Issue
Block a user