Initialize Tizen 2.3
[framework/osp/security-service.git] / src / PrivilegeService.cpp
1 //
2 // Copyright (c) 2012-2013 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                PrivilegeService.cpp
19  * @brief               This is the implementation file for PrivilegeService class.
20  */
21
22 #include <FIo_IpcServer.h>
23 #include <FIo_IIpcServerEventListener.h>
24 #include <FIo_IpcCommonDataTypes.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_PrivilegeManagerServer.h>
27 #include <FSec_PrivilegeManagerMessage.h>
28 #include <FAppPkg_PackageInfoImpl.h>
29
30 #include "PrivilegeService.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
34 using namespace Tizen::App;
35 using namespace Tizen::App::Package;
36 using namespace Tizen::Io;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Security;
39
40 PrivilegeService::PrivilegeService(void)
41         : __pIpcServer(null)
42 {
43
44 }
45
46 PrivilegeService::~PrivilegeService(void)
47 {
48         AppLogTag(OSP_SECURITY_SERVICE, "Entered.");
49
50         __pIpcServer->Stop();
51         delete __pIpcServer;
52
53         AppLogTag(OSP_SECURITY_SERVICE, "Leaved.");
54 }
55
56 result
57 PrivilegeService::Construct(void)
58 {
59         result r = E_SUCCESS;
60
61         AppLogTag(OSP_SECURITY_SERVICE, "Entered.");
62
63         __pIpcServer = new (std::nothrow) _IpcServer();
64         TryReturnResultTag(OSP_SECURITY_SERVICE, __pIpcServer != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
65
66         r = __pIpcServer->Construct("osp.security.ipcserver.privilegemanager", *this, false);
67         TryReturnResultTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
68
69         AppLogTag(OSP_SECURITY_SERVICE, "Leaved.");
70         return r;
71 }
72
73 void
74 PrivilegeService::OnIpcServerStarted(const _IpcServer& server)
75 {
76
77 }
78
79 void
80 PrivilegeService::OnIpcServerStopped(const _IpcServer& server)
81 {
82
83 }
84
85 void
86 PrivilegeService::OnIpcClientConnected(const _IpcServer& server, int clientId)
87 {
88
89 }
90
91 void
92 PrivilegeService::OnIpcClientDisconnected(const _IpcServer&server, int clientId)
93 {
94
95 }
96
97 bool
98 PrivilegeService::RetrievePrivilege(String* pEncryptedBitwise, String* pHmac, ArrayListT < String >* pPrivilegeList, result* pRes)
99 {
100         AppId appId;
101         __pIpcServer->GetClientPackageId().SubString(0, MAX_APP_ID_SIZE, appId);
102
103         *pRes = _PrivilegeManagerServer::RetrievePrivilege(appId, pEncryptedBitwise, pHmac, pPrivilegeList);
104
105         return true;
106 }
107
108 bool
109 PrivilegeService::RetrieveVisibility(String* pEncryptedVisibility, String* pHmac, result* pRes)
110 {
111         AppId appId;
112         __pIpcServer->GetClientPackageId().SubString(0, MAX_APP_ID_SIZE, appId);
113
114         *pRes = _PrivilegeManagerServer::GenerateVisibilityString(appId, pEncryptedVisibility, pHmac);
115
116         return true;
117 }
118
119 void
120 PrivilegeService::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
121 {
122         IPC_BEGIN_MESSAGE_MAP(PrivilegeService, message)
123                                 IPC_MESSAGE_HANDLER_EX(PrivilegeManagerMsg_retrieve, &server, RetrievePrivilege)
124                                 IPC_MESSAGE_HANDLER_EX(PrivilegeManagerMsg_retrieveEx, &server, RetrieveVisibility)
125         IPC_END_MESSAGE_MAP()
126 }
127