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