vpnengine/agileprovisionws/src/agileprovisionservice.cpp
branchRCL_3
changeset 41 e06095241a65
parent 38 9f4e37332ce5
equal deleted inserted replaced
40:473321461bba 41:e06095241a65
       
     1 /*
       
     2 * Copyright (c) 2010 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:  VPN Agile provision service 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <SenXmlServiceDescription.h>
       
    19 #include <SenSoapMessage.h>
       
    20 #include <SenHttpTransportProperties.h>
       
    21 #include <e32debug.h>
       
    22 #include <cmmanagerext.h>
       
    23 #include <cmdestinationext.h>
       
    24 #include "agileprovisionservice.h"
       
    25 #include "agileprovisiondefs.h"
       
    26 
       
    27 
       
    28 CAgileProvisionServiceService* CAgileProvisionServiceService::NewL(MSenServiceConsumer& aObserver, MSenServiceDescription& aServiceDescription)
       
    29 {
       
    30     CSenServiceConnection* pConn = CSenServiceConnection::NewLC(aObserver, aServiceDescription);
       
    31     
       
    32     CAgileProvisionServiceService* pNew = new (ELeave) CAgileProvisionServiceService(pConn, ETrue); // owns connection
       
    33     
       
    34     CleanupStack::Pop(pConn);
       
    35     return pNew;
       
    36 }
       
    37 
       
    38 
       
    39 CAgileProvisionServiceService::CAgileProvisionServiceService(CSenServiceConnection* aConnection, TBool aOwnsConnection) :
       
    40     iConnection(aConnection), iOwnsConnection(aOwnsConnection)
       
    41 {
       
    42 }
       
    43 
       
    44 CAgileProvisionServiceService::~CAgileProvisionServiceService()
       
    45 {
       
    46     delete iCertreq;
       
    47     iCertreq=NULL;
       
    48     if (iOwnsConnection)
       
    49     {
       
    50         delete iConnection;
       
    51     }
       
    52    
       
    53 }
       
    54 
       
    55 
       
    56 void CAgileProvisionServiceService::GetConfAsyncL()
       
    57 {
       
    58     TPtrC8 reqStr;
       
    59  
       
    60     CSenSoapMessage *soapRequest = CSenSoapMessage::NewL();
       
    61     CleanupStack::PushL(soapRequest);
       
    62     
       
    63     TPtrC8 soapActionPtr(KSoapAction);
       
    64     soapRequest->SetSoapActionL( soapActionPtr );
       
    65      
       
    66     
       
    67     TPtrC8 reqBodyStr(KRequest);
       
    68     soapRequest->SetBodyL(reqBodyStr);
       
    69    
       
    70     CSenHttpTransportProperties* pHttpProperties = CSenHttpTransportProperties::NewLC();    
       
    71     
       
    72     using namespace CMManager;
       
    73        
       
    74     RCmManagerExt cmManagerExt;
       
    75     cmManagerExt.OpenL();        
       
    76     CleanupClosePushL( cmManagerExt );     
       
    77 
       
    78     RArray<TUint32> destinationArray;    
       
    79     cmManagerExt.AllDestinationsL( destinationArray );
       
    80     CleanupClosePushL(destinationArray);    
       
    81     TBool destinationExist=EFalse;       
       
    82     for (TInt i = 0; i < destinationArray.Count(); ++i)
       
    83         {
       
    84         RCmDestinationExt destination = cmManagerExt.DestinationL( destinationArray[i] );
       
    85         CleanupClosePushL(destination);
       
    86        
       
    87         if ( destination.Id() == iIapId )
       
    88             {
       
    89              destinationExist=ETrue;
       
    90              CleanupStack::PopAndDestroy(); //destination
       
    91              break;
       
    92             }                
       
    93         CleanupStack::PopAndDestroy(); //destination
       
    94         }
       
    95     destinationArray.Reset();
       
    96     destinationArray.Close();
       
    97     CleanupStack::PopAndDestroy(2); //destinationArray, cmManagerExt
       
    98     
       
    99     if ( destinationExist == 1 ) //ETrue
       
   100         {
       
   101         pHttpProperties->SetSnapIdL(iIapId);
       
   102         }
       
   103     else
       
   104         {
       
   105         pHttpProperties->SetIapIdL(iIapId);
       
   106         }
       
   107     
       
   108     HBufC8* pSerializedProperties = pHttpProperties->AsUtf8L();
       
   109     CleanupStack::PushL(pSerializedProperties);
       
   110     iConnection->SetTransportPropertiesL(*pSerializedProperties);
       
   111        
       
   112     TInt ret = iConnection->SendL(*soapRequest);
       
   113     User::LeaveIfError( ret );
       
   114    
       
   115     iTransactionId = ret ;
       
   116     CleanupStack::PopAndDestroy(pSerializedProperties);
       
   117     CleanupStack::PopAndDestroy(pHttpProperties);
       
   118     CleanupStack::PopAndDestroy(soapRequest);
       
   119 }
       
   120 
       
   121 
       
   122 void CAgileProvisionServiceService::GetCertificateAsyncL( HBufC8* aCertReq )
       
   123 {
       
   124     TPtrC8 reqStr;
       
   125     
       
   126     CSenSoapMessage *soapRequest = CSenSoapMessage::NewL();
       
   127     CleanupStack::PushL(soapRequest);
       
   128     soapRequest->SetSoapActionL( KSoapActionCert );
       
   129     
       
   130     TBase64Codec base64Codec;    
       
   131     HBufC8* certreqBase64 = base64Codec.Base64EncodeLC(*aCertReq);
       
   132     HBufC8* certReqBodyHeap=HBufC8::NewLC(KRequest1().Length() + KRequest2().Length() + certreqBase64->Length());
       
   133     TPtr8 certReqBodyAppend(certReqBodyHeap->Des());
       
   134     certReqBodyAppend=KRequest1;
       
   135     certReqBodyAppend.Append(certreqBase64->Des());
       
   136     certReqBodyAppend.Append(KRequest2);
       
   137     
       
   138     TPtrC8 reqBodyStr(certReqBodyAppend);
       
   139     soapRequest->SetBodyL(reqBodyStr);
       
   140 
       
   141     TInt ret = iConnection->SendL(*soapRequest);
       
   142     User::LeaveIfError( ret );
       
   143     iTransactionId = ret;
       
   144     CleanupStack::PopAndDestroy(); //certReqBodyHeap
       
   145     CleanupStack::PopAndDestroy(); //certreqBase64
       
   146     CleanupStack::PopAndDestroy(); // soapRequest
       
   147 }
       
   148 
       
   149 
       
   150 void CAgileProvisionServiceService::CancelTransaction()
       
   151 {
       
   152     if ( iTransactionId > 0 )
       
   153     {
       
   154         iConnection->CancelTransaction( iTransactionId );
       
   155         iTransactionId = 0;
       
   156     }
       
   157 }
       
   158 
       
   159 void CAgileProvisionServiceService::ResetTransactionId()
       
   160 {
       
   161     iTransactionId = 0;
       
   162 }