2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bartlomiej Grzelewski <b.grzelewski@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @file client-app-permissions.cpp
20 * @author Pawel Polawski (pawel.polawski@partner.samsung.com)
22 * @brief This file contains implementation of
23 * security_server_app_has_privilege function
27 #include <dpl/log/log.h>
28 #include <dpl/exception.h>
30 #include <message-buffer.h>
31 #include <client-common.h>
32 #include <protocols.h>
34 #include <privilege-control.h>
35 #include <security-server.h>
38 int security_server_app_has_privilege(const char *app_label,
40 const char *privilege_name,
43 using namespace SecurityServer;
44 MessageBuffer send, recv;
46 LogDebug("security_server_app_has_privilege() called");
49 if ((NULL == app_label) || (strlen(app_label) == 0)) {
50 LogError("app_id is NULL or empty");
51 return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
53 if ((NULL == privilege_name) || (strlen(privilege_name) == 0)) {
54 LogError("privilege_name is NULL or empty");
55 return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
58 LogError("result is NULL");
59 return SECURITY_SERVER_API_ERROR_INPUT_PARAM;
62 LogDebug("app_label: " << app_label);
63 LogDebug("app_type: " << static_cast<int>(app_type));
64 LogDebug("privilege_name: " << privilege_name);
66 //put data into buffer
67 Serialization::Serialize(send, static_cast<int>(PrivilegeCheckHdrs::CHECK_GIVEN_APP));
68 Serialization::Serialize(send, std::string(app_label));
69 Serialization::Serialize(send, static_cast<int>(app_type));
70 Serialization::Serialize(send, std::string(privilege_name));
72 //send buffer to server
73 int apiResult = sendToServer(SERVICE_SOCKET_APP_PRIVILEGE_BY_NAME, send.Pop(), recv);
74 if (apiResult != SECURITY_SERVER_API_SUCCESS) {
75 LogError("Error in sendToServer. Error code: " << apiResult);
79 //receive response from server
80 Deserialization::Deserialize(recv, apiResult);
81 if (apiResult == SECURITY_SERVER_API_SUCCESS) {
82 Deserialization::Deserialize(recv, *result);
86 } catch (MessageBuffer::Exception::Base &e) {
87 LogError("SecurityServer::MessageBuffer::Exception " << e.DumpToString());
88 } catch (std::exception &e) {
89 LogError("STD exception " << e.what());
91 LogError("Unknown exception occured");
94 return SECURITY_SERVER_API_ERROR_UNKNOWN;