Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2615372288 | |||
| 0889b0923d | |||
| a2b26102de | |||
| dff469a9d7 | |||
| 37074f0102 | |||
| eb4184d488 | |||
| c328b26480 | |||
| 1e702aa0e2 | |||
| d35b311946 | |||
| f02944e596 | |||
| 338eacfd3f | |||
| 0bd0a0f273 | |||
| bf3f4330c0 | |||
| f16850fed9 | |||
| a30a20f6db | |||
| 54b9a80410 |
+2
-8
@@ -22,12 +22,6 @@ add_executable(ezremote_client
|
||||
source/imgui/imgui_widgets.cpp
|
||||
source/imgui/imgui.cpp
|
||||
source/pugixml/pugixml.cpp
|
||||
source/web/callback.cpp
|
||||
source/web/fsinfo.cpp
|
||||
source/web/header.cpp
|
||||
source/web/request.cpp
|
||||
source/web/urn.cpp
|
||||
source/webdav/client.cpp
|
||||
source/http/httplib.cpp
|
||||
source/clients/baseclient.cpp
|
||||
source/clients/apache.cpp
|
||||
@@ -38,9 +32,9 @@ add_executable(ezremote_client
|
||||
source/clients/npxserve.cpp
|
||||
source/clients/nfsclient.cpp
|
||||
source/clients/smbclient.cpp
|
||||
source/clients/webdavclient.cpp
|
||||
source/clients/sftpclient.cpp
|
||||
source/clients/rclone.cpp
|
||||
source/clients/webdav.cpp
|
||||
source/filehost/alldebrid.cpp
|
||||
source/filehost/realdebrid.cpp
|
||||
source/filehost/directhost.cpp
|
||||
@@ -72,7 +66,7 @@ add_executable(ezremote_client
|
||||
|
||||
add_self(ezremote_client)
|
||||
|
||||
add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.17" 32 0)
|
||||
add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.22" 32 0)
|
||||
|
||||
target_link_libraries(ezremote_client
|
||||
c
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# ezRemote Client
|
||||
|
||||
ezRemote Client is an application that allows you to connect the PS4 to remote FTP/SFTP, SMB, NFS, WebDAV, HTTP servers and Google Drive to transfer files. The interface is inspired by Filezilla client which provides a commander like GUI.
|
||||
ezRemote Client is an application that allows you to connect the PS4 to remote FTP/SFTP, SMB(Windows Share), NFS, WebDAV, HTTP servers and Google Drive to transfer files. The interface is inspired by Filezilla client which provides a commander like GUI.
|
||||
|
||||
**New: As of version 1.19**
|
||||
- Install PKG inside Zip files from both local hdd and remote servers.
|
||||
- Extact zip files directly from remote servers.
|
||||
|
||||
**New:** As of version 1.0.8, ezRemote Client has a Web Interface that can be access from any modern browser to manage the PS4 files.
|
||||
|
||||
@@ -27,7 +31,7 @@ To distinguish between FTP, SMB, NFS, WebDAV or HTTP, the URL must be prefix wit
|
||||
then in the password field enter file:///data/ezremote-client
|
||||
```
|
||||
|
||||
- The url format for SMB is
|
||||
- The url format for SMB(Windows Share) is
|
||||
```
|
||||
smb://hostname[:port]/sharename
|
||||
|
||||
@@ -114,7 +118,7 @@ Remote Package Installation with all Remote Server, even if they are password pr
|
||||
- Upload files to the PS4
|
||||
- Download files from the PS4
|
||||
- Install packages on the PS4
|
||||
- Install packages from shared links from mediafire, google and pixeldrain. For other filehost, they can installed via AllDebrid (See AllDebrid website for supported filehost).
|
||||
- Install packages from shared links from mediafire, google and pixeldrain. For other filehost, they can installed via AllDebrid/RealDebrid (See respective websites for supported filehost).
|
||||
|
||||
## How to access the Web Interface ##
|
||||
You need to launch the "ezRemote Client" app on the PS4. Then on any device(laptop, tablet, phone etc..) with web browser goto to http://<ip_address_of_ps4>:8080 . That's all.
|
||||
|
||||
+8
-14
@@ -8,7 +8,7 @@
|
||||
#include "clients/gdrive.h"
|
||||
#include "clients/ftpclient.h"
|
||||
#include "clients/smbclient.h"
|
||||
#include "clients/webdavclient.h"
|
||||
#include "clients/webdav.h"
|
||||
#include "clients/apache.h"
|
||||
#include "clients/nginx.h"
|
||||
#include "clients/npxserve.h"
|
||||
@@ -25,8 +25,6 @@
|
||||
#include "lang.h"
|
||||
#include "actions.h"
|
||||
#include "installer.h"
|
||||
#include "web/request.hpp"
|
||||
#include "web/urn.hpp"
|
||||
#include "system.h"
|
||||
#include "sfo.h"
|
||||
#include "zip_util.h"
|
||||
@@ -778,6 +776,7 @@ namespace Actions
|
||||
if (res != 0)
|
||||
{
|
||||
activity_inprogess = false;
|
||||
file_transfering = false;
|
||||
multi_selected_remote_files.clear();
|
||||
Windows::SetModalMode(false);
|
||||
}
|
||||
@@ -1101,14 +1100,14 @@ namespace Actions
|
||||
std::string host = full_url.substr(0, path_pos);
|
||||
std::string path = full_url.substr(path_pos);
|
||||
|
||||
WebDAV::WebDavClient tmp_client;
|
||||
tmp_client.Connect(host.c_str(), install_pkg_url.username, install_pkg_url.password, false);
|
||||
WebDAVClient tmp_client;
|
||||
tmp_client.Connect(host.c_str(), install_pkg_url.username, install_pkg_url.password);
|
||||
|
||||
sprintf(activity_message, "%s URL to %s", lang_strings[STR_DOWNLOADING], filename);
|
||||
int s = sizeof(pkg_header);
|
||||
memset(&header, 0, s);
|
||||
WebDAV::dict_t response_headers{};
|
||||
int ret = tmp_client.GetHeaders(path.c_str(), &response_headers);
|
||||
|
||||
int ret = tmp_client.Size(path, &bytes_to_download);
|
||||
if (!ret)
|
||||
{
|
||||
sprintf(status_message, "%s - %s", lang_strings[STR_FAILED], lang_strings[STR_CANNOT_READ_PKG_HDR_MSG]);
|
||||
@@ -1118,13 +1117,8 @@ namespace Actions
|
||||
return NULL;
|
||||
}
|
||||
|
||||
auto content_length = WebDAV::get(response_headers, "content-length");
|
||||
if (content_length.length() > 0)
|
||||
bytes_to_download = std::stol(content_length);
|
||||
else
|
||||
bytes_to_download = 1;
|
||||
file_transfering = 1;
|
||||
int is_performed = tmp_client.Get(filename, path.c_str());
|
||||
int is_performed = tmp_client.Get(path, filename);
|
||||
|
||||
if (is_performed == 0)
|
||||
{
|
||||
@@ -1212,7 +1206,7 @@ namespace Actions
|
||||
}
|
||||
else if (strncmp(remote_settings->server, "webdavs://", 10) == 0 || strncmp(remote_settings->server, "webdav://", 9) == 0)
|
||||
{
|
||||
remoteclient = new WebDAV::WebDavClient();
|
||||
remoteclient = new WebDAVClient();
|
||||
}
|
||||
else if (strncmp(remote_settings->server, "smb://", 6) == 0)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "windows.h"
|
||||
|
||||
using httplib::Client;
|
||||
using httplib::DataSink;
|
||||
using httplib::Headers;
|
||||
using httplib::Result;
|
||||
|
||||
@@ -21,15 +22,15 @@ BaseClient::~BaseClient()
|
||||
|
||||
int BaseClient::Connect(const std::string &url, const std::string &username, const std::string &password)
|
||||
{
|
||||
std::string scheme_host_port = url;
|
||||
this->host_url = url;
|
||||
size_t scheme_pos = url.find("://");
|
||||
size_t root_pos = url.find("/", scheme_pos + 3);
|
||||
if (root_pos != std::string::npos)
|
||||
{
|
||||
scheme_host_port = url.substr(0, root_pos);
|
||||
this->host_url = url.substr(0, root_pos);
|
||||
this->base_path = url.substr(root_pos);
|
||||
}
|
||||
client = new httplib::Client(scheme_host_port);
|
||||
client = new httplib::Client(this->host_url);
|
||||
if (username.length() > 0)
|
||||
client->set_basic_auth(username, password);
|
||||
client->set_keep_alive(true);
|
||||
@@ -82,10 +83,13 @@ int BaseClient::Size(const std::string &path, int64_t *size)
|
||||
{
|
||||
if (auto res = client->Head(GetFullPath(path)))
|
||||
{
|
||||
std::string content_length = res->get_header_value("Content-Length");
|
||||
if (content_length.length() > 0)
|
||||
*size = atoll(content_length.c_str());
|
||||
return 1;
|
||||
if (HTTP_SUCCESS(res->status))
|
||||
{
|
||||
std::string content_length = res->get_header_value("Content-Length");
|
||||
if (content_length.length() > 0)
|
||||
*size = atoll(content_length.c_str());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,7 +123,7 @@ int BaseClient::Get(const std::string &outputfile, const std::string &path, uint
|
||||
int BaseClient::GetRange(const std::string &path, DataSink &sink, uint64_t size, uint64_t offset)
|
||||
{
|
||||
char range_header[64];
|
||||
sprintf(range_header, "bytes=%lu-%lu", offset, offset+size-1);
|
||||
sprintf(range_header, "bytes=%lu-%lu", offset, offset + size - 1);
|
||||
Headers headers = {{"Range", range_header}};
|
||||
size_t bytes_read = 0;
|
||||
if (auto res = client->Get(GetFullPath(path), headers,
|
||||
@@ -142,7 +146,7 @@ int BaseClient::GetRange(const std::string &path, DataSink &sink, uint64_t size,
|
||||
int BaseClient::GetRange(const std::string &path, void *buffer, uint64_t size, uint64_t offset)
|
||||
{
|
||||
char range_header[64];
|
||||
sprintf(range_header, "bytes=%lu-%lu", offset, offset+size-1);
|
||||
sprintf(range_header, "bytes=%lu-%lu", offset, offset + size - 1);
|
||||
Headers headers = {{"Range", range_header}};
|
||||
size_t bytes_read = 0;
|
||||
std::vector<char> body;
|
||||
@@ -307,7 +311,7 @@ uint32_t BaseClient::SupportedActions()
|
||||
return REMOTE_ACTION_DOWNLOAD | REMOTE_ACTION_INSTALL | REMOTE_ACTION_EXTRACT;
|
||||
}
|
||||
|
||||
std::string BaseClient::EncodeUrl(const std::string &url)
|
||||
std::string BaseClient::Escape(const std::string &url)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
@@ -324,7 +328,7 @@ std::string BaseClient::EncodeUrl(const std::string &url)
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string BaseClient::DecodeUrl(const std::string &url)
|
||||
std::string BaseClient::UnEscape(const std::string &url)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
|
||||
@@ -39,12 +39,13 @@ public:
|
||||
int Quit();
|
||||
ClientType clientType();
|
||||
uint32_t SupportedActions();
|
||||
static std::string EncodeUrl(const std::string &url);
|
||||
static std::string DecodeUrl(const std::string &url);
|
||||
static std::string Escape(const std::string &url);
|
||||
static std::string UnEscape(const std::string &url);
|
||||
|
||||
protected:
|
||||
httplib::Client *client;
|
||||
std::string base_path;
|
||||
std::string host_url;
|
||||
char response[512];
|
||||
bool connected = false;
|
||||
};
|
||||
|
||||
+13
-13
@@ -111,7 +111,7 @@ int GDriveClient::RequestAuthorization()
|
||||
|
||||
std::string auth_url = std::string(GOOGLE_AUTH_URL "?client_id=") + gg_app.client_id + "&redirect_uri=" + GetRedirectUrl() +
|
||||
"&response_type=code&access_type=offline&scope=" + GetScopes() + "&include_granted_scopes=true";
|
||||
auth_url = EncodeUrl(auth_url);
|
||||
auth_url = Escape(auth_url);
|
||||
std::string launch_uri = std::string("pswebbrowser:search?url=") + auth_url;
|
||||
int ret = sceShellUIUtilLaunchByUri(launch_uri.c_str(), ¶m);
|
||||
|
||||
@@ -222,7 +222,7 @@ int GDriveClient::Rename(const std::string &src, const std::string &dst)
|
||||
if (src_id.compare("root") == 0 || dst_id.compare("root") == 0 || src_id.compare(src_drive_id) == 0 || dst_id.compare(dst_drive_id) == 0)
|
||||
return 0;
|
||||
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(src_id);
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(src_id);
|
||||
if (!src_drive_id.empty())
|
||||
url += "?supportsAllDrives=true";
|
||||
std::string filename = dst.substr(dst.find_last_of("/") + 1);
|
||||
@@ -276,7 +276,7 @@ int GDriveClient::Head(const std::string &path, void *buffer, uint64_t len)
|
||||
std::string id = GetValue(path_id_map, path);
|
||||
std::string drive_id = GetDriveId(path);
|
||||
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(id) + "?alt=media";
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(id) + "?alt=media";
|
||||
if (!drive_id.empty())
|
||||
url += "&supportsAllDrives=true";
|
||||
Headers headers;
|
||||
@@ -310,7 +310,7 @@ int GDriveClient::Get(const std::string &outputfile, const std::string &path, ui
|
||||
|
||||
std::string id = GetValue(path_id_map, path);
|
||||
std::string drive_id = GetDriveId(path);
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(id) + "?alt=media";
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(id) + "?alt=media";
|
||||
if (!drive_id.empty())
|
||||
url += "&supportsAllDrives=true";
|
||||
if (auto res = client->Get(url,
|
||||
@@ -337,7 +337,7 @@ int GDriveClient::GetRange(const std::string &path, DataSink &sink, uint64_t siz
|
||||
std::string id = GetValue(path_id_map, path);
|
||||
std::string drive_id = GetDriveId(path);
|
||||
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(id) + "?alt=media";
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(id) + "?alt=media";
|
||||
if (!drive_id.empty())
|
||||
url += "&supportsAllDrives=true";
|
||||
Headers headers;
|
||||
@@ -367,7 +367,7 @@ int GDriveClient::GetRange(const std::string &path, void *buffer, uint64_t size,
|
||||
std::string id = GetValue(path_id_map, path);
|
||||
std::string drive_id = GetDriveId(path);
|
||||
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(id) + "?alt=media";
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(id) + "?alt=media";
|
||||
if (!drive_id.empty())
|
||||
url += "&supportsAllDrives=true";
|
||||
Headers headers;
|
||||
@@ -406,7 +406,7 @@ int GDriveClient::Update(const std::string &inputfile, const std::string &path)
|
||||
std::string id = GetValue(path_id_map, path);
|
||||
std::string drive_id = GetDriveId(path);
|
||||
|
||||
std::string url = "/upload/drive/v3/files/" + BaseClient::EncodeUrl(id) + "?uploadType=resumable";
|
||||
std::string url = "/upload/drive/v3/files/" + BaseClient::Escape(id) + "?uploadType=resumable";
|
||||
if (!drive_id.empty())
|
||||
url += "&supportsAllDrives=true";
|
||||
Headers headers;
|
||||
@@ -553,7 +553,7 @@ int GDriveClient::Size(const std::string &path, int64_t *size)
|
||||
{
|
||||
std::string id = GetValue(path_id_map, path);
|
||||
std::string drive_id = GetDriveId(path);
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(id) + "?fields=size";
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(id) + "?fields=size";
|
||||
if (!drive_id.empty())
|
||||
url += "&supportsAllDrives=true";
|
||||
if (auto res = client->Get(url))
|
||||
@@ -669,7 +669,7 @@ int GDriveClient::Delete(const std::string &path)
|
||||
if (strcmp(id.c_str(), "root") == 0)
|
||||
return 0;
|
||||
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::EncodeUrl(id);
|
||||
std::string url = std::string("/drive/v3/files/") + BaseClient::Escape(id);
|
||||
if (!drive_id.empty())
|
||||
url += "?supportsAllDrives=true";
|
||||
if (auto res = client->Delete(url))
|
||||
@@ -779,8 +779,8 @@ std::vector<DirEntry> GDriveClient::ListDir(const std::string &path)
|
||||
}
|
||||
|
||||
std::string drive_id = GetDriveId(path);
|
||||
std::string base_url = std::string("/drive/v3/files?q=") + BaseClient::EncodeUrl("\"" + id + "\" in parents") +
|
||||
"&pageSize=1000&fields=" + BaseClient::EncodeUrl("files(id,mimeType,name,modifiedTime,size),nextPageToken");
|
||||
std::string base_url = std::string("/drive/v3/files?q=") + BaseClient::Escape("\"" + id + "\" in parents") +
|
||||
"&pageSize=1000&fields=" + BaseClient::Escape("files(id,mimeType,name,modifiedTime,size),nextPageToken");
|
||||
if (!drive_id.empty())
|
||||
{
|
||||
base_url += "&driveId=" + drive_id + "&corpora=drive&includeItemsFromAllDrives=true&supportsAllDrives=true";
|
||||
@@ -789,7 +789,7 @@ std::vector<DirEntry> GDriveClient::ListDir(const std::string &path)
|
||||
bool find_no_parent = false;
|
||||
if (id.compare(shared_with_me) == 0)
|
||||
{
|
||||
base_url = std::string("/drive/v3/files?q=sharedWithMe&pageSize=1000&fields=") + BaseClient::EncodeUrl("files(id,mimeType,name,modifiedTime,size),nextPageToken");
|
||||
base_url = std::string("/drive/v3/files?q=sharedWithMe&pageSize=1000&fields=") + BaseClient::Escape("files(id,mimeType,name,modifiedTime,size),nextPageToken");
|
||||
}
|
||||
|
||||
std::string next_page_url = base_url;
|
||||
@@ -867,7 +867,7 @@ std::vector<DirEntry> GDriveClient::ListDir(const std::string &path)
|
||||
}
|
||||
}
|
||||
if (next_page_token != nullptr)
|
||||
next_page_url = base_url + "&pageToken=" + BaseClient::EncodeUrl(json_object_get_string(next_page_token));
|
||||
next_page_url = base_url + "&pageToken=" + BaseClient::Escape(json_object_get_string(next_page_token));
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ std::vector<DirEntry> NginxClient::ListDir(const std::string &path)
|
||||
value = lxb_dom_element_get_attribute(lxb_dom_interface_element(node), (const lxb_char_t *)"href", 4, &value_len);
|
||||
tmp = std::string((const char *)value, value_len);
|
||||
tmp = Util::Rtrim(tmp, "/");
|
||||
tmp = BaseClient::DecodeUrl(tmp);
|
||||
tmp = BaseClient::UnEscape(tmp);
|
||||
if (tmp.compare("..") != 0)
|
||||
{
|
||||
sprintf(entry.directory, "%s", path.c_str());
|
||||
|
||||
@@ -141,7 +141,7 @@ std::vector<DirEntry> RCloneClient::ListDir(const std::string &path)
|
||||
tmp_string = std::string((const char *)value, value_len);
|
||||
if (tmp_string[tmp_string.length()-1] == '/')
|
||||
tmp_string = tmp_string.substr(0, tmp_string.length()-1);
|
||||
tmp_string = BaseClient::DecodeUrl(tmp_string);
|
||||
tmp_string = BaseClient::UnEscape(tmp_string);
|
||||
sprintf(entry.name, "%s", tmp_string.c_str());
|
||||
sprintf(entry.directory, "%s", path.c_str());
|
||||
if (path.length() > 0 && path[path.length() - 1] == '/')
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
#include <fstream>
|
||||
#include "common.h"
|
||||
#include "clients/remote_client.h"
|
||||
#include "clients/webdav.h"
|
||||
#include "pugixml/pugiext.hpp"
|
||||
#include "fs.h"
|
||||
#include "lang.h"
|
||||
#include "util.h"
|
||||
#include "system.h"
|
||||
#include "windows.h"
|
||||
|
||||
using httplib::Client;
|
||||
using httplib::Headers;
|
||||
using httplib::Progress;
|
||||
using httplib::Result;
|
||||
using httplib::ContentProvider;
|
||||
|
||||
static const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
std::string WebDAVClient::GetHttpUrl(std::string url)
|
||||
{
|
||||
std::string http_url = std::regex_replace(url, std::regex("webdav://"), "http://");
|
||||
http_url = std::regex_replace(http_url, std::regex("webdavs://"), "https://");
|
||||
return http_url;
|
||||
}
|
||||
|
||||
int WebDAVClient::Connect(const std::string &host, const std::string &user, const std::string &pass)
|
||||
{
|
||||
std::string url = GetHttpUrl(host);
|
||||
return BaseClient::Connect(url, user, pass);
|
||||
}
|
||||
|
||||
Result WebDAVClient::PropFind(const std::string &path, int depth)
|
||||
{
|
||||
Request req;
|
||||
Headers header = {{"Accept", "*/*"}, {"Depth", std::to_string(depth)}};
|
||||
|
||||
req.method = "PROPFIND";
|
||||
req.path = path;
|
||||
req.headers = header;
|
||||
req.progress = Progress();
|
||||
|
||||
return client->send(req);
|
||||
}
|
||||
|
||||
std::vector<DirEntry> WebDAVClient::ListDir(const std::string &path)
|
||||
{
|
||||
std::vector<DirEntry> out;
|
||||
DirEntry entry;
|
||||
Util::SetupPreviousFolder(path, &entry);
|
||||
out.push_back(entry);
|
||||
|
||||
std::string encoded_path = httplib::detail::encode_url(GetFullPath(path));
|
||||
if (auto res = PropFind(encoded_path, 1))
|
||||
{
|
||||
pugi::xml_document document;
|
||||
document.load_buffer(res->body.c_str(), res->body.length());
|
||||
auto multistatus = document.select_node("*[local-name()='multistatus']").node();
|
||||
auto responses = multistatus.select_nodes("*[local-name()='response']");
|
||||
for (auto response : responses)
|
||||
{
|
||||
pugi::xml_node href = response.node().select_node("*[local-name()='href']").node();
|
||||
std::string resource_path = httplib::detail::decode_url(href.first_child().value(), true);
|
||||
|
||||
auto target_path_without_sep = GetFullPath(path);
|
||||
if (!target_path_without_sep.empty() && target_path_without_sep.back() == '/')
|
||||
target_path_without_sep.resize(target_path_without_sep.length() - 1);
|
||||
auto resource_path_without_sep = resource_path.erase(resource_path.find_last_not_of('/') + 1);
|
||||
size_t pos = resource_path_without_sep.find(this->host_url);
|
||||
if (pos != std::string::npos)
|
||||
resource_path_without_sep.erase(pos, this->host_url.length());
|
||||
|
||||
if (resource_path_without_sep == target_path_without_sep)
|
||||
continue;
|
||||
|
||||
pos = resource_path_without_sep.find_last_of('/');
|
||||
auto name = resource_path_without_sep.substr(pos + 1);
|
||||
auto propstat = response.node().select_node("*[local-name()='propstat']").node();
|
||||
auto prop = propstat.select_node("*[local-name()='prop']").node();
|
||||
std::string creation_date = prop.select_node("*[local-name()='creationdate']").node().first_child().value();
|
||||
std::string content_length = prop.select_node("*[local-name()='getcontentlength']").node().first_child().value();
|
||||
std::string m_date = prop.select_node("*[local-name()='getlastmodified']").node().first_child().value();
|
||||
std::string resource_type = prop.select_node("*[local-name()='resourcetype']").node().first_child().name();
|
||||
|
||||
DirEntry entry;
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
entry.selectable = true;
|
||||
sprintf(entry.directory, "%s", path.c_str());
|
||||
sprintf(entry.name, "%s", name.c_str());
|
||||
|
||||
if (path.length() == 1 and path[0] == '/')
|
||||
{
|
||||
sprintf(entry.path, "%s%s", path.c_str(), name.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(entry.path, "%s/%s", path.c_str(), name.c_str());
|
||||
}
|
||||
|
||||
entry.isDir = resource_type.find("collection") != std::string::npos;
|
||||
entry.file_size = 0;
|
||||
if (!entry.isDir)
|
||||
{
|
||||
entry.file_size = std::stoll(content_length);
|
||||
DirEntry::SetDisplaySize(&entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(entry.display_size, "%s", lang_strings[STR_FOLDER]);
|
||||
}
|
||||
|
||||
char modified_date[32];
|
||||
char *p_char = NULL;
|
||||
sprintf(modified_date, "%s", m_date.c_str());
|
||||
p_char = strchr(modified_date, ' ');
|
||||
if (p_char)
|
||||
{
|
||||
OrbisDateTime gmt;
|
||||
OrbisDateTime lt;
|
||||
char month[5];
|
||||
sscanf(p_char, "%hd %s %hd %hd:%hd:%hd", &gmt.day, month, &gmt.year, &gmt.hour, &gmt.minute, &gmt.second);
|
||||
for (int k = 0; k < 12; k++)
|
||||
{
|
||||
if (strcmp(month, months[k]) == 0)
|
||||
{
|
||||
gmt.month = k + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
convertUtcToLocalTime(&gmt, <);
|
||||
entry.modified.day = lt.day;
|
||||
entry.modified.month = lt.month;
|
||||
entry.modified.year = lt.year;
|
||||
entry.modified.hours = lt.hour;
|
||||
entry.modified.minutes = lt.minute;
|
||||
entry.modified.seconds = lt.second;
|
||||
}
|
||||
out.push_back(entry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(this->response, "%s", httplib::to_string(res.error()).c_str());
|
||||
return out;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int WebDAVClient::Put(const std::string &inputfile, const std::string &path, uint64_t offset)
|
||||
{
|
||||
size_t bytes_remaining = FS::GetSize(inputfile);
|
||||
bytes_transfered = 0;
|
||||
|
||||
FILE* in = FS::OpenRead(inputfile);
|
||||
|
||||
if (auto res = client->Put(GetFullPath(path),
|
||||
[&](size_t offset, DataSink &sink)
|
||||
{
|
||||
size_t buf_size = MIN(bytes_remaining, CPPHTTPLIB_RECV_BUFSIZ);
|
||||
char* buf = (char*) malloc(buf_size);
|
||||
FS::Seek(in, offset);
|
||||
|
||||
while (bytes_remaining > 0)
|
||||
{
|
||||
size_t bytes_read = FS::Read(in, buf, buf_size);
|
||||
sink.write(buf, bytes_read);
|
||||
bytes_transfered += bytes_read;
|
||||
bytes_remaining -= bytes_read;
|
||||
}
|
||||
sink.done();
|
||||
free(buf);
|
||||
return true;
|
||||
},
|
||||
"application/octet-stream"))
|
||||
{
|
||||
if (HTTP_SUCCESS(res->status))
|
||||
{
|
||||
FS::Close(in);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
FS::Close(in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WebDAVClient::Mkdir(const std::string &path)
|
||||
{
|
||||
Request req;
|
||||
Headers header = {{"Accept", "*/*"}, {"Connection", "Keep-Alive"}};
|
||||
|
||||
req.method = "MKCOL";
|
||||
req.path = httplib::detail::encode_url(GetFullPath((path)));
|
||||
req.headers = header;
|
||||
req.progress = Progress();
|
||||
|
||||
if (auto res = client->send(req))
|
||||
{
|
||||
if (HTTP_SUCCESS(res->status))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WebDAVClient::Rmdir(const std::string &path, bool recursive)
|
||||
{
|
||||
return Delete(path);
|
||||
}
|
||||
|
||||
int WebDAVClient::Rename(const std::string &src, const std::string &dst)
|
||||
{
|
||||
return Move(src, dst);
|
||||
}
|
||||
|
||||
int WebDAVClient::Delete(const std::string &path)
|
||||
{
|
||||
Request req;
|
||||
Headers header = {{"Accept", "*/*"}, {"Connection", "Keep-Alive"}};
|
||||
|
||||
req.method = "DELETE";
|
||||
req.path = httplib::detail::encode_url(GetFullPath((path)));
|
||||
req.headers = header;
|
||||
req.progress = Progress();
|
||||
|
||||
if (auto res = client->send(req))
|
||||
{
|
||||
if (HTTP_SUCCESS(res->status))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int WebDAVClient::Copy(const std::string &from, const std::string &to)
|
||||
{
|
||||
Request req;
|
||||
Headers header = {{"Accept", "*/*"}, {"Destination", httplib::detail::encode_url(GetFullPath(to)) }};
|
||||
|
||||
req.method = "COPY";
|
||||
req.path = httplib::detail::encode_url(GetFullPath(from));
|
||||
req.headers = header;
|
||||
req.progress = Progress();
|
||||
|
||||
if (auto res = client->send(req))
|
||||
{
|
||||
if (HTTP_SUCCESS(res->status))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WebDAVClient::Move(const std::string &from, const std::string &to)
|
||||
{
|
||||
Request req;
|
||||
Headers header = {{"Accept", "*/*"}, {"Destination", httplib::detail::encode_url(GetFullPath(to)) }};
|
||||
|
||||
req.method = "MOVE";
|
||||
req.path = httplib::detail::encode_url(GetFullPath(from));
|
||||
req.headers = header;
|
||||
req.progress = Progress();
|
||||
|
||||
if (auto res = client->send(req))
|
||||
{
|
||||
if (HTTP_SUCCESS(res->status))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ClientType WebDAVClient::clientType()
|
||||
{
|
||||
return CLIENT_TYPE_WEBDAV;
|
||||
}
|
||||
|
||||
uint32_t WebDAVClient::SupportedActions()
|
||||
{
|
||||
return REMOTE_ACTION_ALL;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef WEBDAV_H
|
||||
#define WEBDAV_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "http/httplib.h"
|
||||
#include "clients/baseclient.h"
|
||||
#include "clients/remote_client.h"
|
||||
#include "common.h"
|
||||
|
||||
class WebDAVClient : public BaseClient
|
||||
{
|
||||
public:
|
||||
int Connect(const std::string &url, const std::string &user, const std::string &pass);
|
||||
int Mkdir(const std::string &path);
|
||||
int Rmdir(const std::string &path, bool recursive);
|
||||
int Rename(const std::string &src, const std::string &dst);
|
||||
int Delete(const std::string &path);
|
||||
int Copy(const std::string &from, const std::string &to);
|
||||
int Move(const std::string &from, const std::string &to);
|
||||
int Put(const std::string &inputfile, const std::string &path, uint64_t offset = 0);
|
||||
std::vector<DirEntry> ListDir(const std::string &path);
|
||||
ClientType clientType();
|
||||
uint32_t SupportedActions();
|
||||
static std::string GetHttpUrl(std::string url);
|
||||
|
||||
private:
|
||||
Result PropFind(const std::string &path, int depth);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,387 +0,0 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "lang.h"
|
||||
#include "webdav/client.hpp"
|
||||
#include "clients/webdavclient.h"
|
||||
#include "windows.h"
|
||||
#include "util.h"
|
||||
#include "system.h"
|
||||
|
||||
static const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
namespace WebDAV
|
||||
{
|
||||
static int DownloadCallback(void *context, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
int64_t *bytes_transfered = (int64_t *)context;
|
||||
*bytes_transfered = reinterpret_cast<int64_t>(dlnow);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static int UploadCallback(void *context, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
int64_t *bytes_transfered = (int64_t *)context;
|
||||
*bytes_transfered = reinterpret_cast<int64_t>(ulnow);
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
int WebDavClient::Connect(const std::string &host, const std::string &user, const std::string &pass)
|
||||
{
|
||||
return Connect(host, user, pass, true);
|
||||
}
|
||||
|
||||
WebDavClient::WebDavClient() {};
|
||||
|
||||
int WebDavClient::Connect(const std::string &host, const std::string &user, const std::string &pass, bool check_enabled)
|
||||
{
|
||||
std::string url = GetHttpUrl(host);
|
||||
std::size_t scheme_pos = url.find_first_of("://");
|
||||
std::string root_folder = "/";
|
||||
if (scheme_pos != std::string::npos)
|
||||
{
|
||||
std::size_t root_folder_pos = url.find_first_of("/", scheme_pos + 3);
|
||||
if (root_folder_pos != std::string::npos)
|
||||
{
|
||||
root_folder = url.substr(root_folder_pos);
|
||||
url = url.substr(0, root_folder_pos);
|
||||
}
|
||||
}
|
||||
WebDAV::dict_t options = {
|
||||
{"webdav_hostname", url},
|
||||
{"webdav_root", root_folder},
|
||||
{"webdav_username", user},
|
||||
{"webdav_password", pass},
|
||||
{"check_enabled", check_enabled ? "1" : "0"}};
|
||||
client = new WebDAV::Client(options);
|
||||
connected = true;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* LastResponse - return a pointer to the last response received
|
||||
*/
|
||||
const char *WebDavClient::LastResponse()
|
||||
{
|
||||
return (const char *)response;
|
||||
}
|
||||
|
||||
/*
|
||||
* IsConnected - return true if connected to remote
|
||||
*/
|
||||
bool WebDavClient::IsConnected()
|
||||
{
|
||||
return connected;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ping - return true if connected to remote
|
||||
*/
|
||||
bool WebDavClient::Ping()
|
||||
{
|
||||
connected = client->check();
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return connected;
|
||||
}
|
||||
|
||||
/*
|
||||
* Quit - disconnect from remote
|
||||
*
|
||||
* return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int WebDavClient::Quit()
|
||||
{
|
||||
if (client != NULL)
|
||||
delete (client);
|
||||
client = NULL;
|
||||
connected = false;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mkdir - create a directory at server
|
||||
*
|
||||
* return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int WebDavClient::Mkdir(const std::string &ppath)
|
||||
{
|
||||
bool ret = client->create_directory(ppath);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Rmdir - remove directory and all files under directory at remote
|
||||
*
|
||||
* return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int WebDavClient::_Rmdir(const std::string &ppath)
|
||||
{
|
||||
bool ret = client->clean(ppath);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Rmdir - remove directory and all files under directory at remote
|
||||
*
|
||||
* return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int WebDavClient::Rmdir(const std::string &path, bool recursive)
|
||||
{
|
||||
if (stop_activity)
|
||||
return 1;
|
||||
|
||||
std::vector<DirEntry> list = ListDir(path);
|
||||
int ret;
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
if (stop_activity)
|
||||
return 1;
|
||||
|
||||
if (list[i].isDir && recursive)
|
||||
{
|
||||
if (strcmp(list[i].name, "..") == 0)
|
||||
continue;
|
||||
ret = Rmdir(list[i].path, recursive);
|
||||
if (ret == 0)
|
||||
{
|
||||
sprintf(status_message, "%s %s", lang_strings[STR_FAIL_DEL_DIR_MSG], list[i].path);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(activity_message, "%s %s\n", lang_strings[STR_DELETING], list[i].path);
|
||||
ret = Delete(list[i].path);
|
||||
if (ret == 0)
|
||||
{
|
||||
sprintf(status_message, "%s %s", lang_strings[STR_FAIL_DEL_FILE_MSG], list[i].path);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret = _Rmdir(path);
|
||||
if (ret == 0)
|
||||
{
|
||||
sprintf(status_message, "%s %s", lang_strings[STR_FAIL_DEL_DIR_MSG], path.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get - issue a GET command and write received data to output
|
||||
*
|
||||
* return 1 if successful, 0 otherwise
|
||||
*/
|
||||
|
||||
int WebDavClient::Get(const std::string &outputfile, const std::string &ppath, uint64_t offset)
|
||||
{
|
||||
bool ret = client->download(ppath, outputfile, &bytes_transfered, DownloadCallback);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool WebDavClient::FileExists(const std::string &ppath)
|
||||
{
|
||||
std::string path = ppath;
|
||||
path = Util::Ltrim(path, "/");
|
||||
bool ret = client->check(path);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WebDavClient::GetRange(const std::string &path, void *buffer, uint64_t size, uint64_t offset)
|
||||
{
|
||||
char *buffer_ptr = nullptr;
|
||||
unsigned long long buffer_size = 0;
|
||||
|
||||
bool ret = client->download_range_to(path, buffer_ptr, buffer_size, offset, offset+size-1);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
if (buffer_size != size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer, buffer_ptr, size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WebDavClient::GetRange(const std::string &path, DataSink &sink, uint64_t size, uint64_t offset)
|
||||
{
|
||||
return client->download_range_to(path, sink, offset, offset+size-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Put - issue a PUT command and send data from input
|
||||
*
|
||||
* return 1 if successful, 0 otherwise
|
||||
*/
|
||||
int WebDavClient::Put(const std::string &inputfile, const std::string &ppath, uint64_t offset)
|
||||
{
|
||||
bool ret = client->upload(ppath, inputfile, &bytes_transfered, UploadCallback);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WebDavClient::Rename(const std::string &src, const std::string &dst)
|
||||
{
|
||||
bool ret = client->move(src, dst);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WebDavClient::Delete(const std::string &ppath)
|
||||
{
|
||||
bool ret = client->clean(ppath);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WebDavClient::Copy(const std::string &from, const std::string &to)
|
||||
{
|
||||
bool ret = client->copy(from, to);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WebDavClient::Move(const std::string &from, const std::string &to)
|
||||
{
|
||||
bool ret = client->move(from, to);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WebDavClient::Size(const std::string &ppath, int64_t *size)
|
||||
{
|
||||
WebDAV::dict_t file_info = client->info(ppath);
|
||||
std::string file_size = WebDAV::get(file_info, "size");
|
||||
if (file_size.empty())
|
||||
return 0;
|
||||
*size = std::stoll(file_size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::vector<DirEntry> WebDavClient::ListDir(const std::string &path)
|
||||
{
|
||||
std::vector<DirEntry> out;
|
||||
DirEntry entry;
|
||||
Util::SetupPreviousFolder(path, &entry);
|
||||
out.push_back(entry);
|
||||
|
||||
WebDAV::dict_items_t files = client->list(path);
|
||||
for (int i = 0; i < files.size(); i++)
|
||||
{
|
||||
DirEntry entry;
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
entry.selectable = true;
|
||||
sprintf(entry.directory, "%s", path.c_str());
|
||||
sprintf(entry.name, "%s", WebDAV::get(files[i], "name").c_str());
|
||||
|
||||
if (path.length() == 1 and path[0] == '/')
|
||||
{
|
||||
sprintf(entry.path, "%s%s", path.c_str(), WebDAV::get(files[i], "name").c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(entry.path, "%s/%s", path.c_str(), WebDAV::get(files[i], "name").c_str());
|
||||
}
|
||||
|
||||
std::string resource_type = WebDAV::get(files[i], "type");
|
||||
entry.isDir = resource_type.find("collection") != std::string::npos;
|
||||
entry.file_size = 0;
|
||||
if (!entry.isDir)
|
||||
{
|
||||
entry.file_size = std::stoll(WebDAV::get(files[i], "size"));
|
||||
DirEntry::SetDisplaySize(&entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(entry.display_size, "%s", lang_strings[STR_FOLDER]);
|
||||
}
|
||||
|
||||
char modified_date[32];
|
||||
char *p_char = NULL;
|
||||
sprintf(modified_date, "%s", WebDAV::get(files[i], "modified").c_str());
|
||||
p_char = strchr(modified_date, ' ');
|
||||
if (p_char)
|
||||
{
|
||||
OrbisDateTime gmt;
|
||||
OrbisDateTime lt;
|
||||
char month[5];
|
||||
sscanf(p_char, "%hd %s %hd %hd:%hd:%hd", &gmt.day, month, &gmt.year, &gmt.hour, &gmt.minute, &gmt.second);
|
||||
for (int k = 0; k < 12; k++)
|
||||
{
|
||||
if (strcmp(month, months[k]) == 0)
|
||||
{
|
||||
gmt.month = k + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
convertUtcToLocalTime(&gmt, <);
|
||||
entry.modified.day = lt.day;
|
||||
entry.modified.month = lt.month;
|
||||
entry.modified.year = lt.year;
|
||||
entry.modified.hours = lt.hour;
|
||||
entry.modified.minutes = lt.minute;
|
||||
entry.modified.seconds = lt.second;
|
||||
}
|
||||
out.push_back(entry);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string WebDavClient::GetPath(std::string ppath1, std::string ppath2)
|
||||
{
|
||||
std::string path1 = ppath1;
|
||||
std::string path2 = ppath2;
|
||||
path1 = Util::Rtrim(Util::Trim(path1, " "), "/");
|
||||
path2 = Util::Rtrim(Util::Trim(path2, " "), "/");
|
||||
path1 = path1 + "/" + path2;
|
||||
return path1;
|
||||
}
|
||||
|
||||
int WebDavClient::Head(const std::string &path, void *buffer, uint64_t len)
|
||||
{
|
||||
char *buffer_ptr = nullptr;
|
||||
unsigned long long buffer_size = 0;
|
||||
|
||||
bool ret = client->download_range_to(path, buffer_ptr, buffer_size, 0, len - 1);
|
||||
sprintf(response, "Http Code %ld", client->status_code());
|
||||
if (buffer_size != len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
memcpy(buffer, buffer_ptr, len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool WebDavClient::GetHeaders(const std::string &path, dict_t *headers)
|
||||
{
|
||||
return client->head(path, headers);
|
||||
}
|
||||
|
||||
WebDAV::Client *WebDavClient::GetClient()
|
||||
{
|
||||
return this->client;
|
||||
}
|
||||
|
||||
ClientType WebDavClient::clientType()
|
||||
{
|
||||
return CLIENT_TYPE_WEBDAV;
|
||||
}
|
||||
|
||||
uint32_t WebDavClient::SupportedActions()
|
||||
{
|
||||
return REMOTE_ACTION_ALL;
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#ifndef WEBDAVCLIENT_H
|
||||
#define WEBDAVCLIENT_H
|
||||
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <regex>
|
||||
#include "http/httplib.h"
|
||||
#include "webdav/client.hpp"
|
||||
#include "clients/remote_client.h"
|
||||
#include "common.h"
|
||||
|
||||
using namespace httplib;
|
||||
|
||||
namespace WebDAV
|
||||
{
|
||||
inline std::string GetHttpUrl(std::string url)
|
||||
{
|
||||
std::string http_url = std::regex_replace(url, std::regex("webdav://"), "http://");
|
||||
http_url = std::regex_replace(http_url, std::regex("webdavs://"), "https://");
|
||||
return http_url;
|
||||
}
|
||||
|
||||
class WebDavClient : public RemoteClient
|
||||
{
|
||||
public:
|
||||
WebDavClient();
|
||||
int Connect(const std::string &url, const std::string &user, const std::string &pass);
|
||||
int Connect(const std::string &url, const std::string &user, const std::string &pass, bool check_enabled);
|
||||
int Mkdir(const std::string &path);
|
||||
int Rmdir(const std::string &path, bool recursive);
|
||||
int Size(const std::string &path, int64_t *size);
|
||||
int Get(const std::string &outputfile, const std::string &path, uint64_t offset=0);
|
||||
int GetRange(const std::string &path, void *buffer, uint64_t size, uint64_t offset);
|
||||
int GetRange(const std::string &path, DataSink &sink, uint64_t size, uint64_t offset);
|
||||
int Put(const std::string &inputfile, const std::string &path, uint64_t offset=0);
|
||||
int Rename(const std::string &src, const std::string &dst);
|
||||
int Delete(const std::string &path);
|
||||
int Copy(const std::string &from, const std::string &to);
|
||||
int Move(const std::string &from, const std::string &to);
|
||||
bool FileExists(const std::string &path);
|
||||
std::vector<DirEntry> ListDir(const std::string &path);
|
||||
bool IsConnected();
|
||||
bool Ping();
|
||||
const char *LastResponse();
|
||||
int Quit();
|
||||
std::string GetPath(std::string path1, std::string path2);
|
||||
int Head(const std::string &path, void *buffer, uint64_t len);
|
||||
bool GetHeaders(const std::string &path, dict_t *headers);
|
||||
WebDAV::Client *GetClient();
|
||||
ClientType clientType();
|
||||
uint32_t SupportedActions();
|
||||
|
||||
private:
|
||||
int _Rmdir(const std::string &path);
|
||||
WebDAV::Client *client;
|
||||
char response[1024];
|
||||
bool connected = false;
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -562,7 +562,7 @@ private:
|
||||
size_t read_buff_off_ = 0;
|
||||
size_t read_buff_content_size_ = 0;
|
||||
|
||||
static const size_t read_buff_size_ = 1024 * 16;
|
||||
static const size_t read_buff_size_ = 1024 * 512;
|
||||
};
|
||||
|
||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
|
||||
@@ -87,11 +87,11 @@
|
||||
#endif
|
||||
|
||||
#ifndef CPPHTTPLIB_RECV_BUFSIZ
|
||||
#define CPPHTTPLIB_RECV_BUFSIZ size_t(16384u)
|
||||
#define CPPHTTPLIB_RECV_BUFSIZ size_t(524288u)
|
||||
#endif
|
||||
|
||||
#ifndef CPPHTTPLIB_COMPRESSION_BUFSIZ
|
||||
#define CPPHTTPLIB_COMPRESSION_BUFSIZ size_t(16384u)
|
||||
#define CPPHTTPLIB_COMPRESSION_BUFSIZ size_t(524288u)
|
||||
#endif
|
||||
|
||||
#ifndef CPPHTTPLIB_THREAD_POOL_COUNT
|
||||
|
||||
+89
-60
@@ -10,9 +10,8 @@
|
||||
#include <orbis/AppInstUtil.h>
|
||||
#include <orbis/UserService.h>
|
||||
#include <orbis/SystemService.h>
|
||||
#include <curl/curl.h>
|
||||
#include <web/request.hpp>
|
||||
#include <web/urn.hpp>
|
||||
#include "clients/webdav.h"
|
||||
#include "clients/remote_client.h"
|
||||
#include "server/http_server.h"
|
||||
#include "installer.h"
|
||||
#include "util.h"
|
||||
@@ -22,8 +21,6 @@
|
||||
#include "system.h"
|
||||
#include "fs.h"
|
||||
#include "sfo.h"
|
||||
#include "clients/webdavclient.h"
|
||||
#include "clients/remote_client.h"
|
||||
|
||||
#define BGFT_HEAP_SIZE (1 * 1024 * 1024)
|
||||
|
||||
@@ -205,7 +202,7 @@ namespace INSTALLER
|
||||
if (strlen(remote_settings->username) == 0 && strlen(remote_settings->password) == 0 &&
|
||||
(remoteclient->clientType() == CLIENT_TYPE_WEBDAV || remoteclient->clientType() == CLIENT_TYPE_HTTP_SERVER))
|
||||
{
|
||||
std::string full_url = WebDAV::GetHttpUrl(remote_settings->server + path);
|
||||
std::string full_url = WebDAVClient::GetHttpUrl(remote_settings->server + path);
|
||||
size_t scheme_pos = full_url.find("://");
|
||||
if (scheme_pos == std::string::npos)
|
||||
return "";
|
||||
@@ -215,32 +212,62 @@ namespace INSTALLER
|
||||
|
||||
if (encodeUrl)
|
||||
{
|
||||
Web::Urn::Path uri(path);
|
||||
CURL *curl = curl_easy_init();
|
||||
path = uri.quote(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
path = httplib::detail::encode_url(path);
|
||||
}
|
||||
|
||||
return host + path;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string encoded_path = path;
|
||||
std::string encoded_site_name = remote_settings->site_name;
|
||||
Web::Urn::Path uri(encoded_path);
|
||||
Web::Urn::Path site_name(encoded_site_name);
|
||||
CURL *curl = curl_easy_init();
|
||||
encoded_path = uri.quote(curl);
|
||||
encoded_site_name = site_name.quote(curl);
|
||||
curl_easy_cleanup(curl);
|
||||
std::string full_url = std::string("http://localhost:") + std::to_string(http_server_port) + "/rmt_inst" + encoded_site_name + encoded_path;
|
||||
|
||||
std::string encoded_path = httplib::detail::encode_url(path);
|
||||
std::string encoded_site_name = httplib::detail::encode_url(remote_settings->site_name);
|
||||
std::string full_url = std::string("http://localhost:") + std::to_string(http_server_port) + "/rmt_inst/" + encoded_site_name + encoded_path;
|
||||
return full_url;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void *CheckBgInstallTaskThread(void *argp)
|
||||
{
|
||||
bool completed = false;
|
||||
OrbisBgftTaskProgress progress_info;
|
||||
BgProgressCheck *bg_check_data = (BgProgressCheck*) argp;
|
||||
int ret;
|
||||
|
||||
while (!completed)
|
||||
{
|
||||
memset(&progress_info, 0, sizeof(progress_info));
|
||||
ret = sceBgftServiceDownloadGetProgress(bg_check_data->task_id, &progress_info);
|
||||
if (ret || (progress_info.transferred > 0 && progress_info.errorResult != 0))
|
||||
{
|
||||
goto finish;
|
||||
}
|
||||
if (progress_info.length > 0)
|
||||
{
|
||||
completed = progress_info.transferred == progress_info.length;
|
||||
bytes_to_download = progress_info.length;
|
||||
bytes_transfered = progress_info.transferred;
|
||||
}
|
||||
sceSystemServicePowerTick();
|
||||
sceKernelUsleep(500000);
|
||||
}
|
||||
finish:
|
||||
if (bg_check_data->pkg_data != nullptr)
|
||||
{
|
||||
bg_check_data->pkg_data->stop_write_thread = true;
|
||||
pthread_join(bg_check_data->pkg_data->thread, NULL);
|
||||
delete(bg_check_data->pkg_data->split_file);
|
||||
free(bg_check_data->pkg_data);
|
||||
RemoveArchivePkgInstallData(bg_check_data->hash);
|
||||
free(bg_check_data);
|
||||
}
|
||||
activity_inprogess = false;
|
||||
file_transfering = false;
|
||||
Windows::SetModalMode(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool canInstallRemotePkg(const std::string &url)
|
||||
{
|
||||
return true;
|
||||
@@ -261,6 +288,7 @@ namespace INSTALLER
|
||||
uint32_t content_type = BE32(header->pkg_content_type);
|
||||
uint32_t flags = BE32(header->pkg_content_flags);
|
||||
bool is_patch = false;
|
||||
bool completed = false;
|
||||
|
||||
switch (content_type)
|
||||
{
|
||||
@@ -363,16 +391,32 @@ namespace INSTALLER
|
||||
file_transfering = true;
|
||||
bytes_to_download = 100;
|
||||
bytes_transfered = 0;
|
||||
while (bytes_transfered < 99)
|
||||
while (!completed)
|
||||
{
|
||||
memset(&progress_info, 0, sizeof(progress_info));
|
||||
ret = sceBgftServiceDownloadGetProgress(task_id, &progress_info);
|
||||
if (ret || (progress_info.transferred > 0 && progress_info.errorResult != 0))
|
||||
return 0;
|
||||
bytes_transfered = (uint32_t)(((float)progress_info.transferred / progress_info.length) * 100.f);
|
||||
|
||||
if (progress_info.length > 0)
|
||||
{
|
||||
completed = progress_info.transferred == progress_info.length;
|
||||
bytes_to_download = progress_info.length;
|
||||
bytes_transfered = progress_info.transferred;
|
||||
}
|
||||
sceSystemServicePowerTick();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BgProgressCheck *bg_check_data = (BgProgressCheck*) malloc(sizeof(BgProgressCheck));
|
||||
memset(bg_check_data, 0, sizeof(BgProgressCheck));
|
||||
bg_check_data->pkg_data = nullptr;
|
||||
bg_check_data->task_id = task_id;
|
||||
bg_check_data->hash = "";
|
||||
ret = pthread_create(&bk_install_thid, NULL, CheckBgInstallTaskThread, bg_check_data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
err:
|
||||
@@ -383,6 +427,8 @@ namespace INSTALLER
|
||||
{
|
||||
int ret;
|
||||
pkg_header header;
|
||||
bool completed = false;
|
||||
|
||||
memset(&header, 0, sizeof(header));
|
||||
if (FS::Head(path.c_str(), (void *)&header, sizeof(header)) == 0)
|
||||
return 0;
|
||||
@@ -444,13 +490,19 @@ namespace INSTALLER
|
||||
file_transfering = true;
|
||||
bytes_to_download = 100;
|
||||
bytes_transfered = 0;
|
||||
while (bytes_transfered < 99)
|
||||
while (!completed)
|
||||
{
|
||||
memset(&progress_info, 0, sizeof(progress_info));
|
||||
ret = sceBgftServiceDownloadGetProgress(task_id, &progress_info);
|
||||
if (ret || (progress_info.transferred > 0 && progress_info.errorResult != 0))
|
||||
return 0;
|
||||
bytes_transfered = (uint32_t)(((float)progress_info.transferred / progress_info.length) * 100.f);
|
||||
|
||||
if (progress_info.length > 0)
|
||||
{
|
||||
completed = progress_info.transferred == progress_info.length;
|
||||
bytes_to_download = progress_info.length;
|
||||
bytes_transfered = progress_info.transferred;
|
||||
}
|
||||
sceSystemServicePowerTick();
|
||||
}
|
||||
return 1;
|
||||
@@ -462,6 +514,8 @@ namespace INSTALLER
|
||||
int InstallLocalPkg(const std::string &path, pkg_header *header, bool remove_after_install)
|
||||
{
|
||||
int ret;
|
||||
bool completed = false;
|
||||
|
||||
if (strncmp(path.c_str(), "/data/", 6) != 0 &&
|
||||
strncmp(path.c_str(), "/user/data/", 11) != 0 &&
|
||||
strncmp(path.c_str(), "/mnt/usb", 8) != 0)
|
||||
@@ -547,15 +601,20 @@ namespace INSTALLER
|
||||
sprintf(activity_message, "%s", lang_strings[STR_WAIT_FOR_INSTALL_MSG]);
|
||||
bytes_to_download = 1;
|
||||
bytes_transfered = 0;
|
||||
while (prog < 99)
|
||||
while (!completed)
|
||||
{
|
||||
memset(&progress_info, 0, sizeof(progress_info));
|
||||
ret = sceBgftServiceDownloadGetProgress(task_id, &progress_info);
|
||||
if (ret || (progress_info.transferred > 0 && progress_info.errorResult != 0))
|
||||
return -3;
|
||||
prog = (uint32_t)(((float)progress_info.transferred / progress_info.length) * 100.f);
|
||||
bytes_to_download = progress_info.length;
|
||||
bytes_transfered = progress_info.transferred;
|
||||
|
||||
if (progress_info.length > 0)
|
||||
{
|
||||
completed = progress_info.transferred == progress_info.length;
|
||||
bytes_to_download = progress_info.length;
|
||||
bytes_transfered = progress_info.transferred;
|
||||
}
|
||||
sceSystemServicePowerTick();
|
||||
}
|
||||
if (auto_delete_tmp_pkg)
|
||||
FS::Rm(path);
|
||||
@@ -729,38 +788,6 @@ namespace INSTALLER
|
||||
archive_pkg_install_data_list.erase(hash);
|
||||
}
|
||||
|
||||
void *CheckBgInstallTaskThread(void *argp)
|
||||
{
|
||||
bool completed = false;
|
||||
OrbisBgftTaskProgress progress_info;
|
||||
BgProgressCheck *bg_check_data = (BgProgressCheck*) argp;
|
||||
int ret;
|
||||
|
||||
while (!completed)
|
||||
{
|
||||
memset(&progress_info, 0, sizeof(progress_info));
|
||||
ret = sceBgftServiceDownloadGetProgress(bg_check_data->task_id, &progress_info);
|
||||
if (ret || (progress_info.transferred > 0 && progress_info.errorResult != 0))
|
||||
{
|
||||
goto finish;
|
||||
}
|
||||
if (progress_info.length > 0)
|
||||
{
|
||||
completed = progress_info.transferred == progress_info.length;
|
||||
}
|
||||
sceSystemServicePowerTick();
|
||||
sceKernelUsleep(500000);
|
||||
}
|
||||
finish:
|
||||
bg_check_data->pkg_data->stop_write_thread = true;
|
||||
pthread_join(bg_check_data->pkg_data->thread, NULL);
|
||||
delete(bg_check_data->pkg_data->split_file);
|
||||
free(bg_check_data->pkg_data);
|
||||
RemoveArchivePkgInstallData(bg_check_data->hash);
|
||||
free(bg_check_data);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool InstallArchivePkg(const std::string &path, ArchivePkgInstallData* pkg_data, bool bg)
|
||||
{
|
||||
pkg_header header;
|
||||
@@ -903,6 +930,8 @@ namespace INSTALLER
|
||||
if (progress_info.length > 0)
|
||||
{
|
||||
completed = progress_info.transferred == progress_info.length;
|
||||
bytes_to_download = progress_info.length;
|
||||
bytes_transfered = progress_info.transferred;
|
||||
}
|
||||
sceSystemServicePowerTick();
|
||||
}
|
||||
|
||||
@@ -1024,9 +1024,9 @@ namespace HttpServer
|
||||
size_t range_len = (req.ranges[0].second - req.ranges[0].first) + 1;
|
||||
if (req.ranges[0].second >= 18000000000000000000ul)
|
||||
{
|
||||
range_len = 524288ul - req.ranges[0].first;
|
||||
range_len = 524288ul;
|
||||
res.set_header("Content-Length", std::to_string(range_len));
|
||||
res.set_header("Content-Range", std::string("bytes ") + std::to_string(req.ranges[0].first)+"-524288/"+std::to_string(range_len));
|
||||
res.set_header("Content-Range", std::string("bytes ") + std::to_string(req.ranges[0].first)+"-" + std::to_string(req.ranges[0].first+524288ul-1) + "/"+std::to_string(range_len));
|
||||
}
|
||||
std::pair<ssize_t, ssize_t> range = req.ranges[0];
|
||||
res.set_content_provider(
|
||||
@@ -1087,9 +1087,9 @@ namespace HttpServer
|
||||
size_t range_len = (req.ranges[0].second - req.ranges[0].first) + 1;
|
||||
if (req.ranges[0].second >= 18000000000000000000ul)
|
||||
{
|
||||
range_len = 524288ul - req.ranges[0].first;
|
||||
range_len = 524288ul;
|
||||
res.set_header("Content-Length", std::to_string(range_len));
|
||||
res.set_header("Content-Range", std::string("bytes ") + std::to_string(req.ranges[0].first)+"-524288/"+std::to_string(range_len));
|
||||
res.set_header("Content-Range", std::string("bytes ") + std::to_string(req.ranges[0].first)+"-" + std::to_string(req.ranges[0].first+524288ul-1) + "/"+std::to_string(range_len));
|
||||
}
|
||||
std::pair<ssize_t, ssize_t> range = req.ranges[0];
|
||||
res.set_content_provider(
|
||||
@@ -1148,10 +1148,20 @@ namespace HttpServer
|
||||
}
|
||||
|
||||
std::string hash = Util::UrlHash(filehost->GetUrl());
|
||||
snprintf(activity_message, 1023, "%s %s", lang_strings[STR_INSTALLING], filehost->GetUrl().c_str());
|
||||
activity_inprogess = true;
|
||||
file_transfering = true;
|
||||
bytes_to_download = 100;
|
||||
bytes_transfered = 0;
|
||||
Windows::SetModalMode(true);
|
||||
|
||||
std::string download_url = filehost->GetDownloadUrl();
|
||||
if (download_url.empty())
|
||||
{
|
||||
failed(res, 200, lang_strings[STR_CANT_EXTRACT_URL_MSG]);
|
||||
activity_inprogess = false;
|
||||
file_transfering = false;
|
||||
Windows::SetModalMode(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1174,10 +1184,13 @@ namespace HttpServer
|
||||
delete(baseclient);
|
||||
|
||||
std::string remote_install_url = std::string("http://localhost:") + std::to_string(http_server_port) + "/rmt_inst/Site%2099/" + hash;
|
||||
int rc = INSTALLER::InstallRemotePkg(remote_install_url, &header, title);
|
||||
int rc = INSTALLER::InstallRemotePkg(remote_install_url, &header, title, false);
|
||||
if (rc == 0)
|
||||
{
|
||||
failed(res, 200, lang_strings[STR_FAIL_INSTALL_FROM_URL_MSG]);
|
||||
activity_inprogess = false;
|
||||
file_transfering = false;
|
||||
Windows::SetModalMode(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1203,12 +1216,18 @@ namespace HttpServer
|
||||
if (ret == 0)
|
||||
{
|
||||
failed(res, 200, lang_strings[STR_FAIL_INSTALL_FROM_URL_MSG]);
|
||||
activity_inprogess = false;
|
||||
file_transfering = false;
|
||||
Windows::SetModalMode(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
failed(res, 200, lang_strings[STR_FAIL_INSTALL_FROM_URL_MSG]);
|
||||
activity_inprogess = false;
|
||||
file_transfering = false;
|
||||
Windows::SetModalMode(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include "http/httplib.h"
|
||||
|
||||
#include "callback.hpp"
|
||||
|
||||
using namespace httplib;
|
||||
|
||||
namespace Web
|
||||
{
|
||||
namespace Callback
|
||||
{
|
||||
namespace Read
|
||||
{
|
||||
size_t stream(char* ptr, size_t item_size, size_t item_count, void* stream)
|
||||
{
|
||||
auto in_stream = reinterpret_cast<std::istream*>(stream);
|
||||
auto read_bytes = static_cast<unsigned long long>(item_size * item_count);
|
||||
auto position = static_cast<unsigned long long>(in_stream->tellg());
|
||||
in_stream->seekg(0, std::ios::end);
|
||||
auto size = static_cast<unsigned long long>(in_stream->tellg());
|
||||
in_stream->seekg(position, std::ios::beg);
|
||||
auto rest_bytes = size - position;
|
||||
read_bytes = std::min<unsigned long long>(read_bytes, rest_bytes);
|
||||
in_stream->read(ptr, read_bytes);
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
size_t buffer(char* ptr, size_t item_size, size_t item_count, void* buffer)
|
||||
{
|
||||
auto data = (Data*)buffer;
|
||||
auto size = static_cast<unsigned long long>(item_size * item_count);
|
||||
auto rest_bytes = data->size - data->position;
|
||||
auto copied_bytes = std::min<unsigned long long>(size, rest_bytes);
|
||||
memcpy(ptr, data->buffer, copied_bytes);
|
||||
data->position += copied_bytes;
|
||||
return copied_bytes;
|
||||
}
|
||||
} // namespace Read
|
||||
|
||||
namespace Write
|
||||
{
|
||||
size_t stream(char* ptr, size_t item_size, size_t item_count, void* stream)
|
||||
{
|
||||
auto out_stream = reinterpret_cast<std::ostream*>(stream);
|
||||
size_t write_bytes = item_size * item_count;
|
||||
out_stream->write(ptr, write_bytes);
|
||||
return write_bytes;
|
||||
}
|
||||
|
||||
size_t buffer(char* ptr, size_t item_size, size_t item_count, void* buffer)
|
||||
{
|
||||
auto data = reinterpret_cast<Data*>(buffer);
|
||||
auto size = static_cast<unsigned long long>(item_size * item_count);
|
||||
auto rest_bytes = data->size - data->position;
|
||||
auto copied_bytes = std::min<unsigned long long>(size, rest_bytes);
|
||||
memcpy(data->buffer, ptr, copied_bytes);
|
||||
data->position += copied_bytes;
|
||||
return copied_bytes;
|
||||
}
|
||||
} // namespace Write
|
||||
|
||||
namespace Append
|
||||
{
|
||||
size_t buffer(char* ptr, size_t item_size, size_t item_count, void* buffer)
|
||||
{
|
||||
auto data = reinterpret_cast<Data*>(buffer);
|
||||
auto append_size = item_size * item_count;
|
||||
auto new_buffer_size = data->size + append_size;
|
||||
auto new_buffer = new char[new_buffer_size];
|
||||
if (data->size != 0) memcpy(new_buffer, data->buffer, data->size);
|
||||
memcpy(new_buffer + data->size, ptr, append_size);
|
||||
delete[] data->buffer;
|
||||
data->buffer = new_buffer;
|
||||
data->size = new_buffer_size;
|
||||
return append_size;
|
||||
}
|
||||
|
||||
size_t stream(char* ptr, size_t item_size, size_t item_count, void* stream)
|
||||
{
|
||||
auto out_stream = reinterpret_cast<std::ostream*>(stream);
|
||||
size_t write_bytes = item_size * item_count;
|
||||
out_stream->seekp(0, std::ios::end);
|
||||
out_stream->write(ptr, write_bytes);
|
||||
return write_bytes;
|
||||
}
|
||||
|
||||
size_t stream2sink(char* ptr, size_t item_size, size_t item_count, void* sink)
|
||||
{
|
||||
auto ostream = reinterpret_cast<DataSink*>(sink);
|
||||
size_t write_bytes = item_size * item_count;
|
||||
ostream->write(ptr, write_bytes);
|
||||
return write_bytes;
|
||||
}
|
||||
} // namespace Append
|
||||
} // namespace Callback
|
||||
} // namespace Web
|
||||
@@ -1,68 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#ifndef WEB_CALLBACK_HPP
|
||||
#define WEB_CALLBACK_HPP
|
||||
|
||||
namespace Web
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
char* buffer;
|
||||
unsigned long long position;
|
||||
unsigned long long size;
|
||||
void reset()
|
||||
{
|
||||
buffer = nullptr;
|
||||
position = 0;
|
||||
size = 0;
|
||||
}
|
||||
~Data()
|
||||
{
|
||||
delete[] buffer;
|
||||
}
|
||||
};
|
||||
|
||||
namespace Callback
|
||||
{
|
||||
namespace Read
|
||||
{
|
||||
size_t stream(char* data, size_t size, size_t count, void* stream);
|
||||
size_t buffer(char* data, size_t size, size_t count, void* buffer);
|
||||
}
|
||||
|
||||
namespace Write
|
||||
{
|
||||
size_t stream(char* data, size_t size, size_t count, void* stream);
|
||||
size_t buffer(char* data, size_t size, size_t count, void* buffer);
|
||||
}
|
||||
|
||||
namespace Append
|
||||
{
|
||||
size_t stream(char* data, size_t size, size_t count, void* stream);
|
||||
size_t buffer(char* data, size_t size, size_t count, void* buffer);
|
||||
size_t stream2sink(char* ptr, size_t item_size, size_t item_count, void* sink);
|
||||
}
|
||||
}
|
||||
} // namespace Web
|
||||
|
||||
#endif
|
||||
@@ -1,42 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#include "fsinfo.hpp"
|
||||
#include <fstream>
|
||||
|
||||
namespace Web
|
||||
{
|
||||
namespace FileInfo
|
||||
{
|
||||
auto exists(const std::string& path) -> bool
|
||||
{
|
||||
std::ifstream file(path);
|
||||
return file.good();
|
||||
}
|
||||
|
||||
auto size(const std::string& path_file) -> unsigned long long
|
||||
{
|
||||
std::ifstream file(path_file, std::ios::binary | std::ios::ate);
|
||||
return static_cast<unsigned long long>(file.tellg());
|
||||
}
|
||||
} // namespace FileInfo
|
||||
} // namespace Web
|
||||
@@ -1,38 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#ifndef WEB_FSINFO_HPP
|
||||
#define WEB_FSINFO_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace Web
|
||||
{
|
||||
namespace FileInfo
|
||||
{
|
||||
auto exists(const std::string& path) -> bool;
|
||||
auto size(const std::string& path_file) -> unsigned long long;
|
||||
} // namespace FileInfo
|
||||
} // namespace Web
|
||||
|
||||
#endif
|
||||
@@ -1,69 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#include "header.hpp"
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace Web
|
||||
{
|
||||
Header::Header(const std::initializer_list<std::string>& init_list) noexcept : handle(nullptr)
|
||||
{
|
||||
for (auto& item : init_list)
|
||||
{
|
||||
this->append(item);
|
||||
}
|
||||
}
|
||||
|
||||
Header::~Header() noexcept
|
||||
{
|
||||
curl_slist_free_all(reinterpret_cast<curl_slist*>(this->handle));
|
||||
}
|
||||
|
||||
Header::Header(Header&& other) noexcept
|
||||
{
|
||||
handle = other.handle;
|
||||
other.handle = nullptr;
|
||||
}
|
||||
|
||||
auto Header::operator=(Header&& other) noexcept -> Header&
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
Header(std::move(other)).swap(*this);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
auto Header::swap(Header& other) noexcept -> void
|
||||
{
|
||||
using std::swap;
|
||||
swap(handle, other.handle);
|
||||
}
|
||||
|
||||
void
|
||||
Header::append(const std::string& item) noexcept
|
||||
{
|
||||
this->handle = curl_slist_append(reinterpret_cast<curl_slist*>(this->handle), item.c_str());
|
||||
}
|
||||
} // namespace Web
|
||||
@@ -1,51 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#ifndef WEB_HEADER_HPP
|
||||
#define WEB_HEADER_HPP
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
namespace Web
|
||||
{
|
||||
class Header final
|
||||
{
|
||||
public:
|
||||
void* handle;
|
||||
|
||||
Header(const std::initializer_list<std::string>& init_list) noexcept;
|
||||
Header(const Header& other) = delete;
|
||||
Header(Header&& other) noexcept;
|
||||
~Header() noexcept;
|
||||
|
||||
auto operator=(const Header& other) -> Header& = delete;
|
||||
auto operator=(Header&& other) noexcept -> Header&;
|
||||
|
||||
void append(const std::string& item) noexcept;
|
||||
|
||||
private:
|
||||
auto swap(Header& other) noexcept -> void;
|
||||
};
|
||||
} // namespace Web
|
||||
|
||||
#endif
|
||||
@@ -1,227 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#include "request.hpp"
|
||||
#include "fsinfo.hpp"
|
||||
#include "util.h"
|
||||
|
||||
namespace Web
|
||||
{
|
||||
static int sockopt_callback(void *clientp, curl_socket_t curlfd, curlsocktype purpose)
|
||||
{
|
||||
int const size = 1048576;
|
||||
if (setsockopt(curlfd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) == -1)
|
||||
{
|
||||
return CURL_SOCKOPT_ERROR;
|
||||
}
|
||||
if (setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) == -1)
|
||||
{
|
||||
return CURL_SOCKOPT_ERROR;
|
||||
}
|
||||
|
||||
return CURL_SOCKOPT_OK;
|
||||
}
|
||||
|
||||
auto inline get(const dict_t &options, const std::string &&name) -> std::string
|
||||
{
|
||||
auto it = options.find(name);
|
||||
if (it == options.end())
|
||||
{
|
||||
return std::string{""};
|
||||
}
|
||||
else
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
Request::Request(dict_t &&options_) : options(options_)
|
||||
{
|
||||
auto hostname = get(options, "hostname");
|
||||
auto username = get(options, "username");
|
||||
auto password = get(options, "password");
|
||||
auto timeout = get(options, "password");
|
||||
|
||||
auto proxy_hostname = get(options, "proxy_hostname");
|
||||
auto proxy_username = get(options, "proxy_username");
|
||||
auto proxy_password = get(options, "proxy_password");
|
||||
|
||||
auto cert_path = get(options, "cert_path");
|
||||
auto key_path = get(options, "key_path");
|
||||
|
||||
this->handle = curl_easy_init();
|
||||
|
||||
this->set(CURLOPT_SSL_VERIFYHOST, 0);
|
||||
this->set(CURLOPT_SSL_VERIFYPEER, 0);
|
||||
|
||||
#ifdef _DEBUG
|
||||
this->set(CURLOPT_VERBOSE, 1);
|
||||
#else
|
||||
this->set(CURLOPT_VERBOSE, 0);
|
||||
#endif
|
||||
if (this->cert_required())
|
||||
{
|
||||
this->set(CURLOPT_SSLCERTTYPE, "PEM");
|
||||
this->set(CURLOPT_SSLKEYTYPE, "PEM");
|
||||
this->set(CURLOPT_SSLCERT, const_cast<char *>(cert_path.c_str()));
|
||||
this->set(CURLOPT_SSLKEY, const_cast<char *>(key_path.c_str()));
|
||||
}
|
||||
|
||||
this->set(CURLOPT_URL, const_cast<char *>(hostname.c_str()));
|
||||
if (!username.empty())
|
||||
{
|
||||
this->set(CURLOPT_HTTPAUTH, static_cast<int>(CURLAUTH_BASIC));
|
||||
auto token = username + ":" + password;
|
||||
this->set(CURLOPT_USERPWD, const_cast<char *>(token.c_str()));
|
||||
}
|
||||
this->set(CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
|
||||
this->set(CURLOPT_FOLLOWLOCATION, 1);
|
||||
this->set(CURLOPT_COOKIEJAR, "/data/ps4-webdav-client/cookies.txt");
|
||||
this->set(CURLOPT_COOKIEFILE, "/data/ps4-webdav-client/cookies.txt");
|
||||
if (timeout.empty())
|
||||
{
|
||||
this->set(CURLOPT_CONNECTTIMEOUT, 15L);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->set(CURLOPT_CONNECTTIMEOUT, atoi(timeout.c_str()));
|
||||
}
|
||||
|
||||
if (!this->proxy_enabled())
|
||||
return;
|
||||
|
||||
this->set(CURLOPT_PROXY, const_cast<char *>(proxy_hostname.c_str()));
|
||||
this->set(CURLOPT_PROXYAUTH, static_cast<int>(CURLAUTH_BASIC));
|
||||
|
||||
if (proxy_username.empty())
|
||||
return;
|
||||
|
||||
if (proxy_password.empty())
|
||||
{
|
||||
this->set(CURLOPT_PROXYUSERNAME, const_cast<char *>(proxy_username.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!username.empty() && !password.empty())
|
||||
{
|
||||
auto token = proxy_username + ":" + proxy_password;
|
||||
this->set(CURLOPT_PROXYUSERPWD, const_cast<char *>(token.c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Request::~Request() noexcept
|
||||
{
|
||||
if (this->handle != nullptr)
|
||||
curl_easy_cleanup(this->handle);
|
||||
}
|
||||
|
||||
auto Request::swap(Request &other) noexcept -> void
|
||||
{
|
||||
using std::swap;
|
||||
swap(handle, other.handle);
|
||||
}
|
||||
|
||||
Request::Request(Request &&other) noexcept : handle{
|
||||
other.handle}
|
||||
{
|
||||
other.handle = nullptr;
|
||||
}
|
||||
|
||||
auto Request::operator=(Request &&other) noexcept -> Request &
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
Request(std::move(other)).swap(*this);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Request::perform() noexcept
|
||||
{
|
||||
if (this->handle == nullptr)
|
||||
return false;
|
||||
this->res = curl_easy_perform(this->handle);
|
||||
auto is_performed = this->res == CURLE_OK;
|
||||
if (!is_performed)
|
||||
return false;
|
||||
this->http_code = 0;
|
||||
curl_easy_getinfo(this->handle, CURLINFO_RESPONSE_CODE, &this->http_code);
|
||||
if (this->http_code < 200 || this->http_code > 299)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Request::proxy_enabled() const noexcept
|
||||
{
|
||||
auto proxy_hostname = get(options, "proxy_hostname");
|
||||
auto proxy_username = get(options, "proxy_username");
|
||||
auto proxy_password = get(options, "proxy_password");
|
||||
bool proxy_hostname_presented = !proxy_hostname.empty();
|
||||
if (!proxy_hostname_presented)
|
||||
return false;
|
||||
bool proxy_username_presented = !proxy_username.empty();
|
||||
bool proxy_password_presented = !proxy_password.empty();
|
||||
if (proxy_password_presented && !proxy_username_presented)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Request::cert_required() const noexcept
|
||||
{
|
||||
const auto cert_path = get(options, "cert_path");
|
||||
const auto key_path = get(options, "key_path");
|
||||
if (cert_path.empty())
|
||||
return false;
|
||||
bool cert_is_existed = FileInfo::exists(cert_path);
|
||||
if (!cert_is_existed)
|
||||
return false;
|
||||
if (key_path.empty())
|
||||
return false;
|
||||
return FileInfo::exists(key_path);
|
||||
}
|
||||
|
||||
long Request::status_code() const noexcept
|
||||
{
|
||||
return this->http_code;
|
||||
}
|
||||
|
||||
int Request::result() const noexcept
|
||||
{
|
||||
return this->res;
|
||||
}
|
||||
|
||||
class Environment
|
||||
{
|
||||
public:
|
||||
Environment()
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
}
|
||||
~Environment()
|
||||
{
|
||||
curl_global_cleanup();
|
||||
}
|
||||
};
|
||||
} // namespace Web
|
||||
|
||||
static const Web::Environment env;
|
||||
@@ -1,74 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#ifndef WEB_REQUEST_HPP
|
||||
#define WEB_REQUEST_HPP
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace Web
|
||||
{
|
||||
bool inline check_code(CURLcode code)
|
||||
{
|
||||
return code == CURLE_OK;
|
||||
}
|
||||
|
||||
using dict_t = std::map<std::string, std::string>;
|
||||
|
||||
class Request
|
||||
{
|
||||
public:
|
||||
explicit Request(dict_t &&options_);
|
||||
Request(const Request &other) = delete;
|
||||
Request(Request &&other) noexcept;
|
||||
~Request() noexcept;
|
||||
|
||||
auto operator=(const Request &other) -> Request & = delete;
|
||||
auto operator=(Request &&other) noexcept -> Request &;
|
||||
|
||||
template <typename T>
|
||||
auto set(CURLoption option, T value) const noexcept -> bool
|
||||
{
|
||||
if (this->handle == nullptr)
|
||||
return false;
|
||||
return check_code(curl_easy_setopt(this->handle, option, value));
|
||||
}
|
||||
|
||||
bool perform() noexcept;
|
||||
long status_code() const noexcept;
|
||||
int result() const noexcept;
|
||||
void *handle;
|
||||
|
||||
private:
|
||||
const dict_t options;
|
||||
dict_t response_header = {};
|
||||
long http_code;
|
||||
int res;
|
||||
bool proxy_enabled() const noexcept;
|
||||
bool cert_required() const noexcept;
|
||||
auto swap(Request &other) noexcept -> void;
|
||||
};
|
||||
} // namespace Web
|
||||
|
||||
#endif
|
||||
@@ -1,262 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
#include "urn.hpp"
|
||||
|
||||
namespace Web
|
||||
{
|
||||
namespace Urn
|
||||
{
|
||||
|
||||
const string Path::separate = "/";
|
||||
const string Path::root = "/";
|
||||
const string Path::param_separate = "&";
|
||||
const string Path::query_separate = "?";
|
||||
|
||||
string encodeUrl(const string &url, void *request)
|
||||
{
|
||||
size_t scheme_pos = url.find("://");
|
||||
size_t root_pos = url.find("/", scheme_pos+3);
|
||||
if (root_pos == string::npos)
|
||||
return url;
|
||||
|
||||
string uri = url.substr(root_pos);
|
||||
auto path = Path(uri);
|
||||
return url.substr(0, root_pos) + path.quote(request);
|
||||
}
|
||||
|
||||
Path::Path(const string& path_, bool force_dir)
|
||||
{
|
||||
string path = path_;
|
||||
if (path_.empty()) path = Path::root;
|
||||
auto first_position = path.find(Path::separate);
|
||||
if (first_position != 0) path = Path::root + path;
|
||||
|
||||
auto last_symbol_index = path.length() - 1;
|
||||
auto last_symbol = path.substr(last_symbol_index, 1);
|
||||
auto is_dir = last_symbol == Path::separate;
|
||||
|
||||
if (force_dir && !is_dir) path += Path::separate;
|
||||
m_path = path;
|
||||
auto double_separte = Path::separate + Path::separate;
|
||||
bool is_find = false;
|
||||
do
|
||||
{
|
||||
auto first_position = m_path.find(double_separte);
|
||||
is_find = first_position != m_path.npos;
|
||||
if (is_find)
|
||||
{
|
||||
m_path.replace(first_position, double_separte.size(), Path::separate);
|
||||
}
|
||||
}
|
||||
while (is_find);
|
||||
}
|
||||
|
||||
Path::Path(std::nullptr_t)
|
||||
{
|
||||
m_path = nullptr;
|
||||
}
|
||||
|
||||
auto Path::path() const -> string
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
auto escape(void* request, const string& name) -> string
|
||||
{
|
||||
string path = curl_easy_escape(request, name.c_str(), static_cast<int>(name.length()));
|
||||
return path;
|
||||
}
|
||||
|
||||
auto split(const string& text, const string& delims) -> vector<string>
|
||||
{
|
||||
vector<string> tokens;
|
||||
auto start = text.find_first_not_of(delims);
|
||||
auto end = text.npos;
|
||||
|
||||
while ((end = text.find_first_of(delims, start)) != text.npos)
|
||||
{
|
||||
tokens.push_back(text.substr(start, end - start));
|
||||
start = text.find_first_not_of(delims, end);
|
||||
}
|
||||
if (start != text.npos)
|
||||
{
|
||||
tokens.push_back(text.substr(start));
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
auto Path::quote(void* request) const -> string
|
||||
{
|
||||
if (this->is_root()) return m_path;
|
||||
|
||||
size_t query_pos = m_path.find_first_of(Path::query_separate);
|
||||
string query;
|
||||
string path;
|
||||
if (query_pos != string::npos)
|
||||
{
|
||||
query = m_path.substr(query_pos+1);
|
||||
path = m_path.substr(0, query_pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = m_path;
|
||||
}
|
||||
auto names = split(path, Path::separate);
|
||||
string quote_path;
|
||||
|
||||
std::for_each(names.begin(), names.end(), ["e_path, request](string & name)
|
||||
{
|
||||
auto escape_name = escape(request, name);
|
||||
quote_path.append(Path::separate);
|
||||
quote_path.append(escape_name);
|
||||
});
|
||||
|
||||
if (is_directory())
|
||||
{
|
||||
quote_path.append(Path::separate);
|
||||
}
|
||||
|
||||
if (query.length()>0)
|
||||
{
|
||||
auto params = split(query, Path::param_separate);
|
||||
if (params.size() > 0)
|
||||
quote_path.append(Path::query_separate);
|
||||
std::for_each(params.begin(), params.end(), ["e_path, request](string & param)
|
||||
{
|
||||
auto param_pair = split(param, "=");
|
||||
if (param_pair.size() == 0)
|
||||
{
|
||||
quote_path.append(Path::param_separate);
|
||||
}
|
||||
else
|
||||
{
|
||||
quote_path.append(escape(request, param_pair[0]));
|
||||
quote_path.append("=");
|
||||
if (param_pair.size() > 1)
|
||||
{
|
||||
quote_path.append(escape(request, param_pair[1]));
|
||||
}
|
||||
quote_path.append(Path::param_separate);
|
||||
}
|
||||
});
|
||||
quote_path.pop_back();
|
||||
}
|
||||
return quote_path;
|
||||
}
|
||||
|
||||
auto Path::name() const -> string
|
||||
{
|
||||
auto path = this->path();
|
||||
auto is_root = path == Path::separate;
|
||||
if (is_root) return string{""};
|
||||
|
||||
if (this->is_directory())
|
||||
{
|
||||
auto path_without_slash = path.substr(0, path.length() - 1);
|
||||
auto pre_last_separate_position = path_without_slash.rfind(Path::separate);
|
||||
auto name = path.substr(pre_last_separate_position + 1);
|
||||
return name;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto last_separate_position = path.rfind(Path::separate);
|
||||
auto name = path.substr(last_separate_position + 1);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
auto Path::parent() const -> Path
|
||||
{
|
||||
if (this->is_root()) return Path{m_path};
|
||||
|
||||
auto last_separate_position = m_path.rfind(Path::separate, m_path.length() - 2);
|
||||
if (last_separate_position == 0) return Path{Path::separate};
|
||||
|
||||
auto parent = m_path.substr(0, last_separate_position + 1);
|
||||
return Path{parent};
|
||||
}
|
||||
|
||||
auto Path::is_directory() const -> bool
|
||||
{
|
||||
auto path = this->path();
|
||||
auto last_symbol_index = path.length() - 1;
|
||||
auto last_symbol = path.substr(last_symbol_index, 1);
|
||||
auto is_equal = last_symbol == Path::separate;
|
||||
return is_equal;
|
||||
}
|
||||
|
||||
auto Path::is_root() const -> bool
|
||||
{
|
||||
return m_path == Path::separate;
|
||||
}
|
||||
|
||||
auto Path::operator+(const string& rhs) const -> Path
|
||||
{
|
||||
return Path{ m_path + rhs };
|
||||
}
|
||||
|
||||
auto Path::operator==(const Path& rhs) const -> bool
|
||||
{
|
||||
if (this->is_root() && rhs.is_root()) return true;
|
||||
if (!this->is_root() && rhs.is_root()) return false;
|
||||
|
||||
string lhs_path;
|
||||
bool is_dir = is_directory();
|
||||
if (is_dir)
|
||||
{
|
||||
lhs_path = m_path.substr(0, m_path.length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs_path = m_path;
|
||||
}
|
||||
string rhs_path;
|
||||
if (rhs.is_directory())
|
||||
{
|
||||
rhs_path = rhs.path();
|
||||
rhs_path = rhs_path.substr(0, rhs_path.length() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
rhs_path = rhs.path();
|
||||
}
|
||||
return lhs_path == rhs_path;
|
||||
}
|
||||
} // namespace Urn
|
||||
} // namespace Web
|
||||
|
||||
auto operator<<(std::ostream& stream, const Web::Urn::Path& path) -> std::ostream&
|
||||
{
|
||||
return stream << path.path();
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#ifndef WEB_URN_HPP
|
||||
#define WEB_URN_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace Web
|
||||
{
|
||||
namespace Urn
|
||||
{
|
||||
using std::string;
|
||||
using std::nullptr_t;
|
||||
|
||||
string encodeUrl(const string &url, void *request);
|
||||
|
||||
class Path
|
||||
{
|
||||
public:
|
||||
|
||||
explicit Path(const string& path_, bool force_dir = false);
|
||||
explicit Path(nullptr_t);
|
||||
|
||||
auto operator+(const std::string& rhs) const -> Path;
|
||||
auto operator==(const Path& rhs) const -> bool;
|
||||
|
||||
auto is_directory() const -> bool;
|
||||
auto is_root() const -> bool;
|
||||
auto name() const -> string;
|
||||
auto parent() const -> Path;
|
||||
auto path() const -> string;
|
||||
auto quote(void* request) const -> string;
|
||||
|
||||
private:
|
||||
|
||||
string m_path;
|
||||
|
||||
static const string separate;
|
||||
static const string root;
|
||||
static const string param_separate;
|
||||
static const string query_separate;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
auto operator<<(std::ostream& stream, const Web::Urn::Path& path) -> std::ostream&;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,419 +0,0 @@
|
||||
/*#***************************************************************************
|
||||
# __ __ _____ _____
|
||||
# Project | | | | | \ / ___|
|
||||
# | |__| | | |\ \ / /
|
||||
# | | | | ) ) ( (
|
||||
# | /\ | | |/ / \ \___
|
||||
# \_/ \_/ |_____/ \_____|
|
||||
#
|
||||
# Copyright (C) 2018, The WDC Project, <rusdevops@gmail.com>, et al.
|
||||
#
|
||||
# This software is licensed as described in the file LICENSE, which
|
||||
# you should have received as part of this distribution.
|
||||
#
|
||||
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
# copies of the Software, and permit persons to whom the Software is
|
||||
# furnished to do so, under the terms of the LICENSE file.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
############################################################################*/
|
||||
|
||||
#ifndef WEBDAV_CLIENT_HPP
|
||||
#define WEBDAV_CLIENT_HPP
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <curl/curl.h>
|
||||
#include "http/httplib.h"
|
||||
|
||||
using namespace httplib;
|
||||
|
||||
namespace WebDAV
|
||||
{
|
||||
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 strings_t = std::vector<std::string>;
|
||||
using dict_t = std::map<std::string, std::string>;
|
||||
using dict_items_t = std::vector<dict_t>;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
///
|
||||
/// \brief WebDAV Client
|
||||
/// \author designerror
|
||||
/// \version 1.1.4
|
||||
/// \date 3/16/2018
|
||||
///
|
||||
class Client
|
||||
{
|
||||
public:
|
||||
|
||||
///
|
||||
/// \param[in] webdav_hostname
|
||||
/// \param[in] webdav_root
|
||||
/// \param[in] webdav_username
|
||||
/// \param[in] webdav_password
|
||||
/// \param[in] proxy_hostname
|
||||
/// \param[in] proxy_username
|
||||
/// \param[in] proxy_password
|
||||
/// \param[in] cert_path
|
||||
/// \param[in] key_path
|
||||
/// \include client/init.cpp
|
||||
///
|
||||
explicit Client(const dict_t& options);
|
||||
|
||||
///
|
||||
/// Get free size of the WebDAV server
|
||||
/// \return size in bytes
|
||||
/// \include client/size.cpp
|
||||
///
|
||||
auto free_size() -> unsigned long long;
|
||||
|
||||
///
|
||||
/// Check for existence of a remote resource
|
||||
/// \param[in] remote_resource
|
||||
/// \include client/check.cpp
|
||||
///
|
||||
auto check(const std::string& remote_resource = "/") -> bool;
|
||||
|
||||
///
|
||||
/// Get information of a remote resource
|
||||
/// \param[in] remote_resource
|
||||
/// \include client/info.cpp
|
||||
///
|
||||
auto info(const std::string& remote_resource) -> dict_t;
|
||||
|
||||
///
|
||||
/// Get information of a remote resource
|
||||
/// \param[in] remote_resource
|
||||
/// \include client/info.cpp
|
||||
///
|
||||
auto head(const std::string& remote_resource, dict_t *headers) -> bool;
|
||||
|
||||
///
|
||||
/// Clean an remote resource
|
||||
/// \param[in] remote_resource
|
||||
/// \include client/clean.cpp
|
||||
///
|
||||
auto clean(const std::string& remote_resource) -> bool;
|
||||
|
||||
///
|
||||
/// Checks whether the resource directory
|
||||
/// \param[in] remote_resource
|
||||
///
|
||||
auto is_directory(const std::string& remote_resource) -> bool;
|
||||
|
||||
///
|
||||
/// List a remote directory
|
||||
/// \param[in] remote_directory
|
||||
/// \include client/list.cpp
|
||||
///
|
||||
auto list(const std::string& remote_directory = "") -> dict_items_t;
|
||||
|
||||
///
|
||||
/// Create a remote directory
|
||||
/// \param[in] remote_directory
|
||||
/// \param[in] recursive
|
||||
/// \include client/mkdir.cpp
|
||||
///
|
||||
auto create_directory(
|
||||
const std::string& remote_directory,
|
||||
bool recursive = false
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Move a remote resource
|
||||
/// \param[in] remote_source_resource
|
||||
/// \param[in] remote_destination_resource
|
||||
/// \include client/move.cpp
|
||||
///
|
||||
auto move(
|
||||
const std::string& remote_source_resource,
|
||||
const std::string& remote_destination_resource
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Copy a remote resource
|
||||
/// \param[in] remote_source_resource
|
||||
/// \param[in] remote_destination_resource
|
||||
/// \include client/copy.cpp
|
||||
///
|
||||
auto copy(
|
||||
const std::string& remote_source_resource,
|
||||
const std::string& remote_destination_resource
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Download a remote file to a local file
|
||||
/// \param[in] remote_file
|
||||
/// \param[in] local_file
|
||||
/// \param[in] progress
|
||||
/// \snippet client/download.cpp download_to_file
|
||||
///
|
||||
auto download(
|
||||
const std::string& remote_file,
|
||||
const std::string& local_file,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Download a remote file to a buffer
|
||||
/// \param[in] remote_file
|
||||
/// \param[out] buffer_ptr
|
||||
/// \param[out] buffer_size
|
||||
/// \param[in] progress
|
||||
/// \snippet client/download.cpp download_to_buffer
|
||||
///
|
||||
auto download_to(
|
||||
const std::string& remote_file,
|
||||
char*& buffer_ptr,
|
||||
unsigned long long& buffer_size,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Download a remote file to a buffer for specified range
|
||||
/// \param[in] remote_file
|
||||
/// \param[out] buffer_ptr
|
||||
/// \param[out] buffer_size
|
||||
/// \param[in] range_from,
|
||||
/// \param[in] range_to
|
||||
/// \param[in] progress
|
||||
/// \snippet client/download.cpp download_to_buffer
|
||||
///
|
||||
auto download_range_to(
|
||||
const std::string& remote_file,
|
||||
char*& buffer_ptr,
|
||||
unsigned long long& buffer_size,
|
||||
uint64_t range_from,
|
||||
uint64_t range_to,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Download a remote file to a buffer for specified range
|
||||
/// \param[in] remote_file
|
||||
/// \param[out] sink,
|
||||
/// \param[in] range_from,
|
||||
/// \param[in] range_to
|
||||
/// \param[in] progress
|
||||
/// \snippet client/download.cpp download_to_buffer
|
||||
///
|
||||
auto download_range_to(
|
||||
const std::string &remote_file,
|
||||
DataSink &sink,
|
||||
uint64_t range_from,
|
||||
uint64_t range_to,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Download a remote file to a stream
|
||||
/// \param[in] remote_file
|
||||
/// \param[out] stream
|
||||
/// \param[in] progress
|
||||
/// \snippet client/download.cpp download_to_stream
|
||||
///
|
||||
auto download_to(
|
||||
const std::string& remote_file,
|
||||
std::ostream& stream,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Asynchronously download a remote file to a local file
|
||||
/// \param[in] remote_file
|
||||
/// \param[in] local_file
|
||||
/// \param[in] callback
|
||||
/// \param[in] progress
|
||||
/// \snippet client/download.cpp async_download_to_file
|
||||
///
|
||||
auto async_download(
|
||||
const std::string& remote_file,
|
||||
const std::string& local_file,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> void;
|
||||
|
||||
///
|
||||
/// Upload a remote file from a local file
|
||||
/// \param[in] remote_file
|
||||
/// \param[in] local_file
|
||||
/// \param[in] progress
|
||||
/// \snippet client/upload.cpp upload_from_file
|
||||
///
|
||||
auto upload(
|
||||
const std::string& remote_file,
|
||||
const std::string& local_file,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Upload a remote file from a buffer
|
||||
/// \param[in] remote_file
|
||||
/// \param[in] buffer_ptr
|
||||
/// \param[in] buffer_size
|
||||
/// \param[in] progress
|
||||
/// \snippet client/upload.cpp upload_from_buffer
|
||||
///
|
||||
auto upload_from(
|
||||
const std::string& remote_file,
|
||||
char* buffer_ptr,
|
||||
unsigned long long buffer_size,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Upload a remote file from a stream
|
||||
/// \param[in] remote_file
|
||||
/// \param[in] stream
|
||||
/// \param[in] progress
|
||||
/// \snippet client/upload.cpp upload_from_stream
|
||||
///
|
||||
auto upload_from(
|
||||
const std::string& remote_file,
|
||||
std::istream& stream,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
///
|
||||
/// Asynchronously upload a remote file from a local file
|
||||
/// \param[in] remote_file
|
||||
/// \param[in] local_file
|
||||
/// \param[in] callback
|
||||
/// \param[in] progress
|
||||
/// \snippet client/upload.cpp async_upload_from_file
|
||||
///
|
||||
auto async_upload(
|
||||
const std::string& remote_file,
|
||||
const std::string& local_file,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> void;
|
||||
|
||||
long status_code();
|
||||
|
||||
private:
|
||||
|
||||
auto sync_download(
|
||||
const std::string& remote_file,
|
||||
const std::string& local_file,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
auto sync_download_to(
|
||||
const std::string& remote_file,
|
||||
char*& buffer_ptr,
|
||||
unsigned long long& buffer_size,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
auto sync_download_range_to(
|
||||
const std::string& remote_file,
|
||||
char*& buffer_ptr,
|
||||
unsigned long long& buffer_size,
|
||||
uint64_t range_from,
|
||||
uint64_t range_to,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
auto sync_download_range_to(
|
||||
const std::string &remote_file,
|
||||
DataSink &sink,
|
||||
uint64_t range_from,
|
||||
uint64_t range_to,
|
||||
callback_t callback,
|
||||
progress_data_t progress_data,
|
||||
progress_t progress
|
||||
) -> bool;
|
||||
|
||||
bool sync_download_to(
|
||||
const std::string& remote_file,
|
||||
std::ostream& stream,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
);
|
||||
|
||||
bool sync_upload(
|
||||
const std::string& remote_file,
|
||||
const std::string& local_file,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
);
|
||||
|
||||
auto sync_upload_from(
|
||||
const std::string& remote_file,
|
||||
char* buffer_ptr,
|
||||
unsigned long long buffer_size,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
auto sync_upload_from(
|
||||
const std::string& remote_file,
|
||||
std::istream& stream,
|
||||
callback_t callback = nullptr,
|
||||
progress_data_t progress_data = nullptr,
|
||||
progress_t progress = nullptr
|
||||
) -> bool;
|
||||
|
||||
enum { buffer_size = 1000 * 1000 };
|
||||
|
||||
std::string webdav_hostname;
|
||||
std::string webdav_root;
|
||||
std::string webdav_username;
|
||||
std::string webdav_password;
|
||||
|
||||
std::string proxy_hostname;
|
||||
std::string proxy_username;
|
||||
std::string proxy_password;
|
||||
|
||||
std::string cert_path;
|
||||
std::string key_path;
|
||||
|
||||
dict_t options();
|
||||
|
||||
long http_code;
|
||||
int result;
|
||||
int check_enabled = 0;
|
||||
};
|
||||
} // namespace WebDAV
|
||||
|
||||
#endif
|
||||
+4
-3
@@ -1621,7 +1621,7 @@ namespace Windows
|
||||
ImGui::OpenPopup(lang_strings[STR_SETTINGS]);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(1050, 80));
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(850, 80), ImVec2(850, 650), NULL, NULL);
|
||||
ImGui::SetNextWindowSizeConstraints(ImVec2(850, 80), ImVec2(850, 750), NULL, NULL);
|
||||
if (ImGui::BeginPopupModal(lang_strings[STR_SETTINGS], NULL, ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
char id[192];
|
||||
@@ -2087,7 +2087,7 @@ namespace Windows
|
||||
activity_inprogess = true;
|
||||
sprintf(activity_message, "%s", "");
|
||||
stop_activity = false;
|
||||
file_transfering = false;
|
||||
file_transfering = true;
|
||||
selected_action = ACTION_NONE;
|
||||
Actions::ExtractLocalZips();
|
||||
break;
|
||||
@@ -2096,7 +2096,7 @@ namespace Windows
|
||||
activity_inprogess = true;
|
||||
sprintf(activity_message, "%s", "");
|
||||
stop_activity = false;
|
||||
file_transfering = false;
|
||||
file_transfering = true;
|
||||
selected_action = ACTION_NONE;
|
||||
Actions::ExtractRemoteZips();
|
||||
break;
|
||||
@@ -2182,6 +2182,7 @@ namespace Windows
|
||||
case ACTION_INSTALL_REMOTE_PKG:
|
||||
sprintf(status_message, "%s", "");
|
||||
activity_inprogess = true;
|
||||
file_transfering = true;
|
||||
sprintf(activity_message, "%s", "");
|
||||
stop_activity = false;
|
||||
Actions::InstallRemotePkgs();
|
||||
|
||||
+4
-1
@@ -289,6 +289,7 @@ namespace ZipUtil
|
||||
{
|
||||
ssize_t len;
|
||||
unsigned char *buffer = (unsigned char *) malloc(ARCHIVE_TRANSFER_SIZE);
|
||||
bytes_transfered = 0;
|
||||
|
||||
/* loop over file contents and write to fd */
|
||||
for (int n = 0;; n++)
|
||||
@@ -307,7 +308,8 @@ namespace ZipUtil
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bytes_transfered += len;
|
||||
|
||||
if (write(fd, buffer, len) != len)
|
||||
{
|
||||
sprintf(status_message, "error write('%s')", pathname.c_str());
|
||||
@@ -350,6 +352,7 @@ namespace ZipUtil
|
||||
return;
|
||||
}
|
||||
|
||||
bytes_to_download = archive_entry_size(e);
|
||||
if ((fd = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0777)) < 0)
|
||||
{
|
||||
sprintf(status_message, "error open('%s')", path.c_str());
|
||||
|
||||
Reference in New Issue
Block a user