iw4x-client/src/Utils/WebIO.hpp

106 lines
2.5 KiB
C++
Raw Normal View History

2015-12-30 18:55:08 -05:00
/*
This project is released under the GPL 2.0 license.
Some parts are based on research by Bas Timmer and the OpenSteamworks project.
Please do no evil.
Initial author: (https://github.com/)momo5502
Started: 2015-03-01
Notes:
Small FTP and HTTP utility class using WinAPI
*/
namespace Utils
{
class WebIO
{
public:
typedef std::map<std::string, std::string> Params;
WebIO();
WebIO(std::string useragent);
WebIO(std::string useragent, std::string url);
~WebIO();
void SetURL(std::string url);
void SetCredentials(std::string username, std::string password);
std::string Post(std::string url, WebIO::Params params);
std::string Post(std::string url, std::string body);
std::string Post(WebIO::Params params);
std::string Post(std::string body);
std::string Get(std::string url);
std::string Get();
2016-01-11 18:48:27 -05:00
WebIO* SetTimeout(DWORD mseconds);
2015-12-30 18:55:08 -05:00
// FTP
bool Connect();
void Disconnect(); // Not necessary
bool SetDirectory(std::string directory);
bool SetRelativeDirectory(std::string directory);
bool GetDirectory(std::string &directory);
bool CreateDirectory(std::string directory);
bool DeleteDirectory(std::string directory);
bool RenameDirectory(std::string directory, std::string newDir);
bool ListDirectories(std::string directory, std::vector<std::string> &list);
bool ListFiles(std::string directory, std::vector<std::string> &list);
bool DeleteFile(std::string file);
bool RenameFile(std::string file, std::string newFile);
bool UploadFile(std::string file, std::string localfile);
bool DownloadFile(std::string file, std::string localfile);
bool UploadFileData(std::string file, std::string data);
bool DownloadFileData(std::string file, std::string &data);
private:
enum Command
{
COMMAND_POST,
COMMAND_GET,
};
struct WebURL
{
std::string protocol;
std::string server;
std::string document;
std::string raw;
};
bool m_isFTP;
std::string m_username;
std::string m_password;
WebURL m_sUrl;
HINTERNET m_hSession;
HINTERNET m_hConnect;
HINTERNET m_hFile;
2016-01-11 18:48:27 -05:00
DWORD m_timeout;
2015-12-30 18:55:08 -05:00
std::string BuildPostBody(WebIO::Params params);
bool IsSecuredConnection();
std::string Execute(const char* command, std::string body);
bool ListElements(std::string directory, std::vector<std::string> &list, bool files);
void OpenSession(std::string useragent);
void CloseSession();
bool OpenConnection();
void CloseConnection();
void FormatPath(std::string &path, bool win); /* if (win == true): / -> \\ */
};
}