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 #include "security_daemon_dbus_config.h"
29 #include "ace_api_popup_validation.h"
32 static WrtSecurity::Communication::Client *communicationClient = NULL;
33 static const int VALIDITY_ONCE_VALUE = 0;
34 static const int VALIDITY_SESSION_VALUE = 1;
35 static const int VALIDITY_ALWAYS_VALUE = 1;
38 ace_return_t ace_popup_validation_initialize(void)
40 if (NULL != communicationClient) {
41 LogError("ace_api_popup_validation already initialized");
42 return ACE_INTERNAL_ERROR;
45 communicationClient = new WrtSecurity::Communication::Client(
46 WrtSecurity::PopupServerApi::INTERFACE_NAME());
47 } Catch (WrtSecurity::Communication::Client::Exception::SecurityCommunicationClientException) {
48 LogError("Can't connect to daemon");
49 return ACE_INTERNAL_ERROR;
55 ace_return_t ace_popup_validation_shutdown(void)
57 if (NULL == communicationClient) {
58 LogError("ace_api_popup_validation not initialized");
59 return ACE_INTERNAL_ERROR;
61 delete communicationClient;
62 communicationClient = NULL;
67 ace_return_t ace_validate_answer(ace_bool_t answer,
68 ace_validity_t validity,
69 const ace_resource_t resource_name,
70 const ace_session_id_t session_id,
71 const ace_param_list_t* param_list,
72 ace_widget_handle_t handle,
73 ace_bool_t* validation_result)
75 if (NULL == resource_name ||
78 NULL == validation_result)
80 LogError("NULL argument(s) passed");
81 return ACE_INVALID_ARGUMENTS;
84 bool dbusAnswer = answer == ACE_TRUE;
89 dbusValidity = VALIDITY_ONCE_VALUE;
90 //static_cast<int>(Prompt::Validity::ONCE);
93 dbusValidity = VALIDITY_SESSION_VALUE;
94 //static_cast<int>(Prompt::Validity::SESSION);
97 dbusValidity = VALIDITY_ALWAYS_VALUE;
98 //static_cast<int>(Prompt::Validity::ALWAYS);
101 LogError("Invalid validity passed");
102 return ACE_INVALID_ARGUMENTS; }
105 std::string subjectId;
106 std::string resourceId(resource_name);
107 std::string sessionId(session_id);
108 std::vector<std::string> keys, values;
110 for (i = 0; i < param_list->count; ++i) {
111 keys.push_back(std::string(param_list->items[i].name));
112 values.push_back(std::string(param_list->items[i].value));
115 bool response = false;
117 communicationClient->call(WrtSecurity::PopupServerApi::VALIDATION_METHOD(),
127 } Catch (WrtSecurity::Communication::Client::Exception::SecurityCommunicationClientException) {
128 LogError("Can't call daemon");
129 return ACE_INTERNAL_ERROR;
132 *validation_result = response ? ACE_TRUE : ACE_FALSE;