obex/obexprotocol/obex/public/obexbase.h
changeset 0 d0791faffa3f
child 1 f8e15b44d440
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2003-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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedAll
       
    19  @released
       
    20 */
       
    21 
       
    22 #ifndef __OBEXBASE_H
       
    23 #define __OBEXBASE_H
       
    24 
       
    25 #include <obextypes.h>
       
    26 #include <mobexnotify.h>
       
    27 
       
    28 class CObexTransportControllerBase;
       
    29 class TObexTransportInfo;
       
    30 class CObexPacket;
       
    31 class CObexNotifyHandlerBase;
       
    32 
       
    33 /**
       
    34 @publishedAll
       
    35 @released
       
    36 
       
    37 This class is the common base class for any object which wishes
       
    38 to use the Obex Server or Client.
       
    39 The class which owns a CObexClient or CObexServer must be provide an object
       
    40 derived from this class to handle the call from the Server/Client for a request
       
    41 for a Password.
       
    42 @see CObex::SetCallBack
       
    43 */
       
    44 class MObexAuthChallengeHandler
       
    45 	{
       
    46 public:
       
    47 	/**
       
    48 	Indicates that the server/client has received an Authentication challenge. The challenge
       
    49 	can only be responded to once a password has been retrieved by some means and passed
       
    50 	back to the calling class. The password is passed back via CObex::UserPasswordL
       
    51 	@param aRealm This will contain the Realm specified by the unit forcing the
       
    52 	Authentication, if no UserID was supplied then this parameter will be of zero length. 
       
    53 	*/
       
    54 	virtual void GetUserPasswordL(const TDesC& aRealm) = 0;
       
    55 		
       
    56 	/**
       
    57  	Returns a null aObject if the extension is not implemented, or a pointer to another interface if it is.
       
    58 	@param aInterface UID of the interface to return
       
    59 	@param aObject the container for another interface as specified by aInterface
       
    60 	*/
       
    61 	IMPORT_C virtual void MOACH_ExtensionInterfaceL(TUid aInterface, void*& aObject);
       
    62 	};
       
    63 
       
    64 /**
       
    65 This class is the common base class for CObexClient and CObexServer. It is 
       
    66 an abstract class and cannot be instantiated in itself. However, it does 
       
    67 contain user functionality common to both client and server connections.
       
    68 
       
    69 Provides the basic OBEX transport functionality (sending and receiving 
       
    70 files)
       
    71 Client and server provide the more specialied APIs for
       
    72 - initiation or response to puts & gets
       
    73 - (possible) handling of more generalised 'objects' (prob. with data buffered through a file).
       
    74 
       
    75 This class is not designed for user derivation
       
    76 
       
    77 @publishedAll
       
    78 @released
       
    79 */
       
    80 NONSHARABLE_CLASS(CObex) : public CBase, protected MObexNotify
       
    81 	{
       
    82 public:
       
    83 	/**
       
    84 	Describes the information set or received in a SETPATH command.
       
    85 	
       
    86 	The first bit of iFlags, 0, can be set to indicate to the receiver of SETPATH to backup a level before applying the path name.
       
    87 	The second bit of iFlags, 1, can be set to indicate to the receiver of SETPATH to NOT create the directory if it doesn't exist.
       
    88 	The iConstants variable is always set to zero as it is reserved. 
       
    89 	The iName variable indicates the directory to create or go to, and does not include the root directory of the receiver (i.e. 
       
    90 	if the directory to be set is C:\notes then iName is set to "notes").
       
    91 	 If  a name is not set then set CObex::TSetPathInfo::iNamePresent to false. 
       
    92 	*/
       
    93 	NONSHARABLE_CLASS(TSetPathInfo)
       
    94 		{
       
    95 	public:
       
    96 		IMPORT_C TSetPathInfo();
       
    97 		TSetPathInfo(const TObexSetPathData& aData);
       
    98 		IMPORT_C TBool Parent() const;
       
    99 		TUint8 iFlags;
       
   100 		TUint8 iConstants;
       
   101 		TBuf<KObexObjectDescriptionSize> iName;
       
   102 		/** Whether iName is present in this SETPATH info */	
       
   103 		TBool iNamePresent;	
       
   104 	private:
       
   105 		// This data padding has been added to help prevent future binary compatibility breaks	
       
   106 		// Neither iPadding1 nor iPadding2 have been zero'd because they are currently not used
       
   107 		TUint32     iPadding1; 
       
   108 		TUint32     iPadding2; 				
       
   109 		};
       
   110 		
       
   111 	/**
       
   112 	Current obex connection state
       
   113 	In general, the further through the enum the values are,
       
   114 	the further through the connection process the state machine
       
   115 	will be.
       
   116 	*/
       
   117 	enum TConnectState 
       
   118 		{ 
       
   119 		EConnIdle,					/** Nothing is happening */
       
   120 		EConnTransport,				/** Transport Link connected not yet established true Link */
       
   121 		EConnObex,					/** full connection established */
       
   122 		ESimpleConnRequest,			/** Connect without Auth has been sent by ClientReceived by Server */
       
   123 		EConnChallRxed,				/**  Server has issued a challenge, to a Client cionnect */
       
   124 		ESimpleConnChallIssued,		/** Server, received Simple Connect but Server Challenge issued */
       
   125 		EChallConnRequested,		/** Connect with Auth has been sent by Client/Received by Server */
       
   126 		EChallConnChallIssued,		/** Server has sent a Challenge & Resp to a Client EChallConnRequest */
       
   127 		EWaitForFinalResponse,		/** Client, waiting for final success/fail not chall-response expected
       
   128 									    Server, Waiting for final Resp fromm Client to Challenge */
       
   129 		EFinalResponseReceived,		/** Server, the final response has been received */
       
   130 		EFinalChallRxed,			/** Server, Client connect with challenge, Server responds with challenge, Client re-issued original/new challenge */
       
   131 		EWaitForUserInput,			/** waiting for the user */
       
   132 		EDropLink					/** drop the link */
       
   133 		};
       
   134 
       
   135 	/**
       
   136 	The Obex operation currently being performed.
       
   137 	*/
       
   138 	enum TOperation 
       
   139 		{ 
       
   140 		EOpConnect		= 0x00, /** Connect */
       
   141 		EOpDisconnect	= 0x01, /** Disconnect */
       
   142 		EOpPut			= 0x02, /** Put */
       
   143 		EOpGet			= 0x03, /** Get */
       
   144 		EOpSetPath		= 0x05, /** SetPath */
       
   145 		EOpAbort		= 0xFF,	/** Abort - must fit in one pkt so final bit is always set */
       
   146 		EOpAbortNoFBit	= 0x7F, /** Abort (internal, never transmitted) */
       
   147 		EOpGetResponse  = 0xFD,	/** Internal - not actually an obex operation. */
       
   148 		EOpIdle			= 0xFE,	/** Internal - not actually an obex operation. */
       
   149 		};
       
   150 		
       
   151 	/**
       
   152 	Flags to suppress the authentication elements of the authentication challenge header.
       
   153 	*/
       
   154 	enum TObexSuppressedAuthElements
       
   155 		{
       
   156 		EObexNoSuppressedAuthElements				= 0x00,
       
   157 		EObexSuppressChallengeOptionsAuthElement	= 0x01,
       
   158 		EObexSuppressRealmAuthElement				= 0x02,
       
   159 		EObexSuppressAllAuthElements				= EObexSuppressChallengeOptionsAuthElement | EObexSuppressRealmAuthElement // Must be last
       
   160 		};
       
   161 	
       
   162 	virtual ~CObex();
       
   163 	IMPORT_C void SetCallBack(MObexAuthChallengeHandler& aCallBack);
       
   164 	IMPORT_C TBool IsConnected() const;
       
   165 	IMPORT_C TBool IsStrictPeer() const;
       
   166 	IMPORT_C const TObexConnectInfo& LocalInfo() const;
       
   167 	IMPORT_C TInt SetLocalWho(const TDesC8& aInfo); 
       
   168     IMPORT_C const TObexConnectInfo& RemoteInfo() const;
       
   169    	IMPORT_C void SuppressAuthenticationHeaderElements(TObexSuppressedAuthElements aSuppressedObexAuthElements);
       
   170 	
       
   171 	virtual void UserPasswordL( const TDesC& aPassword) = 0; 
       
   172 	IMPORT_C void RemoteAddr(TSockAddr& anAddr); 
       
   173 
       
   174 	TConnectState GetConnectState() const;
       
   175 
       
   176 	IMPORT_C TBool IsAuthenticating() const;
       
   177 	
       
   178 	// Handling notified events.
       
   179 	void NotifyProcess(CObexPacket& aPacket);
       
   180 	void NotifyError(TInt aError);
       
   181 	void NotifyTransportUp();
       
   182 	void NotifyTransportDown(TBool);
       
   183 	
       
   184 public: // Implementation of MObexNotify Interface (No longer used)
       
   185 	virtual void Process(CObexPacket& aPacket);
       
   186 	virtual void Error(TInt aError) ;
       
   187 	virtual void TransportUp();
       
   188 	virtual void TransportDown(TBool aForceTransportDeletion);
       
   189 	
       
   190 protected:
       
   191 	CObex();
       
   192 	virtual void ConstructL(TObexTransportInfo& aObexTransportInfo);
       
   193 	virtual TInt ParseConnectPacket(CObexPacket& aPacket) = 0;	
       
   194 	void SetConnectState(TConnectState aNewState);
       
   195 	IMPORT_C TConnectState ConnectState() const;	// same as GetConnectState - has to be maintained here for BC
       
   196 	virtual void OnPacketReceive(CObexPacket& aPacket) =0;
       
   197 	virtual void OnError(TInt aError) =0;
       
   198 	virtual void OnTransportUp() =0;
       
   199 	virtual void OnTransportDown() =0;
       
   200 	void ProcessChallengeL(const TObexInternalHeader& hdr);			//process the received challenge
       
   201 	void ProcessChallResponseL(const TObexInternalHeader& hdr);		//process the response to challenge
       
   202 	TInt GenerateChallenge(CObexPacket& aPacket);					//generate a challenge 
       
   203 	void PrepareChallResponseL(const TDesC& aPassword);				//generate a response to challenge
       
   204 																		//after user Password input
       
   205 	void ForcedTransportDown();
       
   206 	void ControlledTransportDown();
       
   207 	void RemoteInfoCleanup();
       
   208 	void CancelObexConnection();
       
   209 protected:
       
   210 	TConnectState iConnectState;
       
   211 	CObexTransportControllerBase* iTransportController;
       
   212 	TObexConnectInfo iLocalInfo;
       
   213 	TObexConnectInfo iRemoteInfo;
       
   214 	MObexAuthChallengeHandler* iCallBack;
       
   215 	TNonce iOutgoingNonce; //nonce used when challenging
       
   216 	TNonce iIncomingNonce; //nonce used when receiving a challenge
       
   217 	HBufC8* iChallPassword; //password used when challenging
       
   218 	HBufC8* iRespPassword; //password used when responding to a challenge
       
   219 	HBufC8* iRxChallenge;
       
   220 	TBuf8<KChallResponseSize> iOutgoingChallResp;//response to the previously issued challenge
       
   221 								//16 nonce, 16 digest resp, 20 UserID, 3*(tag+size)
       
   222 	TBuf8<KChallResponseSize> iIncomingChallResp;//response received from previous challenge
       
   223 	TBuf8<KObexRespSize> iIncomingRequestDigest;
       
   224 	HBufC* iRemoteUID; //UID of remote device
       
   225 	HBufC* iRemoteRealm;//Realm of remote device
       
   226 	CObexAuthenticator* iAuthEngine;
       
   227 	TBool iChallenge; //to challenge or not to challenge?
       
   228 	TBool iUserIDRequested; //does the challenge insist that a UserID is returned
       
   229 	TBool iReserved; //released boolean now available for future use
       
   230 	TOperation iCurrentOperation;
       
   231 	CObexNotifyHandlerBase* iNotifyHandler;
       
   232 	TUint iSuppressedObexAuthElements;
       
   233 	};
       
   234 
       
   235 #endif // __OBEXBASE_H