omaprovisioning/provisioning/StreamingAdapter/Src/Streamingadapter.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 0 b497e44ab2fc
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
       
     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:  Handles streaming app settings in OMA provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <f32file.h>
       
    21 #include    <CWPCharacteristic.h>
       
    22 #include    <CWPParameter.h>
       
    23 #include    <wpstreamingadapterresource.rsg>
       
    24 #include    <commdb.h>
       
    25 #include    <ApAccessPointItem.h>
       
    26 #include    <ApDataHandler.h>
       
    27 #include    <mpsettingsmodel.h>
       
    28 
       
    29 #include    "WPAdapterUtil.h"
       
    30 #include    "StreamingAdapter.h"
       
    31 #include    "ProvisioningDebug.h"
       
    32 
       
    33 // CONSTANTS
       
    34 #if ( defined (__WINS__) || defined (__WINSCW) ) // this different on hw
       
    35     _LIT( KAdapterName, "WPStreamingAdapterResource" );
       
    36 #else
       
    37     _LIT( KAdapterName, "WPStreamingAdapter" );
       
    38 #endif
       
    39 _LIT(KMaxBandwidthStr,"MAX-BANDWIDTH");
       
    40 _LIT(KMaxUdpPortStr,"MAX-UDP-PORT");
       
    41 _LIT(KMinUdpPortStr,"MIN-UDP-PORT");
       
    42 _LIT(KStreamingAppId, "554");
       
    43 
       
    44 const TInt KInvalidValue = -1;
       
    45 const TInt KProxyEnabled = 1;
       
    46 
       
    47 const TInt KMinUDPPort = 1024; //6970;
       
    48 const TInt KMaxUDPPort = 65535; //32000;
       
    49 const TInt KDefaultMinUDPPort = 6970;
       
    50 const TInt KDefaultMaxUDPPort = 32000;
       
    51 
       
    52 const TInt KBandwidthValue1 = 9050;
       
    53 const TInt KBandwidthValue2 = 13400;
       
    54 const TInt KBandwidthValue3 = 18100;
       
    55 const TInt KBandwidthValue4 = 26800;
       
    56 const TInt KBandwidthValue5 = 27150;
       
    57 const TInt KBandwidthValue6 = 40200;
       
    58 
       
    59 // MODULE DATA STRUCTURES
       
    60 struct TStreamingAdapterData
       
    61     {
       
    62     TPtrC iName;
       
    63     TInt iMaxBw;
       
    64     TInt iMinUdpPort;
       
    65     TInt iMaxUdpPort;
       
    66     CWPCharacteristic* iNapDef;
       
    67     };
       
    68 
       
    69 // ============================ MEMBER FUNCTIONS ===============================
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CStreamingAdapter::CStreamingAdapter
       
    73 // C++ default constructor can NOT contain any code, that
       
    74 // might leave.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 CStreamingAdapter::CStreamingAdapter()
       
    78     {
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CStreamingAdapter::ConstructL
       
    83 // Symbian 2nd phase constructor can leave.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CStreamingAdapter::ConstructL()
       
    87     {
       
    88     FLOG( _L( "[Provisioning] CStreamingAdapter::ConstructL:" ) );
       
    89     
       
    90     TFileName fileName;
       
    91     Dll::FileName( fileName );
       
    92     iTitle = WPAdapterUtil::ReadHBufCL( fileName,
       
    93                                         KAdapterName,
       
    94                                         R_STREAMING_ADAPTER_TITLE );
       
    95                                         
       
    96     FLOG( _L( "[Provisioning] CStreamingAdapter::ConstructL: Done" ) );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CStreamingAdapter::NewL
       
   101 // Two-phased constructor.
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CStreamingAdapter* CStreamingAdapter::NewL()
       
   105     {
       
   106     CStreamingAdapter* self = new(ELeave) CStreamingAdapter; 
       
   107     CleanupStack::PushL(self);
       
   108     self->ConstructL();
       
   109     CleanupStack::Pop(self);
       
   110 
       
   111     return self;
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CStreamingAdapter::~CStreamingAdapter
       
   116 // Destructor
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 CStreamingAdapter::~CStreamingAdapter()
       
   120     {
       
   121     delete iTitle;
       
   122     delete iCurrentData;
       
   123     delete iTempData;
       
   124 	delete iModel;
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CStreamingAdapter::ItemCount
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TInt CStreamingAdapter::ItemCount() const
       
   132     {
       
   133     // If ItemCount() returns zero, the adapter is unloaded at startup. 
       
   134 	// SummaryTitle(), SummaryText(), SaveL(), SetAsDefaultL() and 
       
   135 	// CanSetAsDefault() are called ItemCount() times
       
   136     return iCurrentData ? 1 : 0;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CStreamingAdapter::SummaryTitle
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 const TDesC16& CStreamingAdapter::SummaryTitle(TInt /*aIndex*/) const
       
   144     {
       
   145     return *iTitle;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CStreamingAdapter::SummaryText
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 const TDesC16& CStreamingAdapter::SummaryText(TInt /*aIndex*/) const
       
   153     {
       
   154     return iCurrentData->iName;
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CStreamingAdapter::DetailsL
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 TInt CStreamingAdapter::DetailsL(TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/)
       
   162     {
       
   163     // Detail view is a feature for later release.
       
   164     return KErrNotSupported;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CStreamingAdapter::SaveL
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CStreamingAdapter::SaveL( TInt /*aItem*/ )
       
   172     {
       
   173     FLOG( _L( "[Provisioning] CStreamingAdapter::SaveL:" ) );
       
   174     
       
   175     __ASSERT_DEBUG( iCurrentData->iNapDef, User::Leave( KErrCorrupt ) );
       
   176 
       
   177     InitSettingsModelL();
       
   178         
       
   179     // Load default values
       
   180     iModel->LoadSettingsL(EConfigDefault);
       
   181 
       
   182     // Set max bandwidth value if valid
       
   183     if (iCurrentData->iMaxBw != KInvalidValue)
       
   184         {
       
   185         iModel->SetMaxBandwidth(iCurrentData->iMaxBw, EBearerGPRS);
       
   186         }
       
   187 
       
   188     // Set udp port range if valid
       
   189     if (iCurrentData->iMinUdpPort != KInvalidValue && 
       
   190         iCurrentData->iMaxUdpPort != KInvalidValue)
       
   191         {
       
   192         iModel->SetMinUDPPort(iCurrentData->iMinUdpPort);
       
   193         iModel->SetMaxUDPPort(iCurrentData->iMaxUdpPort);
       
   194         }
       
   195 
       
   196     // Get the IAP id
       
   197 
       
   198     CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
       
   199     CleanupStack::PushL(commDb);
       
   200     CApDataHandler* apDataHandler = CApDataHandler::NewLC(*commDb);
       
   201     CApAccessPointItem* apItem = CApAccessPointItem::NewLC();   
       
   202     
       
   203     TPckgBuf<TUint32> uid;
       
   204     TBool proxyDefined(EFalse);
       
   205     TBool apDefined(EFalse);
       
   206     TBool apWithoutProxyDefined(EFalse);
       
   207 
       
   208     for (TInt i(0); iCurrentData->iNapDef->Data(i).Length() == uid.MaxLength()
       
   209         && !(proxyDefined && apWithoutProxyDefined); i++)
       
   210         {
       
   211         uid.Copy(iCurrentData->iNapDef->Data(i));
       
   212 
       
   213         apDataHandler->AccessPointDataL(uid(), *apItem);
       
   214     
       
   215         TBool useProxy(EFalse);
       
   216         apItem->ReadBool(EApProxyUseProxy, useProxy);
       
   217 
       
   218         if (!apDefined || (!useProxy && !apWithoutProxyDefined))
       
   219             {
       
   220             iModel->SetDefaultAp(uid());
       
   221             apDefined = ETrue;
       
   222 
       
   223             iSavedID.Copy(uid);
       
   224 
       
   225             if (!useProxy)
       
   226                 {
       
   227                 apWithoutProxyDefined = ETrue;
       
   228                 }
       
   229             }
       
   230         
       
   231         if (!proxyDefined && useProxy)
       
   232             {
       
   233            // Get proxy port
       
   234             TUint32 proxyPort(0);
       
   235             apItem->ReadUint(EApProxyPortNumber, proxyPort);
       
   236 
       
   237             // Get proxy host name
       
   238             const HBufC* proxyHost = apItem->ReadConstLongTextL(
       
   239 												EApProxyServerAddress);
       
   240 
       
   241             if(*proxyHost != KNullDesC && proxyPort <= 65535)
       
   242                 {
       
   243                 iModel->SetProxyHostNameL(*proxyHost);
       
   244                 iModel->SetProxyPort(static_cast<TInt>(proxyPort));
       
   245                 iModel->SetProxyMode(KProxyEnabled);
       
   246                 
       
   247                 proxyDefined = ETrue;
       
   248                 }
       
   249             }
       
   250         }
       
   251 
       
   252     CleanupStack::PopAndDestroy(3); // apItem & apDataHandler & commDb
       
   253 
       
   254     iModel->StoreSettingsL();
       
   255     
       
   256     FLOG( _L( "[Provisioning] CStreamingAdapter::SaveL: Done" ) );
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CStreamingAdapter::CanSetAsDefault
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TBool CStreamingAdapter::CanSetAsDefault(TInt /*aItem*/) const
       
   264     {
       
   265     return EFalse;
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CStreamingAdapter::SetAsDefault
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CStreamingAdapter::SetAsDefaultL(TInt /*aItem*/)
       
   273     {
       
   274     // This shouldn't be called because CanSetAsDefault
       
   275     // always returns EFalse.
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // CStreamingAdapter::VisitL
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CStreamingAdapter::VisitL(CWPCharacteristic& aCharacteristic)
       
   283     {
       
   284     switch(aCharacteristic.Type())
       
   285         {
       
   286         case KWPApplication:
       
   287             // Create new iTempData
       
   288             if (iTempData)
       
   289                 {
       
   290                 delete iTempData;
       
   291                 iTempData = NULL;
       
   292                 }
       
   293 
       
   294             iTempData = new (ELeave) TStreamingAdapterData;
       
   295 
       
   296             // Initialize iTempData's members
       
   297             iTempData->iName.Set(KNullDesC);
       
   298             iTempData->iMaxBw = KInvalidValue;
       
   299             iTempData->iMinUdpPort = KInvalidValue;
       
   300             iTempData->iMaxUdpPort = KInvalidValue;
       
   301             iTempData->iNapDef = NULL;
       
   302 
       
   303             // Accept characteristic
       
   304             aCharacteristic.AcceptL(*this);
       
   305 
       
   306             // Check iAppId and validate data
       
   307             if (iAppId == KStreamingAppId && IsValid())
       
   308                 {
       
   309                 // iAppId is correct and data is valid
       
   310                 delete iCurrentData;
       
   311                 iCurrentData = iTempData;
       
   312                 iTempData = NULL;
       
   313                 }
       
   314             else
       
   315                 {
       
   316                 // iAppId is incorrect or data is invalid
       
   317                 delete iTempData;
       
   318                 iTempData = NULL;
       
   319                 }
       
   320             break;
       
   321         default:
       
   322             break;
       
   323         }
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CStreamingAdapter::VisitL
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CStreamingAdapter::VisitL(CWPParameter& aParameter)
       
   331     { 
       
   332     // Check the contents of whole characteristic before overwriting iMaxBw, 
       
   333     // iMinUdpPort and iMaxUdpPort. Might be looking at the wrong application
       
   334 	// characteristic
       
   335     
       
   336     __ASSERT_DEBUG(iTempData, User::Leave(KErrCorrupt));
       
   337     
       
   338     TInt value;
       
   339     switch(aParameter.ID())
       
   340         {
       
   341         case EWPParameterAppID:
       
   342             iAppId.Set(aParameter.Value());
       
   343             break;
       
   344         case EWPParameterName:
       
   345             if (iTempData->iName == KNullDesC)
       
   346                 {
       
   347                 iTempData->iName.Set(aParameter.Value());
       
   348                 }
       
   349             break;
       
   350 		case EWPNamedParameter:
       
   351 			{
       
   352 			if( aParameter.Name().Compare( KMaxBandwidthStr ) == 0
       
   353 				&& !ParseIntegerL( aParameter.Value(), value ) )
       
   354 				{							
       
   355 				iTempData->iMaxBw = value;
       
   356 				}
       
   357 			else if( aParameter.Name().Compare( KMaxUdpPortStr ) == 0
       
   358 				&& !ParseIntegerL( aParameter.Value(), value ) )
       
   359 				{							
       
   360 				iTempData->iMaxUdpPort = value;
       
   361 				}
       
   362 			else if( aParameter.Name().Compare( KMinUdpPortStr ) == 0
       
   363 				&& !ParseIntegerL( aParameter.Value(), value ) )
       
   364 				{							
       
   365                 iTempData->iMinUdpPort = value;
       
   366 				}
       
   367 			break;
       
   368 			}
       
   369         default:
       
   370             break;
       
   371         }
       
   372     }
       
   373 
       
   374 // -----------------------------------------------------------------------------
       
   375 // CStreamingAdapter::VisitLinkL
       
   376 // -----------------------------------------------------------------------------
       
   377 //
       
   378 void CStreamingAdapter::VisitLinkL(CWPCharacteristic& aCharacteristic)
       
   379     { 
       
   380     // Here again, do not overwrite iPXLogical before you're sure
       
   381     // you're looking at the correct APPLICATION
       
   382 
       
   383     __ASSERT_DEBUG(iTempData, User::Leave(KErrCorrupt));
       
   384 
       
   385     switch(aCharacteristic.Type())
       
   386         {
       
   387         //intentional fall-through
       
   388         case KWPNapDef:        
       
   389         case KWPPxLogical:    
       
   390             iTempData->iNapDef = &aCharacteristic;          
       
   391             break;
       
   392         default:
       
   393             break;
       
   394         }
       
   395     }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // CStreamingAdapter::ContextExtension
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 TInt CStreamingAdapter::ContextExtension(MWPContextExtension*& aExtension)
       
   402     {
       
   403     aExtension = this;
       
   404     return KErrNone;
       
   405     }
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // CStreamingAdapter::SaveDataL
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 const TDesC8& CStreamingAdapter::SaveDataL(TInt /*aIndex*/) const
       
   412     {
       
   413     return iSavedID;
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CStreamingAdapter::DeleteL
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 void CStreamingAdapter::DeleteL(const TDesC8& aSaveData)
       
   421     {
       
   422     TUint32 id;
       
   423     
       
   424     InitSettingsModelL();
       
   425     
       
   426     iModel->GetDefaultAp(id);
       
   427 
       
   428     TPckgBuf<TUint32> pckg;
       
   429     pckg.Copy(aSaveData);
       
   430 
       
   431     if (id == pckg())
       
   432         {
       
   433         iModel->LoadSettingsL(EConfigDefault);
       
   434         iModel->StoreSettingsL();
       
   435         }
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CStreamingAdapter::Uid
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 TUint32 CStreamingAdapter::Uid() const
       
   443     {
       
   444     return iDtor_ID_Key.iUid;
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CStreamingAdapter::IsValid
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TBool CStreamingAdapter::IsValid()
       
   452     {
       
   453     TBool validity(EFalse);
       
   454     
       
   455     if (iTempData->iNapDef)
       
   456         {
       
   457         // Validity checks for min and max UDP port values
       
   458         if (iTempData->iMinUdpPort < KMinUDPPort)
       
   459             {
       
   460             iTempData->iMinUdpPort = KDefaultMinUDPPort; 
       
   461             }
       
   462 
       
   463         if (iTempData->iMaxUdpPort > KMaxUDPPort)
       
   464             {
       
   465             iTempData->iMaxUdpPort = KDefaultMaxUDPPort; 
       
   466             }
       
   467 
       
   468         if (iTempData->iMinUdpPort > iTempData->iMaxUdpPort)
       
   469             {
       
   470             iTempData->iMinUdpPort = KInvalidValue;
       
   471             iTempData->iMaxUdpPort = KInvalidValue;
       
   472             }
       
   473         
       
   474         // Validity check for max bandwidth value
       
   475         switch (iTempData->iMaxBw)
       
   476             {
       
   477             case KBandwidthValue1:
       
   478             case KBandwidthValue2:
       
   479             case KBandwidthValue3:
       
   480             case KBandwidthValue4:
       
   481             case KBandwidthValue5:
       
   482             case KBandwidthValue6:
       
   483                 // iMaxBw is valid
       
   484                 break;
       
   485             default:
       
   486                 // iMaxBw is invalid
       
   487                 iTempData->iMaxBw = KInvalidValue;
       
   488                 break;
       
   489             }
       
   490 
       
   491         validity = ETrue;
       
   492         }
       
   493             
       
   494     return validity;
       
   495     }
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 // CStreamingAdapter::ParseIntegerL
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 TInt CStreamingAdapter::ParseIntegerL(const TDesC& aPtr, TInt& aInt) 
       
   502     {
       
   503     TLex lex(aPtr);
       
   504     return lex.Val(aInt);
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CStreamingAdapter::Cleanup
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 void CStreamingAdapter::Cleanup( TAny* aAny )
       
   512 	{
       
   513 	RImplInfoPtrArray* implArray = 
       
   514 		reinterpret_cast< RImplInfoPtrArray*> ( aAny );
       
   515 	implArray->ResetAndDestroy();
       
   516 	implArray->Close();
       
   517 	}
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CStreamingAdapter::InitSettingsModelL
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void CStreamingAdapter::InitSettingsModelL()
       
   524 	{
       
   525 	FLOG( _L( "[Provisioning] CStreamingAdapter::InitSettingsModelL:" ) );
       
   526 	
       
   527     if ( !iModel )
       
   528         {
       
   529         RImplInfoPtrArray impl; 
       
   530     	CleanupStack::PushL( TCleanupItem( Cleanup, &impl ) );
       
   531     	CMPSettingsModel::ListImplementationsL( impl );
       
   532     	if( impl.Count() > 0 )
       
   533             {
       
   534             FLOG( _L( "[Provisioning] CStreamingAdapter::InitSettingsModelL: Creating CMPSettingsModel" ) );
       
   535     	    // using the first available implementation
       
   536             iModel= CMPSettingsModel::NewL( impl[0]->ImplementationUid() );
       
   537             FLOG( _L( "[Provisioning] CStreamingAdapter::InitSettingsModelL: Creating CMPSettingsModel Done" ) );
       
   538         	}
       
   539     	CleanupStack::PopAndDestroy(); // implArray
       
   540         }
       
   541 	}
       
   542 	
       
   543 //  End of File