/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 * 
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IWEAR_SSLCONNECTION_H
#define __IWEAR_SSLCONNECTION_H

#ifndef __IWEAR_CONNECTION_H
#include <net/connection.h>
#endif

#ifndef __IWEAR_SSLFILTER_H
#include <net/sslfilter.h>
#endif

#ifndef __IWEAR_SSLCERTMANAGER_H
#include <net/sslcertmanager.h>
#endif

#define SSL_RECV_BUFSIZE 8192

namespace iwear
{
    namespace net
    {

class SSLConnection : public Connection
{
    private:
        SSLFilter* sslfilter;
	SSLCertManager* certmgr;
	Connection& conn;

	char recv_buf[SSL_RECV_BUFSIZE];
        size_t recv_pos;
        size_t recv_pending;
	int check_result;
	bool connected;

    protected:
	
    public:

	/**
	 * Constructor.
	 * Creates a new SSLConnection using the given Connection as transport.
	 */
	SSLConnection( Connection& );

	static SSLConnection* create( Connection& connection );

	virtual ~SSLConnection();

	virtual bool is_connected( void ) { return this->connected; }

	virtual ssize_t read( void * buf, size_t count, float to = DEFAULT_TIMEOUT, bool check = true );

        virtual string read( size_t count, float to = DEFAULT_TIMEOUT, bool check = true);

        virtual ssize_t write( const void * buf , size_t count, float to = DEFAULT_TIMEOUT, bool check = true );

        virtual ssize_t write( const string& dat, string::size_type pos = 0, float to = DEFAULT_TIMEOUT, bool check = true );

        virtual void disconnect( void );

        virtual void reconnect( float to = DEFAULT_TIMEOUT );

        virtual Connection* accept( float to = DEFAULT_TIMEOUT, bool checkfd = true );

        virtual void init( ssl_role = ssl_client );
	
	virtual bool is_valid_cert( void );

	virtual int cert_check_result( void ) { return this->check_result; };
};
    }
}
#endif

