2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file ace_api_popup_validation.cpp
18 * @author Tomasz Swierczek (t.swierczek@samsung.com)
20 * @brief This file contains implementation of ACE popup validation API.
25 #include <dpl/log/log.h>
26 #include "SecurityCommunicationClient.h"
27 #include "popup_response_server_api.h"
28 #ifdef DBUS_CONNECTION
29 #include "security_daemon_dbus_config.h"
31 #include "ace_api_popup_validation.h"
34 static WrtSecurity::Communication::Client *communicationClient = NULL;
35 static const int VALIDITY_ONCE_VALUE = 0;
36 static const int VALIDITY_SESSION_VALUE = 1;
37 static const int VALIDITY_ALWAYS_VALUE = 1;
40 ace_return_t ace_popup_validation_initialize(void)
42 if (NULL != communicationClient) {
43 LogError("ace_api_popup_validation already initialized");
44 return ACE_INTERNAL_ERROR;
47 communicationClient = new WrtSecurity::Communication::Client(
48 WrtSecurity::PopupServerApi::INTERFACE_NAME());
49 } Catch (WrtSecurity::Communication::Client::Exception::SecurityCommunicationClientException) {
50 LogError("Can't connect to daemon");
51 return ACE_INTERNAL_ERROR;
57 ace_return_t ace_popup_validation_shutdown(void)
59 if (NULL == communicationClient) {
60 LogError("ace_api_popup_validation not initialized");
61 return ACE_INTERNAL_ERROR;
63 delete communicationClient;
64 communicationClient = NULL;
69 ace_return_t ace_validate_answer(ace_bool_t answer,
70 ace_validity_t validity,
71 const ace_resource_t resource_name,
72 const ace_session_id_t session_id,
73 const ace_param_list_t* param_list,
74 ace_widget_handle_t handle,
75 ace_bool_t* validation_result)
77 if (NULL == resource_name ||
80 NULL == validation_result)
82 LogError("NULL argument(s) passed");
83 return ACE_INVALID_ARGUMENTS;
86 bool dbusAnswer = answer == ACE_TRUE;
91 dbusValidity = VALIDITY_ONCE_VALUE;
92 //static_cast<int>(Prompt::Validity::ONCE);
95 dbusValidity = VALIDITY_SESSION_VALUE;
96 //static_cast<int>(Prompt::Validity::SESSION);
99 dbusValidity = VALIDITY_ALWAYS_VALUE;
100 //static_cast<int>(Prompt::Validity::ALWAYS);
103 LogError("Invalid validity passed");
104 return ACE_INVALID_ARGUMENTS; }
107 std::string subjectId;
108 std::string resourceId(resource_name);
109 std::string sessionId(session_id);
110 std::vector<std::string> keys, values;
112 for (i = 0; i < param_list->count; ++i) {
113 keys.push_back(std::string(param_list->items[i].name));
114 values.push_back(std::string(param_list->items[i].value));
117 bool response = false;
119 communicationClient->call(WrtSecurity::PopupServerApi::VALIDATION_METHOD(),
129 } Catch (WrtSecurity::Communication::Client::Exception::SecurityCommunicationClientException) {
130 LogError("Can't call daemon");
131 return ACE_INTERNAL_ERROR;
134 *validation_result = response ? ACE_TRUE : ACE_FALSE;