datacommsserver/esockserver/inc/ES_PROT.H
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 1997-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  @publishedPartner
       
    19  @released
       
    20 */
       
    21 
       
    22 #if !defined(__ES_PROT_H__)
       
    23 #define __ES_PROT_H__
       
    24 
       
    25 #define SYMBIAN_NETWORKING_UPS
       
    26 
       
    27 #include <es_enum.h>
       
    28 
       
    29 #include <e32std.h>
       
    30 
       
    31 	
       
    32 
       
    33 /**
       
    34 End of data,Socket can't receive more data.
       
    35 @publishedPartner
       
    36 @released
       
    37 */
       
    38 const TUint KNewDataEndofData = 0xFFFFFFFF;
       
    39 
       
    40 class CServProviderBase;
       
    41 
       
    42 namespace ESock
       
    43 {
       
    44 class CSocket;		
       
    45 }
       
    46 
       
    47 
       
    48 class MSocketNotify
       
    49 /** Abstract base class used by a CServProviderBase-derived object, through its 
       
    50 iSocket member, to notify the socket server that various events have occurred. 
       
    51 
       
    52 The class provides several up-call member functions.
       
    53 
       
    54 All up-calls on an MSocketNotify should be made in the context of the socket 
       
    55 server's thread - i.e. the thread which called NewSAPL() on the protocol. 
       
    56 
       
    57 @publishedPartner
       
    58 @released Since v5.0 */
       
    59 	{
       
    60 public:
       
    61 	/** Delete and detach flags. */
       
    62 	enum TDelete 
       
    63 		{
       
    64 		/** Delete SAP */	
       
    65 		EDelete,
       
    66 		/** Don't delete SAP */
       
    67 		EDetach
       
    68 		};
       
    69 	/** Error codes. */
       
    70 	enum TOperationBitmasks
       
    71 		{
       
    72 		/** An error has occurred which affects Send() operations */
       
    73 		EErrorSend=0x0000001,  
       
    74 
       
    75 		/** An error has occurred which affects Receive() operations. */
       
    76 		EErrorRecv=0x0000002,
       
    77 
       
    78 		/** An error has occurred which affects Connect() operations */
       
    79 		EErrorConnect=0x0000004,
       
    80 
       
    81 		/** An error has occurred which affects Close() operations */
       
    82 		EErrorClose=0x00000008,
       
    83 
       
    84 		/** An error has occurred which affects Ioctl() operations */
       
    85 		EErrorIoctl=0x00000010,
       
    86 
       
    87 		/** A fatal error has occurred */
       
    88 		EErrorFatal=0x10000000,
       
    89 		
       
    90 		/** An error has occurred which affects all operations */
       
    91 		EErrorAllOperations=0x7fffffff,
       
    92 		};
       
    93 	
       
    94 	/**
       
    95 	Indicates that new data is available on a service access point
       
    96 
       
    97 	For a stream-oriented protocol aCount should be a byte count; for datagram-oriented 
       
    98 	sockets aCount should be a datagram count.
       
    99 	
       
   100 	@note aCount is the amount of new data, not the total amount of data waiting 
       
   101 	to be read.
       
   102 	
       
   103 	@param aCount The amount of new data. A value of KNewDataEndofData indicates 
       
   104 	that the socket is in a half-closed state and will receive no more data. Any subsequent 
       
   105 	reads will complete with KErrEof and a length of 0. */
       
   106 	virtual void NewData(TUint aCount) = 0;
       
   107 	/** Indicates that new buffer space is available on a service. */
       
   108 	virtual void CanSend() = 0;
       
   109 	/** Indicates that a connection attempt has completed successfully (for active opens).
       
   110 	 
       
   111 	There are four versions of this up-call: two are for active opens and two are for passive 
       
   112 	opens. Both active and passive versions support a variant carrying user connection 
       
   113 	data for protocols which support it.
       
   114 	
       
   115 	@note A connection-less protocol should never call the ConnectComplete() up-calls.
       
   116 	@note A protocol should keep a count of sockets which have called ConnectComplete() 
       
   117 	but have not had Start() called. Sockets in this state have their Error() 
       
   118 	and NewData() calls deferred until Start() is called.*/
       
   119 	virtual void ConnectComplete() = 0;
       
   120 	/** Indicates that a connection attempt has completed successfully (for active opens).
       
   121 	 
       
   122 	There are four versions of this up-call: two are for active opens and two are for passive 
       
   123 	opens. Both active and passive versions support a variant carrying user connection 
       
   124 	data for protocols which support it.
       
   125 	
       
   126 	@note A connection-less protocol should never call the ConnectComplete() up-calls.
       
   127 	@note A protocol should keep a count of sockets which have called ConnectComplete() 
       
   128 	but have not had Start() called. Sockets in this state have their Error() 
       
   129 	and NewData() calls deferred until Start() is called.
       
   130 	
       
   131 	@param aConnectData Connect data (if supported).
       
   132 	*/
       
   133 	virtual void ConnectComplete(const TDesC8& aConnectData) = 0;
       
   134 	/** Indicates that a connection attempt has completed successfully (for passive opens). 
       
   135 	
       
   136 	There are four versions of this up-call: two are for active opens and two are for passive 
       
   137 	opens. Both active and passive versions support a variant carrying user connection 
       
   138 	data for protocols which support it.
       
   139 	
       
   140 	The versions of ConnectComplete() for passive opens carry a new SSP (socket service 
       
   141 	provider, or SAP) for the newly created socket. A new socket will then be linked up to 
       
   142 	the SSP and data transfer can take place. The original socket stays listening.
       
   143 	
       
   144 	@note A connection-less protocol should never call the ConnectComplete() up-calls.
       
   145 	@note A protocol should keep a count of sockets which have called ConnectComplete() 
       
   146 	but have not had Start() called. Sockets in this state have their Error() 
       
   147 	and NewData() calls deferred until Start() is called.
       
   148 	
       
   149 	@param aSSP The new SSP for passive opens. 
       
   150 	*/
       
   151     virtual void ConnectComplete(CServProviderBase& aSSP) = 0;
       
   152 	/** Indicates that a connection attempt has completed successfully (for passive opens). 
       
   153 	
       
   154 	There are four versions of this up-call: two are for active opens and two are for passive 
       
   155 	opens. Both active and passive versions support a variant carrying user connection 
       
   156 	data for protocols which support it.
       
   157 	
       
   158 	The versions of ConnectComplete() for passive opens carry a new SSP (socket service 
       
   159 	provider, or SAP) for the newly created socket. A new socket will then be linked up to 
       
   160 	the SSP and data transfer can take place. The original socket stays listening.
       
   161 	
       
   162 	@note A connection-less protocol should never call the ConnectComplete() up-calls.
       
   163 	@note A protocol should keep a count of sockets which have called ConnectComplete() 
       
   164 	but have not had Start() called. Sockets in this state have their Error() 
       
   165 	and NewData() calls deferred until Start() is called.
       
   166 	
       
   167 	@param aSSP The new SSP for passive opens. 
       
   168 	@param aConnectData Connect data (if supported). */
       
   169 	virtual void ConnectComplete(CServProviderBase& aSSP,const TDesC8& aConnectData) = 0;
       
   170 	/** Indicates that the SAP has finished closing down. 
       
   171 	
       
   172 	This up-call is the response to a Shutdown(). A connection-oriented protocol should call 
       
   173 	CanClose() when it has terminated communications with the remote host. Protocols can call 
       
   174 	CanClose() from within their Shutdown() code. After CanClose() has been called, an SAP may 
       
   175 	be deleted by the socket server.
       
   176 	
       
   177 	@note The protocol must not access the CServProviderBase object after calling CanClose().
       
   178 	@param aDelete Delete SAP. 
       
   179 	*/
       
   180 	virtual void CanClose(TDelete aDelete=EDelete) = 0;
       
   181 	/** Indicates that the SAP has finished closing down. 
       
   182 	
       
   183 	This up-call is the response to a Shutdown(). A connection-oriented protocol should call 
       
   184 	CanClose() when it has terminated communications with the remote host. Protocols can call 
       
   185 	CanClose() from within their Shutdown() code. After CanClose() has been called, an SAP may 
       
   186 	be deleted by the socket server.
       
   187 	
       
   188 	@note The protocol must not access the CServProviderBase object after calling CanClose().
       
   189 	@param aDisconnectData Any user data carried on the disconnect frame.
       
   190 	@param aDelete Delete SAP. 
       
   191 	*/
       
   192 	virtual void CanClose(const TDesC8& aDisconnectData,TDelete aDelete=EDelete) = 0;
       
   193 	/** Tells the socket server that an error state has arisen within the protocol. 
       
   194 	
       
   195 	It should not be used to report programmatic errors, either in the protocol 
       
   196 	itself or the socket server (a panic should be used in these cases). When 
       
   197 	Error() is called on a connection-oriented socket, the socket is moved into 
       
   198 	a dead state which denies user access to it.
       
   199 	
       
   200 	@param anError KErrNone or another of the system-wide error codes. 
       
   201 	@param anOperationMask A bitmask of TOperationBitmasks values specifying which 
       
   202 	pending operations are affected by the Error up-call. */
       
   203 	virtual void Error(TInt anError,TUint anOperationMask=EErrorAllOperations) = 0;
       
   204 	/** Indicates that the other end of a connection has disconnected.
       
   205 	
       
   206 	This is analogous to CanClose(), but in this case the other end initiated it. 
       
   207 	
       
   208 	Once the client has called Shutdown() it is	illegal to call Disconnect(). Instead, 
       
   209 	CanClose() or Error(KErrDisconnected) should be called.
       
   210 	*/
       
   211 	virtual void Disconnect(void) = 0;
       
   212 	/** Indicates that the other end of a connection has disconnected.
       
   213 	
       
   214 	This is analogous to CanClose(), but in this case the other end initiated it. 
       
   215 	
       
   216 	Once the client has called Shutdown() it is	illegal to call Disconnect(). Instead, 
       
   217 	CanClose() or Error(KErrDisconnected) should be called. 
       
   218 	
       
   219 	@param aConnectData User data in the disconnect frame.
       
   220 	*/
       
   221 	virtual void Disconnect(TDesC8& aDisconnectData) = 0;
       
   222 	/** Indicates that the currently pending Ioctl has completed.
       
   223 	
       
   224 	The parameter aBuf is protocol defined - in fact it is defined by the specific 
       
   225 	Ioctl.
       
   226 	
       
   227 	@param aBuf Any data requested by the Ioctl operation. */
       
   228 	virtual void IoctlComplete(TDesC8* aBuf) = 0;
       
   229 
       
   230 	/**
       
   231 	Indicates that there are no bearer available
       
   232 
       
   233 	@param  aConnectionParams, the connection parameters.
       
   234 	*/
       
   235 	virtual void NoBearer(const TDesC8& aConnectionParams) = 0;
       
   236 
       
   237 	/**
       
   238 	Indicates the bearer available.
       
   239 
       
   240 	@param aConnectionInfo, Information about socket connection.
       
   241 	*/
       
   242 	virtual void Bearer(const TDesC8& aConnectionInfo) = 0;
       
   243 
       
   244 	/**
       
   245 	Indicates that this socket is now completed an asynchronous join
       
   246 	with a sub-connection. It now can use the properties of the sub-connection
       
   247 	*/
       
   248 	virtual void JoinedSubConnection() {;};
       
   249 
       
   250 	/**
       
   251 	Indicates that this socket was not able to complete an asynchronous join
       
   252 	with a sub-connection. The socket is still joined, but cannot use the
       
   253 	properties of the sub-connection
       
   254 	
       
   255 	@param aError Reason the socket could not be joined
       
   256 	*/
       
   257 	virtual void SubConnectionJoinFailed(TInt /*aError*/) {;};
       
   258 
       
   259 	/**
       
   260 	Indicates that this socket has now completed an asynchronous leave
       
   261 	from a sub-connection. The socket is now connected to the sub-connection
       
   262 	anymore.
       
   263 	*/
       
   264 	virtual void LeftSubConnection() {;};
       
   265 	};
       
   266 
       
   267 
       
   268 
       
   269 /**
       
   270 @publishedPartner
       
   271 @released
       
   272 */
       
   273 const TInt KUnlimitedSockets=-1;
       
   274 
       
   275 struct TServerProtocolDesc : public TProtocolDesc
       
   276 /**
       
   277 Contains data that describes a particular protocol. 
       
   278 @publishedPartner
       
   279 @released
       
   280 
       
   281 @see CProtocolFamilyBase::ProtocolList(). 
       
   282 */
       
   283 	{
       
   284 	TInt iServiceTypeInfo;  //< Options from TProtocolServiceInfo bitwise OR'd together. @see TProtocolServiceInfo
       
   285 	TInt iNumSockets;       //< The maximum number of SSPs the protocol supports
       
   286 	};
       
   287 
       
   288 
       
   289 class MResolverNotify
       
   290 /**
       
   291 @publishedPartner
       
   292 @released
       
   293 */
       
   294 	{
       
   295 public:
       
   296 	virtual void QueryComplete(TInt anError)=0;
       
   297 	};
       
   298 
       
   299 /**
       
   300 Security checker class passed down to providers which is used to perform security checks on the client
       
   301 of the provider.  The provider calls the CheckPolicy(...) method with a suitable TSecurityPolicy
       
   302 class and a diagnostic string as arguments.
       
   303 
       
   304 @see CServProviderBase
       
   305 @see CResolverProvdBase
       
   306 
       
   307 @code
       
   308 _LIT_SECURITY_POLICY_C1(myPolicy1, ECapabilityNetworkServices);
       
   309 ...
       
   310 TInt CMyProvider::SecurityCheck(MProvdSecurityChecker *aChecker)
       
   311 {
       
   312 	...
       
   313 	if (aChecker->CheckPolicy(myPolicy1, "CMyProvider main") == KErrNone)
       
   314 	{
       
   315 		// client has NetworkServices capability
       
   316 	}
       
   317 	...
       
   318 }
       
   319 @endcode
       
   320 
       
   321 @publishedPartner
       
   322 @released
       
   323 */
       
   324 class MProvdSecurityChecker 
       
   325 {
       
   326 public:
       
   327 	/**
       
   328 	Check the security policy of a client process.
       
   329 	
       
   330 	Called from a socket or resolver provider to check whether the client process conforms to a security policy.
       
   331 	
       
   332 	@param aPolicy A TSecurityPolicy class instance containing the security information to be checked against the client.
       
   333 	@param aDiagnostic A diagnostic string used when logging system-wide security failures, else 0.
       
   334 	@return KErrNone if client process has the required security information, else KErrPermissionDenied.
       
   335 	(In the future, some other system error may be returned).
       
   336 	*/
       
   337 	virtual TInt CheckPolicy(const TSecurityPolicy& aPolicy, const char *aDiagnostic) = 0;
       
   338 };
       
   339 
       
   340 namespace ESock
       
   341 {
       
   342 class CSubConnectionProviderBase;
       
   343 }
       
   344 
       
   345 class RMBufChain;
       
   346 class CServProviderBase : public CBase
       
   347 /** Service Access Point.
       
   348 
       
   349 Provides transport services to a single protocol. Several of the calls to 
       
   350 CServProviderBase have pre-conditions attached to them - for example 
       
   351 a connection oriented protocol must have its local address set (either by 
       
   352 a SetLocalName() or AutoBind()) before it is opened. If the socket server 
       
   353 calls the CServProviderBase in such an erroneous way, the protocol should panic.
       
   354 
       
   355 @publishedPartner
       
   356 @released Since 5.0 */
       
   357 	{
       
   358 	friend class ProtocolManager;
       
   359 public:
       
   360 
       
   361 	/** Describes the behaviour the SAP should take on shutdown.*/
       
   362 	enum TCloseType 
       
   363 	{
       
   364 		ENormal,        //< The protocol should shutdown gracefully — no further input or output will be requested.
       
   365 		EStopInput,     //< The protocol should shut down gracefully — all further and pending input should be discarded.
       
   366 		EStopOutput,    //< The protocol should shutdown gracefully — all pending output should be discarded.
       
   367 		EImmediate      //< The protocol should close the connection immediately and free all resources without performing a graceful disconnect.
       
   368 	};
       
   369 	IMPORT_C CServProviderBase();
       
   370 	IMPORT_C virtual ~CServProviderBase();
       
   371 
       
   372 	IMPORT_C virtual void SetNotify(MSocketNotify* aSocket);
       
   373 	//V1.0 itf support
       
   374 	IMPORT_C virtual void SetSockType(TUint aSockType);
       
   375 	IMPORT_C TUint SockType() const;
       
   376 
       
   377 	IMPORT_C virtual void JoinSubConnectionL(ESock::CSubConnectionProviderBase& aSubConnProvider);
       
   378 	IMPORT_C virtual void LeaveSubConnection(ESock::CSubConnectionProviderBase& aSubConnProvider);
       
   379 
       
   380 public:
       
   381 
       
   382 /**
       
   383 pure virtual
       
   384 */
       
   385 	/**
       
   386 	Start a service provider.
       
   387 	*/
       
   388 	virtual void Start()=0;
       
   389 	/** Gets the local name (address) of the socket service provider entity. The format 
       
   390 	of the data in the TSockAddr object is defined by individual protocols.
       
   391 	
       
   392 	The local address is the address of the local machine plus a local port number. 
       
   393 	Generally only the port number is important, unless you have two IP interfaces, 
       
   394 	for example.
       
   395 	
       
   396 	@param anAddr The address to be filled in */
       
   397 	virtual void LocalName(TSockAddr& anAddr) const =0;
       
   398 	/** Sets the local name (address) of the socket service provider entity. The format 
       
   399 	of the data in the TSockAddr object is defined by individual protocols.
       
   400 	
       
   401 	@param anAddr The address 
       
   402 	@return Returns KErrNone if the local name is correctly set or, if this is 
       
   403 	not the case, an informative error number. */
       
   404 	virtual TInt SetLocalName(TSockAddr& anAddr)=0;
       
   405 	/** Gets the remote name (address) of the socket service provider entity. The format 
       
   406 	of the data in the TSockAddr object is defined by individual protocols.
       
   407 	
       
   408 	A remote address is either the address you're sending data to (non connection-oriented 
       
   409 	sockets)* or the remote end of the connection. It is the address of the remote 
       
   410 	machine (your peer in the network) plus a port number.
       
   411 	
       
   412 	@note RemName is only meaningful if the socket server client has called Connect() 
       
   413 	to set up a default address for SendTo(). This function will only be called 
       
   414 	on the protocol if this is the case.
       
   415 	
       
   416 	@param anAddr The address to be filled in */
       
   417 	virtual void RemName(TSockAddr& anAddr) const =0;
       
   418 	/** Sets the remote name (address) of the socket service provider entity. The format 
       
   419 	of the data in the TSockAddr object is defined by individual protocols.
       
   420 	
       
   421 	@param anAddr The address 
       
   422 	@return Returns KErrNone if the remote name is correctly set or, if this is 
       
   423 	not the case, an informative error number. */
       
   424 	virtual TInt SetRemName(TSockAddr& anAddr)=0;
       
   425 	/** Gets some protocol specific option when called by the socket server on behalf of a 
       
   426 	client. A protocol may pass the request down a protocol	stack (to protocols it is bound 
       
   427 	to) using the GetOption() function of CProtocolBase.
       
   428 	
       
   429 	@param aLevel Option level.
       
   430 	@param aName Option name.
       
   431 	@param anOption Option data.
       
   432 	@return System wide error code.
       
   433 	*/
       
   434 	virtual TInt GetOption(TUint level,TUint name,TDes8& anOption)const =0;
       
   435 	/** Performs some protocol specific IO control. 
       
   436 	
       
   437 	@note If this function is called erroneously, the protocol should call Error() on the 
       
   438 	socket. If an Ioctl call is already outstanding, the client will be panicked with the 
       
   439 	value ETwoIoctls.
       
   440 	
       
   441 	@param aLevel Option level.
       
   442 	@param aName Option name.
       
   443 	@param anOption Option data.
       
   444 	@return System wide error code.
       
   445 	*/
       
   446 	virtual void Ioctl(TUint level,TUint name,TDes8* anOption)=0;
       
   447 	/** Cancels an outstanding Ioctl call. You are guaranteed only to have one outstanding 
       
   448 	at once. 
       
   449 	
       
   450 	@param aLevel IOCTL level. 
       
   451 	@param aName IOCTL name. 
       
   452 	*/
       
   453 	virtual void CancelIoctl(TUint aLevel,TUint aName)=0;
       
   454 	/** Sets some protocol specific option when called by the socket server on behalf of a 
       
   455 	client. A protocol may pass the request down a protocol	stack (to protocols it is bound 
       
   456 	to) using the SetOption() function	of CProtocolBase.
       
   457 	
       
   458 	@param aLevel Option level.
       
   459 	@param aName Option name.
       
   460 	@param anOption Option data.
       
   461 	@return System wide error code.
       
   462 	*/
       
   463 	virtual TInt SetOption(TUint level,TUint name,const TDesC8& anOption)=0;
       
   464 	virtual void ActiveOpen()=0;
       
   465 	/** Initiates a connection operation - this means that it tells the protocol to 
       
   466 	attempt to connect to a peer. It is called by the socket server in response 
       
   467 	to a connect request from a client. 
       
   468 	
       
   469 	This version of the function has user data in the connection frame.
       
   470 	
       
   471 	Only ever called on connection-oriented sockets. Such a socket 
       
   472 	should always have both the local address and the remote address specified 
       
   473 	before this function is called. If this is not the case then the protocol 
       
   474 	should panic.
       
   475 	
       
   476 	When a connection has completed, the protocol should call ConnectComplete() 
       
   477 	on its TNotify. If an error occurs during connection the protocol should not 
       
   478 	call ConnectComplete() at all; instead it should call Error().
       
   479 	
       
   480 	@param aConnectionData If the protocol supports user specified connection 
       
   481 	data, then it will be held in this buffer. */
       
   482 	virtual void ActiveOpen(const TDesC8& aConnectionData)=0;
       
   483 	/** Tells the protocol to start waiting for an incoming connection request on this 
       
   484 	socket (i.e. port). It is called by the socket server in response to a listen 
       
   485 	request from a client.
       
   486 	
       
   487 	Only ever called on connection-oriented sockets. Such a socket 
       
   488 	should always have both the local address and the remote address specified 
       
   489 	before this function is called. If this is not the case, then the protocol 
       
   490 	should panic.
       
   491 	
       
   492 	The aQue parameter is the number of sockets which can be waiting for an outstanding 
       
   493 	Start after calling ConnectComplete(). The protocol should keep a count of 
       
   494 	sockets in this state - incrementing a variable in ConnectComplete(), and 
       
   495 	decrementing it in Start().
       
   496 	
       
   497 	When a connection has completed, the protocol should call ConnectComplete() 
       
   498 	on its TNotify. If an error occurs during connection the protocol should not 
       
   499 	call ConnectComplete() at all; instead it should call Error().
       
   500 	
       
   501 	@param aQueSize Size of connect queue. 
       
   502 	*/
       
   503 	virtual TInt PassiveOpen(TUint aQueSize)=0;
       
   504 	/** Tells the protocol to start waiting for an incoming connection request on this 
       
   505 	socket (i.e. port). It is called by the socket server in response to a listen 
       
   506 	request from a client.
       
   507 	
       
   508 	This version of the function has user data in the connection frame.
       
   509 	
       
   510 	Only ever called on connection-oriented sockets. Such a socket 
       
   511 	should always have both the local address and the remote address specified 
       
   512 	before this function is called. If this is not the case then the protocol 
       
   513 	should panic.
       
   514 	
       
   515 	The aQue parameter is the number of sockets which can be waiting for an outstanding 
       
   516 	Start after calling ConnectComplete(). The protocol should keep a count of 
       
   517 	sockets in this state - incrementing a variable in ConnectComplete(), and 
       
   518 	decrementing it in Start().
       
   519 	
       
   520 	When a connection has completed the protocol should call ConnectComplete() 
       
   521 	on its TNotify. If an error occurs during connection the protocol should not 
       
   522 	call ConnectComplete() at all; instead it should call Error().
       
   523 	
       
   524 	@param aQueSize size of connect queue 
       
   525 	@param aConnectionData if the protocol supports user specified connection data 
       
   526 	then it will be held in this buffer. */
       
   527 	virtual TInt PassiveOpen(TUint aQueSize,const TDesC8& aConnectionData)=0;
       
   528 	/** Terminates a connection (or closes a non connection-oriented socket down).
       
   529 	 
       
   530 	The value of the option argument specifies the type of processing which will 
       
   531 	be required of the protocol after this function is called.
       
   532 	
       
   533 	Normally, when the socket server has called Shutdown() for a socket, it will 
       
   534 	wait for the socket to call CanClose() before destroying the CServProviderBase 
       
   535 	object. However, if the option argument is EImmediate, the CServProviderBase 
       
   536 	will be destroyed as soon as Shutdown() returns.
       
   537 	
       
   538 	@param option The shutdown type. */
       
   539 	virtual void Shutdown(TCloseType option)=0;
       
   540 	/** Terminates a connection (or closes a non connection-oriented socket down). 
       
   541 	
       
   542 	The value of the option argument specifies the type of processing which will 
       
   543 	be required of the protocol after this function is called.
       
   544 	
       
   545 	Normally, when the socket server has called Shutdown() for a socket, it will 
       
   546 	wait for the socket to call CanClose() before destroying the CServProviderBase 
       
   547 	object. However, if the option argument is EImmediate, the CServProviderBase 
       
   548 	will be destroyed as soon as Shutdown() returns.
       
   549 	
       
   550 	@param option The shutdown type. 
       
   551 	@param aDisconnectionData If the protocol supports disconnect data, any such 
       
   552 	data required will be held in this buffer. */
       
   553 	virtual void Shutdown(TCloseType option,const TDesC8& aDisconnectionData)=0;
       
   554 	/** Specifies that the protocol should choose a local address for the service access 
       
   555 	point itself. */
       
   556 	virtual void AutoBind()=0;
       
   557 
       
   558 // protocol read/write data; ESock v1.5 calls down to the v1.5 itf (RMBufChain). 
       
   559 // v1.5-ready protocols implement this, laggard protocols inherit these base class
       
   560 // implementations which call the v1.0 descriptor itf instead. 
       
   561 
       
   562 	/** Sends data onto the network via the protocol.
       
   563 	
       
   564 	Connection-oriented sockets must be in a connected state (that is ConnectComplete() has 
       
   565 	been called on their MSocketNotify before Write() is called).
       
   566 	 
       
   567 	The socket server keeps track of how much data is waiting and then tries to send it all 
       
   568 	until the protocol tells it to hold off by returning 0 (datagram sockets) or 'less than 
       
   569 	all data consumed' (stream sockets) to Write(). The protocol should call CanSend() when it 
       
   570 	is ready to send more data.
       
   571 	
       
   572 	anAddr is the address to write the data to.	Connection oriented sockets always use the 
       
   573 	default value.
       
   574 	
       
   575 	@param aDesc The data to be sent.
       
   576 	@param aOptions Protocol specific options.
       
   577 	@param anAddr Address to write the data to.
       
   578 	
       
   579 	@returns For stream-oriented protocols the return value is the number of bytes actually written. 
       
   580 	If this is less than the length of the descriptor then the protocol should call CanSend() 
       
   581 	when it is ready to send more data. For datagram-oriented protocols, the write should return 
       
   582 	either 0 if the write cannot be completed, or the length of the descriptor if the write succeeds - 
       
   583 	no other values are valid. If the Write() must return 0, then it should call CanSend() when it is 
       
   584 	ready to send more data. If the Write() fails due to some error, then it should call Error() with 
       
   585 	an informative error number.
       
   586 	*/
       
   587 	IMPORT_C virtual TUint Write(const TDesC8& aDesc,TUint options, TSockAddr* anAddr=NULL);
       
   588 	/** Sends data onto the network via the protocol.
       
   589 	
       
   590 	Connection-oriented sockets must be in a connected state (that is ConnectComplete() has 
       
   591 	been called on their MSocketNotify before Write() is called).
       
   592 	 
       
   593 	The socket server keeps track of how much data is waiting and then tries to send it all 
       
   594 	until the protocol tells it to hold off by returning 0 (datagram sockets) or 'less than 
       
   595 	all data consumed' (stream sockets) to Write(). The protocol should call CanSend() when it 
       
   596 	is ready to send more data.
       
   597 	
       
   598 	anAddr is the address to write the data to.	Connection oriented sockets always use the 
       
   599 	default value.
       
   600 	
       
   601 	@param aData The data to be sent.
       
   602 	@param aOptions Protocol specific options.
       
   603 	@param anAddr Address to write the data to.
       
   604 	
       
   605 	@returns For stream-oriented protocols the return value is the number of bytes actually written. 
       
   606 	If this is less than the length of the descriptor then the protocol should call CanSend() 
       
   607 	when it is ready to send more data. For datagram-oriented protocols, the write should return 
       
   608 	either 0 if the write cannot be completed, or the length of the descriptor if the write succeeds - 
       
   609 	no other values are valid. If the Write() must return 0, then it should call CanSend() when it is 
       
   610 	ready to send more data. If the Write() fails due to some error, then it should call Error() with 
       
   611 	an informative error number.
       
   612 	*/
       
   613 	IMPORT_C virtual TInt Write(RMBufChain& aData, TUint aOptions, TSockAddr* anAddr=NULL);
       
   614 
       
   615 	/** Gets data which the protocol has indicated is waiting in its buffers using the NewData 
       
   616 	up-call on the MSocketNotify. 
       
   617 	
       
   618 	GetData() will only ever be called for as much data as the protocol has specified it can process 
       
   619 	using the NewData up-call. 
       
   620 	
       
   621 	For stream oriented protocols GetData() should fill the descriptor with data from the stream. On 
       
   622 	a datagram protocol GetData() should copy one datagram into the descriptor and set the length of 
       
   623 	the descriptor. If a full datagram will not fit into the supplied descriptor, the overflow should 
       
   624 	be discarded. 
       
   625 	
       
   626 	anAddr should be filled in by the protocol with the address of where the data came from.
       
   627 	
       
   628 	@param aDesc  The buffer for data.
       
   629 	@param aOptions Protocol specific options.
       
   630 	@param anAddr Address where the data came from.
       
   631 	*/
       
   632 	IMPORT_C virtual void GetData(TDes8& aDesc,TUint options,TSockAddr* anAddr=NULL);
       
   633 	/** Gets data which the protocol has indicated is waiting in its buffers using the NewData 
       
   634 	up-call on the MSocketNotify. 
       
   635 	
       
   636 	GetData() will only ever be called for as much data as the protocol has specified it can process 
       
   637 	using the NewData up-call. 
       
   638 	
       
   639 	For stream oriented protocols GetData() should fill the descriptor with data from the stream. On 
       
   640 	a datagram protocol GetData() should copy one datagram into the descriptor and set the length of 
       
   641 	the descriptor. If a full datagram will not fit into the supplied descriptor, the overflow should 
       
   642 	be discarded. 
       
   643 	
       
   644 	anAddr should be filled in by the protocol with the address of where the data came from.
       
   645 	
       
   646 	@param aDesc  The buffer for data.
       
   647 	@param aOptions Protocol specific options.
       
   648 	@param anAddr Address where the data came from.
       
   649 	*/
       
   650 	IMPORT_C virtual TInt GetData(RMBufChain& aData, TUint aLength, TUint aOptions, TSockAddr* anAddr=NULL);
       
   651 
       
   652 	/**  Use the class instance argument to perform security policy checks on the originating client process.
       
   653 	
       
   654 	This method is called when a SAP is created and when a socket is transferred between sessions.  The SAP is
       
   655 	required to check whether the originating client process has enough privileges to request services from the SAP.
       
   656 	The MProvdSecurityChecker class instance is used to perform security policy checks.  The SAP may choose
       
   657 	to perform a security policy check in its SecurityCheck(...) method, or it may choose to store the
       
   658 	MProvdSecurityChecker class instance argument and perform checking later (i.e. when subsequent
       
   659 	SAP methods are called).
       
   660 	
       
   661 	@param aSecurityChecker Pointer to class used by SAP to perform security checks on the client process.  This
       
   662 	pointer becomes invalid when the SAP is destroyed or detached.
       
   663 	@returns KErrPermissionDenied if SAP wishes to disallow access to the client, else KErrNone.  This would
       
   664 	normally be as a result of calling MProvdSecurityChecker::CheckPolicy(...) with a suitable security policy argument.
       
   665 	*/
       
   666 	IMPORT_C virtual TInt SecurityCheck(MProvdSecurityChecker *aSecurityChecker);
       
   667 	
       
   668 protected:
       
   669 	/** On socket creation, the socket server sets this member to point to a server 
       
   670 	notification interface. */
       
   671 	MSocketNotify* iSocket;
       
   672 private:
       
   673 	//V1.0 interface support specifics
       
   674 	HBufC8* iV1ShimDataIn;
       
   675 	HBufC8* iV1ShimDataOut;
       
   676 	TUint iSockType;
       
   677 	};
       
   678 
       
   679 class CProtocolBase;
       
   680 class CResolverProvdBase : public CBase
       
   681 /**
       
   682 @publishedPartner
       
   683 @released
       
   684 */
       
   685 	{
       
   686 	friend class ProtocolManager;
       
   687 public:
       
   688 	inline void SetNotify(MResolverNotify* aNotifier);
       
   689 
       
   690 	/**
       
   691 	@internalComponent
       
   692 	*/
       
   693 	virtual void CancelCurrentOperation()=0;
       
   694 
       
   695 	/**  Use the class instance argument to perform security policy checks on the originating client process.
       
   696 	
       
   697 	This method is called when a resolver is created.  The resolver is required to check whether the originating
       
   698 	client process has enough privileges to request services from the resolver.  The MProvdSecurityChecker
       
   699 	class instance is used to perform security policy checks.  The resolver may choose to perform a security
       
   700 	policy check in its SecurityCheck(...) method, or it may choose to store the MProvdSecurityChecker class
       
   701 	instance argument and use it to perform checking later (i.e. when subsequent resolver methods are called).
       
   702 	
       
   703 	@param aSecurityChecker Pointer to class used by resolver to perform security checks on the client process.  This
       
   704 	pointer becomes invalid when the resolver is destroyed or detached.
       
   705 	@returns KErrPermissionDenied if resolver wishes to disallow access to the client, else KErrNone.  This would
       
   706 	normally be as a result of calling MProvdSecurityChecker::CheckPolicy(...) with a suitable security policy argument.
       
   707 	*/
       
   708 	IMPORT_C virtual TInt SecurityCheck(MProvdSecurityChecker *aSecurityChecker);
       
   709 	
       
   710 protected:
       
   711 	MResolverNotify* iNotify;
       
   712 private:
       
   713 	CProtocolBase* iProtocol;
       
   714 	};
       
   715 
       
   716 class CHostResolvProvdBase : public CResolverProvdBase
       
   717 /**
       
   718 Provides Host name resolver service
       
   719 @publishedPartner
       
   720 @released
       
   721 */
       
   722 	{
       
   723 	friend class ProtocolManager;
       
   724 public:
       
   725 
       
   726 	/**
       
   727 	Get the Host name by name
       
   728 	@param aName, results of name queries
       
   729 	*/
       
   730 	virtual void GetByName(TNameRecord& aName)=0;
       
   731 
       
   732 	/**
       
   733 	Gets the Host name by address
       
   734 	@param aName, results of name queries
       
   735 	*/
       
   736 	virtual void GetByAddress(TNameRecord& aName)=0;
       
   737 
       
   738 	/**
       
   739 	Sets the Host name
       
   740 	@param aNameBuf, name to set
       
   741 	*/
       
   742 	virtual void SetHostName(TDes& aNameBuf)=0;
       
   743 
       
   744 	/**
       
   745 	Gets the Host name 
       
   746 	@param aNameBuf, name to retrieve
       
   747 	*/
       
   748 	virtual void GetHostName(TDes& aNameBuf)=0;
       
   749 	IMPORT_C virtual TInt SetOption(TUint level,TUint name,const TDesC8& anOption);
       
   750     IMPORT_C virtual void Query(const TDesC8& aQryBuf, TDes8& aResBuf, TInt aCounter);
       
   751 	};
       
   752 
       
   753 class CServiceResolvProvdBase : public CResolverProvdBase
       
   754 /**
       
   755 @publishedPartner
       
   756 @released
       
   757 */
       
   758 	{
       
   759 	friend class ProtocolManager;
       
   760 public:
       
   761 	
       
   762 	/**
       
   763 	Get the Host name by name
       
   764 	@param aName, results of name queries
       
   765 	*/
       
   766 	virtual void GetByName(const TDesC& aNameBuf,TInt32& aPortNum)=0;
       
   767 	
       
   768 	/**
       
   769 	Gets the Host name by address
       
   770 	@param aName, results of name queries
       
   771 	*/
       
   772 	virtual void GetByNumber(TDes& aNameBuf,TInt32 aPortNum)=0;
       
   773 	
       
   774 	/**
       
   775 	Sets the Host name
       
   776 	@param aNameBuf, name to set
       
   777 	*/
       
   778 	virtual void RegisterService(const TDesC& aNameBuf,TInt32 aPortNum)=0;
       
   779 	
       
   780 	/**
       
   781 	Gets the Host name 
       
   782 	@param aNameBuf, name to retrieve
       
   783 	*/
       
   784 	virtual void RemoveService(const TDesC& aNameBuf,TInt32 aPortNum)=0;
       
   785 	};
       
   786 
       
   787 class CNetDBProvdBase : public CResolverProvdBase
       
   788 /**
       
   789 Provides network Database access
       
   790 @publishedPartner
       
   791 @released
       
   792 */
       
   793 	{
       
   794 	friend class ProtocolManager;
       
   795 public:
       
   796 	virtual void Query(TDes8& aBuffer)=0;
       
   797 	virtual void Add(TDes8& aBuffer)=0;
       
   798 	virtual void Remove(TDes8& aBuffer)=0;
       
   799 	};
       
   800 
       
   801 namespace ESock
       
   802 {
       
   803 class CSubConnectionProviderBase;
       
   804 }
       
   805 
       
   806 
       
   807 class CProtocolFamilyBase;
       
   808 class RMBufChain;
       
   809 class CProtocolRef;
       
   810 class CProtocolBase : public CBase
       
   811 /** Protocols created by protocol families must be instances of sub-classes of 
       
   812 the abstract CProtocolBase.
       
   813 @publishedPartner
       
   814 @released Since v5.0 */
       
   815 	{
       
   816 	friend class ProtocolManager;
       
   817 	friend class CProtocolRef;
       
   818 
       
   819 public:
       
   820 	IMPORT_C virtual CServProviderBase* NewSAPL(TUint aProtocol);
       
   821 	IMPORT_C virtual CHostResolvProvdBase* NewHostResolverL();
       
   822 	IMPORT_C virtual CServiceResolvProvdBase* NewServiceResolverL();
       
   823 	IMPORT_C virtual CNetDBProvdBase* NewNetDatabaseL();
       
   824 	IMPORT_C CProtocolBase();
       
   825 	IMPORT_C virtual ~CProtocolBase();
       
   826 	CProtocolFamilyBase* ProtocolFamily();
       
   827 	IMPORT_C virtual void Close();
       
   828 	IMPORT_C virtual void Open();
       
   829 	IMPORT_C virtual void CloseNow();
       
   830 	IMPORT_C virtual void StartSending(CProtocolBase* aProtocol);	// Up
       
   831 	IMPORT_C TPtrC Tag();
       
   832 	IMPORT_C virtual void InitL(TDesC& aTag);	// From ProtocolManager before all binding.
       
   833 	IMPORT_C virtual void StartL();	// From Protocol Manager - after all binding
       
   834 	IMPORT_C virtual void BindL(CProtocolBase* protocol, TUint id);	// From higher protocol
       
   835 	IMPORT_C virtual void BindToL(CProtocolBase* protocol);	// From Protocol Manager
       
   836 	IMPORT_C virtual TInt Send(RMBufChain& aPDU,CProtocolBase* aSourceProtocol=NULL);	// Down
       
   837 	IMPORT_C virtual TInt Send(TDes8& aPDU,TSockAddr* to,TSockAddr* from=NULL,CProtocolBase* aSourceProtocol=NULL);	// Done
       
   838 	IMPORT_C virtual void Process(RMBufChain&,CProtocolBase* aSourceProtocol=NULL);	// Up
       
   839 	IMPORT_C virtual void Process(TDes8& aPDU,TSockAddr* from,TSockAddr* to=NULL,CProtocolBase* aSourceProtocol=NULL);	// Up
       
   840 	IMPORT_C virtual TInt GetOption(TUint level,TUint name,TDes8& option,CProtocolBase* aSourceProtocol=NULL);	// Down
       
   841 	IMPORT_C virtual TInt SetOption(TUint level,TUint name,const TDesC8& option,CProtocolBase* aSourceProtocol=NULL);	// Down
       
   842 	IMPORT_C virtual void Error(TInt anError,CProtocolBase* aSourceProtocol=NULL);	// Up
       
   843 
       
   844 // Pure virtual
       
   845 	/** Fills in the passed TServerProtocolDesc with data describing the protocol. 
       
   846 	
       
   847 	@param aProtocolDesc Protocol description object to fill in */
       
   848 	virtual void Identify(TServerProtocolDesc* aProtocolDesc)const =0;	// from anyone.
       
   849 
       
   850 	inline TInt RefCount() const;
       
   851 protected:
       
   852 	IMPORT_C void CanClose();	// Up
       
   853 private:
       
   854 	void TryDelete();
       
   855 protected:
       
   856 //	TProtocolDesc iDesc;
       
   857 private:
       
   858 	CProtocolRef* iManagerRef;
       
   859 	TInt iRefCount;
       
   860 	};
       
   861 
       
   862 namespace ESock
       
   863 {
       
   864 class CConnection;
       
   865 }
       
   866 class CProtocolFamilyRef;
       
   867 class CLibUnloader;
       
   868 class CConnectionProvdBase;
       
   869 class CProtocolFamilyBase : public CBase
       
   870 /** Defines the interface for protocol families. 
       
   871 
       
   872 Protocol families must:
       
   873 
       
   874 be able to identify the protocols which they can create
       
   875 
       
   876 be able to create instances of protocol objects for all the protocols they 
       
   877 advertise 
       
   878 
       
   879 @publishedPartner
       
   880 @released */
       
   881 	{
       
   882 friend class ProtocolManager;
       
   883 friend class CProtocolFamilyRef;
       
   884 public:
       
   885 	IMPORT_C virtual ~CProtocolFamilyBase();
       
   886 	IMPORT_C CProtocolFamilyBase();
       
   887 	IMPORT_C virtual void Close();
       
   888 	IMPORT_C virtual void Open();
       
   889 	IMPORT_C virtual TInt Remove();
       
   890 	IMPORT_C virtual TBool QueryVersionSupported(const TVersion& aVer) const;
       
   891 
       
   892 	void SetLibraryL(RLibrary& aLib);
       
   893 
       
   894 	// Pure virtual
       
   895 	/** Initialises a protocol family. 
       
   896 	
       
   897 	After the CProtocolFamilyBase-derived object has been created, the first function 
       
   898 	called by the socket server on that object is Install(). It is at this point that the
       
   899 	CProtocolFamilyBase-derived object should perform any initialisation which it needs.
       
   900 	
       
   901 	@return System-wide error code */
       
   902 	virtual TInt Install()=0;
       
   903 	/** Creates a new protocol object. 
       
   904 	
       
   905 	During socket creation, after the socket server has called Open() on a protocol family, 
       
   906 	it next calls this function to create an instance of a CProtocolBase-derived object - 
       
   907 	the protocol itself.
       
   908 	
       
   909 	@param aSockType A supported socket type for the protocol family as advertised 
       
   910 	in the protocol list. 
       
   911 	@param aProtocol A protocol number specifying a protocol returned by ProtocolList(). 
       
   912 	
       
   913 	@return A protocol, or NULL if some error has prevented the protocol from being 
       
   914 	created. */
       
   915 	virtual CProtocolBase * NewProtocolL(TUint aSockType,TUint aProtocol)=0;
       
   916 	/** Gets a list of supported protocols. 
       
   917 	
       
   918 	Called during initialisation, directly after Install(). ProtocolList() returns a list 
       
   919 	of all the protocols in the protocol family. The protocol family object should allocate 
       
   920 	memory to hold an array of TServerProtocolDesc structures. This function should then 
       
   921 	fill them in and return the pointer and a count of the number of protocols 
       
   922 	supported. The socket server caches this information, so that it does not 
       
   923 	need to keep the protocol module loaded.
       
   924 	
       
   925 	The protocol family should not attempt to use static data (which it can't) 
       
   926 	or to free this memory later, as the socket server will automatically free 
       
   927 	this storage.
       
   928 	
       
   929 	@param aProtocolList This pointer is set to point to memory allocated by the 
       
   930 	protocol family and filled in as described above 
       
   931 	@return The number of protocols in this protocol family (and entries in the 
       
   932 	list of protocols) */
       
   933 	virtual TUint ProtocolList(TServerProtocolDesc*& aProtocolList)=0;
       
   934 
       
   935 	inline TInt RefCount() const;
       
   936 
       
   937 protected:
       
   938 
       
   939 	/** Contains version information */
       
   940 	TVersion iVersion;
       
   941 private:
       
   942 	TInt iRefCount;
       
   943 	CLibUnloader* iLibUnloader;
       
   944 	CProtocolFamilyRef* iManagerRef;
       
   945 	};
       
   946 
       
   947 /**
       
   948 @publishedPartner
       
   949 @released
       
   950 */
       
   951 typedef CProtocolFamilyBase* (*TProtocolNew)();
       
   952 
       
   953 
       
   954 
       
   955 class TSoOwnerInfo
       
   956 /**
       
   957 Class used to communicate the owner of a socket from ESOCK to Provider.
       
   958 
       
   959 Note that this only represents the thread/process that initially opened the socket and
       
   960 not, for example, any subsequent thread/process that issues IPC's on the socket from a
       
   961 shared session.
       
   962 
       
   963 @publishedPartner.
       
   964 @released
       
   965 */
       
   966 	{
       
   967 public:
       
   968 	TUidType    iUid;
       
   969 	TProcessId  iProcessId;
       
   970 	TThreadId   iThreadId;	
       
   971 	};
       
   972 
       
   973 
       
   974 
       
   975 /**
       
   976 UID of Protocol Modules
       
   977 @publishedPartner
       
   978 @released */
       
   979 const TInt KUidProtocolModule = 0x1000004A;
       
   980 
       
   981 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   982 #include <es_prot_internal.h>
       
   983 #endif
       
   984 
       
   985 #include <es_prot.inl>
       
   986 
       
   987 #endif