omaprovisioning/provisioning/ProvisioningEngine/Src/WPAdapterUtil.cpp
changeset 0 b497e44ab2fc
child 35 0deca9b72b62
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:  WPAdapterUtil is a utility class for reading resource strings.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 #include <barsc.h>
       
    24 #include <bautils.h>
       
    25 #include <uri16.h>
       
    26 #include "CWPCharacteristic.h"
       
    27 #include "WPAdapterUtil.h"
       
    28 #include "TWPFindAccesspoint.h"
       
    29 #include <data_caging_path_literals.hrh>
       
    30 #include "CWPInternetAPDB.h"
       
    31 
       
    32 #include <ApUtils.h>
       
    33 #include "ProvisioningDebug.h"
       
    34 #include <cmmanager.h>
       
    35 #include <cmmanagerext.h>
       
    36 #include <cmconnectionmethod.h>
       
    37 #include <cmconnectionmethodext.h>
       
    38 #include <cmdestination.h>
       
    39 #include <cmdestinationext.h>
       
    40 #include <cmmanagerdef.h>
       
    41 #include "ProvisioningInternalCRKeys.h"
       
    42 #include <centralrepository.h>
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 typedef TBool (*TParseFunc)( TLex& aLex );
       
    46 LOCAL_C TBool DoOrReverse( TParseFunc aFunc, TLex& aLex );
       
    47 LOCAL_C TBool Star( TParseFunc aFunc, TLex& aLex );
       
    48 LOCAL_C TBool CheckIPv6Hex4( TLex& aLex );
       
    49 LOCAL_C TBool CheckIPv6ColonHex4( TLex& aLex );
       
    50 LOCAL_C TBool CheckIPv6HexSeq( TLex& aLex );
       
    51 LOCAL_C TBool CheckIPv6HexPart( TLex& aLex );
       
    52 LOCAL_C TBool CheckIPv4AddressPart( TLex& aLex );
       
    53 LOCAL_C TBool CheckIPv4Address( TLex& aLex );
       
    54 LOCAL_C TBool CheckIPv6Address( TLex& aLex );
       
    55 //Local functions for Internet Parameter handling
       
    56 //Get Cenrep key (Operator value)
       
    57 LOCAL_C void GetCenrepKeyL(TDes8& aValue);
       
    58 
       
    59 //Get Access Point ID from Database of Internet connection Methods
       
    60 //or from Internet SNAP
       
    61 LOCAL_C TUint GetAPIDFromDBorSNAPL(TDesC& aOrig);
       
    62 
       
    63 //Get the Latest Access Point ID from Internet SNAP
       
    64 LOCAL_C TUint GetInternetSnapLatestAPIDL(RCmDestinationExt& InternetDestination);
       
    65 
       
    66 // Get the destination of purpose Internet
       
    67 LOCAL_C void GetInternetSnapDestinationL(RCmManagerExt& aCmManager, RCmDestinationExt& InternetDestination);
       
    68 
       
    69 // Set the Internet Access point in Internet SNAP and 
       
    70 // Database of Internet connection Methods
       
    71 LOCAL_C void SetAPtoDBandSNAPL(const TUint aAPID, const TDesC& aOriginator);
       
    72 
       
    73 using namespace CMManager;
       
    74 
       
    75 /// Default resource file suffix
       
    76 _LIT( KResourceFileSuffix, ".rsc" );
       
    77 
       
    78 // ============================ MEMBER FUNCTIONS ===============================
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // WPAdapterUtil::AccesspointL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C CWPCharacteristic* WPAdapterUtil::AccesspointL( 
       
    85                                             CWPCharacteristic& aCharacteristic )
       
    86     {
       
    87     TWPFindAccesspoint finder;
       
    88     aCharacteristic.AcceptL( finder );
       
    89     return finder.iNapDef;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // WPAdapterUtil::ReadHBufCL
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C HBufC* WPAdapterUtil::ReadHBufCL( const TDesC& aDllPath, 
       
    97                                            const TDesC& aAdapterName,
       
    98                                            TInt aResourceId )
       
    99     {
       
   100     // Open a file server session
       
   101     RFs fs;
       
   102     User::LeaveIfError(fs.Connect());
       
   103     CleanupClosePushL(fs);
       
   104 
       
   105     // Open the resource file
       
   106     RResourceFile resourceFile;
       
   107     FindAndOpenResourceFileLC(fs, aDllPath, aAdapterName, resourceFile);
       
   108 
       
   109     TResourceReader resReader;
       
   110     resReader.SetBuffer( resourceFile.AllocReadLC( aResourceId ) );
       
   111     HBufC* text = resReader.ReadHBufCL();
       
   112 
       
   113     CleanupStack::PopAndDestroy(3); // resourceFile, fs, aResourceId
       
   114 
       
   115     return text;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // WPAdapterUtil::FindAndOpenResourceFileLC
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void WPAdapterUtil::FindAndOpenResourceFileLC( RFs& aFs, 
       
   123                                                const TDesC& aDllPath, 
       
   124                                                const TDesC& aAdapterName, 
       
   125                                                RResourceFile& aResFile )
       
   126     {
       
   127     // Get the drive from DLL file name
       
   128     TFileName fileName( aDllPath.Left( KMaxFileName ) );
       
   129     TParsePtrC parse( fileName );
       
   130     fileName = parse.Drive();
       
   131 
       
   132     fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   133     fileName.Append( aAdapterName );
       
   134     fileName.Append( KResourceFileSuffix );
       
   135 
       
   136     // Retrieve the correct suffix
       
   137     BaflUtils::NearestLanguageFile( aFs, fileName );
       
   138 
       
   139     // Open the file
       
   140     aResFile.OpenL( aFs, fileName );
       
   141     CleanupClosePushL( aResFile );
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // WPAdapterUtil::CheckURI
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 EXPORT_C TBool WPAdapterUtil::CheckURI( const TDesC& aUrl )
       
   149     {
       
   150     TUriParser16 uriParser;
       
   151     TInt err = uriParser.Parse( aUrl );
       
   152     return err == KErrNone 
       
   153         && uriParser.IsPresent(EUriScheme)
       
   154         && uriParser.IsPresent(EUriHost);
       
   155     }
       
   156 
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // WPAdapterUtil::CheckIPv4
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 EXPORT_C TBool WPAdapterUtil::CheckIPv4( const TDesC& aIP )
       
   163     {
       
   164     /*
       
   165     * ABNF
       
   166     * IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
       
   167     */
       
   168 
       
   169     TLex lex( aIP );
       
   170 
       
   171     return CheckIPv4Address( lex );
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // WPAdapterUtil::CheckIPv6
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 EXPORT_C TBool WPAdapterUtil::CheckIPv6( const TDesC& aIP )
       
   179     {
       
   180     /*
       
   181     * ABNF from RFC2373
       
   182     * IPv6address = hexpart [ ":" IPv4address ]
       
   183     * IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
       
   184     *
       
   185     * IPv6prefix  = hexpart "/" 1*2DIGIT
       
   186     *
       
   187     * hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ]
       
   188     * hexseq  = hex4 *( ":" hex4)
       
   189     * hex4    = 1*4HEXDIG
       
   190     */
       
   191 
       
   192     TLex lex( aIP );
       
   193     TLex lexipv4( aIP );
       
   194     
       
   195     if(!CheckIPv4Address( lexipv4 ))
       
   196 		return CheckIPv6Address( lex );
       
   197 		else
       
   198     return EFalse;
       
   199     }
       
   200 
       
   201 // ----------------------------------------------------
       
   202 // CheckIPv6Address()
       
   203 // IPv6address = hexpart [ ":" IPv4address ]
       
   204 // ----------------------------------------------------
       
   205 //
       
   206 LOCAL_C TBool CheckIPv6Address( TLex& aLex )
       
   207     {
       
   208     TBool result( CheckIPv6HexPart( aLex ) );
       
   209     if( aLex.Peek() == '.' )
       
   210         {
       
   211         while( aLex.Peek() != ':' && aLex.Offset() > 0 )
       
   212             {
       
   213             aLex.UnGet();
       
   214             }
       
   215         aLex.Inc();
       
   216         result = CheckIPv4Address( aLex );
       
   217         }
       
   218 
       
   219     return result && aLex.Eos();
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------
       
   223 // CheckIPv4Address()
       
   224 // IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
       
   225 // ----------------------------------------------------
       
   226 //
       
   227 LOCAL_C TBool CheckIPv4Address( TLex& aLex )
       
   228     {
       
   229     return CheckIPv4AddressPart( aLex ) 
       
   230         && aLex.Get() == '.'
       
   231         && CheckIPv4AddressPart( aLex ) 
       
   232         && aLex.Get() == '.'
       
   233         && CheckIPv4AddressPart( aLex ) 
       
   234         && aLex.Get() == '.'
       
   235         && CheckIPv4AddressPart( aLex ) && aLex.Get() == '\0' ;
       
   236     }
       
   237 
       
   238 // ----------------------------------------------------
       
   239 // CheckIPv4AddressPart()
       
   240 // 1*3DIGIT
       
   241 // ----------------------------------------------------
       
   242 //
       
   243 LOCAL_C TBool CheckIPv4AddressPart( TLex& aLex )
       
   244     {
       
   245     TBool result( aLex.Peek().IsDigit() );
       
   246     aLex.Inc();
       
   247     if( aLex.Peek().IsDigit() )
       
   248         {
       
   249         aLex.Inc();
       
   250         if( aLex.Peek().IsDigit() )
       
   251             {
       
   252             aLex.Inc();
       
   253             }
       
   254         }
       
   255 
       
   256     return result;
       
   257     }
       
   258 
       
   259 // ----------------------------------------------------
       
   260 // CheckIPv6HexPart()
       
   261 // hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ]
       
   262 // ----------------------------------------------------
       
   263 //
       
   264 LOCAL_C TBool CheckIPv6HexPart( TLex& aLex )
       
   265     {
       
   266     TBool hexSeq( DoOrReverse( CheckIPv6HexSeq, aLex ) );
       
   267     TBool doubleSemiColon( EFalse );
       
   268     if( aLex.Peek() == ':' )
       
   269         {
       
   270         aLex.Inc();
       
   271         if( aLex.Get() == ':' )
       
   272             {
       
   273             doubleSemiColon = ETrue;
       
   274             DoOrReverse( CheckIPv6HexSeq, aLex );
       
   275             }
       
   276         }
       
   277 
       
   278     return hexSeq || doubleSemiColon;
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------
       
   282 // CheckIPv6HexSeq()
       
   283 // hexseq  = hex4 *( ":" hex4)
       
   284 // ----------------------------------------------------
       
   285 //
       
   286 LOCAL_C TBool CheckIPv6HexSeq( TLex& aLex )
       
   287     {
       
   288     TBool result( CheckIPv6Hex4( aLex ) );
       
   289     if( result )
       
   290         {
       
   291         Star( CheckIPv6ColonHex4, aLex );
       
   292         }
       
   293     return result;
       
   294     }
       
   295 
       
   296 // ----------------------------------------------------
       
   297 // CheckIPv6ColonHex4()
       
   298 // ":" hex4
       
   299 // Used as a helper to give to Star()
       
   300 // ----------------------------------------------------
       
   301 //
       
   302 LOCAL_C TBool CheckIPv6ColonHex4( TLex& aLex )
       
   303     {
       
   304     return aLex.Get() == ':'
       
   305         && CheckIPv6Hex4( aLex );
       
   306     }
       
   307 
       
   308 // ----------------------------------------------------
       
   309 // CheckIPv6Hex4()
       
   310 // hex4    = 1*4HEXDIG
       
   311 // ----------------------------------------------------
       
   312 //
       
   313 LOCAL_C TBool CheckIPv6Hex4( TLex& aLex )
       
   314     {
       
   315     _LIT( KHexDigits, "0123456789ABCDEF" );
       
   316 
       
   317     TPtrC hexDigits( KHexDigits );
       
   318     TBool foundOne( EFalse );
       
   319     while( hexDigits.LocateF( aLex.Peek() ) != KErrNotFound )
       
   320         {
       
   321         foundOne = ETrue;
       
   322         aLex.Inc();
       
   323         }
       
   324 
       
   325     return foundOne;
       
   326     }
       
   327 
       
   328 // ----------------------------------------------------
       
   329 // DoOrReverse()
       
   330 // Calls aFunc. If it fails, the lexer is returned to 
       
   331 // the state before calling DoOrReverse().
       
   332 // ----------------------------------------------------
       
   333 //
       
   334 LOCAL_C TBool DoOrReverse( TParseFunc aFunc, TLex& aLex )
       
   335     {
       
   336     TLexMark mark;
       
   337     aLex.Mark( mark );
       
   338     if( (*aFunc)(aLex) )
       
   339         {
       
   340         return ETrue;
       
   341         }
       
   342     else
       
   343         {
       
   344         aLex.UnGetToMark( mark );
       
   345         return EFalse;
       
   346         }
       
   347     }
       
   348 
       
   349 // ----------------------------------------------------
       
   350 // Star()
       
   351 // Calls aFunc repeatedly until aFunc returns EFalse.
       
   352 // The lexer is left to the state where it was after
       
   353 // the last succesful aFunc call. Returns ETrue if
       
   354 // at least one call to aFunc succeeded.
       
   355 // ----------------------------------------------------
       
   356 //
       
   357 LOCAL_C TBool Star( TParseFunc aFunc, TLex& aLex )
       
   358     {
       
   359     TBool hasMore( ETrue );
       
   360     TBool hasOne( EFalse );
       
   361     while( hasMore )
       
   362         {
       
   363         if( DoOrReverse( aFunc, aLex ) )
       
   364             {
       
   365             hasOne = ETrue; 
       
   366             }
       
   367         else
       
   368             {
       
   369             hasMore = EFalse;
       
   370             }
       
   371         }
       
   372 
       
   373     return hasOne;
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // WPAdapterUtil::SetAPDetailsL
       
   378 // -----------------------------------------------------------------------------
       
   379 
       
   380 EXPORT_C void WPAdapterUtil::SetAPDetailsL(TUint aAPId)
       
   381     {
       
   382     FLOG( _L( "[WPAdapterUtil] WPAdapterUtil::SetAPDetailsL:" ) );
       
   383 
       
   384     TBuf8<KOriginatorMaxLength> Orig;
       
   385 
       
   386     //Get Originator from the Cenrep Key
       
   387     GetCenrepKeyL(Orig);
       
   388     //Convert to TBuf
       
   389     TBuf<KOriginatorMaxLength> Orig1;
       
   390     Orig1.Copy(Orig);
       
   391 
       
   392     CCommsDatabase* commDb = CCommsDatabase::NewL();
       
   393     CleanupStack::PushL( commDb );
       
   394     CApUtils* aputils = CApUtils::NewLC( *commDb );
       
   395 
       
   396     TUint32 apid = 0;
       
   397     //Get IAP ID from WAPID
       
   398     TRAPD( ERROR, apid = aputils->IapIdFromWapIdL( aAPId ) );
       
   399     User::LeaveIfError(ERROR);
       
   400 
       
   401     //Set AP to SNAP and DB
       
   402     TRAPD(err,SetAPtoDBandSNAPL(apid, Orig1));
       
   403     User::LeaveIfError(err);
       
   404 
       
   405     CleanupStack::PopAndDestroy(2); //aputils, commDb 
       
   406 
       
   407     FLOG( _L( "[Provisioning] WPAdapterUtil::SetAPDetailsL: done" ) );
       
   408 
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // WPAdapterUtil::GetAPIDL
       
   413 // -----------------------------------------------------------------------------
       
   414 EXPORT_C TUint WPAdapterUtil::GetAPIDL()
       
   415     {
       
   416     FLOG( _L( "[Provisioning] WPAdapterUtil::GetAPIDL:" ) );
       
   417 
       
   418     TBuf8<KOriginatorMaxLength> Orig;
       
   419 
       
   420     //Get Originator from the P&S Key
       
   421     GetCenrepKeyL(Orig);
       
   422 
       
   423     //Convert to TBuf
       
   424     TBuf<KOriginatorMaxLength> Orig1;
       
   425     Orig1.Copy(Orig);
       
   426 
       
   427     TUint apid;
       
   428     //Get the APID from DB or SNAP
       
   429     apid = GetAPIDFromDBorSNAPL(Orig1);
       
   430 
       
   431     FLOG( _L( "[Provisioning] WPAdapterUtil::GetAPIDL:done" ) );
       
   432     return apid;
       
   433 
       
   434     }
       
   435 
       
   436 // -----------------------------------------------------------------------------
       
   437 //GetCenrepKeyL
       
   438 // -----------------------------------------------------------------------------
       
   439 //	
       
   440 LOCAL_C void GetCenrepKeyL(TDes8& aValue)
       
   441     {
       
   442     FLOG( _L( "[Provisioning] WPAdapterUtil GetCenrepKeyL" ) );
       
   443     CRepository* rep = NULL;
       
   444     TInt errorStatus = KErrNone;
       
   445 
       
   446     TRAPD( errVal, rep = CRepository::NewL(KCRUidOMAProvisioningLV));
       
   447 
       
   448     if(errVal == KErrNone)
       
   449         {
       
   450         errorStatus = rep->Get( KOMAProvOriginatorContent ,aValue );
       
   451         }
       
   452     else
       
   453         {
       
   454         errorStatus = errVal;
       
   455         }
       
   456 
       
   457     if(rep)
       
   458         {
       
   459         delete rep;
       
   460         }
       
   461 
       
   462     if(errorStatus != KErrNone )
       
   463         {
       
   464         User::Leave(errorStatus);
       
   465         }
       
   466     FLOG( _L( "[Provisioning] WPAdapterUtil GetCenrepKeyL: done" ) );
       
   467     }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // GetAPIDFromDBorSNAPL
       
   471 // -----------------------------------------------------------------------------
       
   472 // 
       
   473 LOCAL_C TUint GetAPIDFromDBorSNAPL(TDesC& aOrig)
       
   474     {
       
   475     FLOG( _L( "[Provisioning] WPAdapterUtil GetAPIDFromDBorSNAPL" ) );
       
   476 
       
   477     RArray<TAccessPointItem> AccessPointItem;
       
   478     RArray<TAccessPointItem> AccessPointItem2;
       
   479     CWPInternetAPDB *db = CWPInternetAPDB::NewLC();
       
   480     RCmConnectionMethodExt connection;
       
   481 
       
   482     RCmManagerExt cmManager;
       
   483     cmManager.OpenL();
       
   484     CleanupClosePushL( cmManager );
       
   485 
       
   486     if (aOrig.Length())
       
   487         {
       
   488         //Read the Accesspoint data from DB, for the same originator
       
   489         db->ReadDbItemsForOrigL(AccessPointItem, aOrig);
       
   490 
       
   491         }
       
   492 
       
   493     //Read the Accesspoint data from DB, for all originators
       
   494     db->ReadDbItemsL(AccessPointItem2);
       
   495 
       
   496     TInt APOrigCount = AccessPointItem.Count();
       
   497     TInt APCount = AccessPointItem2.Count();
       
   498     //Valid APID of same originator
       
   499     TBool APIDofSameOrig = EFalse;
       
   500     //Valid APID of same originator
       
   501     TBool APIDofOtherOrig = EFalse;
       
   502 
       
   503     //HBufC *AccessPointName = NULL;
       
   504 
       
   505     TUint apid = 0;
       
   506     TUint apid1;
       
   507 
       
   508     if (APOrigCount)
       
   509         {
       
   510         TInt i;
       
   511 
       
   512         for ( i = APOrigCount - 1; i >= 0; i-- )
       
   513             {
       
   514             apid1 = AccessPointItem[i].iAPID;
       
   515             TRAPD(err, connection = cmManager.ConnectionMethodL(apid1));
       
   516             if (err == KErrNone)
       
   517                 {
       
   518                 CleanupClosePushL( connection );
       
   519 
       
   520                 if (AccessPointItem[i].iBearerType == connection.GetIntAttributeL(ECmBearerType))
       
   521                     {
       
   522                     //Valid access point of same originator is found
       
   523                     APIDofSameOrig = ETrue;
       
   524                     apid = apid1;
       
   525                     CleanupStack::PopAndDestroy();
       
   526                     break;
       
   527                     }
       
   528 
       
   529                 CleanupStack::PopAndDestroy();
       
   530                 }
       
   531 
       
   532             }
       
   533 
       
   534         //No valid access points of same originator
       
   535         //Get Access Point which is of other originator
       
   536         if(!APIDofSameOrig)
       
   537             {
       
   538 
       
   539             TInt j;
       
   540             TBool InvalidAPIDofOrig;
       
   541             for (i = APCount - 1; i >= 0; i-- )
       
   542                 {
       
   543                 apid1 = AccessPointItem2[i].iAPID;
       
   544 
       
   545                 for (InvalidAPIDofOrig = EFalse, j = APOrigCount - 1; j >= 0; j-- )
       
   546                     {
       
   547                     if(apid1 == AccessPointItem[j].iAPID)
       
   548                         {
       
   549                         InvalidAPIDofOrig = ETrue;
       
   550                         break;
       
   551                         }
       
   552                     }
       
   553 
       
   554                 TRAPD(err, connection = cmManager.ConnectionMethodL(apid1));
       
   555                 if (err == KErrNone)
       
   556                     {
       
   557                     CleanupClosePushL( connection );
       
   558                     if (!j && !InvalidAPIDofOrig &&
       
   559                             AccessPointItem2[i].iBearerType == connection.GetIntAttributeL(ECmBearerType))
       
   560 
       
   561                         {
       
   562                         //Valid access point of Other originator is found
       
   563                         APIDofOtherOrig = ETrue;
       
   564                         apid = apid1;
       
   565                         CleanupStack::PopAndDestroy(); //connection
       
   566                         break;
       
   567                         }
       
   568                     CleanupStack::PopAndDestroy(); //connection
       
   569                     }
       
   570 
       
   571                 }
       
   572             }
       
   573         }
       
   574 
       
   575     //No access points of same originator and valid 
       
   576     //Get Access Point of other originator
       
   577     if (APCount && !APIDofSameOrig && !APIDofOtherOrig)
       
   578         {
       
   579         for (TInt i = APCount - 1; i >= 0; i-- )
       
   580             {
       
   581             apid1 = AccessPointItem2[i].iAPID;
       
   582             TRAPD(err, connection = cmManager.ConnectionMethodL(apid1));
       
   583 
       
   584             if (err == KErrNone)
       
   585                 {
       
   586                 CleanupClosePushL( connection );
       
   587                 if ( AccessPointItem2[i].iBearerType == connection.GetIntAttributeL(ECmBearerType))
       
   588                     {
       
   589                     APIDofOtherOrig = ETrue;
       
   590                     apid = apid1;
       
   591                     CleanupStack::PopAndDestroy(); //connection
       
   592                     break;
       
   593                     }
       
   594 
       
   595                 CleanupStack::PopAndDestroy(); //connection
       
   596                 }
       
   597             }
       
   598 
       
   599         }
       
   600 
       
   601     //No valid access points of same originator and other originators
       
   602     //Get Access Point from Internet SNAP
       
   603     if (!APIDofSameOrig && !APIDofOtherOrig)
       
   604         {
       
   605         //Implementation to get the latest APID from Internet SNAP
       
   606         RCmDestinationExt InternetDestination;
       
   607         TRAPD(err, GetInternetSnapDestinationL(cmManager,InternetDestination ));
       
   608         if (err == KErrNone)
       
   609             {
       
   610             CleanupClosePushL( InternetDestination );
       
   611             FLOG(_L(" CleanupClosePushL done" ));
       
   612             //SIM provisioned, DM provisioned or user created access point 
       
   613             apid = GetInternetSnapLatestAPIDL(InternetDestination);
       
   614             CleanupStack::PopAndDestroy(); // InternetDestination
       
   615             }
       
   616 
       
   617         }
       
   618 
       
   619     CleanupStack::PopAndDestroy(2); //cmManager and db
       
   620     AccessPointItem.Reset();
       
   621     AccessPointItem2.Reset();
       
   622 
       
   623     FLOG( _L( "[Provisioning] WPAdapterUtil GetAPIDFromDBorSNAPL: done" ) );
       
   624     return apid;
       
   625     }
       
   626 
       
   627 // -----------------------------------------------------------------------------
       
   628 // GetInternetSnapLatestAPIDL
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 LOCAL_C TUint GetInternetSnapLatestAPIDL(RCmDestinationExt& InternetDestination)
       
   632     {
       
   633     FLOG( _L( "[Provisioning] WPAdapterUtil GetInternetSnapLatestAPIDL" ) );
       
   634     TInt APSNAPCount = InternetDestination.ConnectionMethodCount();
       
   635     TUint apid = 0;
       
   636 
       
   637     RCmConnectionMethodExt connection;
       
   638 
       
   639     //Return Connection method 
       
   640     if (APSNAPCount)
       
   641         {
       
   642 
       
   643         connection = InternetDestination.ConnectionMethodL(APSNAPCount - 1);
       
   644         CleanupClosePushL( connection );
       
   645         apid = connection.GetIntAttributeL( ECmIapId );
       
   646         CleanupStack::PopAndDestroy();
       
   647 
       
   648         }
       
   649 
       
   650     FLOG( _L( "[Provisioning] WPAdapterUtil GetInternetSnapLatestAPIDL: done" ) );
       
   651     return apid;
       
   652     }
       
   653 
       
   654 // -----------------------------------------------------------------------------
       
   655 // GetInternetSnapDestinationL
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 LOCAL_C void GetInternetSnapDestinationL(RCmManagerExt& aCmManager,RCmDestinationExt& aDestination )
       
   659     {
       
   660     FLOG( _L( "[Provisioning] WPAdapterUtil GetInternetSnapDestinationL" ) );
       
   661     RArray<TUint32> destinationIds;
       
   662 
       
   663     aCmManager.AllDestinationsL( destinationIds );
       
   664     const TInt destinationCount = destinationIds.Count();
       
   665 
       
   666     RCmDestinationExt destination;
       
   667 
       
   668     TInt counter;
       
   669 
       
   670     for ( counter = 0; counter < destinationCount; counter++ )
       
   671         {
       
   672         destination = aCmManager.DestinationL(destinationIds[counter] );
       
   673         CleanupClosePushL( destination );
       
   674         TSnapPurpose purpose;
       
   675         purpose = (TSnapPurpose) (destination.MetadataL(CMManager::ESnapMetadataPurpose ));
       
   676 
       
   677         if (purpose == ESnapPurposeInternet)
       
   678             {
       
   679             aDestination = destination;
       
   680             CleanupStack::PopAndDestroy(); // destination
       
   681             break;
       
   682 
       
   683             }
       
   684         CleanupStack::PopAndDestroy(); // destination
       
   685 
       
   686         }
       
   687 
       
   688     destinationIds.Reset(); // destinationIds
       
   689 
       
   690     if (counter == destinationCount )
       
   691         {
       
   692         User::Leave(KErrNotFound);
       
   693         }
       
   694 
       
   695     FLOG( _L( "[Provisioning] WPAdapterUtil GetInternetSnapDestinationL: done" ) );
       
   696 
       
   697     }
       
   698 
       
   699 // -----------------------------------------------------------------------------
       
   700 // SetAPtoDBandSNAPL
       
   701 // -----------------------------------------------------------------------------
       
   702 //	
       
   703 LOCAL_C void SetAPtoDBandSNAPL(const TUint aAPID, const TDesC& aOriginator)
       
   704     {
       
   705     FLOG( _L( "[Provisioning] WPAdapterUtil SetAPtoDBandSNAPL" ) );
       
   706     TInt ERROR;
       
   707     RCmManagerExt cmManager;
       
   708     TRAPD(err,cmManager.OpenL());
       
   709     User::LeaveIfError(err);
       
   710     CleanupClosePushL( cmManager ); // CS:1
       
   711 
       
   712 
       
   713     RCmConnectionMethodExt connection = cmManager.ConnectionMethodL( aAPID );
       
   714     CleanupClosePushL( connection ); // CS:2
       
   715 
       
   716     //Implementation to update the DB file with Access Point, Bearer Type
       
   717     // and Originator
       
   718     const TUint32 BearerType = connection.GetIntAttributeL(ECmBearerType);
       
   719 
       
   720     CWPInternetAPDB *db = CWPInternetAPDB::NewLC(); // CS:3
       
   721 
       
   722     TInt Index;
       
   723     TRAPD(err1, db->SaveToDatabaseL(Index, aAPID, BearerType, aOriginator ));
       
   724     User::LeaveIfError(err1);
       
   725 
       
   726     RCmDestinationExt InternetDestination;
       
   727 
       
   728     TRAP(ERROR, GetInternetSnapDestinationL(cmManager,InternetDestination ));
       
   729 
       
   730     if (ERROR == KErrNone)
       
   731         {
       
   732 
       
   733         CleanupClosePushL( InternetDestination ); // CS:4	
       
   734 
       
   735         TRAP(ERROR, InternetDestination.AddConnectionMethodL( connection ));
       
   736         if (ERROR == KErrNone)
       
   737             {
       
   738             TRAP(ERROR, InternetDestination.UpdateL());
       
   739             }
       
   740 
       
   741         CleanupStack::PopAndDestroy();
       
   742 
       
   743         }
       
   744 
       
   745     if (ERROR != KErrNone)
       
   746         {
       
   747         db->DeleteFromDatabaseL(aAPID);
       
   748         User::LeaveIfError(ERROR);
       
   749         }
       
   750 
       
   751     CleanupStack::PopAndDestroy();
       
   752     CleanupStack::PopAndDestroy( &connection );
       
   753     CleanupStack::PopAndDestroy();
       
   754 
       
   755     FLOG( _L( "[Provisioning] WPAdapterUtil SetAPtoDBandSNAPL: done" ) );
       
   756     }
       
   757 //  End of File