HttpBridge.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2002-2009 Moxie Marlinspike
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. * USA
  18. */
  19. #include "HttpBridge.hpp"
  20. #include <boost/enable_shared_from_this.hpp>
  21. #include <iostream>
  22. using namespace boost::asio;
  23. void HttpBridge::shuttle() {
  24. this->closed = 0;
  25. Bridge::shuttle(&(*clientSocket), &serverSocket);
  26. }
  27. void HttpBridge::setFinishedWithHeaders() {
  28. state = SHUFFLING_DATA;
  29. std::string userAgent("User-Agent");
  30. std::string &agentValue = headers.getHeader(userAgent);
  31. ip::address address = clientSocket->remote_endpoint().address();
  32. listener->setUserAgentFor(address, agentValue);
  33. }
  34. void HttpBridge::processClientInput(char *buffer, int length) {
  35. if (state == READING_HEADERS)
  36. if (headers.process(buffer, length))
  37. setFinishedWithHeaders();
  38. }
  39. void HttpBridge::close() {
  40. if (!closed) closed = 1;
  41. if (clientSocket->is_open()) {
  42. clientSocket->cancel();
  43. clientSocket->close();
  44. }
  45. if (serverSocket.is_open()) {
  46. serverSocket.cancel();
  47. serverSocket.close();
  48. }
  49. }