2023-08-02 14:36:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <optional>
|
|
|
|
#include <ctime>
|
|
|
|
#include <vector>
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
struct FileEntry
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
time_t last_modified;
|
|
|
|
bool folder;
|
|
|
|
int size;
|
|
|
|
};
|
|
|
|
|
|
|
|
class WebDavClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebDavClient(std::string web_root, std::string local_root);
|
|
|
|
~WebDavClient();
|
|
|
|
/// Configure this instance to use HTTP simple auth
|
|
|
|
void set_basic_auth(std::string username, std::string password);
|
2023-08-07 11:27:37 +02:00
|
|
|
/// Configure the pad state for user confirmation
|
|
|
|
void set_pad_state(PadState *pad);
|
2023-08-02 14:36:47 +02:00
|
|
|
/// Make a directory on the remote server
|
|
|
|
bool mkcol(std::string web_path_rel, std::optional<u64> mtime);
|
|
|
|
/// Push a file to the remote WebDAV collection
|
|
|
|
bool push(std::string path, std::string web_path_rel);
|
|
|
|
/// Pull a file from remote WebDAV collection
|
|
|
|
bool pull(std::string path, std::string web_path_rel);
|
|
|
|
/// Get a list of remote files
|
|
|
|
std::optional<std::vector<FileEntry>> get_remote_files();
|
|
|
|
/// compare the local file with the remote file specified by web_path_rel
|
|
|
|
/// if local is newer, upload. if remote newer, pull and overwrite
|
|
|
|
/// the remote path will be appended to web_root
|
|
|
|
bool compareAndUpdate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CURL *curl;
|
2023-08-07 11:27:37 +02:00
|
|
|
PadState *pad;
|
2023-08-02 14:36:47 +02:00
|
|
|
std::string web_root; // Base URL
|
|
|
|
std::string local_root;
|
|
|
|
bool use_basic_auth;
|
|
|
|
std::string username;
|
|
|
|
std::string password;
|
|
|
|
void reset();
|
2023-08-07 11:27:37 +02:00
|
|
|
bool user_confirm();
|
2023-08-02 14:36:47 +02:00
|
|
|
};
|