Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <string>
00034
00035 #include <boost/asio.hpp>
00036
00037 using boost::asio::ip::tcp;
00038
00039 #include "../api/ana.hpp"
00040
00041 #ifndef ASIO_PROXY_CONNECTION
00042 #define ASIO_PROXY_CONNECTION
00043
00044 struct proxy_connection_manager
00045 {
00046 virtual ~proxy_connection_manager() {}
00047
00048 virtual void handle_proxy_connection(const boost::system::error_code&,
00049 ana::connection_handler*,
00050 ana::timer*) = 0;
00051 };
00052
00053 struct proxy_information
00054 {
00055 proxy_information() :
00056 proxy_address(),
00057 proxy_port(),
00058 user_name(),
00059 password()
00060 {
00061 }
00062
00063 std::string proxy_address;
00064 std::string proxy_port;
00065 std::string user_name;
00066 std::string password;
00067 };
00068
00069 class proxy_connection
00070 {
00071 public:
00072 proxy_connection(tcp::socket& socket,
00073 proxy_information pi,
00074 ana::address address,
00075 ana::port port,
00076 ana::timer* timer);
00077
00078 void connect( proxy_connection_manager* manager, ana::connection_handler* handler );
00079
00080 private:
00081 std::string* generate_connect_request() const;
00082 std::string* generate_base64_credentials() const;
00083
00084 void do_connect( );
00085
00086 void handle_connect(const boost::system::error_code& ec,
00087 tcp::resolver::iterator endpoint_iterator);
00088
00089 void handle_sent_request(const boost::system::error_code& ec, std::string* request);
00090
00091 void handle_response( boost::asio::streambuf* buf,
00092 const boost::system::error_code&,
00093 size_t );
00094
00095 bool finds( const std::string& source, char const* pattern );
00096
00097 std::string base64_encode(char const* bytes_to_encode, unsigned int in_len) const;
00098
00099
00100 tcp::socket& socket_;
00101
00102 const proxy_information proxy_info_;
00103
00104 ana::address address_;
00105 ana::port port_;
00106
00107 proxy_connection_manager* manager_;
00108 ana::connection_handler* conn_handler_;
00109
00110 bool authenticating_;
00111 ana::timer* timer_;
00112 };
00113
00114 #endif