Add stub implementation of libcynara-admin API functions 45/23845/3
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 3 Jul 2014 16:45:54 +0000 (18:45 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Mon, 7 Jul 2014 07:04:46 +0000 (09:04 +0200)
Prepare Logic and ApiInterface classes skeletons.
Remove old empty admin-api.cpp file.

Change-Id: I498e0e904dbd9dea3a07eaaa998a30fce21cb4e5

src/admin/CMakeLists.txt
src/admin/admin-api.cpp [deleted file]
src/admin/api/ApiInterface.h [new file with mode: 0644]
src/admin/api/admin-api.cpp [new file with mode: 0644]
src/admin/logic/Logic.cpp [new file with mode: 0644]
src/admin/logic/Logic.h [new file with mode: 0644]

index f78af24..bbf0ebc 100644 (file)
 #
 
 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 (file)
index 30b187c..0000000
+++ /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 <l.wojciechow@partner.samsung.com>
-* @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 (file)
index 0000000..5a9acbc
--- /dev/null
@@ -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 <l.wojciechow@partner.samsung.com>
+ * @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 <string>
+
+#include <cynara-admin.h>
+
+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 (file)
index 0000000..0809232
--- /dev/null
@@ -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 <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Implementation of external libcynara-admin API
+ */
+
+#include <new>
+
+#include <common.h>
+#include <cynara-admin.h>
+
+#include <api/ApiInterface.h>
+#include <logic/Logic.h>
+
+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 (file)
index 0000000..25b7e5e
--- /dev/null
@@ -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 <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains implementation of Logic class - main libcynara-admin class
+ */
+
+#include <memory>
+
+#include <protocol/Protocol.h>
+#include <protocol/ProtocolAdmin.h>
+#include <sockets/SocketClient.h>
+
+#include "Logic.h"
+
+namespace Cynara {
+
+const std::string adminSocketPath("/run/cynara/cynara-admin.socket");
+
+Logic::Logic() {
+    m_socketClient = std::make_shared<SocketClient>(adminSocketPath,
+                                                    std::make_shared<ProtocolAdmin>());
+}
+
+} // namespace Cynara
diff --git a/src/admin/logic/Logic.h b/src/admin/logic/Logic.h
new file mode 100644 (file)
index 0000000..ac3dba2
--- /dev/null
@@ -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 <l.wojciechow@partner.samsung.com>
+ * @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 <string>
+
+#include <sockets/SocketClient.h>
+
+#include <api/ApiInterface.h>
+
+namespace Cynara {
+
+class Logic : public ApiInterface {
+private:
+    SocketClientPtr m_socketClient;
+
+public:
+    Logic();
+    virtual ~Logic() = default;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_ADMIN_LOGIC_LOGIC_H_ */