@ -1,7 +1,6 @@
@@ -1,7 +1,6 @@
# include <ctime>
# include <iomanip>
# include <boost/bind.hpp>
# include <boost/lexical_cast.hpp>
# include <boost/date_time/posix_time/posix_time.hpp>
# include "Base.h"
# include "FS.h"
@ -24,7 +23,6 @@ namespace i2p
@@ -24,7 +23,6 @@ namespace i2p
{
namespace util
{
const std : : string HTTPConnection : : itoopieImage =
" <img alt= \" ICToopie Icon \" src= \" data:image/png;base64, "
" iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXM "
@ -205,7 +203,6 @@ namespace util
@@ -205,7 +203,6 @@ namespace util
const char HTTP_COMMAND_I2P_TUNNELS [ ] = " i2p_tunnels " ;
const char HTTP_COMMAND_JUMPSERVICES [ ] = " jumpservices= " ;
const char HTTP_PARAM_ADDRESS [ ] = " address " ;
namespace misc_strings
{
@ -214,7 +211,7 @@ namespace util
@@ -214,7 +211,7 @@ namespace util
const char crlf [ ] = { ' \r ' , ' \n ' } ;
} // namespace misc_strings
std : : vector < boost : : asio : : const_buffer > HTTPConnection : : reply : : to_buffers ( int status )
{
std : : vector < boost : : asio : : const_buffer > buffers ;
@ -237,7 +234,7 @@ namespace util
@@ -237,7 +234,7 @@ namespace util
default : status_string + = " WTF " ;
}
buffers . push_back ( boost : : asio : : buffer ( status_string , status_string . size ( ) ) ) ;
buffers . push_back ( boost : : asio : : buffer ( misc_strings : : crlf ) ) ;
buffers . push_back ( boost : : asio : : buffer ( misc_strings : : crlf ) ) ;
for ( std : : size_t i = 0 ; i < headers . size ( ) ; + + i )
{
@ -831,7 +828,7 @@ namespace util
@@ -831,7 +828,7 @@ namespace util
if ( ! i2p : : client : : context . GetAddressBook ( ) . GetIdentHash ( address , destination ) )
{
LogPrint ( eLogWarning , " HTTPServer: Unknown address " , address ) ;
SendReply ( " <html> " + itoopieImage + " <br> \r \n Unknown address " + address + " </html> " , 404 ) ;
SendError ( " Unknown address " + address ) ;
return ;
}
@ -855,11 +852,13 @@ namespace util
@@ -855,11 +852,13 @@ namespace util
if ( ecode ! = boost : : asio : : error : : operation_aborted )
{
auto leaseSet = i2p : : client : : context . GetSharedLocalDestination ( ) - > FindLeaseSet ( destination ) ;
if ( leaseSet & & ! leaseSet - > IsExpired ( ) )
if ( leaseSet & & ! leaseSet - > IsExpired ( ) ) {
SendToDestination ( leaseSet , port , buf , len ) ;
else
// still no LeaseSet
SendReply ( leaseSet ? " <html> " + itoopieImage + " <br> \r \n Leases expired</html> " : " <html> " + itoopieImage + " LeaseSet not found</html> " , 504 ) ;
} else if ( leaseSet ) {
SendError ( " LeaseSet expired " ) ;
} else {
SendError ( " LeaseSet not found " ) ;
}
}
}
@ -893,7 +892,7 @@ namespace util
@@ -893,7 +892,7 @@ namespace util
else
{
if ( ecode = = boost : : asio : : error : : timed_out )
SendReply ( " <html> " + itoopieImage + " <br> \r \n Not responding</html> " , 504 ) ;
SendError ( " Host not responding " ) ;
else if ( ecode ! = boost : : asio : : error : : operation_aborted )
Terminate ( ) ;
}
@ -911,7 +910,7 @@ namespace util
@@ -911,7 +910,7 @@ namespace util
m_Reply . headers [ 0 ] . name = " Date " ;
m_Reply . headers [ 0 ] . value = std : : string ( time_buff ) ;
m_Reply . headers [ 1 ] . name = " Content-Length " ;
m_Reply . headers [ 1 ] . value = boo st: : lexical_cast < std : : string > ( m_Reply . content . size ( ) ) ;
m_Reply . headers [ 1 ] . value = std : : to_string ( m_Reply . content . size ( ) ) ;
m_Reply . headers [ 2 ] . name = " Content-Type " ;
m_Reply . headers [ 2 ] . value = " text/html " ;
}
@ -920,6 +919,11 @@ namespace util
@@ -920,6 +919,11 @@ namespace util
std : : bind ( & HTTPConnection : : HandleWriteReply , shared_from_this ( ) , std : : placeholders : : _1 ) ) ;
}
void HTTPConnection : : SendError ( const std : : string & content )
{
SendReply ( " <html> " + itoopieImage + " <br> \r \n " + content + " </html> " , 504 ) ;
}
HTTPServer : : HTTPServer ( const std : : string & address , int port ) :
m_Thread ( nullptr ) , m_Work ( m_Service ) ,
m_Acceptor ( m_Service , boost : : asio : : ip : : tcp : : endpoint ( boost : : asio : : ip : : address : : from_string ( address ) , port ) )
@ -978,6 +982,3 @@ namespace util
@@ -978,6 +982,3 @@ namespace util
}
}
}