2014-01-30 03:28:07 +00:00
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2014-12-23 02:20:39 +00:00
|
|
|
#include <iostream>
|
2014-10-31 18:17:52 +00:00
|
|
|
#include <boost/asio.hpp>
|
2014-02-01 13:28:30 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include <boost/filesystem/fstream.hpp>
|
2014-01-30 03:28:07 +00:00
|
|
|
|
2014-02-01 03:09:55 +00:00
|
|
|
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
|
|
|
|
|
2014-01-30 03:28:07 +00:00
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2014-02-01 03:09:55 +00:00
|
|
|
namespace config
|
|
|
|
{
|
|
|
|
extern std::map<std::string, std::string> mapArgs;
|
|
|
|
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
|
|
|
|
void OptionParser(int argc, const char* const argv[]);
|
|
|
|
int GetArg(const std::string& strArg, int nDefault);
|
|
|
|
std::string GetArg(const std::string& strArg, const std::string& strDefault);
|
|
|
|
const char* GetCharArg(const std::string& strArg, const std::string& nDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace filesystem
|
|
|
|
{
|
2014-11-17 20:28:52 +00:00
|
|
|
void SetAppName (const std::string& name);
|
|
|
|
std::string GetAppName ();
|
|
|
|
|
2014-02-01 03:51:58 +00:00
|
|
|
const boost::filesystem::path &GetDataDir();
|
2014-03-13 18:22:32 +00:00
|
|
|
std::string GetFullPath (const std::string& filename);
|
2014-02-01 03:09:55 +00:00
|
|
|
boost::filesystem::path GetDefaultDataDir();
|
|
|
|
boost::filesystem::path GetConfigFile();
|
2015-11-20 12:52:38 +00:00
|
|
|
boost::filesystem::path GetTunnelsConfigFile();
|
2014-02-01 03:09:55 +00:00
|
|
|
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
|
|
|
|
std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
|
2014-12-13 23:35:53 +00:00
|
|
|
boost::filesystem::path GetCertificatesDir();
|
2014-02-01 03:09:55 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 06:22:11 +00:00
|
|
|
namespace http
|
|
|
|
{
|
2014-12-22 21:45:50 +00:00
|
|
|
const char ETAG[] = "ETag";
|
2014-12-24 14:45:25 +00:00
|
|
|
const char IF_NONE_MATCH[] = "If-None-Match";
|
2014-12-22 21:45:50 +00:00
|
|
|
const char IF_MODIFIED_SINCE[] = "If-Modified-Since";
|
|
|
|
const char LAST_MODIFIED[] = "Last-Modified";
|
|
|
|
const char TRANSFER_ENCODING[] = "Transfer-Encoding";
|
|
|
|
|
2014-01-31 06:22:11 +00:00
|
|
|
std::string httpRequest(const std::string& address);
|
2015-02-20 17:21:33 +00:00
|
|
|
std::string GetHttpContent (std::istream& response);
|
2014-12-23 02:20:39 +00:00
|
|
|
void MergeChunkedResponse (std::istream& response, std::ostream& merged);
|
2014-04-17 22:54:15 +00:00
|
|
|
int httpRequestViaI2pProxy(const std::string& address, std::string &content); // return http code
|
2015-02-07 17:34:25 +00:00
|
|
|
std::string urlDecode(const std::string& data);
|
2014-04-17 22:54:15 +00:00
|
|
|
|
2014-01-31 06:22:11 +00:00
|
|
|
struct url {
|
|
|
|
url(const std::string& url_s); // omitted copy, ==, accessors, ...
|
|
|
|
private:
|
|
|
|
void parse(const std::string& url_s);
|
|
|
|
public:
|
2014-04-06 20:18:55 +00:00
|
|
|
std::string protocol_, host_, path_, query_;
|
2014-04-17 20:22:54 +00:00
|
|
|
std::string portstr_;
|
|
|
|
unsigned int port_;
|
|
|
|
std::string user_;
|
|
|
|
std::string pass_;
|
2014-01-31 06:22:11 +00:00
|
|
|
};
|
|
|
|
}
|
2014-10-31 18:17:52 +00:00
|
|
|
|
|
|
|
namespace net
|
|
|
|
{
|
|
|
|
int GetMTU (const boost::asio::ip::address& localAddress);
|
|
|
|
}
|
2014-01-30 03:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|