- Main Page
- Related Pages
- Classes
- Files
- Examples

- File List
- File Members

# SidClientSession.hpp

Go to the documentation of this file.

    00001 #ifndef Sid_ClientSession_HPP_INCLUDED
    00002 #define Sid_ClientSession_HPP_INCLUDED
    00003
    00004 #include "SidSession.hpp"
    00005 #include "SidClientConnection.hpp"
    00006 #include "SidProtocolBinClient.hpp"
    00007 #include "SidTLSEncryption.hpp"
    00008
    00009 namespace Sid {
    00010
    00011 class ClientSession : public Session, public CommandInterface,  public ConnectionStateListener {
    00012
    00013 public:
    00014         typedef Sid::TcpClientConnection   TcpClientConnection;
    00015         typedef Sid::LocalClientConnection LocalClientConnection;
    00016
    00017         class TLSTcpClientConnection : public TcpClientConnection, protected TLSEncryptionSocketServer {
    00018         public:
    00019                 TLSTcpClientConnection(const char* certificate_buf, const char* host, int port, const char* log_path = 0, int retries = 0, int retry_delay = 1, ConnectionStateListener* listener = 0)
    00020                         : TcpClientConnection(host, port, log_path, retries, retry_delay, listener) {
    00021                            set_non_blocking();
    00022                            server.init(certificate_buf, m_socket, listener);
    00023                         }
    00024                 virtual int recv(uint num_bytes, char* dest, uint /*non_blocking_read_ahead*/){
    00025                         int rd;
    00026                         while ((rd = server.read(num_bytes, dest)) == 0) wait_input();
    00027                         return rd;
    00028                 }
    00029                 virtual int send(uint num_bytes, const char* src, bool){
    00030                         return server.write(num_bytes, src);
    00031                 }
    00032                 TLSEncryptionSocketServer server;
    00033                 SKYPEKIT_DISABLE_COPY(TLSTcpClientConnection);
    00034         };
    00035
    00036         class TLSLocalClientConnection : public LocalClientConnection, protected TLSEncryptionSocketServer {
    00037         public:
    00038                 TLSLocalClientConnection(const char* certificate_buf, const char* name, const char* log_path = 0, int retries = 0, int retry_delay = 1, ConnectionStateListener* listener = 0)
    00039                         : LocalClientConnection(name, log_path, retries, retry_delay, listener) {
    00040                            set_non_blocking();
    00041                            server.init(certificate_buf, m_socket, listener);
    00042                         }
    00043                 virtual int recv(uint num_bytes, char* dest, uint /*non_blocking_read_ahead*/){
    00044                         int rd;
    00045                         while ((rd = server.read(num_bytes, dest)) == 0) wait_input();
    00046                         return rd;
    00047                 }
    00048                 virtual int send(uint num_bytes, const char* src, bool){
    00049                         return server.write(num_bytes, src);
    00050                 }
    00051                 TLSEncryptionSocketServer server;
    00052                 SKYPEKIT_DISABLE_COPY(TLSLocalClientConnection);
    00053         };
    00054
    00055         ClientSession(int num_threads);
    00056         ~ClientSession();
    00057
    00058         LocalClientConnection* create_local_connection(const char* certificate_buf, const char* local, const char* streamlog, int retries, int retry_delay);
    00059         TcpClientConnection* create_tcp_connection(const char* certificate_buf, const char* server, int port, const char* streamlog, int retries, int retry_delay);
    00060
    00061         TransportInterface::Status init_with_setup(const char* setup, const char* certificate_buf, const char* local, const char* streamlog = 0, int retries = 10, int retry_delay = 5);
    00062         TransportInterface::Status init_with_setup(const char* setup, const char* certificate_buf, const char* server, int port, const char* streamlog = 0, int retries = 10, int retry_delay = 5);
    00063         TransportInterface::Status init(const char* certificate_buf, const char* local, const char* streamlog = 0, int retries = 10, int retry_delay = 5);
    00064         TransportInterface::Status init(const char* certificate_buf, const char* server, int port, const char* streamlog = 0, int retries = 10, int retry_delay = 5);
    00065         TransportInterface::Status init(Connection*, const char* setup_request = "");
    00066
    00067         virtual bool start() = 0;
    00068         void stop();
    00069
    00070         virtual Protocol::BinClient* create_protocol(Connection* connection);
    00071
    00072         //ConnectionStateListener callbacks
    00073         virtual void Disconnected() { }
    00074         virtual void Connected() { }
    00075         virtual void Connecting() { }
    00076         virtual void OnError(CONNECTION_ERROR /*err*/) { }
    00077
    00078         void set_transport_encryption(bool enabled) {
    00079                 m_secure_connection = enabled;
    00080         }
    00081
    00082 protected:
    00083         TransportInterface::Status handshake(Connection*, const char* request, const char* expected_response);
    00084
    00085         Connection*          m_connection;
    00086         Protocol::BinClient* m_protocol;
    00087         int m_started;
    00088         bool m_secure_connection;
    00089
    00090 protected:
    00091         bool is_server_connected() { return m_connection ? m_connection->is_connected() : false; }
    00092         SKYPEKIT_DISABLE_COPY(ClientSession);
    00093 };
    00094
    00095 } // Sid
    00096
    00097 #endif
    00098

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

(c) Skype Technologies S.A. Confidential/Proprietary

Last updated: Fri Mar 16 2012