Fixing communication problem with security-server
[platform/core/security/security-manager.git] / ace_client / src / ace_api_client.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        ace_api_client.cpp
18  * @author      Tomasz Swierczek (t.swierczek@samsung.com)
19  * @version     1.0
20  * @brief       This file contains implementation of ACE client API
21  */
22
23 #include <dpl/log/log.h>
24 #include <ace_popup_handler.h>
25 #include "ace_api_client.h"
26 #include "ace-client/ace_client.h"
27
28 #include <string>
29 #include <vector>
30 #include <dpl/dbus/dbus_client.h>
31 #include "popup_response_server_api.h"
32 #include "security_daemon_dbus_config.h"
33 //#include "PromptModel.h"
34
35 ace_return_t ace_client_initialize(ace_popup_handler_func_t handler)
36 {
37     if (!AceClient::AceThinClientSingleton::Instance().isInitialized()) {
38         return ACE_INTERNAL_ERROR;
39     }
40     popup_func = handler;
41     // Changed order of checks to make API run with old popup implementation
42     // instead of always needing the popup handler to be implemented.
43     if (NULL == handler) {
44         LogError("NULL argument(s) passed");
45         return ACE_INVALID_ARGUMENTS;
46     }
47     return ACE_OK;
48 }
49
50 ace_return_t ace_client_shutdown(void)
51 {
52     popup_func = NULL;
53     return ACE_OK;
54 }
55
56 ace_return_t ace_check_access(const ace_request_t* request, ace_bool_t* access)
57 {
58     if (NULL == request || NULL == access) {
59         LogError("NULL argument(s) passed");
60         return ACE_INVALID_ARGUMENTS;
61     }
62
63     AceClient::AceRequest aceRequest;
64     aceRequest.sessionId = request->session_id;
65     aceRequest.widgetHandle = request->widget_handle;
66
67     aceRequest.apiFeatures.count = request->feature_list.count;
68     aceRequest.apiFeatures.apiFeature =
69             const_cast<const char**>(request->feature_list.items);
70     aceRequest.functionName = NULL; // TODO will  be removed
71     aceRequest.deviceCapabilities.devcapsCount = request->dev_cap_list.count;
72     aceRequest.deviceCapabilities.paramsCount = request->dev_cap_list.count;
73
74     char** devCapNames = new char*[request->dev_cap_list.count];
75     AceClient::AceParamList* paramList =
76             new AceClient::AceParamList[request->dev_cap_list.count];
77
78     unsigned int i;
79     for (i = 0; i < request->dev_cap_list.count; ++i) {
80         devCapNames[i] = request->dev_cap_list.items[i].name;
81         paramList[i].count = request->dev_cap_list.items[i].param_list.count;
82
83         paramList[i].param = new AceClient::AceParam[
84                                request->dev_cap_list.items[i].param_list.count];
85
86         unsigned int j;
87         for (j = 0; j < request->dev_cap_list.items[i].param_list.count; ++j) {
88             paramList[i].param[j].name =
89                     request->dev_cap_list.items[i].param_list.items[j].name;
90             paramList[i].param[j].value =
91                     request->dev_cap_list.items[i].param_list.items[j].value;
92
93         }
94     }
95
96     aceRequest.deviceCapabilities.devCapNames =
97             const_cast<const char**>(devCapNames);
98     aceRequest.deviceCapabilities.params = paramList;
99
100     bool ret = false;
101
102     Try {
103         ret = AceClient::AceThinClientSingleton::
104                 Instance().checkFunctionCall(aceRequest);
105         *access = ret ? ACE_TRUE : ACE_FALSE;
106     } Catch (AceClient::AceThinClient::Exception::AceThinClientException) {
107         LogError("Ace client exception");
108         delete [] devCapNames;
109         for (i = 0; i < request->dev_cap_list.count; ++i) {
110             delete [] paramList[i].param;
111         }
112         delete [] paramList;
113         return ACE_INTERNAL_ERROR;
114     }
115
116     delete [] devCapNames;
117     for (i = 0; i < request->dev_cap_list.count; ++i) {
118         delete [] paramList[i].param;
119     }
120     delete [] paramList;
121     return ACE_OK;
122 }