Skip to content

Commit

Permalink
extract address
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jan 15, 2014
1 parent 5856310 commit 68a0643
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
22 changes: 20 additions & 2 deletions HTTPServer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
#include "base64.h"
#include "Log.h"
#include "Tunnel.h"
#include "TransitTunnel.h"
#include "Transports.h"
Expand Down Expand Up @@ -45,7 +46,7 @@ namespace util

void HTTPConnection::Receive ()
{
m_Socket->async_read_some (boost::asio::buffer (m_Buffer),
m_Socket->async_read_some (boost::asio::buffer (m_Buffer, 8192),
boost::bind(&HTTPConnection::HandleReceive, this,
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
Expand All @@ -54,7 +55,12 @@ namespace util
{
if (!ecode)
{
HandleRequest ();
m_Buffer[bytes_transferred] = 0;
auto address = ExtractAddress ();
if (address.find ('?') != std::string::npos)
HandleDestinationRequest ("zmw2cyw2vj7f6obx3msmdvdepdhnw2ctc4okza2zjxlukkdfckhq");
else
HandleRequest ();
boost::asio::async_write (*m_Socket, m_Reply.to_buffers(),
boost::bind (&HTTPConnection::HandleWrite, this,
boost::asio::placeholders::error));
Expand All @@ -64,6 +70,18 @@ namespace util
Terminate ();
}

std::string HTTPConnection::ExtractAddress ()
{
char * get = strstr (m_Buffer, "GET");
if (get)
{
char * http = strstr (get, "HTTP");
if (http)
return std::string (get + 3, http - get - 3);
}
return "";
}

void HTTPConnection::HandleWrite (const boost::system::error_code& ecode)
{
Terminate ();
Expand Down
5 changes: 3 additions & 2 deletions HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ namespace util
void HandleRequest ();
void HandleDestinationRequest (std::string b32);
void FillContent (std::stringstream& s);

std::string ExtractAddress ();

private:

boost::asio::ip::tcp::socket * m_Socket;
boost::array<char, 8192> m_Buffer;
char m_Buffer[8192];
request m_Request;
reply m_Reply;
};
Expand Down

0 comments on commit 68a0643

Please sign in to comment.