Update secure logs in FIO
[platform/framework/native/appfw.git] / src / io / FIo_NormalRegistry.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FIo_NormalRegistry.cpp
19  * @brief       This is the implementation file for _NormalRegistry class.
20  */
21
22 #include <unistd.h>
23 #include <new>
24
25 #include <FBaseInteger.h>
26 #include <FBaseDouble.h>
27 #include <FBaseFloat.h>
28 #include <FBaseUuId.h>
29 #include <FBaseByteBuffer.h>
30 #include <FBaseColIEnumerator.h>
31 #include <FBaseUtilStringTokenizer.h>
32 #include <FBaseResult.h>
33 #include <FBaseSysLog.h>
34 #include <FIoFile.h>
35 #include <FIoRegistry.h>
36
37 #include <FBase_StringConverter.h>
38 #include <FIo_FileImpl.h>
39 #include <FIo_NormalRegistry.h>
40 #include <FIo_SecureIoUtil.h>
41
42 using namespace Tizen::Base;
43
44 namespace Tizen { namespace Io
45 {
46
47 _NormalRegistry::_NormalRegistry(void)
48 {
49 }
50
51 _NormalRegistry::~_NormalRegistry(void)
52 {
53         if (_write == true && _FileImpl::IsFileExist(_regPath) == true && _update == true)
54         {
55                 this->Flush();
56         }
57
58         _sectionList.RemoveAll(true);
59
60         delete[] _pBuffer; //clear existing buffer
61         _pBuffer = null;
62         _length = 0;
63 }
64
65 result
66 _NormalRegistry::Construct(const String& regPath, const char* pOpenMode)
67 {
68         SysAssertf(_constructed == false, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
69
70         bool isValidOpenMode = this->VerifyRegistryOpenMode(pOpenMode);
71         SysTryReturnResult(NID_IO, isValidOpenMode == true, E_INVALID_ARG, "The specified openMode is invalid. (%s)", pOpenMode);
72
73         result r = this->Load(regPath, pOpenMode);
74         SysSecureTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to load the registry file (%ls).",
75                         GetErrorMessage(r), regPath.GetPointer());
76
77         if (_pBuffer && _length >= SECURE_REG_HEADER_SIZE_V1)
78         {
79                 r = _SecureIoUtil::CheckSecureRegistryHeader(&_pBuffer, &_length, regPath, false);
80                 SysTryReturnResult(NID_IO, !IsFailed(r), E_INVALID_ARG, "Can not open the secure file in normal mode.");
81         }
82
83         r = this->Parse();
84         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to parse the registry file (%ls).",
85                         GetErrorMessage(r), regPath.GetPointer());
86
87         _constructed = true;
88         _regPath.Clear();
89         _regPath.Append(regPath);
90
91         return r;
92 }
93
94 result
95 _NormalRegistry::Flush(void)
96 {
97         result r = this->PrepareToWrite();
98         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to prepare to write.", GetErrorMessage(r));
99
100         r = this->Write();
101         SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to write registry file.", GetErrorMessage(r));
102
103         return r;
104 }
105
106 }} // Tizen::Io
107