|
1 /* |
|
2 * Copyright (c) 2007-2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "metadatafilehandler.h" |
|
20 #include <f32file.h> |
|
21 |
|
22 namespace java |
|
23 { |
|
24 namespace security |
|
25 { |
|
26 |
|
27 bool JavaCertStoreMetadataFileHandler::writeState(std::string aFilePath, int aState) |
|
28 { |
|
29 int len = aFilePath.size(); |
|
30 HBufC* filePath = HBufC::NewL(len); |
|
31 CleanupStack::PushL(filePath); |
|
32 TPtr ptr = filePath->Des(); |
|
33 TPtr8 ptr8((unsigned char *)aFilePath.c_str(),len); |
|
34 ptr8.SetLength(len); |
|
35 ptr.Copy(ptr8); |
|
36 RFs rFs; |
|
37 RFile stateFile; |
|
38 bool res = false; |
|
39 int err = rFs.Connect(); |
|
40 if (err == KErrNone) |
|
41 { |
|
42 err = stateFile.Open(rFs, ptr, EFileWrite); |
|
43 if (err == KErrNotFound) |
|
44 { |
|
45 err = stateFile.Create(rFs, ptr, EFileWrite); |
|
46 } |
|
47 if (err == KErrNone) |
|
48 { |
|
49 CleanupClosePushL(stateFile); |
|
50 TPckgBuf<TUint32> state(aState); |
|
51 stateFile.Write(0, state); |
|
52 CleanupStack::PopAndDestroy(); // state file |
|
53 res = true; |
|
54 } |
|
55 } |
|
56 CleanupStack::PopAndDestroy(); // file path |
|
57 return res; |
|
58 } |
|
59 |
|
60 int JavaCertStoreMetadataFileHandler::readState(std::string aFilePath) |
|
61 { |
|
62 int state = STATE_UNDEFINED; |
|
63 int len = aFilePath.size(); |
|
64 HBufC* filePath = HBufC::NewL(len); |
|
65 CleanupStack::PushL(filePath); |
|
66 TPtr ptr = filePath->Des(); |
|
67 TPtr8 ptr8((unsigned char *)aFilePath.c_str(),len); |
|
68 ptr8.SetLength(len); |
|
69 ptr.Copy(ptr8); |
|
70 RFs rFs; |
|
71 RFile stateFile; |
|
72 int err = rFs.Connect(); |
|
73 if (err == KErrNone) |
|
74 { |
|
75 err = stateFile.Open(rFs, ptr, EFileRead); |
|
76 if (err == KErrNone) |
|
77 { |
|
78 CleanupClosePushL(stateFile); |
|
79 TPckgBuf<TUint32> tmp; |
|
80 err = stateFile.Read(0, tmp); |
|
81 CleanupStack::PopAndDestroy(); // state file |
|
82 if (err == KErrNone) |
|
83 { |
|
84 state = tmp(); |
|
85 } |
|
86 } |
|
87 } |
|
88 CleanupStack::PopAndDestroy(); // file path |
|
89 return state; |
|
90 } |
|
91 |
|
92 } //end namespace security |
|
93 } //end namespace java |