ana/src/asio_proxy_connection.hpp

Go to the documentation of this file.
00001 /* $Id: asio_proxy_connection.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 
00003 /**
00004  * @file
00005  * @brief Header file of the client side proxy connection for the ana project.
00006  *
00007  * ana: Asynchronous Network API.
00008  * Copyright (C) 2010 - 2012 Guillermo Biset.
00009  *
00010  * This file is part of the ana project.
00011  *
00012  * System:         ana
00013  * Language:       C++
00014  *
00015  * Author:         Guillermo Biset
00016  * E-Mail:         billybiset AT gmail DOT com
00017  *
00018  * ana is free software: you can redistribute it and/or modify
00019  * it under the terms of the GNU General Public License as published by
00020  * the Free Software Foundation, either version 2 of the License, or
00021  * (at your option) any later version.
00022  *
00023  * ana is distributed in the hope that it will be useful,
00024  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00025  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026  * GNU General Public License for more details.
00027  *
00028  * You should have received a copy of the GNU General Public License
00029  * along with ana.  If not, see <http://www.gnu.org/licenses/>.
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         // Attributes
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Tue May 22 2012 01:03:40 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs