pkiutilities/ocsp/transport/transportdefault.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     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 // COCSPTransportDefault.  Looks at the URI and creates appropriate transport
       
    15 // object to send the request.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <ocsptransport.h>
       
    20 #include "panic.h"
       
    21 #include "ocsp.h"
       
    22 
       
    23 #include <uri8.h>
       
    24 
       
    25 _LIT8(KHttpString, "http");
       
    26 
       
    27 EXPORT_C COCSPTransportDefault* COCSPTransportDefault::NewL(TUint32& aIap)
       
    28 	{
       
    29 	COCSPTransportDefault* self = new (ELeave) COCSPTransportDefault(aIap);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 COCSPTransportDefault::COCSPTransportDefault(TUint32& aIap)
       
    34 	: iIap(aIap)
       
    35 	{
       
    36 	}
       
    37 
       
    38 COCSPTransportDefault::~COCSPTransportDefault()
       
    39 	{
       
    40 	delete iTransport;
       
    41 	}
       
    42 
       
    43 void COCSPTransportDefault::SendRequest(const TDesC8& aURI, 
       
    44 										const TDesC8& aRequest,
       
    45 										const TInt aTimeout,
       
    46 									    TRequestStatus& iStatus)
       
    47 	{
       
    48 	TRAPD(err, CreateTransportL(aURI));
       
    49 	if (err)
       
    50 		{
       
    51 		TRequestStatus* status = &iStatus;
       
    52 		User::RequestComplete(status, err);
       
    53 		}
       
    54 	else
       
    55 		{
       
    56 		iTransport->SendRequest(aURI, aRequest, aTimeout, iStatus);
       
    57 		}
       
    58 	}
       
    59 
       
    60 void COCSPTransportDefault::CancelRequest()
       
    61 	{
       
    62 	if (iTransport)
       
    63 		{
       
    64 		iTransport->CancelRequest();
       
    65 		}
       
    66 	}
       
    67 
       
    68 TPtrC8 COCSPTransportDefault::GetResponse() const
       
    69 	{
       
    70 	ASSERT(iTransport);
       
    71 	return iTransport->GetResponse();
       
    72 	}
       
    73 
       
    74 COCSPTransportDefault::TTransportScheme COCSPTransportDefault::IdentifySchemeL(const TDesC8& aURI)
       
    75 	{
       
    76 	TTransportScheme ret = ETransportSchemeNotSupported;
       
    77 	
       
    78 	TUriParser8 uri;
       
    79 	TInt error = uri.Parse(aURI);
       
    80 	if (error != KErrNone || !uri.IsPresent(EUriScheme))
       
    81 		{
       
    82 		return ret;
       
    83 		}
       
    84 	const TPtrC8 scheme = uri.Extract(EUriScheme);
       
    85 			
       
    86 	RStringPool stringPool;
       
    87 	stringPool.OpenL();
       
    88 	CleanupClosePushL(stringPool);
       
    89 
       
    90 	RStringF schemeF = stringPool.OpenFStringL(scheme);
       
    91 	CleanupClosePushL(schemeF);
       
    92 	RStringF httpF = stringPool.OpenFStringL(KHttpString);
       
    93 	CleanupClosePushL(httpF);
       
    94 
       
    95 	if (schemeF == httpF)
       
    96 		{
       
    97 		ret = ETransportSchemeHTTP;
       
    98 		}
       
    99 
       
   100 	CleanupStack::PopAndDestroy(3); // close httpF, schemeF, stringPool
       
   101 
       
   102 	return ret;
       
   103 	}
       
   104 
       
   105 
       
   106 void COCSPTransportDefault::CreateTransportL(const TDesC8& aURI)
       
   107 	{
       
   108 	TTransportScheme scheme = IdentifySchemeL(aURI);
       
   109 
       
   110 	if (iTransport && iScheme == scheme)
       
   111 		{
       
   112 		return; // reuse existing transport
       
   113 		}
       
   114 
       
   115 	delete iTransport;
       
   116 	iTransport = NULL;
       
   117 	
       
   118 	switch (scheme)
       
   119 		{
       
   120 		case ETransportSchemeHTTP:
       
   121 			iTransport = COCSPTransportHttp::NewL(aURI, iIap);
       
   122 			break;
       
   123 			
       
   124 		default:
       
   125 			User::Leave(OCSP::KErrInvalidURI);
       
   126 			break;
       
   127 		}
       
   128 
       
   129 	iScheme = scheme;
       
   130 	}