diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 0ae7a3dc..3cf956cc 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -60,9 +60,20 @@ namespace util { m_Buffer[bytes_transferred] = 0; auto address = ExtractAddress (); - //LogPrint (address); if (address.length () > 1) // not just '/' - HandleDestinationRequest (address.substr (1)); // exclude '/' + { + std::string uri ("/"), b32; + size_t pos = address.find ('/', 1); + if (pos == std::string::npos) + b32 = address.substr (1); // excluding leading '/' to end of line + else + { + b32 = address.substr (1, pos - 1); // excluding leading '/' to next '/' + uri = address.substr (pos); // rest of line + } + + HandleDestinationRequest (b32, uri); + } else HandleRequest (); boost::asio::async_write (*m_Socket, m_Reply.to_buffers(), @@ -149,10 +160,14 @@ namespace util s << "

Flibusta

"; } - void HTTPConnection::HandleDestinationRequest (std::string b32) + void HTTPConnection::HandleDestinationRequest (const std::string& b32, const std::string& uri) { uint8_t destination[32]; - i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32); + if (i2p::data::Base32ToByteStream (b32.c_str (), b32.length (), destination, 32) != 32) + { + LogPrint ("Invalid Base32 address ", b32); + return; + } auto leaseSet = i2p::data::netdb.FindLeaseSet (destination); if (!leaseSet || !leaseSet->HasNonExpiredLeases ()) { @@ -173,7 +188,7 @@ namespace util auto s = i2p::stream::CreateStream (leaseSet); if (s) { - std::string request = "GET / HTTP/1.1\n Host:" + b32 + ".b32.i2p\n"; + std::string request = "GET " + uri + " HTTP/1.1\n Host:" + b32 + ".b32.i2p\n"; s->Send ((uint8_t *)request.c_str (), request.length (), 10); std::stringstream ss; uint8_t buf[8192]; @@ -193,7 +208,7 @@ namespace util else // nothing received ss << "Not responding"; s->Close (); - //DeleteStream (s); + DeleteStream (s); m_Reply.content = ss.str (); m_Reply.headers.resize(2); diff --git a/HTTPServer.h b/HTTPServer.h index 90aacfc0..a62a2074 100644 --- a/HTTPServer.h +++ b/HTTPServer.h @@ -48,7 +48,7 @@ namespace util void HandleWrite(const boost::system::error_code& ecode); void HandleRequest (); - void HandleDestinationRequest (std::string b32); + void HandleDestinationRequest (const std::string& b32, const std::string& uri); void FillContent (std::stringstream& s); std::string ExtractAddress (); diff --git a/Streaming.cpp b/Streaming.cpp index 05f838fa..3f4f53e6 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -318,7 +318,7 @@ namespace stream void StreamingDestination::HandleNextPacket (Packet * packet) { - uint32_t sendStreamID = be32toh (*(uint32_t *)(packet->buf)); + uint32_t sendStreamID = packet->GetSendStreamID (); auto it = m_Streams.find (sendStreamID); if (it != m_Streams.end ()) it->second->HandleNextPacket (packet);