epoc32/include/securesocket.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Secure Sockets
    15 // 
    16 //
    17 
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 #ifndef __SECURESOCKET_H__
    25 #define __SECURESOCKET_H__
    26 
    27 #include <e32base.h>
    28 #include <e32cons.h>
    29 #include <c32comm.h>
    30 #include <es_sock.h>
    31 #include <ssl.h>
    32 
    33 #include <sslerr.h>
    34 #include <x509cert.h>
    35 
    36 #include <securesocketinterface.h>
    37 //Secure Socket specific panic
    38 _LIT(KSecureSocketPanic,"SecureSocket Panic");
    39 
    40 /** 
    41  * Maximum length of the protocol name. 
    42  * 
    43  * @internalComponent
    44  */
    45 const TInt KMaxProtocolName = 32;
    46 
    47 class TSecSocketProtocol
    48 /** 
    49  * The secure socket protocol class. 
    50  * 
    51  * @internalComponent
    52  *
    53  * @since v7.0 
    54  */
    55 	{
    56 public:
    57 	/** Protocol name. */
    58 	TBuf<KMaxProtocolName> iName;
    59 	/** Handle to the DLL. */
    60 	RLibrary iLibrary;
    61 	static inline TInt Offset()
    62 	/** 
    63 	* Gets the offset to the iSlink member.
    64 	* 
    65 	* @return The offset to the iSlink member. */
    66 		{return _FOFF(TSecSocketProtocol,iSlink);}
    67 	// Moved the implementation to the cpp file
    68 	virtual ~TSecSocketProtocol();
    69 private:
    70     TSglQueLink   iSlink;
    71 	};
    72 
    73 
    74 class TSecureSocketGlobals
    75 /** 
    76  * Class to store the Secure Sockets Globals. 
    77  * 
    78  * @internalComponent
    79  * 
    80  * @since v7.0 
    81  */
    82 	{
    83 public:
    84 	inline TSecureSocketGlobals():
    85 			iSecureSocketProtocols(TSecSocketProtocol::Offset()),
    86 	/** Constructor. */
    87 			iSecureSocketProtocolsIter(iSecureSocketProtocols),
    88 			iUseCount(0){};	
    89 	/** List of supported protocols. */
    90 	TSglQue<TSecSocketProtocol> iSecureSocketProtocols;
    91 	/** A templated class that provides for iterating through the list of supported 
    92 	* protocols. */
    93 	TSglQueIter<TSecSocketProtocol> iSecureSocketProtocolsIter;
    94 	/** Use counter. */
    95 	TInt iUseCount;
    96 	};
    97 
    98 class MGenericSecureSocket;
    99 
   100 /** 
   101  * Definition for the entry point function exported by Secure Socket modules. 
   102  * 
   103  * @internalComponent
   104  */
   105 typedef TInt (*TSecSockDllLibraryFunction)( RSocket& aSocket, const TDesC& aProtocol );
   106 typedef TInt (*TSecSockDllLibraryGenericFunction)(MGenericSecureSocket& aSocket, const TDesC& aProtocol);
   107 
   108 /** 
   109  * Definition for the entry point for the cleanup function exported by secureSocket modules
   110  * 
   111  * @internalComponent
   112  */
   113 typedef void (*TSecSockDllUnloadFunction)( TAny* );
   114 
   115 class CSecureSocketLibraryLoader : public CBase
   116 /** 
   117  * Factory class for creating secure sockets. 
   118  * 
   119  * @internalAll
   120  *
   121  * @since v6.2 */
   122  // Create and reference Secure Sockets
   123 	{
   124 public:
   125 	static  TInt OpenL(const TDesC& aProtocolName,TSecSockDllLibraryFunction& anEntryPoint);
   126 	static  TInt OpenL(const TDesC& aProtocolName, TSecSockDllLibraryGenericFunction& aEntryPoint);
   127 	static void FindItemInDbL(const TDesC& aProtocolName, TDes& aLibraryName);
   128 	IMPORT_C static	void Unload();
   129 
   130 private:
   131 	static  void OpenWithIdL(TInt aId, const TDesC& aProtocolName, TLibraryFunction& aEntryPoint);
   132 	};
   133 
   134 
   135 class CSecureSocket : public CBase
   136 /** 
   137  * Secure sockets class. 
   138  * 
   139  * @publishedAll
   140  * @released
   141  *
   142  * @since v6.2 */
   143  // New secure sockets can be created through the static CSecureSocket::NewL method.
   144  // @public
   145 	{
   146 public:
   147 	IMPORT_C static CSecureSocket* NewL(RSocket& aSocket,const TDesC& aProtocol);
   148 	IMPORT_C static CSecureSocket* NewL(MGenericSecureSocket& aSocket,const TDesC& aProtocol);
   149 
   150 	/** Standard destructor. */
   151 	~CSecureSocket();
   152  
   153 	// export CSecureSocket methods
   154 	IMPORT_C TInt AvailableCipherSuites( TDes8& aCiphers );
   155 	IMPORT_C void CancelAll();
   156 	IMPORT_C void CancelHandshake();	
   157 	IMPORT_C void CancelRecv();
   158 	IMPORT_C void CancelSend();
   159 	IMPORT_C const CX509Certificate* ClientCert();
   160 	IMPORT_C TClientCertMode ClientCertMode();
   161 	IMPORT_C TDialogMode DialogMode();
   162 	IMPORT_C void Close();
   163 	IMPORT_C TInt CurrentCipherSuite( TDes8& aCipherSuite );
   164 	IMPORT_C void FlushSessionCache();
   165 	IMPORT_C TInt GetOpt(TUint aOptionName, TUint aOptionLevel, TDes8& aOption);
   166     IMPORT_C TInt GetOpt(TUint aOptionName, TUint aOptionLevel, TInt& aOption);
   167 	IMPORT_C TInt Protocol(TDes& aProtocol);
   168 	IMPORT_C void Recv (TDes8& aDesc, TRequestStatus& aStatus );
   169 	IMPORT_C void RecvOneOrMore( TDes8& aDesc, TRequestStatus& aStatus, TSockXfrLength& aLen );
   170 	IMPORT_C void RenegotiateHandshake(TRequestStatus& aStatus );
   171 	IMPORT_C void Send( const TDesC8& aDesc, TRequestStatus& aStatus, TSockXfrLength& aLen );
   172 	IMPORT_C void Send( const TDesC8& aDesc, TRequestStatus& aStatus );
   173 	IMPORT_C const CX509Certificate* ServerCert();
   174 	IMPORT_C TInt SetAvailableCipherSuites(const TDesC8& aCiphers);
   175 	IMPORT_C TInt SetClientCert(const CX509Certificate& aCert);
   176 	IMPORT_C TInt SetClientCertMode(const TClientCertMode aClientCertMode);
   177 	IMPORT_C TInt SetDialogMode(const TDialogMode aDialogMode);
   178 	IMPORT_C TInt SetProtocol(const TDesC& aProtocol);
   179 	IMPORT_C TInt SetOpt(TUint aOptionName, TUint aOptionLevel, const TDesC8& aOption=TPtrC8(NULL,0));
   180 	IMPORT_C TInt SetOpt(TUint aOptionName, TUint aOptionLevel, TInt aOption);
   181 	IMPORT_C TInt SetServerCert(const CX509Certificate& aCert);	
   182 	IMPORT_C void StartClientHandshake(TRequestStatus& aStatus);
   183 	IMPORT_C void StartServerHandshake(TRequestStatus& aStatus);	
   184 
   185 private:
   186 	void ConstructL(RSocket& aSocket,const TDesC& aProtocol);
   187 	void ConstructL(MGenericSecureSocket& aSocket,const TDesC& aProtocol);
   188 
   189 	enum {ESecureSocketStateOpen, ESecureSocketStateClosed};
   190 
   191 	TUint iSecureSocketState;
   192 
   193 	TSecSockDllLibraryFunction iUNUSED;
   194 	MSecureSocket* iSecureImplementation;
   195 	};
   196 
   197 #endif // __SECURESOCKET_H__