mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.3 KiB
158 lines
4.3 KiB
11 years ago
|
#ifndef UTIL_H
|
||
|
#define UTIL_H
|
||
|
|
||
|
#include <map>
|
||
|
#include <string>
|
||
10 years ago
|
#include <iostream>
|
||
10 years ago
|
#include <boost/asio.hpp>
|
||
11 years ago
|
#include <boost/filesystem.hpp>
|
||
|
#include <boost/filesystem/fstream.hpp>
|
||
11 years ago
|
|
||
11 years ago
|
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
|
||
|
|
||
11 years ago
|
namespace i2p
|
||
|
{
|
||
|
namespace util
|
||
|
{
|
||
10 years ago
|
namespace config
|
||
|
{
|
||
|
extern std::map<std::string, std::string> mapArgs;
|
||
|
extern std::map<std::string, std::vector<std::string> > mapMultiArgs;
|
||
10 years ago
|
|
||
|
/**
|
||
|
* Parses command line arguments, i.e. stores them in config::mapArgs.
|
||
|
*/
|
||
10 years ago
|
void OptionParser(int argc, const char* const argv[]);
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @return a command line argument from config::mapArgs as an int
|
||
|
* @param nDefault the default value to be returned
|
||
|
*/
|
||
10 years ago
|
int GetArg(const std::string& strArg, int nDefault);
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @return a command line argument from config::mapArgs as a std::string
|
||
|
* @param strDefault the default value to be returned
|
||
|
*/
|
||
10 years ago
|
std::string GetArg(const std::string& strArg, const std::string& strDefault);
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @return a command line argument from config::mapArgs as a C-style string
|
||
|
* @param nDefault the default value to be returned
|
||
|
*/
|
||
10 years ago
|
const char* GetCharArg(const std::string& strArg, const std::string& nDefault);
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
namespace filesystem
|
||
|
{
|
||
10 years ago
|
/**
|
||
|
* Change the application name.
|
||
|
*/
|
||
|
void SetAppName(const std::string& name);
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* @return the application name.
|
||
|
*/
|
||
|
std::string GetAppName();
|
||
|
|
||
|
/**
|
||
|
* @return the path of the i2pd directory
|
||
|
*/
|
||
|
const boost::filesystem::path& GetDataDir();
|
||
|
|
||
|
/**
|
||
|
* @return the full path of a file within the i2pd directory
|
||
|
*/
|
||
|
std::string GetFullPath(const std::string& filename);
|
||
|
|
||
|
/**
|
||
|
* @return the path of the configuration file
|
||
|
*/
|
||
10 years ago
|
boost::filesystem::path GetConfigFile();
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @return the default directory for i2pd data
|
||
|
*/
|
||
|
boost::filesystem::path GetDefaultDataDir();
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Read a configuration file and store its contents in the given maps.
|
||
|
*/
|
||
10 years ago
|
void ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet,
|
||
11 years ago
|
std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @return the path of the certificates directory
|
||
|
*/
|
||
10 years ago
|
boost::filesystem::path GetCertificatesDir();
|
||
|
}
|
||
11 years ago
|
|
||
10 years ago
|
namespace http
|
||
|
{
|
||
|
const char ETAG[] = "ETag";
|
||
|
const char IF_NONE_MATCH[] = "If-None-Match";
|
||
|
const char IF_MODIFIED_SINCE[] = "If-Modified-Since";
|
||
|
const char LAST_MODIFIED[] = "Last-Modified";
|
||
|
const char TRANSFER_ENCODING[] = "Transfer-Encoding";
|
||
10 years ago
|
|
||
10 years ago
|
/**
|
||
|
* Perform an HTTP request.
|
||
|
* @return the result of the request, or an empty string if it fails
|
||
|
*/
|
||
10 years ago
|
std::string httpRequest(const std::string& address);
|
||
10 years ago
|
|
||
|
/**
|
||
|
* @return the content of the given HTTP stream without headers
|
||
|
*/
|
||
|
std::string GetHttpContent(std::istream& response);
|
||
|
|
||
|
/**
|
||
|
* Merge chunks of a HTTP response into the gien std:ostream object.
|
||
|
*/
|
||
|
void MergeChunkedResponse(std::istream& response, std::ostream& merged);
|
||
|
|
||
|
/**
|
||
|
* Send an HTTP request through the i2p proxy.
|
||
|
* @return the HTTP status code
|
||
|
*/
|
||
|
int httpRequestViaI2pProxy(const std::string& address, std::string &content);
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return the decoded url
|
||
|
*/
|
||
10 years ago
|
std::string urlDecode(const std::string& data);
|
||
|
|
||
10 years ago
|
/**
|
||
|
* Provides functionality for parsing URLs.
|
||
|
*/
|
||
10 years ago
|
struct url {
|
||
10 years ago
|
/**
|
||
|
* Parse a url given as a string.
|
||
|
*/
|
||
|
url(const std::string& url_s);
|
||
|
private:
|
||
|
void parse(const std::string& url_s);
|
||
|
public:
|
||
|
std::string protocol_, host_, path_, query_;
|
||
|
std::string portstr_;
|
||
|
unsigned int port_;
|
||
|
std::string user_;
|
||
|
std::string pass_;
|
||
10 years ago
|
};
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
namespace net
|
||
|
{
|
||
10 years ago
|
/**
|
||
|
* @return the maximum transmission unit, or 576 on failure
|
||
|
*/
|
||
|
int GetMTU(const boost::asio::ip::address& localAddress);
|
||
10 years ago
|
}
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#endif
|