epoc32/include/mw/obexbase.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     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 public: // Implementation of MObexNotify Interface (No longer used)
   172 	virtual void Process(CObexPacket& aPacket);
   173 	virtual void Error(TInt aError);
   174 	virtual void TransportUp();
   175 	virtual void TransportDown(TBool aForceTransportDeletion);
   176 	
   177 public:
   178 	virtual void UserPasswordL( const TDesC& aPassword) = 0; 
   179 	IMPORT_C void RemoteAddr(TSockAddr& anAddr); 
   180 
   181 	TConnectState GetConnectState() const;
   182 
   183 	IMPORT_C TBool IsAuthenticating() const;
   184 	
   185 	// Handling notified events.
   186 	void NotifyProcess(CObexPacket& aPacket);
   187 	void NotifyError(TInt aError);
   188 	void NotifyTransportUp();
   189 	void NotifyTransportDown(TBool);
   190 	
   191 protected:
   192 	CObex();
   193 	virtual void ConstructL(TObexTransportInfo& aObexTransportInfo);
   194 	virtual TInt ParseConnectPacket(CObexPacket& aPacket) = 0;	
   195 	void SetConnectState(TConnectState aNewState);
   196 	IMPORT_C TConnectState ConnectState() const;	// same as GetConnectState - has to be maintained here for BC
   197 	virtual void OnPacketReceive(CObexPacket& aPacket) =0;
   198 	virtual void OnError(TInt aError) =0;
   199 	virtual void OnTransportUp() =0;
   200 	virtual void OnTransportDown() =0;
   201 	void ProcessChallengeL(const TObexInternalHeader& hdr);			//process the received challenge
   202 	void ProcessChallResponseL(const TObexInternalHeader& hdr);		//process the response to challenge
   203 	TInt GenerateChallenge(CObexPacket& aPacket);					//generate a challenge 
   204 	void PrepareChallResponseL(const TDesC& aPassword);				//generate a response to challenge
   205 																		//after user Password input
   206 	void ForcedTransportDown();
   207 	void ControlledTransportDown();
   208 	void RemoteInfoCleanup();
   209 	void CancelObexConnection();
   210 protected:
   211 	TConnectState iConnectState;
   212 	CObexTransportControllerBase* iTransportController;
   213 	TObexConnectInfo iLocalInfo;
   214 	TObexConnectInfo iRemoteInfo;
   215 	MObexAuthChallengeHandler* iCallBack;
   216 	TNonce iOutgoingNonce; //nonce used when challenging
   217 	TNonce iIncomingNonce; //nonce used when receiving a challenge
   218 	HBufC8* iChallPassword; //password used when challenging
   219 	HBufC8* iRespPassword; //password used when responding to a challenge
   220 	HBufC8* iRxChallenge;
   221 	TBuf8<KChallResponseSize> iOutgoingChallResp;//response to the previously issued challenge
   222 								//16 nonce, 16 digest resp, 20 UserID, 3*(tag+size)
   223 	TBuf8<KChallResponseSize> iIncomingChallResp;//response received from previous challenge
   224 	TBuf8<KObexRespSize> iIncomingRequestDigest;
   225 	HBufC* iRemoteUID; //UID of remote device
   226 	HBufC* iRemoteRealm;//Realm of remote device
   227 	CObexAuthenticator* iAuthEngine;
   228 	TBool iChallenge; //to challenge or not to challenge?
   229 	TBool iUserIDRequested; //does the challenge insist that a UserID is returned
   230 	TBool iReserved; //released boolean now available for future use
   231 	TOperation iCurrentOperation;
   232 	CObexNotifyHandlerBase* iNotifyHandler;
   233 	TUint iSuppressedObexAuthElements;
   234 	};
   235 
   236 #endif // __OBEXBASE_H