epoc32/include/app/imsk.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/imsk.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Copyright (c) 1998-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@2
     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
williamr@2
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.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
// This file contains the API definition for the class CImTextServerSession.
williamr@2
    15
// This class creates sockets and is responsible for transmitting data between client and the server 
williamr@2
    16
// 
williamr@2
    17
//
williamr@2
    18
williamr@2
    19
williamr@2
    20
williamr@2
    21
/**
williamr@2
    22
 @file
williamr@2
    23
*/
williamr@2
    24
williamr@2
    25
williamr@2
    26
#ifndef __IMSK_H__
williamr@2
    27
#define __IMSK_H__
williamr@2
    28
williamr@2
    29
#include <e32base.h>
williamr@2
    30
#include <es_sock.h>
williamr@2
    31
#include <in_sock.h>
williamr@2
    32
#include <f32file.h>
williamr@2
    33
#include <mentact.h>
williamr@2
    34
#include <miutlog.h>
williamr@2
    35
#include <miut_err.h>
williamr@2
    36
#include <miuthdr.h>
williamr@2
    37
williamr@2
    38
#ifdef _DEBUG
williamr@2
    39
#define __IMSK_SIMULATION
williamr@2
    40
#endif
williamr@2
    41
williamr@2
    42
// Enable Scripting in Debug Builds only
williamr@2
    43
#ifdef _DEBUG
williamr@2
    44
#define __IMSK_SCRIPTING
williamr@2
    45
#endif
williamr@2
    46
williamr@2
    47
const TInt EActivePriorityHigh = 1;
williamr@2
    48
const TInt KCarriageLineFeedLength=2;
williamr@2
    49
/** Max numeric IP address len = "0:0:0:0:0:0:194.217.242.23" = 45 chars */
williamr@2
    50
const TInt KImskIPAddressLen=45;				// Max numeric IP address len = "255.255.255.255" = 15 chars
williamr@2
    51
williamr@2
    52
/** Maximum buffer size of the received data 
williamr@2
    53
@internalTechnology
williamr@2
    54
@released
williamr@2
    55
*/
williamr@2
    56
typedef TBuf8<KImMailMaxBufferSize> TImMailBuffer;
williamr@2
    57
williamr@2
    58
/** received buffer data line type
williamr@2
    59
@internalTechnology
williamr@2
    60
@released
williamr@2
    61
*/
williamr@2
    62
enum TImLineType
williamr@2
    63
	{ 
williamr@2
    64
	ECRLFTerminated, 
williamr@2
    65
	EBufferTooSmall, 
williamr@2
    66
	EReceiveBufferFull,
williamr@2
    67
	EReceiveBufferEmpty
williamr@2
    68
	};
williamr@2
    69
williamr@2
    70
williamr@2
    71
class CImLog;
williamr@2
    72
class CImTextServerScript;
williamr@2
    73
class CImIAPPreferences;
williamr@2
    74
class CImConnect;
williamr@2
    75
class CSecureSocket;
williamr@2
    76
class CImSocketIdleTimer;
williamr@2
    77
williamr@2
    78
/**
williamr@2
    79
Creates/opens socket and sends and receives data.
williamr@2
    80
williamr@2
    81
@publishedAll
williamr@2
    82
@released	
williamr@2
    83
*/
williamr@2
    84
class CImTextServerSession : public CMsgActive
williamr@2
    85
	{
williamr@2
    86
public:
williamr@2
    87
	enum TImOperationMode{
williamr@2
    88
		EImServerMode,
williamr@2
    89
		EImClientMode
williamr@2
    90
		};
williamr@2
    91
williamr@2
    92
/**
williamr@2
    93
	//cat				Construction
williamr@2
    94
	@fn				NewL()
williamr@2
    95
	Intended Usage	:	Static factory constructor. Uses two phase construction and 
williamr@2
    96
						leaves nothing on the CleanupStack.
williamr@2
    97
	@since			6.0
williamr@2
    98
	@leave			KErrNoMemory.
williamr@2
    99
	@return			A pointer to the newly created CImTextServerSession object. 
williamr@2
   100
	@pre 			None
williamr@2
   101
	@post			A fully constructed and initialised CImTextServerSession object.
williamr@2
   102
	
williamr@2
   103
 */
williamr@2
   104
	IMPORT_C static CImTextServerSession *NewL();
williamr@2
   105
williamr@2
   106
	/**
williamr@2
   107
	@internalTechnology
williamr@2
   108
	@released
williamr@2
   109
	*/
williamr@2
   110
	IMPORT_C static CImTextServerSession* NewL(RSocketServ& aSocketServ, CImConnect& aConnect);
williamr@2
   111
williamr@2
   112
/**
williamr@2
   113
	//cat				Construction
williamr@2
   114
	@fn				NewL(TInt aSendIdleTime, TInt aReceiveIdleTime)
williamr@2
   115
	Intended Usage	:	Static factory constructor. Uses two phase construction and 
williamr@2
   116
						leaves nothing on the CleanupStack.
williamr@2
   117
	@since			7.0s
williamr@2
   118
	@param			aSendIdleTime is the time for which the idle timer runs (for a send)
williamr@2
   119
	@param			aReceiveIdleTime is the time for which the idle timer runs (for a recieve)
williamr@2
   120
	@leave			KErrNoMemory.
williamr@2
   121
	@return			A pointer to the newly created CImTextServerSession object. 
williamr@2
   122
	@pre 				None
williamr@2
   123
	@post				A fully constructed and initialised CImTextServerSession object.
williamr@2
   124
 */
williamr@2
   125
	IMPORT_C static CImTextServerSession* NewL(TInt aSendIdleTime, TInt aReceiveIdleTime);
williamr@2
   126
williamr@2
   127
	/**
williamr@2
   128
	@internalTechnology
williamr@2
   129
	@released
williamr@2
   130
	*/
williamr@2
   131
	IMPORT_C static CImTextServerSession* NewL(TInt aSendIdleTime, TInt aReceiveIdleTime, RSocketServ& aSocketServ, CImConnect& aConnect);
williamr@2
   132
williamr@2
   133
/**
williamr@2
   134
	//cat				Destruction
williamr@2
   135
	@fn				~CImTextServerSession()
williamr@2
   136
	Intended Usage	:	Destructor.
williamr@2
   137
	@since			6.0	
williamr@2
   138
 */
williamr@2
   139
	~CImTextServerSession();
williamr@2
   140
williamr@2
   141
/**
williamr@2
   142
	@fn				QueueConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, TBool aEnableTimeout = ETrue)
williamr@2
   143
	Intended Usage	:	Queue a connect assuming the socket is successfully opened.
williamr@2
   144
	Error Condition	:	KErrNoMemory
williamr@2
   145
	@since			6.0
williamr@2
   146
	@param			aStatus	Asynchronous completion status
williamr@2
   147
	@param			anAddressDesc is the IP address		
williamr@2
   148
	@param			aIAPPreferences is the IAP connection preference to be used		
williamr@2
   149
	@param			aPortNum is the port number eg. 143, 25, 110.
williamr@2
   150
	@param			aEnableTimeout Not used		
williamr@2
   151
	@pre 			None
williamr@2
   152
	@post			connection is ready to send and receive data.
williamr@2
   153
 */
williamr@2
   154
	IMPORT_C void QueueConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, TBool aEnableTimeout = ETrue);
williamr@2
   155
williamr@2
   156
	IMPORT_C void QueueConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, const TDesC8& aSSLDomainName);
williamr@2
   157
williamr@2
   158
/**
williamr@2
   159
	@fn				SSLQueueConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, TBool aEnableTimeout = ETrue)
williamr@2
   160
	Intended Usage	:	Queue a wrapped SSL connect on an socket assuming the socket is successfully opened.
williamr@2
   161
	Error Condition	:	KErrNoMemory, EImskSocketOpen
williamr@2
   162
	@since			7.0s
williamr@2
   163
	@param			aStatus	Asynchronous completion status
williamr@2
   164
	@param			anAddressDesc is the IP address		
williamr@2
   165
	@param			aIAPPreferences is the IAP connection preference to be used		
williamr@2
   166
	@param			aPortNum is the port number eg. 993, 465, 995.
williamr@2
   167
	@param			aEnableTimeout Not used		
williamr@2
   168
	@pre 			None
williamr@2
   169
	@post			connection is ready to send and receive data.
williamr@2
   170
 */
williamr@2
   171
	IMPORT_C void SSLQueueConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, TBool aEnableTimeout = ETrue);
williamr@2
   172
williamr@2
   173
	IMPORT_C void SSLQueueConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, const TDesC8& aSSLDomainName);
williamr@2
   174
williamr@2
   175
/**
williamr@2
   176
	@fn				Disconnect()
williamr@2
   177
	Intended Usage	:	To disconnect and close socket connection.
williamr@2
   178
	Error Condition	:	None
williamr@2
   179
	@since			6.0
williamr@2
   180
	@pre 			None
williamr@2
   181
	@post			connection is closed.
williamr@2
   182
  */
williamr@2
   183
	IMPORT_C void Disconnect();
williamr@2
   184
	IMPORT_C void Disconnect(TRequestStatus &aStatus);
williamr@2
   185
	void TimeOut();
williamr@2
   186
williamr@2
   187
williamr@2
   188
	IMPORT_C const TDesC& LocalName();
williamr@2
   189
/**
williamr@2
   190
	This method should be called before Send/SendQueueReceive() 
williamr@2
   191
	TLS command is sent.
williamr@2
   192
	@fn				SetSSLTLSResponseL(const TDesC8& aDesc)
williamr@2
   193
	Intended Usage	:	To use for secure connection.
williamr@2
   194
	Error Condition	:	KErrNoMemory
williamr@2
   195
	@since			6.2
williamr@2
   196
	@param			aDesc is the positive response the MTM expects from the connected
williamr@2
   197
					server for TLS command. e.g.  OK, +OK, 220 etc..		
williamr@2
   198
	@pre 			aDesc cannot be zero length
williamr@2
   199
	@leave			EImskNoTLSResponseString
williamr@2
   200
	@post			iTLSResponse is filled with aDesc contents
williamr@2
   201
williamr@2
   202
  */
williamr@2
   203
	IMPORT_C void SetSSLTLSResponseL(const TDesC8& aDesc);
williamr@2
   204
williamr@2
   205
/**
williamr@2
   206
	@fn				Send(TRequestStatus &aStatus, const TDesC8& aDesc)
williamr@2
   207
	Intended Usage	:	To send data.
williamr@2
   208
	Error Condition	:	None
williamr@2
   209
	@since			6.0
williamr@2
   210
	@param			aStatus	Asynchronous completion status
williamr@2
   211
	@param			aDesc is the aData to be sent
williamr@2
   212
	@post			None
williamr@2
   213
williamr@2
   214
  */
williamr@2
   215
williamr@2
   216
	//sends
williamr@2
   217
	IMPORT_C void Send(TRequestStatus &aStatus, const TDesC8& aDesc);
williamr@2
   218
	IMPORT_C void SendWithTimeout(TRequestStatus& aStatus, TInt aIdleTime, const TDesC8& aDesc); 
williamr@2
   219
	IMPORT_C void SendQueueReceiveWithTimeout(TRequestStatus& aStatus, TInt aIdleTime, const TDesC8& aDesc); 
williamr@2
   220
	IMPORT_C void Send(TRequestStatus &aStatus, TRefByValue<const TDesC8> aFmt,...);
williamr@2
   221
/**
williamr@2
   222
	@fn				SendQueueReceive(TRequestStatus &aStatus, const TDesC8& aDesc)
williamr@2
   223
	Intended Usage	:	To send data and queue a receive.
williamr@2
   224
	Error Condition	:	None
williamr@2
   225
	@since			6.0
williamr@2
   226
	@param			aStatus	Asynchronous completion status	
williamr@2
   227
	@param			aDesc is the aData to be sent
williamr@2
   228
	@post			Sends the data and queues a receive.
williamr@2
   229
	GetCurrentTextLine should be called after this method to read received data
williamr@2
   230
	*/
williamr@2
   231
	IMPORT_C void SendQueueReceive(TRequestStatus &aStatus, const TDesC8& aDesc);
williamr@2
   232
	IMPORT_C void SendQueueReceive(TRequestStatus &aStatus, TRefByValue<const TDesC8> aFmt,...);
williamr@2
   233
williamr@2
   234
    //receives
williamr@2
   235
/**
williamr@2
   236
	Returns first full line of data received from socket to user
williamr@2
   237
	@fn				GetCurrentTextLine(TDes8& aDesc)
williamr@2
   238
	Intended Usage	:	To return received data.
williamr@2
   239
	Error Condition	:	None
williamr@2
   240
	@since			6.0
williamr@2
   241
	@param			aDesc will be filled with received buffer
williamr@2
   242
	@post			returns the received buffer in the form of aDesc
williamr@2
   243
	@return			EReceiveBufferEmpty when received data is empty
williamr@2
   244
					EBufferTooSmall when aDesc length is smaller than received data
williamr@2
   245
					ECRLFTerminated when received data is complete (full line)
williamr@2
   246
					EReceiveBufferFull when received data length is more than aDesc length
williamr@2
   247
	GetCurrentTextLine should be called after Send methods
williamr@2
   248
	*/
williamr@2
   249
	IMPORT_C TImLineType GetCurrentTextLine(TDes8& aDesc);
williamr@2
   250
/**
williamr@2
   251
	User queues a new request from the socket (unless there's a full line of data in buffer
williamr@2
   252
	then signal user and there's no need to make a receive request)
williamr@2
   253
	@fn				QueueReceiveNextTextLine(TRequestStatus &aStatus)
williamr@2
   254
	Intended Usage	:	User queues a new request from the socket.
williamr@2
   255
	Error Condition	:	None
williamr@2
   256
	@since			6.0
williamr@2
   257
	@param			aStatus for asynchronous request
williamr@2
   258
	
williamr@2
   259
	*/
williamr@2
   260
	IMPORT_C void QueueReceiveNextTextLine(TRequestStatus &aStatus);
williamr@2
   261
/**
williamr@2
   262
	@fn				ReceiveBinaryData(TRequestStatus &aStatus, TDes8& aDes,TInt aLen)
williamr@2
   263
	Intended Usage	:	Users queue a request for received data
williamr@2
   264
	Error Condition	:	None
williamr@2
   265
	@since			6.0
williamr@2
   266
	@param			aStatus	Asynchronous completion status	
williamr@2
   267
	@param			aDes is the aData to be received
williamr@2
   268
	@param			aLen is the length of the data the user wants to read
williamr@2
   269
	@post			aDes will be filled with received data of aLen.
williamr@2
   270
	ReceiveBinaryData should be called after Send.
williamr@2
   271
	*/
williamr@2
   272
	IMPORT_C void ReceiveBinaryData(TRequestStatus &aStatus, TDes8& aDes,TInt aLen);
williamr@2
   273
williamr@2
   274
	IMPORT_C void LogText(const TDesC8& aString);						// write string into log file
williamr@2
   275
	IMPORT_C void LogError(const TDesC8& aString,const TInt aError);		// write string and integer into log file
williamr@2
   276
williamr@2
   277
/**
williamr@2
   278
	@fn				GetIAPValue(TUint32 &aIAP)
williamr@2
   279
	Intended Usage	:	Returns the IAP we are connecting/connected with in aIAP or returns an error code
williamr@2
   280
	@since			6.0
williamr@2
   281
	@param			aIAP will be the current IAP 
williamr@2
   282
	@post			aIAP will be filled with current IAP connected.
williamr@2
   283
	@return			will return genconn errors if any
williamr@2
   284
	*/
williamr@2
   285
williamr@2
   286
	IMPORT_C TInt GetIAPValue(TUint32 &aIAP);
williamr@2
   287
/**
williamr@2
   288
	@fn				GetRConnectionName(TName &aName)
williamr@2
   289
	Intended Usage	:	Returns the name of the RConnection.
williamr@2
   290
	@since			9.1
williamr@2
   291
	@param			aName Buffer in which the name is returned. 
williamr@2
   292
	@post			aName will be filled with current name of the RConnection.
williamr@2
   293
	@return			KErrNone if successful, or another of the system-wide error codes.
williamr@2
   294
	*/
williamr@2
   295
williamr@2
   296
	IMPORT_C TInt GetRConnectionName(TName &aName);
williamr@2
   297
williamr@2
   298
/** Returns the bearer type we are connected to with in aBearer or returns an error code */
williamr@2
   299
	IMPORT_C TInt GetIAPBearer(TUint32 &aBearer);
williamr@2
   300
williamr@2
   301
/**
williamr@2
   302
	@internalTechnology
williamr@2
   303
williamr@2
   304
	@fn				GetLastSocketActivityTimeout(TUint32& aTimeout)
williamr@2
   305
	Intended Usage	:	Returns the last socket activity timeout value
williamr@2
   306
	@since			9.1
williamr@2
   307
	@param			aTimeout is a return argument containing the timeout if it was found
williamr@2
   308
	@post				aTimeout will be filled with the timeout value
williamr@2
   309
	@return			Returns KErrNone, KErrNotFound or KErrBadHandle
williamr@2
   310
	*/
williamr@2
   311
	IMPORT_C TInt GetLastSocketActivityTimeout(TUint32& aTimeout);
williamr@2
   312
williamr@2
   313
/**
williamr@2
   314
	@fn				GetSocketServ()
williamr@2
   315
	Intended Usage	:	Returns the Socket Server
williamr@2
   316
	@since			8.0
williamr@2
   317
	@return			Socket Server
williamr@2
   318
	*/
williamr@2
   319
	RSocketServ& GetSocketServ();
williamr@2
   320
williamr@2
   321
/**
williamr@2
   322
	@fn				GetConnectionStage()
williamr@2
   323
	Intended Usage	:	Gets the stage of the connection process obtained from RConnection
williamr@2
   324
	@since			7.0s
williamr@2
   325
	@return			The current connection stage from RConnection or a system-wide error code.
williamr@2
   326
williamr@2
   327
	*/
williamr@2
   328
	IMPORT_C TInt GetConnectionStage();
williamr@2
   329
williamr@2
   330
/**
williamr@2
   331
	@fn				SocketIdle()
williamr@2
   332
	Intended Usage	:	disconnects the socket and notifies the observer when the socket has been idle
williamr@2
   333
						for some time
williamr@2
   334
	@since			7.0s
williamr@2
   335
 */
williamr@2
   336
	void SocketIdle();
williamr@2
   337
williamr@2
   338
/**
williamr@2
   339
	@fn				SetPrimaryTextServerSession(CImTextServerSession& aPrimaryTextServerSession)
williamr@2
   340
	Intended Usage	:	Users set only on the secondary session 
williamr@2
   341
	@since			9.2
williamr@2
   342
	@param			aPrimaryTextServerSession is PrimarySession's TextServerSession
williamr@2
   343
	@pre 			None
williamr@2
   344
	@post			Going to be use on the secondary session
williamr@2
   345
*/
williamr@2
   346
	IMPORT_C void SetPrimaryTextServerSession(CImTextServerSession* aPrimaryTextServerSession);
williamr@2
   347
williamr@2
   348
/**
williamr@2
   349
	@fn				GetCImConnect()
williamr@2
   350
	Intended Usage	:	Returns the CImConnect object
williamr@2
   351
	@since			9.2
williamr@2
   352
	@return			CImConnect 
williamr@2
   353
	@post			Going to be use on the secondary session
williamr@2
   354
    */
williamr@2
   355
	CImConnect* GetCImConnect();
williamr@2
   356
	
williamr@2
   357
// Depreciated functions - do not use.
williamr@2
   358
	IMPORT_C void QueueConnect(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, TBool aEnableTimeout = ETrue);
williamr@2
   359
	IMPORT_C void QueueConnect(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, TInt aType, TBool aEnableTimeout = ETrue);
williamr@2
   360
	IMPORT_C void QueueConnect(TRequestStatus& aStatus,const TDesC& anAddressDesc, TInt aPortNum, TCallBack aDisconnectFunction,const TUint32 aIntraddress,TInt aType, TBool aEnableTimeout = ETrue);
williamr@2
   361
	IMPORT_C void QueueConnect(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum,const TUint32 aIAPaddress, TInt aType, TBool aEnableTimeout = ETrue);
williamr@2
   362
	IMPORT_C void QueueConnect(TRequestStatus& aStatus,const TDesC& anAddressDesc, TInt aPortNum, TCallBack aDisconnectFunction, TBool aEnableTimeout = ETrue);
williamr@2
   363
	IMPORT_C void QueueConnect(TRequestStatus& aStatus,const TDesC& anAddressDesc, TInt aPortNum, TCallBack aDisconnectFunction, const CImIAPPreferences& aIAPPreferences,TInt aType, TBool aEnableTimeout = ETrue);
williamr@2
   364
	IMPORT_C TInt Send(const TDesC8& aDesc);
williamr@2
   365
	IMPORT_C TInt Send(TRefByValue<const TDesC8> aFmt,...);
williamr@2
   366
	IMPORT_C TInt SendReceive(const TDesC8& aDesc);
williamr@2
   367
	IMPORT_C TInt Receive(TDes8& rDes);
williamr@2
   368
	IMPORT_C void Receive(TRequestStatus &aStatus, TDes8& rDes);
williamr@2
   369
	IMPORT_C static CImTextServerSession *NewLC (TImOperationMode aMode, RSocketServ &aServerServ);
williamr@2
   370
	IMPORT_C static CImTextServerSession *NewL(RSocketServ &aServerServ);
williamr@2
   371
	//Do not call SetSecurity.  Call SetSSLTLSResponseL
williamr@2
   372
	IMPORT_C TInt SetSecurity(TBool aSecurityOn, TBool aUnattendedMode = FALSE);
williamr@2
   373
	IMPORT_C void PerformLogging(TBool aLogging);
williamr@2
   374
williamr@2
   375
private:
williamr@2
   376
/**
williamr@2
   377
	//cat			Construction and Destruction
williamr@2
   378
	@fn				CImTextServerSession()
williamr@2
   379
	Intended Usage	:	Constructor. First phase of two-phase construction method. Does 
williamr@2
   380
						non-allocating construction.
williamr@2
   381
	@since			6.0
williamr@2
   382
	
williamr@2
   383
 */
williamr@2
   384
	CImTextServerSession();
williamr@2
   385
williamr@2
   386
	CImTextServerSession(RSocketServ& aSocketServ, CImConnect& aConnect);
williamr@2
   387
/**
williamr@2
   388
	//cat				Construction
williamr@2
   389
	@fn				CImTextServerSession(TInt aSendIdleTime, TInt aReceiveIdleTime)
williamr@2
   390
	Intended Usage	:	Constructor. First phase of two-phase construction method. Does 
williamr@2
   391
						non-allocating construction.
williamr@2
   392
	@since			7.0s
williamr@2
   393
	@param			aSendIdleTime is the time for which the idle timer runs (for a send)
williamr@2
   394
	@param			aReceiveIdleTime  is the time for which the idle timer runs (for a receive)
williamr@2
   395
 */
williamr@2
   396
	CImTextServerSession(TInt aSendIdleTime, TInt aReceiveIdleTime);
williamr@2
   397
williamr@2
   398
	CImTextServerSession(TInt aSendIdleTime, TInt aReceiveIdleTime, RSocketServ& aSocketServ, CImConnect& aConnect);
williamr@2
   399
williamr@2
   400
/**
williamr@2
   401
	//cat			Construction and Destruction.
williamr@2
   402
	@fn				ConstructL()
williamr@2
   403
	Intended Usage	:	Second phase of two-phase construction method. Does any 
williamr@2
   404
						allocations required to fully construct the object.
williamr@2
   405
	@since			6.0
williamr@2
   406
	@leave			KErrNoMemory.
williamr@2
   407
	@pre 			First phase of construction is complete
williamr@2
   408
	@post			The object is fully constructed and initialised.	
williamr@2
   409
 */
williamr@2
   410
	void ConstructL();
williamr@2
   411
williamr@2
   412
	TInt Open();
williamr@2
   413
	void Close();
williamr@2
   414
williamr@2
   415
	void CreateLogFile(TInt aPortNum);
williamr@2
   416
	void OpenScriptFile(TInt aPortNum);
williamr@2
   417
williamr@2
   418
	void DoRunL();
williamr@2
   419
	void DoComplete(TInt& aStatusValue);						// Cleanup code
williamr@2
   420
	void DoCancel();
williamr@2
   421
williamr@2
   422
	// these called from DoRunL;
williamr@2
   423
	void SocketConnect();
williamr@2
   424
	void DoConnectedToSocketL();
williamr@2
   425
	void DoQueueConnect();
williamr@2
   426
williamr@2
   427
	void RealReceive(TDes8& aDesc);
williamr@2
   428
	void RealSend(const TDesC8& aDesc);
williamr@2
   429
/** 
williamr@2
   430
	@fn				ParseSSLTLSResponseL()
williamr@2
   431
	Intended Usage	:	session will compare the response(for TLS command)
williamr@2
   432
						with the MTMs response 						
williamr@2
   433
	@since			6.2
williamr@2
   434
	@leave			KImskSSLTLSNegotiateFailed if the response doesn't match 
williamr@2
   435
	@post			CSecureSocket object is created
williamr@2
   436
	*/
williamr@2
   437
	void ParseSSLTLSResponseL();
williamr@2
   438
williamr@2
   439
/** 
williamr@2
   440
	@fn				CreateSecureSocketL()
williamr@2
   441
	Intended Usage	:	to use secure socket connection 						
williamr@2
   442
	@since			6.2
williamr@2
   443
	@leave			None 
williamr@2
   444
	@post			CSecureSocket object is created and iSecurityState is set to EImSecurityStateOn;
williamr@2
   445
	*/
williamr@2
   446
	void CreateSecureSocketL();
williamr@2
   447
williamr@2
   448
/**
williamr@2
   449
	@fn				QueueGenericConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, TBool aEnableTimeout = ETrue)
williamr@2
   450
	Intended Usage	:	Queue a standard or wrapped SSL connect on an socket assuming the socket is successfully opened.  Called by SSLQueueConnectL and QueueConnectL
williamr@2
   451
	Error Condition	:	KErrNoMemory, EImskSocketOpen
williamr@2
   452
	@since			7.0s
williamr@2
   453
	@param			aStatus	Asynchronous completion status	
williamr@2
   454
	@param			anAddressDesc is the IP address		
williamr@2
   455
	@param			aIAPPreferences is the IAP connection preference to be used		
williamr@2
   456
	@param			aPortNum is the port number eg. 143, 993
williamr@2
   457
	@param			aSSLDomainName SSL domain name to use for secure sockets
williamr@2
   458
	@pre 			None
williamr@2
   459
	@post			connection is ready to send and receive data.
williamr@2
   460
 */
williamr@2
   461
	void QueueGenericConnectL(TRequestStatus &aStatus,const TDesC& anAddressDesc, TInt aPortNum, const CImIAPPreferences& aIAPPreferences, const TDesC8& aSSLDomainName);
williamr@2
   462
williamr@2
   463
#if defined(__IMSK_SIMULATION)
williamr@2
   464
	void ReadNextPeriod();
williamr@2
   465
	TUint32 GetTokenValue(TInt aTokenLen, const TPtrC8& aBuffer);
williamr@2
   466
	TBool IsSuspended();	
williamr@2
   467
	TBool SuspendPeriodSet();
williamr@2
   468
	void ResetSuspendPeriod();
williamr@2
   469
	void SetAfterTimer();
williamr@2
   470
	TInt ReadConfigNum(const TDesC& aName);
williamr@2
   471
#endif
williamr@2
   472
williamr@2
   473
	enum TImSocketState
williamr@2
   474
		{
williamr@2
   475
		EImClosed, 
williamr@2
   476
		EImResolve, 
williamr@2
   477
		EImConnect,   
williamr@2
   478
		EImSendReceive,
williamr@2
   479
		EImDialUsingOverride,
williamr@2
   480
		EImTLSHandShakeStarted,
williamr@2
   481
		EImSendReceiveTimedOut
williamr@2
   482
		};
williamr@2
   483
williamr@2
   484
	enum TImSendReceiveState
williamr@2
   485
		{ 
williamr@2
   486
		EImInactive, 
williamr@2
   487
		EImSending,
williamr@2
   488
		EImReceiving, 
williamr@2
   489
		EImReceivingBinaryData,
williamr@2
   490
		EImSendingQueueReceive,
williamr@2
   491
		EImSuspended,          //used when we are in a simulated GPRS suspend.
williamr@2
   492
		};
williamr@2
   493
williamr@2
   494
	enum TImSecurityState
williamr@2
   495
		{
williamr@2
   496
		EImSecurityStateOff,
williamr@2
   497
		EImSecurityStateOn,
williamr@2
   498
		EImSecurityStateFailed
williamr@2
   499
		};
williamr@2
   500
private:
williamr@2
   501
	/** handle to the socket */
williamr@2
   502
	RSocket							iSocket;
williamr@2
   503
	/** handle to RSocketServ */
williamr@2
   504
	RSocketServ						iServ;
williamr@2
   505
	/** handle to Hostresolver */
williamr@2
   506
	RHostResolver					iHostResolver;
williamr@2
   507
	/** handle to secure socket for SSL/TLS connection */
williamr@2
   508
	CSecureSocket*					iSecureSocket;
williamr@2
   509
williamr@2
   510
	TUint32 iCurrentIAPcache;
williamr@2
   511
	/** Used to find if IAP is cached */
williamr@2
   512
	TBool							iIAPCached;  // true if the above value can be used.
williamr@2
   513
	/** result of the host resolver */
williamr@2
   514
	TNameEntry						iHostent;
williamr@2
   515
	/** port number e.g. 25 for SMTP, 143 for IMAP and 110 for POP */
williamr@2
   516
	TInt							iPortNum;
williamr@2
   517
	/**  server address */
williamr@2
   518
	TPtrC							iAddressDesc;
williamr@2
   519
	/** data returned by the socket */
williamr@2
   520
	TImMailBuffer					iReceive;
williamr@2
   521
	TSockXfrLength					iLen;
williamr@2
   522
	TImSocketState					iState;
williamr@2
   523
	TImSendReceiveState				iSendReceive;
williamr@2
   524
williamr@2
   525
	HBufC8*							iBuffer;
williamr@2
   526
	TImLineType						iCurrentLineType;
williamr@2
   527
williamr@2
   528
	/** to log connection data  */
williamr@2
   529
	CImLog*							iLog;
williamr@2
   530
	/** IP address name */
williamr@2
   531
	TBuf<KImskIPAddressLen>			iLocalName;
williamr@2
   532
	/** secure state i.e to use Secure socket */
williamr@2
   533
williamr@2
   534
	TImSecurityState				iSecurityState;
williamr@2
   535
	const CImIAPPreferences*		iIAPPreferences;
williamr@2
   536
williamr@2
   537
	CImConnect*						iConnect;
williamr@2
   538
williamr@2
   539
	TDes8*							iReceiveData; // buffer we just recieved data into
williamr@2
   540
williamr@2
   541
williamr@2
   542
	HBufC8*							iSentData;
williamr@2
   543
	/** response for different mail protocols like 220,+OK, OK, BAD */
williamr@2
   544
	HBufC8*							iTLSResponse; //response for different mail protocols like 220,+OK, OK, BAD
williamr@2
   545
	/** internal flag to read tls response */
williamr@2
   546
	TBool							iReadTLSResponse;
williamr@2
   547
	TBool							iPerformLogging;
williamr@2
   548
	TBool							iWrappedSocket;
williamr@2
   549
williamr@2
   550
	CImSocketIdleTimer*				iSocketIdleTimer;
williamr@2
   551
	TTimeIntervalMicroSeconds32		iSendIdleTime;
williamr@2
   552
	TTimeIntervalMicroSeconds32		iReceiveIdleTime;
williamr@2
   553
williamr@2
   554
	/** A shorter idle timeout, used when a fast response is expected */
williamr@2
   555
	TTimeIntervalMicroSeconds32		iSendShortIdleTime;
williamr@2
   556
	TTimeIntervalMicroSeconds32		iReceiveShortIdleTime;
williamr@2
   557
williamr@2
   558
williamr@2
   559
#ifdef __IMSK_SCRIPTING
williamr@2
   560
	CImTextServerScript*			iScript;
williamr@2
   561
#endif
williamr@2
   562
williamr@2
   563
#if defined(__IMSK_SIMULATION)
williamr@2
   564
williamr@2
   565
	RFs								iFs;
williamr@2
   566
williamr@2
   567
williamr@2
   568
	TUint32							iScriptedIAP; // value to return for iap when scripting
williamr@2
   569
	TUint32							iBearerIAP; // value to return for bearer when scripting
williamr@2
   570
williamr@2
   571
williamr@2
   572
	TImSendReceiveState             iSuspendedState;
williamr@2
   573
	
williamr@2
   574
	RTimer							iSuspendTimer;
williamr@2
   575
williamr@2
   576
	RFile							iGprsFile;
williamr@2
   577
williamr@2
   578
	TBool							iGprsConfigExists;
williamr@2
   579
williamr@2
   580
	TInt							iCfgFilePos;	
williamr@2
   581
williamr@2
   582
	TTime							iLastSuspend;	// time last suspension took place
williamr@2
   583
													// in universal time
williamr@2
   584
williamr@2
   585
	TTimeIntervalSeconds 			iStart;		// number of seconds since last delay
williamr@2
   586
												// before the following delay occurs.
williamr@2
   587
												// if 0 no suspend is required.
williamr@2
   588
	TTimeIntervalSeconds 			iDuration;	// how long to delay. If 0 no suspend is
williamr@2
   589
												// required
williamr@2
   590
	TBool							iRepeat;	// repeat the above delay for an 
williamr@2
   591
												// infinite period
williamr@2
   592
williamr@2
   593
	HBufC8*							iSendData; // suspended data 
williamr@2
   594
#endif // __IMSK_SIMULATION
williamr@2
   595
	
williamr@2
   596
	CImTextServerSession*			iPrimaryTextServerSession; //Only going to be set on the secondary session
williamr@2
   597
	
williamr@2
   598
	TBool iClientOwnsConnection;
williamr@2
   599
williamr@2
   600
	/** SSL domain name for secure sockets */
williamr@2
   601
	HBufC8* iSSLDomainName;
williamr@2
   602
	TBool							iSocketIdleTimeSet;          // iSocketIdleTimeSet=ETrue, if smtp server did not responds within 10 seconds after sending "."
williamr@2
   603
	};
williamr@2
   604
williamr@2
   605
#endif