omaprovisioning/pnputil/src/PnpProvUtil.cpp
changeset 0 b497e44ab2fc
child 22 19fb38abab1d
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  provides interface for application to set UID and 
       
    15  *                provisioning adapters to set the settings application ID.
       
    16  *                PNPMS client get these values before activating service.
       
    17  *                This class can be used for launching online support in different modes
       
    18  *
       
    19 */
       
    20 
       
    21 
       
    22 #include <PnpProvUtil.h>
       
    23 #include <centralrepository.h>
       
    24 #include "PnpUtilPrivateCRKeys.h"
       
    25 #include <apgcli.h>
       
    26 #include <apacmdln.h>
       
    27 
       
    28 _LIT( KSpace," ");
       
    29 _LIT( KQuote, "\"" );
       
    30 _LIT( KServerParam, "s" );
       
    31 _LIT( KPageParam, "p" );
       
    32 _LIT( KReasonParam, "r" );
       
    33 _LIT( KQueryParam, "q" );
       
    34 _LIT( KAutoStartParam, "a" );
       
    35 _LIT( KTokenOverrideParam, "t" );
       
    36 _LIT( KServerPrefix, "www");
       
    37 _LIT( KPageString, "page1");
       
    38 _LIT( KHelpquery, "query");
       
    39 
       
    40 const TUid KServiceHelpUID = { 0x10204338 };
       
    41 
       
    42 const TInt KBufferMaxLength = 128; 
       
    43 const TInt KBufferMinLength = 2;
       
    44 
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CPnpProvUtil::CPnpProvUtil
       
    48 // C++ default constructor can NOT contain any code, that
       
    49 // might leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CPnpProvUtil::CPnpProvUtil()
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CPnpProvUtil::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CPnpProvUtil::ConstructL()
       
    62     {
       
    63     //No values to assign	
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CPnpProvUtil::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CPnpProvUtil* CPnpProvUtil::NewL()
       
    72     {
       
    73 
       
    74     CPnpProvUtil* self = NewLC();
       
    75     CleanupStack::Pop();
       
    76 
       
    77     return self; 
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CPnpProvUtil::NewLC
       
    82 // Two-phased constructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CPnpProvUtil* CPnpProvUtil::NewLC()
       
    86     {
       
    87     CPnpProvUtil* self = new( ELeave ) CPnpProvUtil;
       
    88 
       
    89     CleanupStack::PushL( self );
       
    90     self->ConstructL();
       
    91 
       
    92     return self;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // Destructor
       
    97 // -----------------------------------------------------------------------------
       
    98 CPnpProvUtil::~CPnpProvUtil()
       
    99     {   
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // SetLaunchedApplicationDetailsL
       
   104 // -----------------------------------------------------------------------------
       
   105 EXPORT_C void CPnpProvUtil::SetApplicationUidL(TUint32 aUid)
       
   106     {
       
   107     // Set UID of application into Cenrep Key for identifying the application
       
   108     // that triggered PNPMS client for service activation
       
   109 
       
   110     TBuf<50> uidval;
       
   111 
       
   112     // In case of resetting the cenrep value 	 
       
   113     if(aUid == 0)
       
   114         uidval= KNullDesC;
       
   115     else	
       
   116         uidval.Num(aUid, EHex);
       
   117 
       
   118     SetCenrepValueL(KCRUidPnpUtil,KPnPProvUtilAppUID, uidval);
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // GetLaunchedApplicationDetailsL
       
   123 // -----------------------------------------------------------------------------
       
   124 EXPORT_C TUint32 CPnpProvUtil::GetApplicationUidL()
       
   125     {
       
   126     // Get UID of application from Cenrep set by SetApplicationUidL
       
   127     // Return application UID to PNPMS client for service activation
       
   128 
       
   129     TUint32 uidval = 0; 
       
   130 
       
   131     TBuf<50> buf;
       
   132     GetCenrepValueL(KCRUidPnpUtil,KPnPProvUtilAppUID,buf);
       
   133 
       
   134     // If Cenrep value is empty then return UID with 0
       
   135 
       
   136     if( buf.Compare(KNullDesC) != 0 ) 
       
   137         {
       
   138         TLex lex(buf);
       
   139         lex.Val(uidval, EHex);
       
   140 
       
   141         }
       
   142 
       
   143     return uidval;
       
   144 
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // SetProvAdapterAppIdL
       
   149 // -----------------------------------------------------------------------------
       
   150 EXPORT_C void CPnpProvUtil::SetProvAdapterAppIdL(TDesC& appID)
       
   151     {	
       
   152 
       
   153     // This function set Provisioning adapter Application ID
       
   154     // for example: Email Provisioning settings: 110,143 
       
   155 
       
   156 
       
   157     TBuf<KBufferMaxLength> getValue;
       
   158     GetCenrepValueL(KCRUidPnpUtil,KPnPProvUtilProvAdapID, getValue );
       
   159 
       
   160     // Passing Null reference indicates clearing the Provisioning application
       
   161     // ID keys
       
   162 
       
   163     if(appID.Compare(_L(""))==0)
       
   164         SetCenrepValueL(KCRUidPnpUtil,KPnPProvUtilProvAdapID, appID );
       
   165     else
       
   166         {
       
   167         // If same adapter requests to set more than one application ID then
       
   168         // new application ID will be appended to existing one 
       
   169         // for example: Email app can have more than one app ID(POP3 and IMPA4)
       
   170 
       
   171         if(getValue.Compare(_L("")))
       
   172             {
       
   173             getValue.Append(_L(","));
       
   174             getValue.Append(appID);	
       
   175             }
       
   176         else	
       
   177             {
       
   178             getValue.Append(appID); 
       
   179             }
       
   180 
       
   181         SetCenrepValueL(KCRUidPnpUtil,KPnPProvUtilProvAdapID, getValue );
       
   182         }
       
   183 
       
   184 
       
   185 
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // GetProvAdapterAppIdsL
       
   190 // -----------------------------------------------------------------------------
       
   191 EXPORT_C void CPnpProvUtil::GetProvAdapterAppIdsL(RPointerArray<HBufC>& array)
       
   192     {
       
   193 
       
   194     // Get list of provisioning application IDs set by a particular 
       
   195     // provisioning adapter
       
   196 
       
   197     TBuf<KBufferMaxLength> getValue;
       
   198     GetCenrepValueL(KCRUidPnpUtil,KPnPProvUtilProvAdapID, getValue);
       
   199 
       
   200     ParseValueL(getValue, array);
       
   201 
       
   202     TBufC<KBufferMinLength> buf(_L(""));
       
   203     SetProvAdapterAppIdL(buf);
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // LaunchOnlineSupportL
       
   208 // -----------------------------------------------------------------------------
       
   209 
       
   210 EXPORT_C void CPnpProvUtil::LaunchOnlineSupportL(TDesC& aUri,TConnectReason aConnectReason, TStartMode aMode, TBool aTokenOverride , TDesC& aQueryString )
       
   211     {
       
   212 
       
   213     TBuf<KBufferMaxLength> cmdLineString;
       
   214 
       
   215     // Get constructed command line string and pass it as command line argument for starting the application
       
   216     ConstructCmdLineStringL(aUri, aConnectReason, aMode, aTokenOverride, aQueryString,cmdLineString );
       
   217 
       
   218 
       
   219     //online Support is launched from Command Line Symbian Framework	 
       
   220 
       
   221     RApaLsSession appArcSession;
       
   222     User::LeaveIfError( appArcSession.Connect() );
       
   223     CleanupClosePushL( appArcSession );
       
   224 
       
   225 
       
   226     TApaAppInfo info;
       
   227     User::LeaveIfError( appArcSession.GetAppInfo( info,KServiceHelpUID  ) );
       
   228 
       
   229     CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   230 
       
   231     cmdLine->SetExecutableNameL( info.iFullName );
       
   232 
       
   233     TBuf8<KBufferMaxLength> params;
       
   234     params.Copy( cmdLineString.Left( KBufferMaxLength) );
       
   235     cmdLine->SetTailEndL( params );
       
   236 
       
   237     TInt err = appArcSession.StartApp( *cmdLine );
       
   238     if( err != KErrNone )
       
   239         {
       
   240 
       
   241         User::Leave( err );
       
   242         }
       
   243     CleanupStack::PopAndDestroy( cmdLine );
       
   244     CleanupStack::PopAndDestroy(); // appArcSession.Close();
       
   245 
       
   246 
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // ConstructUriWithPnPUtilL
       
   251 // -----------------------------------------------------------------------------
       
   252 
       
   253 EXPORT_C void CPnpProvUtil::ConstructUriWithPnPUtilL(TDes& /*aUri*/, TServers /*aServer*/)
       
   254     {
       
   255     User::Leave(KErrNotSupported);
       
   256     }
       
   257 
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // SetCenrepValueL
       
   261 // -----------------------------------------------------------------------------
       
   262 void CPnpProvUtil::SetCenrepValueL(TUid aRepositoryUid,TUint32 aKey,TDesC& aValue)
       
   263     {
       
   264 
       
   265     // Set cenrep value to key specified as parameter to this function
       
   266 
       
   267     CRepository * rep = NULL;
       
   268     TInt errorStatus = KErrNone;
       
   269     TBuf<KBufferMaxLength> getValue(aValue);
       
   270 
       
   271     TRAPD( errVal, rep = CRepository::NewL(aRepositoryUid));
       
   272 
       
   273     if(errVal == KErrNone)
       
   274         {
       
   275         errorStatus =  rep->Set( aKey , getValue );
       
   276         }
       
   277     else
       
   278         {
       
   279         errorStatus = errVal;
       
   280         }
       
   281 
       
   282     if(rep)
       
   283         {
       
   284         delete rep;
       
   285         }
       
   286 
       
   287 
       
   288     if(errorStatus != KErrNone )
       
   289         {
       
   290         User::Leave(errorStatus);
       
   291         }
       
   292 
       
   293 
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // GetCenrepValueL
       
   298 // -----------------------------------------------------------------------------
       
   299 void CPnpProvUtil::GetCenrepValueL(TUid aRepositoryUid,TUint32 aKey, TDes& aValue)
       
   300     {
       
   301 
       
   302     // Get cenrep value of key specified as parameter to this function
       
   303 
       
   304     CRepository * rep = NULL;
       
   305     TInt errorStatus = KErrNone;
       
   306 
       
   307     TRAPD( errVal, rep = CRepository::NewL(aRepositoryUid));
       
   308 
       
   309     if(errVal == KErrNone)
       
   310         {
       
   311         errorStatus =  rep->Get( aKey , aValue );
       
   312         }
       
   313     else
       
   314         {
       
   315         errorStatus =  errVal;
       
   316         }
       
   317 
       
   318     if(rep)
       
   319         {
       
   320         delete rep;
       
   321         }
       
   322 
       
   323 
       
   324     if(errorStatus != KErrNone )
       
   325         {
       
   326         User::Leave(errorStatus);
       
   327         }
       
   328 
       
   329     }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // ParseValueL 
       
   333 // -----------------------------------------------------------------------------
       
   334 
       
   335 void CPnpProvUtil::ParseValueL(TDesC& aValue, RPointerArray<HBufC>& array )
       
   336     {
       
   337 
       
   338     // Parse buffer with comma as delimiter and return list of items	
       
   339 
       
   340     TLex aLex(aValue);
       
   341 
       
   342     while(aLex.Peek() != '\x00')
       
   343         {
       
   344 
       
   345         aLex.Mark();
       
   346         while(aLex.Peek()!=',' && aLex.Peek()!='\x00')
       
   347             aLex.Inc();
       
   348 
       
   349         TPtrC aPtr = aLex.MarkedToken(); 
       
   350 
       
   351 
       
   352         HBufC *buf18 = aPtr.AllocL();
       
   353         array.Append(buf18); 
       
   354 
       
   355         if(aLex.Peek()=='\x00') // end of string
       
   356             break; 
       
   357 
       
   358         aLex.Inc();
       
   359 
       
   360         }
       
   361     }
       
   362 
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // ConstructCmdLineStringL
       
   366 // -----------------------------------------------------------------------------
       
   367 
       
   368 void CPnpProvUtil::ConstructCmdLineStringL(TDesC& aUri,TConnectReason aConnectReason, TStartMode aMode, TBool aTokenOverride, TDesC& aQueryString, TDes& aPnPUtilUri)
       
   369     {
       
   370 
       
   371 
       
   372     TInt tokennum;
       
   373     TBuf<KBufferMaxLength> cmdLineString;
       
   374 
       
   375     cmdLineString.Zero();
       
   376 
       
   377     cmdLineString.Append( KServerParam );
       
   378     cmdLineString.Append( KQuote );
       
   379     cmdLineString.Append( KServerPrefix );
       
   380     cmdLineString.Append( KQuote );
       
   381 
       
   382     cmdLineString.Append( KSpace );
       
   383     cmdLineString.Append( KPageParam );
       
   384     cmdLineString.Append( KQuote );
       
   385     cmdLineString.Append( KPageString );
       
   386     cmdLineString.Append( KQuote );
       
   387 
       
   388     cmdLineString.Append( KSpace );
       
   389     cmdLineString.Append( KReasonParam );
       
   390     cmdLineString.AppendNum( aConnectReason );
       
   391 
       
   392     // Non interactive mode of settings download is not supported at server side and only interactive mode is supported
       
   393 
       
   394     if(aMode == EStartInteractive)
       
   395         {
       
   396         cmdLineString.Append( KSpace );
       
   397         cmdLineString.Append( KAutoStartParam );
       
   398         cmdLineString.AppendNum( 0 );
       
   399 
       
   400         }
       
   401     else
       
   402         {
       
   403         //Silent mode is not supported by PnPMS server
       
   404         User::Leave(KErrNotSupported);
       
   405         }
       
   406 
       
   407     cmdLineString.Append( KSpace );
       
   408     cmdLineString.Append( KTokenOverrideParam );
       
   409 
       
   410     if(aTokenOverride == EFalse)
       
   411         tokennum = 0;
       
   412     else
       
   413         tokennum = 1;
       
   414 
       
   415     cmdLineString.AppendNum( tokennum );
       
   416 
       
   417 
       
   418     //Help Query parameter is not supported by Server so default "query" string will be set
       
   419 
       
   420     cmdLineString.Append( KSpace );
       
   421     cmdLineString.Append( KQueryParam );
       
   422     cmdLineString.Append( KQuote );
       
   423     cmdLineString.Append( KHelpquery );
       
   424     cmdLineString.Append( KQuote );
       
   425 
       
   426     aPnPUtilUri.Copy(cmdLineString);
       
   427 
       
   428     }
       
   429 
       
   430 
       
   431