|
1 // Copyright (c) 2005-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 // A transport that logs the ocsp requests made to a file and then calls another |
|
15 // transport to send the request. |
|
16 // |
|
17 // |
|
18 |
|
19 #include "requestlogger.h" |
|
20 |
|
21 #include <f32file.h> |
|
22 |
|
23 CTOCSPRequestLogger* CTOCSPRequestLogger::NewL(const TDesC& aRequestFile, MOCSPTransport* aTransport) |
|
24 { |
|
25 CTOCSPRequestLogger* self = new (ELeave) CTOCSPRequestLogger; |
|
26 CleanupStack::PushL(self); |
|
27 self->ConstructL(aRequestFile, aTransport); |
|
28 CleanupStack::Pop(self); |
|
29 return self; |
|
30 } |
|
31 |
|
32 |
|
33 CTOCSPRequestLogger::CTOCSPRequestLogger() |
|
34 { |
|
35 } |
|
36 |
|
37 |
|
38 void CTOCSPRequestLogger::ConstructL(const TDesC& aRequestFile, MOCSPTransport* aTransport) |
|
39 { |
|
40 User::LeaveIfError(iFs.Connect()); |
|
41 |
|
42 TInt err = iFs.MkDirAll(aRequestFile); |
|
43 if (err != KErrAlreadyExists) |
|
44 { |
|
45 User::LeaveIfError(err); |
|
46 } |
|
47 |
|
48 User::LeaveIfError(iWriteStream.Replace(iFs, aRequestFile, EFileWrite | EFileShareExclusive)); |
|
49 |
|
50 // Initially we write a request count of zero, this gets updates as each |
|
51 // request is logged |
|
52 iWriteStream.WriteUint32L(0); |
|
53 |
|
54 iTransport = aTransport; |
|
55 } |
|
56 |
|
57 |
|
58 CTOCSPRequestLogger::~CTOCSPRequestLogger() |
|
59 { |
|
60 iWriteStream.Close(); |
|
61 iFs.Close(); |
|
62 delete iTransport; |
|
63 } |
|
64 |
|
65 |
|
66 void CTOCSPRequestLogger::SendRequest(const TDesC8& aURI, |
|
67 const TDesC8& aRequest, |
|
68 const TInt aTimeout, |
|
69 TRequestStatus& aStatus) |
|
70 { |
|
71 TRAPD(err, LogRequestL(aURI, aRequest)); |
|
72 |
|
73 if (err == KErrNone) |
|
74 { |
|
75 iTransport->SendRequest(aURI, aRequest, aTimeout, aStatus); |
|
76 } |
|
77 else |
|
78 { |
|
79 TRequestStatus* status = &aStatus; |
|
80 User::RequestComplete(status, err); |
|
81 } |
|
82 } |
|
83 |
|
84 void CTOCSPRequestLogger::LogRequestL(const TDesC8& aURI, |
|
85 const TDesC8& aRequest) |
|
86 { |
|
87 ++iTotalRequests; |
|
88 |
|
89 MStreamBuf* sink = iWriteStream.Sink(); |
|
90 |
|
91 sink->SeekL(MStreamBuf::EWrite, EStreamBeginning, 0); |
|
92 iWriteStream.WriteUint32L(iTotalRequests); |
|
93 |
|
94 sink->SeekL(MStreamBuf::EWrite, EStreamEnd, 0); |
|
95 iWriteStream.WriteUint32L(aURI.Length()); |
|
96 iWriteStream.WriteL(aURI); |
|
97 iWriteStream.WriteUint32L(aRequest.Length()); |
|
98 iWriteStream.WriteL(aRequest); |
|
99 |
|
100 iWriteStream.CommitL(); |
|
101 } |
|
102 |
|
103 |
|
104 void CTOCSPRequestLogger::CancelRequest() |
|
105 { |
|
106 iTransport->CancelRequest(); |
|
107 } |
|
108 |
|
109 |
|
110 TPtrC8 CTOCSPRequestLogger::GetResponse() const |
|
111 { |
|
112 return iTransport->GetResponse(); |
|
113 } |