|
|
@ -2,8 +2,6 @@ |
|
|
|
#include <sstream> |
|
|
|
#include <sstream> |
|
|
|
#include <openssl/x509.h> |
|
|
|
#include <openssl/x509.h> |
|
|
|
#include <openssl/pem.h> |
|
|
|
#include <openssl/pem.h> |
|
|
|
#include <boost/lexical_cast.hpp> |
|
|
|
|
|
|
|
#include <boost/date_time/local_time/local_time.hpp> |
|
|
|
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp> |
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp> |
|
|
|
#include <boost/property_tree/ini_parser.hpp> |
|
|
|
#include <boost/property_tree/ini_parser.hpp> |
|
|
|
|
|
|
|
|
|
|
@ -16,6 +14,7 @@ |
|
|
|
#include "Crypto.h" |
|
|
|
#include "Crypto.h" |
|
|
|
#include "FS.h" |
|
|
|
#include "FS.h" |
|
|
|
#include "Log.h" |
|
|
|
#include "Log.h" |
|
|
|
|
|
|
|
#include "HTTP.h" |
|
|
|
#include "Config.h" |
|
|
|
#include "Config.h" |
|
|
|
#include "NetDb.h" |
|
|
|
#include "NetDb.h" |
|
|
|
#include "RouterContext.h" |
|
|
|
#include "RouterContext.h" |
|
|
@ -278,24 +277,21 @@ namespace client |
|
|
|
void I2PControlService::SendResponse (std::shared_ptr<ssl_socket> socket, |
|
|
|
void I2PControlService::SendResponse (std::shared_ptr<ssl_socket> socket, |
|
|
|
std::shared_ptr<I2PControlBuffer> buf, std::ostringstream& response, bool isHtml) |
|
|
|
std::shared_ptr<I2PControlBuffer> buf, std::ostringstream& response, bool isHtml) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t len = response.str ().length (), offset = 0; |
|
|
|
std::string out; |
|
|
|
if (isHtml) |
|
|
|
std::size_t len; |
|
|
|
{ |
|
|
|
if (isHtml) { |
|
|
|
std::ostringstream header; |
|
|
|
i2p::http::HTTPRes res; |
|
|
|
header << "HTTP/1.1 200 OK\r\n"; |
|
|
|
res.code = 200; |
|
|
|
header << "Connection: close\r\n"; |
|
|
|
res.add_header("Content-Type", "application/json"); |
|
|
|
header << "Content-Length: " << boost::lexical_cast<std::string>(len) << "\r\n"; |
|
|
|
res.add_header("Connection", "close"); |
|
|
|
header << "Content-Type: application/json\r\n"; |
|
|
|
res.body = response.str(); |
|
|
|
header << "Date: "; |
|
|
|
out = res.to_string(); |
|
|
|
auto facet = new boost::local_time::local_time_facet ("%a, %d %b %Y %H:%M:%S GMT"); |
|
|
|
} else { |
|
|
|
header.imbue(std::locale (header.getloc(), facet)); |
|
|
|
out = response.str(); |
|
|
|
header << boost::posix_time::second_clock::local_time() << "\r\n"; |
|
|
|
} |
|
|
|
header << "\r\n"; |
|
|
|
std::copy(out.begin(), out.end(), buf->begin()); |
|
|
|
offset = header.str ().size (); |
|
|
|
len = out.length(); |
|
|
|
memcpy (buf->data (), header.str ().c_str (), offset); |
|
|
|
boost::asio::async_write (*socket, boost::asio::buffer (buf->data (), len), |
|
|
|
} |
|
|
|
|
|
|
|
memcpy (buf->data () + offset, response.str ().c_str (), len); |
|
|
|
|
|
|
|
boost::asio::async_write (*socket, boost::asio::buffer (buf->data (), offset + len), |
|
|
|
|
|
|
|
boost::asio::transfer_all (), |
|
|
|
boost::asio::transfer_all (), |
|
|
|
std::bind(&I2PControlService::HandleResponseSent, this, |
|
|
|
std::bind(&I2PControlService::HandleResponseSent, this, |
|
|
|
std::placeholders::_1, std::placeholders::_2, socket, buf)); |
|
|
|
std::placeholders::_1, std::placeholders::_2, socket, buf)); |
|
|
@ -322,7 +318,7 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
InsertParam (results, "API", api); |
|
|
|
InsertParam (results, "API", api); |
|
|
|
results << ","; |
|
|
|
results << ","; |
|
|
|
std::string token = boost::lexical_cast<std::string>(i2p::util::GetSecondsSinceEpoch ()); |
|
|
|
std::string token = std::to_string(i2p::util::GetSecondsSinceEpoch ()); |
|
|
|
m_Tokens.insert (token); |
|
|
|
m_Tokens.insert (token); |
|
|
|
InsertParam (results, "Token", token); |
|
|
|
InsertParam (results, "Token", token); |
|
|
|
} |
|
|
|
} |
|
|
|