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>
|
2016-04-27 16:08:08 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
2014-02-01 03:09:55 +00:00
|
|
|
|
2016-06-14 15:55:44 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
std::string to_string(T value)
|
|
|
|
{
|
|
|
|
return boost::lexical_cast<std::string>(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-30 03:28:07 +00:00
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2016-04-27 16:08:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
wrapper arround boost::lexical_cast that "never" fails
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
T lexical_cast(const std::string & str, const T fallback) {
|
|
|
|
try {
|
|
|
|
return boost::lexical_cast<T>(str);
|
|
|
|
} catch ( ... ) {
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 06:22:11 +00:00
|
|
|
namespace http
|
|
|
|
{
|
2016-02-19 15:04:52 +00:00
|
|
|
// in (lower case)
|
|
|
|
const char ETAG[] = "etag"; // ETag
|
|
|
|
const char LAST_MODIFIED[] = "last-modified"; // Last-Modified
|
|
|
|
const char TRANSFER_ENCODING[] = "transfer-encoding"; // Transfer-Encoding
|
|
|
|
const char CONTENT_ENCODING[] = "content-encoding"; // Content-Encoding
|
|
|
|
// out
|
2014-12-24 14:45:25 +00:00
|
|
|
const char IF_NONE_MATCH[] = "If-None-Match";
|
2016-02-19 15:04:52 +00:00
|
|
|
const char IF_MODIFIED_SINCE[] = "If-Modified-Since";
|
|
|
|
|
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);
|
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);
|
2016-06-29 15:06:51 +00:00
|
|
|
const boost::asio::ip::address GetInterfaceAddress(const std::string & ifname, bool ipv6=false);
|
2014-10-31 18:17:52 +00:00
|
|
|
}
|
2016-07-14 13:23:33 +00:00
|
|
|
|
|
|
|
namespace config
|
|
|
|
{
|
|
|
|
/** get the host to use from out config, for use in RouterContext.cpp */
|
|
|
|
std::string GetHost(bool ipv4=true, bool ipv6=true);
|
|
|
|
}
|
2014-01-30 03:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|