omaprovisioning/provisioning/accesspointadapter/Src/CWPAPPhysicalProxy.cpp
changeset 1 a9c0ce913924
equal deleted inserted replaced
0:b497e44ab2fc 1:a9c0ce913924
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Defines a class, which holds physical proxy information.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 
       
    24 #include "CWPAPPhysicalProxy.h"				// Own header
       
    25 #include <CWPCharacteristic.h>
       
    26 #include <CWPParameter.h>
       
    27 #include <WPAdapterUtil.h>
       
    28 #include <featmgr.h>
       
    29 #include "CWPAPLogicalProxy.h"
       
    30 #include "CWPAPPort.h"
       
    31 #include "CWPAPNapdef.h"
       
    32 #include "WPAPAdapter.pan"
       
    33 #include "CWPLog.h"
       
    34 #include "WPAPDefs.h"
       
    35 #include <cmconnectionmethodext.h>
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CWPAPPhysicalProxy::NewL
       
    41 // Two-phased constructor.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CWPAPPhysicalProxy* CWPAPPhysicalProxy::NewLC( 
       
    45                                             const TDesC& aDefaultName, 
       
    46                                             CWPCharacteristic& aCharacteristic, 
       
    47     CWPCharacteristic& aLogicalCharacteristic,
       
    48     CWPAPPort*& aPort )
       
    49 	{
       
    50 	CWPAPPhysicalProxy* self = new(ELeave) CWPAPPhysicalProxy( 
       
    51 	                                                    aDefaultName, 
       
    52                                                         aLogicalCharacteristic,
       
    53                                                         aPort ); 
       
    54 	CleanupStack::PushL( self );
       
    55 	self->ConstructL();
       
    56     aCharacteristic.AcceptL( *self );
       
    57 	return self;
       
    58 	}
       
    59 	
       
    60 // -----------------------------------------------------------------------------
       
    61 // Destructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CWPAPPhysicalProxy::~CWPAPPhysicalProxy()
       
    65 	{
       
    66 	delete iPort;
       
    67 
       
    68     iNapdefs.ResetAndDestroy();
       
    69     iNapdefs.Close();
       
    70 	}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CWPAPPhysicalProxy::ValidateL
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 TBool CWPAPPhysicalProxy::ValidateL()
       
    77 	{
       
    78 	TBool isValid( EFalse );
       
    79 
       
    80 	// We must have proxy address otherwise this proxy isn't valid.
       
    81 	if ( iProxyAddr )
       
    82 		{
       
    83 		switch ( iPxAddrType )
       
    84 			{
       
    85 			case EPxAddrTypeIPv4:
       
    86 				{
       
    87 				isValid = WPAdapterUtil::CheckIPv4( iProxyAddr->Value() );
       
    88 				break;
       
    89 				}
       
    90             case EPxAddrTypeIPv6:
       
    91                 {
       
    92                 isValid = FeatureManager::FeatureSupported( KFeatureIdIPv6 )
       
    93                     && WPAdapterUtil::CheckIPv6( iProxyAddr->Value() );
       
    94                 break;
       
    95                 }
       
    96 			case EPxAddrTypeUnsupported:
       
    97 				{
       
    98 				isValid = EFalse;
       
    99 				break;
       
   100 				}
       
   101 			default: // default value is assumed to be EPxAddrTypeIPv4
       
   102 				{
       
   103 				isValid = WPAdapterUtil::CheckIPv4( iProxyAddr->Value() );
       
   104 				}
       
   105 			}
       
   106 		}
       
   107 	return isValid;
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CWPAPPhysicalProxy::AddDataL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CWPAPPhysicalProxy::AddDataL( RCmConnectionMethodExt& aCmItem )
       
   115 	{  
       
   116 	LOG("--CWPAP CWPAPPhysicalProxy::AddDataL begin--");	
       
   117 	TInt err(KErrNone);
       
   118 	
       
   119 	// CMManager
       
   120 	aCmItem.SetStringAttributeL( CMManager::ECmWapIPGatewayAddress, iProxyAddr->Value());
       
   121 	LOG2("CWPAP EApWapStartPage, value: %S, err: %d",
       
   122 	                                             &iProxyAddr->Value(), err);
       
   123 
       
   124 	//CMManager
       
   125 	aCmItem.SetStringAttributeL( CMManager::ECmIPGateway, iProxyAddr->Value());
       
   126 	LOG2("CWPAP EApIspIPGateway, value: %S, err: %d",
       
   127 	                                             &iProxyAddr->Value(), err);
       
   128 
       
   129 	//CMManager 
       
   130 	aCmItem.SetStringAttributeL( CMManager::ECmProxyServerName, iProxyAddr->Value() );
       
   131 	LOG2("CWPAP EApProxyServerAddress, value: %S, err: %d",
       
   132 	                                                &iProxyAddr->Value(), err);
       
   133 	                                               
       
   134 
       
   135 	// Store port data
       
   136 	if ( iPort )
       
   137         {
       
   138         iPort->AddDataL( aCmItem );
       
   139         }
       
   140     
       
   141     if ( iLogicalPort)
       
   142         {
       
   143         iLogicalPort->AddDataL( aCmItem );
       
   144         }
       
   145     if ( err ) err = 0; // prevent compiler warning
       
   146     
       
   147 	LOG("--CWPAP CWPAPPhysicalProxy::AddDataL end--");	
       
   148 	}
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CWPAPPhysicalProxy::AddItemsL
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CWPAPPhysicalProxy::AddItemsL( RPointerArray<CWPAPAccesspointItem>& aItems,
       
   155                                     CWPAPItemBase* iLogicalProxy, 
       
   156                                     CWPAPItemBase* /*iPhysicalProxy*/ ) 
       
   157 	{
       
   158     TInt count( 0 );
       
   159     for( TInt i( 0 ); i < iNapdefs.Count(); i++ )
       
   160         {
       
   161         CWPAPNapdef* pp = iNapdefs[ i ];
       
   162         if( pp->ValidateL() )
       
   163             {
       
   164             count += pp->AddItemsL( aItems, iLogicalProxy, this );
       
   165             }
       
   166         }
       
   167 
       
   168     return count;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CWPAPPhysicalProxy::Name
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 const TDesC& CWPAPPhysicalProxy::Name()
       
   176 	{
       
   177     if( iName )
       
   178         {
       
   179         return iName->Value();
       
   180         }
       
   181     else 
       
   182         {
       
   183         return KNullDesC;
       
   184         }
       
   185 	}
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CWPAPPhysicalProxy::VisitL
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CWPAPPhysicalProxy::VisitL( CWPCharacteristic& aCharacteristic )
       
   192 	{
       
   193 	TInt type = aCharacteristic.Type();
       
   194 	
       
   195 	// Accept only KWPPort characteristics
       
   196 	// One valid port is enough for us
       
   197 	if ( type == KWPPort && !iPort )
       
   198 		{
       
   199         CWPAPPort* port = CWPAPPort::NewLC( aCharacteristic );
       
   200 
       
   201 		if ( port->ValidateL() )
       
   202 			{
       
   203 			iPort = port;
       
   204 			CleanupStack::Pop( port );
       
   205 			}
       
   206 		else // Data not valid.
       
   207 			{
       
   208 			CleanupStack::PopAndDestroy( port );
       
   209 			}
       
   210 		}
       
   211 	}
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CWPAPPhysicalProxy::VisitL
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CWPAPPhysicalProxy::VisitL( CWPParameter& aParameter)
       
   218 	{
       
   219 	TInt id = aParameter.ID();
       
   220 	const TDesC& value = aParameter.Value();
       
   221 
       
   222 	if ( value.Length() == 0 )
       
   223 		{
       
   224 		// No use to store zero length value.
       
   225 		return;
       
   226 		}
       
   227 
       
   228 	switch ( id )
       
   229 		{
       
   230 		case EWPParameterPxAddrFQDN: // iGatewayIPAddress
       
   231 			{
       
   232 			// Implementation comments:
       
   233 			// The value of this field is a domain name but we can't 
       
   234 			// at the moment resolve this to IP address 
       
   235 			// (at least from this adapter).
       
   236 			// Therefore this field can't be used. 
       
   237 			// EWPParameterPxAddr is supported
       
   238 			// and should be used.
       
   239 
       
   240 			/// Validate the domain name
       
   241 			/// Resolve to IP address
       
   242 
       
   243 			/* // Uncomment if domain name can be validated and IP address resolved
       
   244 			// Add only if we haven't already received this field
       
   245 			if ( !IsReceived( EWPParameterPxAddrFQDN_id ))
       
   246 				{
       
   247 				iGatewayIPAddress = &aParameter;
       
   248 				MarkReceived( EWPParameterPxAddrFQDN_id );
       
   249 				}
       
   250 			*/
       
   251 			break;
       
   252 			}
       
   253 		case EWPParameterPxAddr: // iGatewayIPAddress
       
   254 			{
       
   255 			// Accept only first occurrence of either PxAddr or PxAddrFQDN
       
   256 			if ( IsReceived( EWPParameterPxAddrFQDN_id ) ||
       
   257 				IsReceived( EWPParameterPxAddr_id ) )
       
   258 				{
       
   259 				return;
       
   260 				}
       
   261 			else 
       
   262 				{
       
   263 				// The max allowed lenght for proxy address is 45 bytes. 
       
   264 				// Nothing is stored if max lenght is exceeded
       
   265 				if ( aParameter.Value().Length() < 46 )
       
   266 					{
       
   267 					iProxyAddr = &aParameter;
       
   268 					MarkReceived( EWPParameterPxAddr_id );
       
   269 					}
       
   270 				}
       
   271 			break;
       
   272 			}
       
   273 		case EWPParameterPxAddrType:
       
   274 			{
       
   275 			if ( !IsReceived( EWPParameterPxAddrType_id ) )
       
   276 				{
       
   277 				// Only IPv4 addresses are supported.
       
   278 				if ( value == KIPV4 )
       
   279 					{
       
   280 					iPxAddrType = EPxAddrTypeIPv4;
       
   281 					}
       
   282                 else if( value == KIPV6 )
       
   283                     {
       
   284                     iPxAddrType = EPxAddrTypeIPv6;
       
   285                     }
       
   286 				else
       
   287 					{
       
   288 					iPxAddrType = EPxAddrTypeUnsupported;
       
   289 					}
       
   290 				MarkReceived( EWPParameterPxAddrType_id );
       
   291 				}
       
   292 			break;
       
   293 			}
       
   294         case EWPParameterName:
       
   295             {
       
   296             if( !iName )
       
   297                 {
       
   298                 iName = &aParameter;
       
   299                 }
       
   300             break;
       
   301             }
       
   302 		default:
       
   303 			{
       
   304 			// Just let through
       
   305 			}
       
   306 		}
       
   307 	}
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CWPAPPhysicalProxy::VisitL
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CWPAPPhysicalProxy::VisitLinkL( CWPCharacteristic& aLink )
       
   314 	{
       
   315     CWPAPNapdef* item = CWPAPNapdef::NewLC( ETrue,
       
   316                                             iDefaultName,
       
   317                                             iLogicalCharacteristic,
       
   318                                             aLink );
       
   319     User::LeaveIfError( iNapdefs.Append( item ) );
       
   320     CleanupStack::Pop( item ); // item
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CWPAPPhysicalProxy::CWPAPPhysicalProxy
       
   325 // C++ default constructor can NOT contain any code, that
       
   326 // might leave.
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 CWPAPPhysicalProxy::CWPAPPhysicalProxy( 
       
   330                                const TDesC& aDefaultName, 
       
   331                                CWPCharacteristic& aLogicalCharacteristic,
       
   332                                CWPAPPort*& aPort ) 
       
   333 	                         : CWPAPItemBase( aDefaultName ), 
       
   334                                iLogicalPort( aPort ),
       
   335                                iNapdefs( KInitialArraySize ),
       
   336                                iLogicalCharacteristic( aLogicalCharacteristic )
       
   337 	{
       
   338 	}
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CWPAPPhysicalProxy::ConstructL
       
   342 // Symbian 2nd phase constructor can leave.
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CWPAPPhysicalProxy::ConstructL()
       
   346 	{
       
   347 	}
       
   348 
       
   349 // End of File