From 581fb9cd470e99442f5138d37aaccc022419708f Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Thu, 3 Jul 2014 18:45:54 +0200 Subject: [PATCH] Add stub implementation of libcynara-admin API functions Prepare Logic and ApiInterface classes skeletons. Remove old empty admin-api.cpp file. Change-Id: I498e0e904dbd9dea3a07eaaa998a30fce21cb4e5 --- src/admin/CMakeLists.txt | 9 ++++- src/admin/admin-api.cpp | 23 ----------- src/admin/api/ApiInterface.h | 40 +++++++++++++++++++ src/admin/api/admin-api.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++++ src/admin/logic/Logic.cpp | 40 +++++++++++++++++++ src/admin/logic/Logic.h | 45 +++++++++++++++++++++ 6 files changed, 225 insertions(+), 25 deletions(-) delete mode 100644 src/admin/admin-api.cpp create mode 100644 src/admin/api/ApiInterface.h create mode 100644 src/admin/api/admin-api.cpp create mode 100644 src/admin/logic/Logic.cpp create mode 100644 src/admin/logic/Logic.h diff --git a/src/admin/CMakeLists.txt b/src/admin/CMakeLists.txt index f78af24..bbf0ebc 100644 --- a/src/admin/CMakeLists.txt +++ b/src/admin/CMakeLists.txt @@ -17,12 +17,17 @@ # SET(LIB_CYNARA_ADMIN_VERSION_MAJOR 0) -SET(LIB_CYNARA_ADMIN_VERSION ${LIB_CYNARA_ADMIN_VERSION_MAJOR}.0.1) +SET(LIB_CYNARA_ADMIN_VERSION ${LIB_CYNARA_ADMIN_VERSION_MAJOR}.0.2) SET(CYNARA_LIB_CYNARA_ADMIN_PATH ${CYNARA_PATH}/admin) SET(LIB_CYNARA_ADMIN_SOURCES - ${CYNARA_LIB_CYNARA_ADMIN_PATH}/admin-api.cpp + ${CYNARA_LIB_CYNARA_ADMIN_PATH}/api/admin-api.cpp + ${CYNARA_LIB_CYNARA_ADMIN_PATH}/logic/Logic.cpp + ) + +INCLUDE_DIRECTORIES( + ${CYNARA_LIB_CYNARA_ADMIN_PATH} ) ADD_LIBRARY(${TARGET_LIB_CYNARA_ADMIN} SHARED ${LIB_CYNARA_ADMIN_SOURCES}) diff --git a/src/admin/admin-api.cpp b/src/admin/admin-api.cpp deleted file mode 100644 index 30b187c..0000000 --- a/src/admin/admin-api.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -* 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 admin-api.cpp -* @author Lukasz Wojciechowski -* @version 1.0 -* @brief Implementation of external libcynara-admin API -*/ - -// empty file for init cynara commit diff --git a/src/admin/api/ApiInterface.h b/src/admin/api/ApiInterface.h new file mode 100644 index 0000000..5a9acbc --- /dev/null +++ b/src/admin/api/ApiInterface.h @@ -0,0 +1,40 @@ +/* + * 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 ApiInterface.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains libcynara-admin API interface definition. + */ + +#ifndef SRC_ADMIN_API_APIINTERFACE_H_ +#define SRC_ADMIN_API_APIINTERFACE_H_ + +#include + +#include + +namespace Cynara { + +class ApiInterface { +public: + ApiInterface() = default; + virtual ~ApiInterface() = default; +}; + +} // namespace Cynara + +#endif /* SRC_ADMIN_API_APIINTERFACE_H_ */ diff --git a/src/admin/api/admin-api.cpp b/src/admin/api/admin-api.cpp new file mode 100644 index 0000000..0809232 --- /dev/null +++ b/src/admin/api/admin-api.cpp @@ -0,0 +1,93 @@ +/* + * 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 admin-api.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief Implementation of external libcynara-admin API + */ + +#include + +#include +#include + +#include +#include + +struct cynara_admin { + Cynara::ApiInterface *impl; + + cynara_admin(Cynara::ApiInterface *_impl) : impl(_impl) { + } + ~cynara_admin() { + delete impl; + } +}; + +CYNARA_API +int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) { + if (!pp_cynara_admin) + return CYNARA_ADMIN_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_ADMIN_API_SUCCESS; +} + +CYNARA_API +int cynara_admin_finish(struct cynara_admin *p_cynara_admin) { + delete p_cynara_admin; + + return CYNARA_ADMIN_API_SUCCESS; +} + +CYNARA_API +int cynara_admin_set_policies(struct cynara_admin *p_cynara_admin, + const cynara_admin_policy *const *policies) { + if (!p_cynara_admin || !p_cynara_admin->impl) + return CYNARA_ADMIN_API_INVALID_PARAM; + if (!policies) + return CYNARA_ADMIN_API_INVALID_PARAM; + + //todo This is a stub. Parameters should be passed to p_cynara_admin->impl + return CYNARA_ADMIN_API_SUCCESS; +} + +CYNARA_API +int cynara_admin_set_bucket(struct cynara_admin *p_cynara_admin, const char *bucket, + int operation, const char *extra UNUSED) { + if (!p_cynara_admin || !p_cynara_admin->impl) + return CYNARA_ADMIN_API_INVALID_PARAM; + if (!bucket) + return CYNARA_ADMIN_API_INVALID_PARAM; + switch (operation) { + case CYNARA_ADMIN_DELETE: + //todo This is a stub. Parameters should be passed to p_cynara_admin->impl + return CYNARA_ADMIN_API_SUCCESS; + case CYNARA_ADMIN_DENY: + case CYNARA_ADMIN_ALLOW: + //todo This is a stub. Parameters should be passed to p_cynara_admin->impl + return CYNARA_ADMIN_API_SUCCESS; + case CYNARA_ADMIN_BUCKET: + default: + return CYNARA_ADMIN_API_INVALID_PARAM; + } +} diff --git a/src/admin/logic/Logic.cpp b/src/admin/logic/Logic.cpp new file mode 100644 index 0000000..25b7e5e --- /dev/null +++ b/src/admin/logic/Logic.cpp @@ -0,0 +1,40 @@ +/* + * 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 Logic.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains implementation of Logic class - main libcynara-admin class + */ + +#include + +#include +#include +#include + +#include "Logic.h" + +namespace Cynara { + +const std::string adminSocketPath("/run/cynara/cynara-admin.socket"); + +Logic::Logic() { + m_socketClient = std::make_shared(adminSocketPath, + std::make_shared()); +} + +} // namespace Cynara diff --git a/src/admin/logic/Logic.h b/src/admin/logic/Logic.h new file mode 100644 index 0000000..ac3dba2 --- /dev/null +++ b/src/admin/logic/Logic.h @@ -0,0 +1,45 @@ +/* + * 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 Logic.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file contains definition of Logic class - main libcynara-admin class + */ + +#ifndef SRC_ADMIN_LOGIC_LOGIC_H_ +#define SRC_ADMIN_LOGIC_LOGIC_H_ + +#include + +#include + +#include + +namespace Cynara { + +class Logic : public ApiInterface { +private: + SocketClientPtr m_socketClient; + +public: + Logic(); + virtual ~Logic() = default; +}; + +} // namespace Cynara + +#endif /* SRC_ADMIN_LOGIC_LOGIC_H_ */ -- 2.7.4