%package -n libcynara-admin-devel
Summary: Cynara - admin client library (devel)
Requires: libcynara-admin = %{version}-%{release}
+Requires: libcynara-commons-devel = %{version}-%{release}
%description -n libcynara-admin-devel
admin client library (devel) for setting, listing and removing policies
%files -n libcynara-admin-devel
%{_includedir}/cynara/cynara-admin.h
-%{_includedir}/cynara/cynara-admin-error.h
%{_includedir}/cynara/cynara-admin-types.h
%{_libdir}/libcynara-admin.so
%{_libdir}/pkgconfig/cynara-admin.pc
#include <types/PolicyType.h>
#include <cynara-admin.h>
-#include <cynara-admin-error.h>
+#include <cynara-client-error.h>
#include <api/ApiInterface.h>
#include <logic/Logic.h>
CYNARA_API
int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) {
if (!pp_cynara_admin)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
try {
*pp_cynara_admin = new cynara_admin(new Cynara::Logic);
} catch (const std::bad_alloc &ex) {
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
}
init_log();
LOGD("Cynara admin initialized");
- return CYNARA_ADMIN_API_SUCCESS;
+ return CYNARA_API_SUCCESS;
}
CYNARA_API
int cynara_admin_finish(struct cynara_admin *p_cynara_admin) {
delete p_cynara_admin;
- return CYNARA_ADMIN_API_SUCCESS;
+ return CYNARA_API_SUCCESS;
}
CYNARA_API
int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin,
const struct cynara_admin_policy *const *policies) {
if (!p_cynara_admin || !p_cynara_admin->impl)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
if (!policies)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
std::map<Cynara::PolicyBucketId, std::vector<Cynara::Policy>> insertOrUpdate;
std::map<Cynara::PolicyBucketId, std::vector<Cynara::PolicyKey>> remove;
for (auto i = policies; *i; i++) {
const cynara_admin_policy *policy = *i;
if(!policy->bucket || !policy->client || !policy->user || !policy->privilege)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
switch (policy->result) {
case CYNARA_ADMIN_DELETE:
break;
case CYNARA_ADMIN_BUCKET:
if (!policy->result_extra)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
insertOrUpdate[policy->bucket].push_back(Cynara::Policy(key(policy),
Cynara::PolicyResult(
Cynara::PredefinedPolicyType::BUCKET,
break;
case CYNARA_ADMIN_NONE:
default:
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
}
}
} catch (const std::bad_alloc &ex) {
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
}
return p_cynara_admin->impl->setPolicies(insertOrUpdate, remove);
int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *bucket,
int operation, const char *extra) {
if (!p_cynara_admin || !p_cynara_admin->impl)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
if (!bucket)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
std::string extraStr;
try {
extraStr = extra ? extra : "";
} catch (const std::bad_alloc &ex) {
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
}
switch (operation) {
case CYNARA_ADMIN_DELETE:
return p_cynara_admin->impl->insertOrUpdateBucket(bucket,
Cynara::PolicyResult(Cynara::PredefinedPolicyType::NONE));
}
- return CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED;
+ return CYNARA_API_OPERATION_NOT_ALLOWED;
case CYNARA_ADMIN_BUCKET:
default:
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
}
}
const char *client, const char *user, const char *privilege,
int *result, char **result_extra) {
if (!p_cynara_admin || !p_cynara_admin->impl)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
if (!start_bucket)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
if (!client || !user || !privilege)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
if (!result || !result_extra)
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
Cynara::PolicyResult policyResult;
int ret = p_cynara_admin->impl->adminCheck(start_bucket, recursive != 0,
Cynara::PolicyKey(client, user, privilege),
policyResult);
- if (ret != CYNARA_ADMIN_API_SUCCESS)
+ if (ret != CYNARA_API_SUCCESS)
return ret;
} catch (const std::bad_alloc &ex) {
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
} catch (const std::length_error &ex) {
- return CYNARA_ADMIN_API_INVALID_PARAM;
+ return CYNARA_API_INVALID_PARAM;
}
char *str = nullptr;
if (!policyResult.metadata().empty()) {
str = strdup(policyResult.metadata().c_str());
if (!str)
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
}
*result = static_cast<int>(policyResult.policyType());
*result_extra = str;
- return CYNARA_ADMIN_API_SUCCESS;
+ return CYNARA_API_SUCCESS;
}
#include <cinttypes>
#include <memory>
-#include <cynara-admin-error.h>
+#include <cynara-client-error.h>
#include <common.h>
#include <exceptions/Exception.h>
#include <exceptions/UnexpectedErrorException.h>
try {
if (!ensureConnection()) {
LOGE("Cannot connect to cynara. Service not available.");
- return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE;
+ return CYNARA_API_SERVICE_NOT_AVAILABLE;
}
ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber();
ResponsePtr response;
while (!(response = m_socketClient->askCynaraServer(request))) {
if (!m_socketClient->connect())
- return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE;
+ return CYNARA_API_SERVICE_NOT_AVAILABLE;
}
codeResponse = std::dynamic_pointer_cast<CodeResponse>(response);
if (!codeResponse) {
LOGC("Critical error. Casting Response to CodeResponse failed.");
- return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR;
+ return CYNARA_API_UNKNOWN_ERROR;
}
LOGD("codeResponse: code [%" PRIu16 "]", codeResponse->m_code);
switch (codeResponse->m_code) {
case CodeResponse::Code::OK:
LOGI("Policies set successfully.");
- return CYNARA_ADMIN_API_SUCCESS;
+ return CYNARA_API_SUCCESS;
case CodeResponse::Code::NOT_ALLOWED:
LOGE("Cynara service answered: Operation not allowed.");
- return CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED;
+ return CYNARA_API_OPERATION_NOT_ALLOWED;
case CodeResponse::Code::NO_BUCKET:
LOGE("Trying to use unexisting bucket.");
- return CYNARA_ADMIN_API_BUCKET_NOT_FOUND;
+ return CYNARA_API_BUCKET_NOT_FOUND;
default:
LOGE("Unexpected response code from server: [%d]",
static_cast<int>(codeResponse->m_code));
- return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR;
+ return CYNARA_API_UNKNOWN_ERROR;
}
} catch (const std::bad_alloc &ex) {
LOGE("Cynara admin client out of memory.");
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
} catch (const std::exception &ex) {
LOGE("Unexpected client error: <%s>", ex.what());
- return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR;
+ return CYNARA_API_UNKNOWN_ERROR;
}
}
try {
if (!ensureConnection()) {
LOGE("Cannot connect to cynara. Service not available.");
- return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE;
+ return CYNARA_API_SERVICE_NOT_AVAILABLE;
}
ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber();
ResponsePtr response;
while (!(response = m_socketClient->askCynaraServer(request))) {
if (!m_socketClient->connect())
- return CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE;
+ return CYNARA_API_SERVICE_NOT_AVAILABLE;
}
checkResponse = std::dynamic_pointer_cast<CheckResponse>(response);
if (!checkResponse) {
LOGC("Casting Response to CheckResponse failed.");
- return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR;
+ return CYNARA_API_UNKNOWN_ERROR;
}
LOGD("checkResponse: policyType [%" PRIu16 "], metadata <%s>",
checkResponse->m_resultRef.metadata().c_str());
result = checkResponse->m_resultRef;
- return CYNARA_ADMIN_API_SUCCESS;
+ return CYNARA_API_SUCCESS;
} catch (const UnexpectedErrorException &ex) {
LOGE(ex.what());
- return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR;
+ return CYNARA_API_UNKNOWN_ERROR;
} catch (const std::bad_alloc &ex) {
LOGE("Cynara admin client out of memory.");
- return CYNARA_ADMIN_API_OUT_OF_MEMORY;
+ return CYNARA_API_OUT_OF_MEMORY;
} catch (const std::exception &ex) {
LOGE("Unexpected client error: <%s>", ex.what());
- return CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR;
+ return CYNARA_API_UNKNOWN_ERROR;
}
}
INSTALL(FILES
${CYNARA_PATH}/include/cynara-admin.h
- ${CYNARA_PATH}/include/cynara-admin-error.h
${CYNARA_PATH}/include/cynara-admin-types.h
${CYNARA_PATH}/include/cynara-client.h
${CYNARA_PATH}/include/cynara-client-async.h
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-/**
- * @file src/include/cynara-admin-error.h
- * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
- * @author Zofia Abramowska <z.abramowska@samsung.com>
- * @version 1.0
- * @brief This file contains error codes of administration APIs of Cynara.
- */
-
-#ifndef CYNARA_ADMIN_ERROR_H
-#define CYNARA_ADMIN_ERROR_H
-
-/**
- * \name Return Codes
- * exported by the foundation API.
- * result codes begin with the start error code and extend into negative direction.
- * @{
-*/
-
-/*! \brief indicating the result of the one specific API is successful or access is allowed */
-#define CYNARA_ADMIN_API_SUCCESS 0
-
-/*! \brief indicating client process is running out of memory */
-#define CYNARA_ADMIN_API_OUT_OF_MEMORY -1
-
-/*! \brief indicating the API's parameter is malformed */
-#define CYNARA_ADMIN_API_INVALID_PARAM -2
-
-/*! \brief service not available (cannot connect to cynara service) */
-#define CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE -3
-
-/*! \brief unexpected error in client library */
-#define CYNARA_ADMIN_API_UNEXPECTED_CLIENT_ERROR -4
-
-/*! \brief cynara service does not allow to perform requested operation */
-#define CYNARA_ADMIN_API_OPERATION_NOT_ALLOWED -5
-
-/*! \brief cynara service hasn't found requested bucket */
-#define CYNARA_ADMIN_API_BUCKET_NOT_FOUND -6
-/** @}*/
-
-#endif // CYNARA_ADMIN_ERROR_H
#ifndef CYNARA_ADMIN_H
#define CYNARA_ADMIN_H
-#include <cynara-admin-error.h>
#include <cynara-admin-types.h>
+#include <cynara-client-error.h>
#ifdef __cplusplus
extern "C" {
*
* \param[out] pp_cynara_admin address of pointer for created cynara_admin structure.
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or error code otherwise.
*
* \brief Initialize cynara-admin library.
*/
*
* \param[in] p_cynara_admin cynara_admin structure created in cynara_admin_initialize.
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or error code otherwise.
*
* \brief Release cynara-admin library.
*/
* \param[in] p_cynara_admin cynara admin structure.
* \param[in] policies NULL terminated array of pointers to policy structures.
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or error code otherwise.
*
* \brief Insert, update or delete policies in cynara database.
*/
* \param[in] operation type of operation (default policy or CYNARA_ADMIN_DELETE)
* \param[in] extra additional data for default policy (will be available with cynara extensions)
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or error code otherwise.
*
* \brief Add, remove or update buckets in cynara database.
*/
* \param[out] result placeholder for matched policy type.
* \param[out] result_extra placeholder for matched policy additional data (see Important Notes!).
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or error code otherwise.
*
* \brief Raw check client and user access for given privilege without using plugins extensions.
*/
/*! \brief indicating that provided method is not supported by library */
#define CYNARA_API_METHOD_NOT_SUPPORTED -6
+/*! \brief cynara service does not allow to perform requested operation */
+#define CYNARA_API_OPERATION_NOT_ALLOWED -7
+
+/*! \brief cynara service hasn't found requested bucket */
+#define CYNARA_API_BUCKET_NOT_FOUND -8
+
/*! \brief indicating an unknown error */
-#define CYNARA_API_UNKNOWN_ERROR -7
+#define CYNARA_API_UNKNOWN_ERROR -9
/** @}*/
#ifndef CYNARA_OFFLINE_ADMIN_H
#define CYNARA_OFFLINE_ADMIN_H
-#include <cynara-admin-error.h>
#include <cynara-admin-types.h>
+#include <cynara-client-error.h>
#ifdef __cplusplus
extern "C" {
* \param[out] pp_cynara_offline_admin address of pointer for created cynara_offline_admin
* structure.
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or negative error code otherwise.
*
* \brief Initialize cynara-offline-admin library.
*/
* \param[in] p_cynara_offline_admin cynara_offline_admin structure created
* in cynara_offline_admin_initialize.
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or negative error code otherwise.
*
* \brief Release cynara-offline-admin library.
*/
* \param[in] p_cynara_offline_admin cynara offline admin structure.
* \param[in] policies NULL terminated array of pointers to policy structures.
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or negative error code otherwise.
*
* \brief Insert, update or delete policies in cynara database.
*/
* \param[in] operation type of operation (default policy or CYNARA_ADMIN_DELETE)
* \param[in] extra additional data for default policy (will be available with cynara extensions)
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or negative error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or negative error code otherwise.
*
* \brief Add, remove or update buckets in cynara database.
*/
* \param[out] result placeholder for matched policy type
* \param[out] result_extra placeholder for matched policy additional data (see Important Notes!)
*
- * \return CYNARA_ADMIN_API_SUCCESS on success, or error code otherwise.
+ * \return CYNARA_API_SUCCESS on success, or error code otherwise.
*
* \brief Raw check client, user access for given privilege without using plugins extensions.
*/