datacommsserver/esockserver/inc/es_config.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #if !defined (__ES_CONFIG_H__)
       
    17 #define __ES_CONFIG_H__
       
    18 
       
    19 #include <in_sock.h>
       
    20 
       
    21 // configuration daemon structures for use with
       
    22 // RConnection::Ioctl()
       
    23 
       
    24 class TConnectionAddress
       
    25 /**
       
    26   * TConnectionAddress class
       
    27   *
       
    28   * For use when querying for the configured
       
    29   * address with RConnection::Ioctl() using 
       
    30   * the KConnGetCurrentAddr constant. The client
       
    31   * must provide the IP version the request is meant for
       
    32   *
       
    33   * @publishedPartner
       
    34   * @released
       
    35   */
       
    36 	{
       
    37 public:
       
    38 	TUint32 iAddressFamily;		// KAfInet or KAfInet6
       
    39 	TSockAddr iAddr;
       
    40 	};
       
    41 typedef TPckgBuf<TConnectionAddress> TConnectionAddrBuf;
       
    42 
       
    43 
       
    44 class TConnectionLeaseInfo
       
    45 /**
       
    46   * TConnectionLeaseInfo class
       
    47   *
       
    48   * For use when querying for the lease time
       
    49   * remaining with RConnection::Ioctl() using
       
    50   * the KConnGetLeaseTimeRemain constant.  The client
       
    51   * must provide the IP version the request is meant for
       
    52   *
       
    53   * @publishedPartner
       
    54   * @released
       
    55   */
       
    56 	{
       
    57 public:
       
    58 	TUint iAddressFamily;		// KAfInet or KAfInet6	
       
    59 	TUint iSecondsRemaining;
       
    60 	};
       
    61 typedef TPckgBuf<TConnectionLeaseInfo> TConnectionLeaseInfoBuf;
       
    62 
       
    63 
       
    64 template <class T>
       
    65 class TPckgDes
       
    66 /**
       
    67   * TPckgDes - dynamic packaging using user allocated buffer
       
    68   *
       
    69   * The buffer starts with structure \<T\> followed by an arbitrary buffer starting at iPtr8
       
    70   * the idea is that we can send a structure and dynamically allocated buffer as one continuous
       
    71   * descriptor rather than pack a structure having a pointer to another descriptor.
       
    72   *
       
    73   * @publishedPartner
       
    74   * @released
       
    75   */
       
    76 	{
       
    77 public:
       
    78 	TPckgDes(TDes8& aDes) :
       
    79 		iDes(&aDes)
       
    80 		/**
       
    81 		 * @param aDes User buffer to hold data fetched.
       
    82 		 */
       
    83 		{
       
    84 		}
       
    85 		
       
    86 	inline T& operator()()
       
    87 		{
       
    88 	 	return(*((T *)iDes->Ptr()));
       
    89 		}
       
    90 		
       
    91 	inline TPtr8 Buf()
       
    92 		{
       
    93 	 	return TPtr8(const_cast<TUint8*>(iDes->Ptr()) + sizeof(T), iDes->Length() - sizeof(T), iDes->MaxLength() - sizeof(T));
       
    94 		}
       
    95 
       
    96 	inline void SetBufLengthL(TInt aNewLength)
       
    97 		{
       
    98 		TInt newLength = aNewLength + sizeof(T);
       
    99 		if (newLength > iDes->MaxLength())
       
   100 			{
       
   101     		User::Leave(KErrOverflow);
       
   102      		}
       
   103 	 	iDes->SetLength(newLength);
       
   104 		}
       
   105 
       
   106 protected:
       
   107    TDes8* iDes; //user allocated descriptor
       
   108    };
       
   109    
       
   110 
       
   111 class TDhcpRawOptionDataPckg : public TPckgDes<TUint8>
       
   112 /**
       
   113   * TDhcpRawOptionDataPckg - provide simple interface for sending the dhcp raw option.
       
   114   *
       
   115   * The data contained in the package is the opcode and the value of the raw option.
       
   116   * The length of the buffer is set with the length of the descriptor containing 'the
       
   117   * opcode + the raw option data' by the DHCP component.
       
   118   *
       
   119   * e.g. The DNS option in DHCP message is represented by opcode 6. On requesting for DNS option using 
       
   120   * RConnection::Ioctl(), if the data received in the buffer is 6 192 168 0 1 192 168 0 2 then  
       
   121   * 6 is the DNS option code and 192 168 0 1 and 192 168 0 2 are the IP addresses of DNS servers.
       
   122   *
       
   123   * @publishedPartner
       
   124   * @released
       
   125   */
       
   126 	{
       
   127 public:
       
   128  	TDhcpRawOptionDataPckg(TDes8& aDes)  :
       
   129 		TPckgDes<TUint8>(aDes)
       
   130 		/**
       
   131 		 * @param aDes User buffer to hold data fetched.
       
   132 		 */
       
   133 		{
       
   134 		}	
       
   135 
       
   136 	inline void SetOpCode(TUint8 aOpCode)
       
   137 		/**
       
   138 		 * SetOpCode. Make sure the buffer is at least 4 bytes long.
       
   139 		 * @param aOpCode Desired DHCP Raw option.
       
   140 		 *
       
   141 		 */
       
   142 		{
       
   143 		TBuf8<1> buf;
       
   144 		buf.FillZ(1);
       
   145 		buf[0]=aOpCode;
       
   146 		iDes->Replace(0,1,buf);
       
   147 		}
       
   148 
       
   149 	inline TUint8 OpCode()
       
   150 		{
       
   151 		return *(iDes->Ptr());
       
   152 		} 	
       
   153 	};
       
   154 
       
   155 /**
       
   156   * SSipServerAddr structure
       
   157   *
       
   158   * For use when querying for the SIP server addresses with 
       
   159   * RConnection::Ioctl() using the KConnGetSipServerAddr constant.  
       
   160   * The client must provide the index of the address being
       
   161   * requested.
       
   162   *
       
   163   * @publishedPartner
       
   164   * @released
       
   165   */
       
   166 struct SSipServerAddr
       
   167 	{
       
   168 	TInt index;
       
   169 	TInetAddr address;
       
   170 	};
       
   171 
       
   172 typedef TPckgBuf<SSipServerAddr> TSipServerAddrBuf;
       
   173 
       
   174 /**
       
   175   * SSipServerDomain structure
       
   176   *
       
   177   * For use when querying for the SIP server domains with
       
   178   * RConnection::Ioctl() using the KConnGetSipServerDomain constant.
       
   179   * The client must provide the index of the name being
       
   180   * requested.
       
   181   *
       
   182   * @publishedPartner
       
   183   * @released
       
   184   */
       
   185 struct SSipServerDomain
       
   186 	{
       
   187 	TInt index;
       
   188 	THostName domainName;
       
   189 	};
       
   190 
       
   191 typedef TPckgBuf<SSipServerDomain> TSipServerDomainBuf;
       
   192 #ifdef SYMBIAN_TCPIPDHCP_UPDATE 
       
   193 /**
       
   194   * SDomainSearchList structure
       
   195   *
       
   196   * For use when querying for the list of domain names with
       
   197   * RConnection::Ioctl() using the KConnGetDomainSearchList constant.
       
   198   * The client must provide the index of the name being
       
   199   * requested.
       
   200   *
       
   201   * @publishedPartner
       
   202   * @released
       
   203   */
       
   204 struct SDomainSearchList
       
   205 	{
       
   206 	TInt index;
       
   207 	THostName domainname;
       
   208 	};
       
   209 
       
   210 typedef TPckgBuf<SDomainSearchList> TDomainSearchListBuf;
       
   211 
       
   212 /**
       
   213   * SDNSServerAddr structure
       
   214   *
       
   215   * For use when querying for the list of Recursive DNS Servers with
       
   216   * RConnection::Ioctl() using the KConnGetDNSServerList constant.
       
   217   * The client must provide the index of the name being
       
   218   * requested.
       
   219   *
       
   220   * @publishedPartner
       
   221   * @released
       
   222   */
       
   223 struct SDNSServerAddr
       
   224 	{
       
   225 	TInt index;
       
   226 	TInetAddr addres;
       
   227 	};
       
   228 
       
   229 typedef TPckgBuf<SDNSServerAddr> TDNSServerAddrBuf;
       
   230 #endif //SYMBIAN_TCPIPDHCP_UPDATE 
       
   231 
       
   232 struct STftpServerAddr
       
   233 /**
       
   234   * STftpServerAddr structure
       
   235   *
       
   236   * For use when querying for the TFTP server addresses with 
       
   237   * RConnection::Ioctl() using the KConnGetTftpServerAddr constant.  
       
   238   * The client must provide the index of the address being
       
   239   * requested.
       
   240   *
       
   241   * @publishedPartner
       
   242   * @released
       
   243   */
       
   244 	{
       
   245 	TInt index;
       
   246 	TInetAddr address;
       
   247 	};
       
   248 typedef TPckgBuf<STftpServerAddr> TTftpServerAddrBuf;
       
   249 
       
   250 
       
   251 /**
       
   252   * TTftpServerNameBuf structure
       
   253   *
       
   254   * For use when querying for the TFTP server name with 
       
   255   * RConnection::Ioctl() using the KConnGetSipServerName constant.  
       
   256   *
       
   257   * @publishedPartner
       
   258   * @released
       
   259   */
       
   260 typedef TBuf<256> TTtfpServNameBuf;
       
   261 
       
   262 class TDhcpRawOptionMultipleDataPckg : public TPckgDes<TUint8>
       
   263 /**
       
   264  * For use when an application wants to access multiple raw parameter options.
       
   265  * The descriptor contains a list of OpCodes. After the RConnection::Ioctl() call has 
       
   266  * completed, the descriptor will contain the number of parameters in the first byte 
       
   267  * followed by parameter opcode, length and data for each parameter option.
       
   268  *	
       
   269  *	@code
       
   270  *     Message	
       
   271  *	     -------------------------------   
       
   272  *		|	|	|	|		|
       
   273  *		|op1|op2|-	|		|
       
   274  *		 -------------------------------
       
   275  *  @endcode
       
   276  * @publishedPartner
       
   277  * @released
       
   278 */
       
   279 	{
       
   280 public:
       
   281  	TDhcpRawOptionMultipleDataPckg(TDes8& aDes)  :
       
   282 		TPckgDes<TUint8>(aDes)
       
   283 	//Constructor for the class. Pushing Buffer containing number
       
   284 	//of OpCode in iDes.  
       
   285 		{
       
   286 		//Setting data length of descriptor as NULL
       
   287 		iDes->SetLength(NULL);
       
   288 		}
       
   289 
       
   290 	inline void AddRawOptionCodeL(const TUint8 aOpCode)
       
   291 	/**
       
   292 	 * Sets parameters one at a time.
       
   293 	 * The only thing the application provides is the OpCode.
       
   294 	 * @param aOpCode The OpCode supplied by the user.
       
   295 	*/
       
   296 		{
       
   297 		//  ---------------------
       
   298 		// |      |		|..........................
       
   299 		// |OP1   |	OP2	|
       
   300 		// |      |     |.......................
       
   301 		// ----------------------
       
   302 		//Data will be appended at the end of the buffer. Length of buffer will indicate
       
   303 		//number of opcodes as every thing is 1 byte
       
   304 		iDes->Append(aOpCode);
       
   305 		   
       
   306 		}
       
   307 		
       
   308    	inline TInt GetRawParameterData(const TUint8 aOpCode ,TPtrC8& aDes)
       
   309    	/**
       
   310    	 * Returns the data portion corresponding to the supplied opcode.  
       
   311 	 * It's only meaningful to call this after an Ioctl() call.
       
   312 	 *
       
   313    	 * @code
       
   314    	 *  ---------------------------------------------------
       
   315    	 * |No. of |      |Data  |      |       |Data  |       |
       
   316    	 * |opcodes| OP1  |Length| Data |  OP2  |Length| Data  |
       
   317    	 * |       |      |      |      |       |      |       |
       
   318    	 *  --------------------------------------------------- 
       
   319    	 * @endcode
       
   320    	 *
       
   321    	 * @param aOpCode The opcode passed by the user.
       
   322    	 * @param aDes On return, it contains the message opcode data.
       
   323    	 * @return KErrNone if aOpCode is found, else KErrNotFound 
       
   324    	*/
       
   325 		{
       
   326 		TUint8 opCodeIterated=0;
       
   327 		TUint8 opCodeIterator= 1;
       
   328 		const TUint8 sizeOfOpcodeAndDataBytes = 2;
       
   329 		const TUint8 sizeOfLengthByte = 1;
       
   330 	
       
   331 		//extracting number of opcodes. First byte of Descriptor will contain number of bytes
       
   332 		TUint8 numberOfOpcodes  = *(iDes->Ptr());
       
   333 		
       
   334 		//taking pointer to base location of aDes.
       
   335 		const TUint8* desBasePtr=iDes->Ptr();
       
   336 	
       
   337 		//While loop true conditions are opCodeFound if Particular opcode is extracted or All opcode in 
       
   338 		//descriptor are iterated and OpCode is not found.
       
   339 		while( opCodeIterated < numberOfOpcodes)
       
   340 			{
       
   341 			//If opcode is found then come out of loop and TPtr will be passed in the descriptor. Pointer is returned to the 
       
   342 			//start byte of data for that particular Opcode with length of the data.
       
   343  			if(aOpCode==*(desBasePtr+opCodeIterator))
       
   344 				{
       
   345 				TInt dataLength = *(desBasePtr+(opCodeIterator+sizeOfLengthByte));
       
   346   				aDes.Set(const_cast<TUint8*>((desBasePtr+opCodeIterator)+sizeOfOpcodeAndDataBytes),dataLength);	
       
   347 				return KErrNone;
       
   348 				}
       
   349 		
       
   350 			//Opcode iterator is iterated in such a way that it will always point to opcode location.
       
   351 			opCodeIterator += *(desBasePtr+(opCodeIterator+sizeOfLengthByte))+sizeOfOpcodeAndDataBytes;
       
   352 			opCodeIterated++;
       
   353 			}//while loop.
       
   354 		return KErrNotFound;
       
   355 		}
       
   356 		
       
   357 	inline TUint8 NumOfOptionRetrieved()
       
   358 	/**
       
   359 	 * Gets the number of opcode data buffers.
       
   360 	 * It's only meaningful to call this after an Ioctl() call.
       
   361 	 * @return The number of opcode data buffers.
       
   362 	 */
       
   363 		{
       
   364 		return *(iDes->Ptr());
       
   365 		}
       
   366 	};
       
   367 
       
   368 
       
   369 
       
   370 #endif
       
   371 
       
   372 
       
   373 
       
   374