vpnengine/vpnmanager/src/vpnapiservant.cpp
branchRCL_3
changeset 22 9f4e37332ce5
parent 2 ef893827b4d1
child 23 473321461bba
equal deleted inserted replaced
20:352850cbed81 22:9f4e37332ce5
     1 /*
     1 /*
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 * Description: Handles API requests for VPN Manager.
    14 * Description: Handles API requests for VPN Manager.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 #include <e32std.h>
       
    20 #include <f32file.h>
       
    21 
       
    22 #include "fileutil.h"
    20 #include "vpnapiservant.h"
    23 #include "vpnapiservant.h"
    21 #include "policystore.h"
    24 #include "policystore.h"
    22 #include "policyimporter.h"
    25 #include "policyimporter.h"
    23 #include "pwdchanger.h"
    26 #include "pwdchanger.h"
    24 #include "vpnapidefs.h"
    27 #include "vpnapidefs.h"
    25 #include "vpnmanagerserverdefs.h"
    28 #include "vpnmanagerserverdefs.h"
       
    29 #include "vpnextapiservantdefs.h"
    26 #include "vpnmaninternal.h"
    30 #include "vpnmaninternal.h"
    27 #include "log_r6.h"
    31 #include "log_r6.h"
       
    32 #include "agileprovisionws.h"
       
    33 #include "agileprovisiondefs.h"
       
    34 #include "cmmanagerutils.h"
    28 
    35 
    29 
    36 
    30 CVpnApiServant* CVpnApiServant::NewL(RFs& aFs)
    37 CVpnApiServant* CVpnApiServant::NewL(RFs& aFs)
    31     {
    38     {
    32     CVpnApiServant* self = new (ELeave) CVpnApiServant(aFs);
    39     CVpnApiServant* self = new (ELeave) CVpnApiServant(aFs);
    34     self->ConstructL();
    41     self->ConstructL();
    35     CleanupStack::Pop(); // self
    42     CleanupStack::Pop(); // self
    36     return self;
    43     return self;
    37     }
    44     }
    38 
    45 
    39 CVpnApiServant::CVpnApiServant(RFs& aFs) : iFs(aFs)
    46 CVpnApiServant::CVpnApiServant(RFs& aFs) : iFs(aFs), iFileUtil(aFs)
    40     {
    47     {
    41     }
    48     }
    42 
    49 
    43 void CVpnApiServant::ConstructL()
    50 void CVpnApiServant::ConstructL()
    44     {
    51     {
   111             
   118             
   112         case EVpnUpdatePolicyData:
   119         case EVpnUpdatePolicyData:
   113             UpdatePolicyDataL(aMessage);
   120             UpdatePolicyDataL(aMessage);
   114             break;
   121             break;
   115             
   122             
       
   123         
       
   124         //Policy Provision Methods
       
   125         case EExtCreateProvisionServer:
       
   126             CreateProvisionServerL(aMessage);
       
   127             break;
       
   128          
       
   129         case EExtVPNPolicyServerList:
       
   130             ListProvisionServerL(aMessage);
       
   131             break;
       
   132             
       
   133         case EExtVPNPolicyServerDetails:
       
   134             GetProvisionServerDetailsL(aMessage);
       
   135             break;
       
   136             
       
   137         case EExtSynchronizePolicyServer:
       
   138             SynchronizeVPNPolicyServerL(aMessage);
       
   139             break;
       
   140             
       
   141         case EExtDeletePolicyServer:
       
   142              DeleteVPNPolicyServerL(aMessage);
       
   143              break;
       
   144         
       
   145         case EExtCancelSynchronize:
       
   146              CancelSynchronize(aMessage);
       
   147              break;
       
   148         
       
   149         case EExtGetPolicyName:
       
   150              GetVPNPolicyNameL(aMessage);
       
   151              break;
       
   152              
   116         default:
   153         default:
   117             requestHandled = EFalse;
   154             requestHandled = EFalse;
   118             break;
   155             break;
   119         }
   156         }
   120 
   157 
   242         }
   279         }
   243         
   280         
   244             
   281             
   245     aMessage.Complete(ret);
   282     aMessage.Complete(ret);
   246     
   283     
   247     LOG(Log::Printf(_L("CVpnApiServant::GetPolicyDetailsL: aMesage completed withd %d"), ret));    
   284     LOG(Log::Printf(_L("CVpnApiServant::GetPolicyDetailsL: aMessage completed withd %d"), ret));    
   248     }
   285     }
   249 
   286 
   250 void CVpnApiServant::DeletePolicyL(const RMessage2& aMessage)
   287 void CVpnApiServant::DeletePolicyL(const RMessage2& aMessage)
   251     {
   288     {
   252     TVpnPolicyId policyId;
   289     TVpnPolicyId policyId;
   516     }
   553     }
   517     CleanupStack::PopAndDestroy(); // policyData
   554     CleanupStack::PopAndDestroy(); // policyData
   518 
   555 
   519     aMessage.Complete(KErrNone);
   556     aMessage.Complete(KErrNone);
   520     }
   557     }
       
   558 
       
   559 void CVpnApiServant::CreateProvisionServerL( const RMessage2& aMessage )
       
   560     {
       
   561       TAgileProvisionApiServerSettings* serverCreate = new (ELeave) TAgileProvisionApiServerSettings();
       
   562       CleanupStack::PushL(serverCreate);
       
   563       TPckg<TAgileProvisionApiServerSettings> pckgServerCreate(*serverCreate);
       
   564       aMessage.ReadL(0, pckgServerCreate);
       
   565       TAgileProvisionServerLocals* serverAccountLocalData = new (ELeave) TAgileProvisionServerLocals();
       
   566       CleanupStack::PushL(serverAccountLocalData);
       
   567       serverAccountLocalData->iSelection = serverCreate->iSelection;
       
   568       serverAccountLocalData->iServerAddress.Copy(serverCreate->iServerUrl);
       
   569       serverAccountLocalData->iServerNameLocal.Copy(serverCreate->iServerNameLocal);
       
   570   
       
   571       TFileName serverFilePath;
       
   572       User::LeaveIfError(iFs.PrivatePath(serverFilePath));
       
   573       serverFilePath.Append(KProvisionServerSettings);   
       
   574          
       
   575       /* Check if file allready exists and copy policy and vpn iap id to a new file */
       
   576       TFileName policyFileName;
       
   577       TUint32 agileProvisionAPId=0;
       
   578             
       
   579       if ( iFileUtil.FileExists(serverFilePath) )
       
   580          {
       
   581           HBufC8* fileData=iFileUtil.LoadFileDataL(serverFilePath);
       
   582           CleanupStack::PushL(fileData);
       
   583              
       
   584           TPtrC8 restOfData = fileData->Des();
       
   585                 
       
   586           TInt bofInt;
       
   587           TInt line=1;             
       
   588           while ( (bofInt=restOfData.Find(KCRLF)) != KErrNotFound && line < KPolicyFileLine )
       
   589                 {
       
   590                 restOfData.Set(restOfData.Mid(bofInt + KCRLF().Length()));
       
   591                 line++;                                  
       
   592                 }
       
   593           TInt iapIdStart=restOfData.Find(KCRLF);
       
   594           HBufC16* iapIdBuf;
       
   595                  
       
   596           if ( iapIdStart!=KErrNotFound )
       
   597               {
       
   598               TPtrC8 iapIdPtr=restOfData.Mid(iapIdStart + KCRLF().Length(),restOfData.Length()-KCRLF().Length()-iapIdStart);
       
   599               iapIdBuf=iFileUtil.To16BitL(iapIdPtr);
       
   600               CleanupStack::PushL(iapIdBuf);
       
   601               TLex iapIdConverter(*iapIdBuf);
       
   602               iapIdConverter.Val(agileProvisionAPId,EDecimal);     
       
   603               CleanupStack::PopAndDestroy(iapIdBuf);           
       
   604               }
       
   605                  
       
   606           if ( agileProvisionAPId >0)
       
   607               {
       
   608                restOfData.Set(restOfData.Mid(0,iapIdStart));
       
   609                HBufC16* policyFileNameBuf = iFileUtil.To16BitL(restOfData);
       
   610                policyFileName = *policyFileNameBuf;
       
   611                delete policyFileNameBuf;
       
   612               }
       
   613           CleanupStack::PopAndDestroy(fileData);
       
   614           }
       
   615       /* end of saving old values */
       
   616       
       
   617       //IAP data Max value 255 
       
   618       TBuf<10> iapIdStr;
       
   619       TBuf<10> iapModeStr;
       
   620       TBuf<10> iapAgileIdStr;
       
   621       
       
   622       iapIdStr.Num(serverAccountLocalData->iSelection.iId);
       
   623       iapModeStr.Num(serverAccountLocalData->iSelection.iResult);
       
   624       HBufC* serverSettingsDataBuf;
       
   625       if ( agileProvisionAPId >0 )
       
   626           {
       
   627           iapAgileIdStr.Num(agileProvisionAPId);
       
   628                                                                                                                           
       
   629           serverSettingsDataBuf = HBufC::NewL(serverAccountLocalData->iServerNameLocal.Length() + serverAccountLocalData->iServerAddress.Length() + 
       
   630                                               iapIdStr.Length() + iapModeStr.Length() + policyFileName.Length() + iapAgileIdStr.Length() + 5*(KCRLF().Length()) );
       
   631           }
       
   632       else
       
   633           {                                                                                                         
       
   634           serverSettingsDataBuf = HBufC::NewL(serverAccountLocalData->iServerNameLocal.Length() + serverAccountLocalData->iServerAddress.Length() +
       
   635                                               iapIdStr.Length() + iapModeStr.Length() + 3*(KCRLF().Length()) );
       
   636           }
       
   637       CleanupStack::PushL(serverSettingsDataBuf);
       
   638       TPtr tPtr(serverSettingsDataBuf->Des());
       
   639       tPtr.Copy(serverAccountLocalData->iServerAddress);
       
   640       _LIT(KCRLF, "\r\n"); 
       
   641       tPtr.Append(KCRLF);
       
   642       tPtr.Append(serverAccountLocalData->iServerNameLocal);
       
   643       tPtr.Append(KCRLF);
       
   644       tPtr.Append(iapIdStr);
       
   645       tPtr.Append(KCRLF);
       
   646       tPtr.Append(iapModeStr);
       
   647       if ( agileProvisionAPId >0 )
       
   648           {
       
   649           tPtr.Append(KCRLF);
       
   650           tPtr.Append(policyFileName);
       
   651           tPtr.Append(KCRLF);
       
   652           tPtr.Append(iapAgileIdStr);
       
   653           }
       
   654      
       
   655       iFileUtil.SaveFileDataL(serverFilePath,tPtr);
       
   656       CleanupStack::PopAndDestroy(3);
       
   657       aMessage.Complete(KErrNone);
       
   658     }
       
   659 
       
   660 void CVpnApiServant::ListProvisionServerL( const RMessage2& aMessage )
       
   661     {
       
   662       _LIT8(KCRLF, "\r\n");
       
   663       
       
   664       const TInt KEolLen = 2;
       
   665       
       
   666       TAgileProvisionApiServerListElem* serverList = new (ELeave) TAgileProvisionApiServerListElem();
       
   667       CleanupStack::PushL(serverList);
       
   668       TPckg<TAgileProvisionApiServerListElem> serverPckg(*serverList);
       
   669           
       
   670       TFileName serverFilePath;
       
   671       User::LeaveIfError(iFs.PrivatePath(serverFilePath));
       
   672       serverFilePath.Append(KProvisionServerSettings);   
       
   673       
       
   674       HBufC8* fileData(NULL);
       
   675      
       
   676       if ( iFileUtil.FileExists(serverFilePath) )
       
   677           {
       
   678           fileData=iFileUtil.LoadFileDataL(serverFilePath);
       
   679           CleanupStack::PushL(fileData);
       
   680           TInt endOfLine=fileData->Find(KCRLF);
       
   681           serverList->iServerUrl=fileData->Mid(0,endOfLine);
       
   682           
       
   683           TInt startOfLine(endOfLine+KEolLen);
       
   684           TPtrC8 nameData=fileData->Right(fileData->Length()-startOfLine);
       
   685           endOfLine=nameData.Find(KCRLF);
       
   686           HBufC16* serverName=iFileUtil.To16BitL(nameData.Left(endOfLine));
       
   687           serverList->iServerNameLocal=*serverName;
       
   688           delete serverName;
       
   689           serverName = NULL;
       
   690           }
       
   691       
       
   692       aMessage.WriteL(0, serverPckg);
       
   693       if ( iFileUtil.FileExists(serverFilePath) )
       
   694           CleanupStack::PopAndDestroy(fileData);
       
   695       
       
   696       CleanupStack::PopAndDestroy(serverList);
       
   697       aMessage.Complete(KErrNone);
       
   698     }
       
   699 
       
   700 void CVpnApiServant::GetProvisionServerDetailsL( const RMessage2& aMessage )
       
   701     {
       
   702      
       
   703       TAgileProvisionApiServerSettings* serverList = new (ELeave) TAgileProvisionApiServerSettings();
       
   704       CleanupStack::PushL(serverList);
       
   705       TPckg<TAgileProvisionApiServerSettings> serverPckg(*serverList);
       
   706       
       
   707       _LIT8(KCRLF, "\r\n");     
       
   708       
       
   709       TFileName serverFilePath;
       
   710       User::LeaveIfError(iFs.PrivatePath(serverFilePath));
       
   711       serverFilePath.Append(KProvisionServerSettings);  
       
   712       
       
   713       HBufC8* fileData(NULL);
       
   714       const TInt KEolLen = 2;
       
   715       TBool serverFileExist = EFalse;
       
   716       
       
   717       if ( iFileUtil.FileExists(serverFilePath) )
       
   718          {
       
   719           fileData=iFileUtil.LoadFileDataL(serverFilePath);
       
   720           CleanupStack::PushL(fileData);  
       
   721           TInt endOfLine=fileData->Find(KCRLF);
       
   722           serverList->iServerUrl=fileData->Mid(0,endOfLine);
       
   723                 
       
   724           TInt startOfLine(endOfLine+2);
       
   725           TPtrC8 nameData=fileData->Right(fileData->Length()-startOfLine);
       
   726           endOfLine=nameData.Find(KCRLF);      
       
   727              
       
   728           HBufC16* serverName=iFileUtil.To16BitL(nameData.Left(endOfLine));
       
   729           serverList->iServerNameLocal=*serverName;
       
   730           delete serverName;
       
   731           serverName = NULL;
       
   732           
       
   733           startOfLine = endOfLine + KEolLen;
       
   734           TPtrC8 iapIdData=nameData.Right(nameData.Length()-startOfLine);
       
   735           endOfLine=iapIdData.Find(KCRLF);
       
   736           TLex8 iapIdConverter(iapIdData.Left(endOfLine));
       
   737           TUint idInt;
       
   738           iapIdConverter.Val(idInt);
       
   739           serverList->iSelection.iId = idInt;
       
   740         
       
   741           startOfLine = endOfLine + KEolLen;
       
   742           TPtrC8 iapModeData=iapIdData.Right(iapIdData.Length()-startOfLine);
       
   743           TLex8 iapModeConverter;
       
   744           endOfLine=iapModeData.Find(KCRLF);
       
   745           if ( endOfLine==KErrNotFound )
       
   746               iapModeConverter = iapModeData;
       
   747           else
       
   748               iapModeConverter = iapModeData.Left(endOfLine);
       
   749               
       
   750           iapModeConverter.Val(idInt);
       
   751           CMManager::TCmSettingSelectionMode selectionMode = (CMManager::TCmSettingSelectionMode) idInt;
       
   752           serverList->iSelection.iResult = selectionMode; 
       
   753           serverFileExist = ETrue;   
       
   754           }
       
   755       aMessage.WriteL(0, serverPckg);
       
   756       
       
   757       if ( serverFileExist )
       
   758           CleanupStack::PopAndDestroy(fileData);
       
   759       
       
   760       CleanupStack::PopAndDestroy(serverList);
       
   761       
       
   762       aMessage.Complete(KErrNone);
       
   763     }
       
   764 
       
   765 void CVpnApiServant::SynchronizeVPNPolicyServerL( const RMessage2& aMessage )
       
   766     {
       
   767     iPolicyImporter = CPolicyImporter::NewL(aMessage, *this, *iPolicyStore, iFs);
       
   768     
       
   769     //Asynchronous call
       
   770     iPolicyImporter->SynchronizeVpnPolicyServerL();
       
   771     }
       
   772 
       
   773 void CVpnApiServant::DeleteVPNPolicyServerL( const RMessage2& aMessage )
       
   774     {
       
   775     TFileName serverFilePath;
       
   776     User::LeaveIfError(iFs.PrivatePath(serverFilePath));
       
   777     serverFilePath.Append(KProvisionServerSettings);  
       
   778     iFileUtil.DeleteFileL(serverFilePath);
       
   779     aMessage.Complete(KErrNone);
       
   780     }
       
   781 
       
   782 void CVpnApiServant::CancelSynchronize( const RMessage2& aMessage )
       
   783     {
       
   784     if (iPolicyImporter)
       
   785         {
       
   786         if ( iPolicyImporter->iAgileProvisionWs != NULL )
       
   787             {
       
   788             CAgileProvisionWs* ws = iPolicyImporter->iAgileProvisionWs;
       
   789             ws->CancelGetPolicy();
       
   790             }
       
   791         iPolicyImporter->Cancel();
       
   792         delete iPolicyImporter;
       
   793         iPolicyImporter = NULL;
       
   794         }
       
   795     aMessage.Complete(KErrCancel);
       
   796     }
       
   797 
       
   798 void CVpnApiServant::GetVPNPolicyNameL( const RMessage2& aMessage )
       
   799     {
       
   800     TAgileProvisionPolicy* policy = new (ELeave) TAgileProvisionPolicy();
       
   801     CleanupStack::PushL(policy);
       
   802     TPckg<TAgileProvisionPolicy> serverPckg(*policy);
       
   803     
       
   804     _LIT8(KCRLF, "\r\n");
       
   805     
       
   806     TFileName serverFilePath;
       
   807     User::LeaveIfError(iFs.PrivatePath(serverFilePath));
       
   808     serverFilePath.Append(KProvisionServerSettings);  
       
   809     
       
   810     HBufC8* fileData(NULL);
       
   811          
       
   812     const TInt KEolLen = 2;
       
   813     TBool serverFileExist = EFalse;
       
   814     
       
   815     if ( iFileUtil.FileExists(serverFilePath) )
       
   816        {
       
   817         fileData=iFileUtil.LoadFileDataL(serverFilePath);
       
   818         CleanupStack::PushL(fileData);   
       
   819         TInt endOfLine=fileData->Find(KCRLF);
       
   820         if (endOfLine<=0)
       
   821             User::Leave(KErrArgument);
       
   822                         
       
   823         TInt startOfLine(endOfLine + KEolLen);
       
   824         TPtrC8 nameData=fileData->Right(fileData->Length()-startOfLine);
       
   825         endOfLine=nameData.Find(KCRLF);      
       
   826         if (endOfLine<=0)
       
   827             User::Leave(KErrArgument);      
       
   828                 
       
   829         startOfLine = endOfLine + KEolLen;
       
   830         TPtrC8 iapIdData=nameData.Right(nameData.Length()-startOfLine);
       
   831         endOfLine=iapIdData.Find(KCRLF);
       
   832         if (endOfLine<=0)
       
   833             User::Leave(KErrArgument);      
       
   834            
       
   835         startOfLine = endOfLine + KEolLen;
       
   836         TPtrC8 iapModeData=iapIdData.Right(iapIdData.Length()-startOfLine);
       
   837         endOfLine=iapModeData.Find(KCRLF);
       
   838         if (endOfLine<=0)
       
   839             User::Leave(KErrArgument);      
       
   840         
       
   841         startOfLine = endOfLine + KEolLen;
       
   842         TPtrC8 policyData=iapModeData.Right(iapModeData.Length()-startOfLine);
       
   843         endOfLine=policyData.Find(KCRLF);
       
   844         if (endOfLine<=0)
       
   845             User::Leave(KErrArgument);      
       
   846         
       
   847         HBufC16* policyName = iFileUtil.To16BitL(policyData.Left(endOfLine));
       
   848         policy->iPolicyName = *policyName;
       
   849         delete policyName;
       
   850         policyName=NULL;
       
   851         serverFileExist = ETrue;
       
   852         }
       
   853 
       
   854     aMessage.WriteL(0, serverPckg);
       
   855     
       
   856     if ( serverFileExist )
       
   857         CleanupStack::PopAndDestroy(fileData);
       
   858     
       
   859     CleanupStack::PopAndDestroy(policy);
       
   860     
       
   861     aMessage.Complete(KErrNone);
       
   862     }