applayerprotocols/httpservice/src/chttpclientauthentication.cpp
branchRCL_3
changeset 7 337070b4fa18
child 39 c0c2f28ace9c
equal deleted inserted replaced
3:5ee1d9ce5878 7:337070b4fa18
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "chttpclientauthentication.h"
       
    17 #include "mhttpserviceauthentication.h"
       
    18 
       
    19 CHttpClientAuthentication* CHttpClientAuthentication::New(RHTTPSession aSesion, MHTTPServiceAuthentication* aCallback)
       
    20     {
       
    21     CHttpClientAuthentication* self = new CHttpClientAuthentication;
       
    22     TInt err = self->Construct(aSesion, aCallback);
       
    23     if(err != KErrNone)
       
    24         {
       
    25         delete self;
       
    26         self = NULL;
       
    27         }
       
    28     return self;
       
    29     }
       
    30 
       
    31 TInt CHttpClientAuthentication::Construct(RHTTPSession aSession, MHTTPServiceAuthentication* aCallback)
       
    32     {      
       
    33     // Install this class as the callback for authentication requests
       
    34     TRAPD(err, InstallAuthenticationL(aSession));
       
    35     iHTTPServiceAuthentication = aCallback;
       
    36     return err;
       
    37     }
       
    38 
       
    39 void CHttpClientAuthentication::FillCredentialsL(RString& aRealm, RString& aUsername, RString& aPassword, RBuf8& aClientUsername, RBuf8& aClientPassword)
       
    40     {  
       
    41     aUsername = aRealm.Pool().OpenStringL(aClientUsername);
       
    42     aPassword = aRealm.Pool().OpenStringL(aClientPassword);
       
    43     }
       
    44 
       
    45 TBool CHttpClientAuthentication::GetCredentialsL(const TUriC8& aURI, RString aRealm, 
       
    46                                    RStringF aAuthenticationType,
       
    47                                    RString& aUsername, 
       
    48                                    RString& aPassword)
       
    49     {
       
    50     //User credentials
       
    51     RBuf8 clientUsername;
       
    52     RBuf8 clientPassword;    
       
    53      
       
    54     User::LeaveIfError(iHTTPServiceAuthentication->OnAuthentication(aURI.UriDes(), aRealm.DesC(), aAuthenticationType.DesC(), clientUsername, clientPassword));
       
    55     
       
    56     FillCredentialsL(aRealm, aUsername, aPassword, clientUsername, clientPassword);
       
    57     
       
    58     clientUsername.Close();
       
    59     clientPassword.Close();    
       
    60     
       
    61     return ETrue;    
       
    62     }