2 * Copyright (c) 2014 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 src/client/api/client-api.cpp
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
20 * @brief Implementation of external libcynara-client API
27 #include <exceptions/TryCatch.h>
30 #include <cynara-client.h>
31 #include <cynara-client-error.h>
32 #include <api/ApiInterface.h>
33 #include <logic/Logic.h>
36 Cynara::ApiInterface *impl;
38 cynara(Cynara::ApiInterface *_impl) : impl(_impl) {
46 int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNUSED)
49 return CYNARA_API_INVALID_PARAM;
51 return Cynara::tryCatch([&]() {
52 *pp_cynara = new cynara(new Cynara::Logic);
56 LOGD("Cynara client initialized");
58 return CYNARA_API_SUCCESS;
63 int cynara_finish(cynara *p_cynara)
67 return CYNARA_API_SUCCESS;
71 int cynara_check(cynara *p_cynara, const char *client, const char *client_session, const char *user,
72 const char *privilege)
74 if(!p_cynara || !p_cynara->impl)
75 return CYNARA_API_INVALID_PARAM;
76 if(!client || !client_session || !user || !privilege)
77 return CYNARA_API_INVALID_PARAM;
79 return Cynara::tryCatch([&]() {
80 std::string clientStr;
81 std::string clientSessionStr;
83 std::string privilegeStr;
87 clientSessionStr = client_session;
89 privilegeStr = privilege;
90 } catch (const std::length_error &e) {
92 return CYNARA_API_INVALID_PARAM;
94 return p_cynara->impl->check(clientStr, clientSessionStr, userStr, privilegeStr);