Add async api stub implementation 30/27230/12
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 4 Sep 2014 13:50:32 +0000 (15:50 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Fri, 10 Oct 2014 12:43:05 +0000 (14:43 +0200)
Below are listed asynchronous API functions with its value
returned for valid params and enough memory (stub version).
- cynara_async_initialize     CYNARA_API_SUCCESS
- cynara_finish
- cynara_async_cache_check    CYNARA_API_CACHE_MISS
- cynara_async_create_request CYNARA_API_MAX_PENDING_REQUESTS
- cynara_async_process        CYNARA_API_SUCCESS
- cynara_async_cancel_request CYNARA_API_SUCCESS

Change-Id: Ic10d04adc5e7d45fa643a1e817db2670c05790cf

14 files changed:
CMakeLists.txt
packaging/cynara.spec
packaging/libcynara-client-async.manifest [new file with mode: 0644]
pkgconfig/CMakeLists.txt
pkgconfig/cynara-client-async/CMakeLists.txt [new file with mode: 0644]
pkgconfig/cynara-client-async/cynara-client-async.pc.in [new file with mode: 0644]
src/CMakeLists.txt
src/client-async/CMakeLists.txt [new file with mode: 0644]
src/client-async/api/ApiInterface.h [new file with mode: 0644]
src/client-async/api/client-async-api.cpp [new file with mode: 0644]
src/client-async/logic/Logic.cpp [new file with mode: 0644]
src/client-async/logic/Logic.h [new file with mode: 0644]
src/include/CMakeLists.txt
src/include/cynara-client-async.h

index 0623e9a..ba5fe97 100644 (file)
@@ -78,6 +78,7 @@ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
 
 SET(TARGET_CYNARA "cynara")
 SET(TARGET_LIB_CYNARA "cynara-client")
+SET(TARGET_LIB_CYNARA_ASYNC "cynara-client-async")
 SET(TARGET_LIB_CYNARA_COMMON "cynara-client-commons")
 SET(TARGET_LIB_CYNARA_ADMIN "cynara-admin")
 SET(TARGET_CYNARA_COMMON "cynara-commons")
index 4d1c960..7508fbf 100644 (file)
@@ -7,15 +7,16 @@ License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001:    cynara.manifest
 Source1002:    libcynara-client.manifest
-Source1003:    libcynara-admin.manifest
-Source1004:    cynara-tests.manifest
-Source1005:    libcynara-client-commons.manifest
-Source1006:    libcynara-commons.manifest
-Source1007:    libcynara-creds-commons.manifest
-Source1008:    libcynara-creds-dbus.manifest
-Source1009:    libcynara-creds-socket.manifest
-Source1010:    libcynara-session.manifest
-Source1011:    libcynara-storage.manifest
+Source1003:    libcynara-client-async.manifest
+Source1004:    libcynara-admin.manifest
+Source1005:    cynara-tests.manifest
+Source1006:    libcynara-client-commons.manifest
+Source1007:    libcynara-commons.manifest
+Source1008:    libcynara-creds-commons.manifest
+Source1009:    libcynara-creds-dbus.manifest
+Source1010:    libcynara-creds-socket.manifest
+Source1011:    libcynara-session.manifest
+Source1012:    libcynara-storage.manifest
 Requires:      default-ac-domains
 Requires(pre): pwdutils
 Requires(post):   smack
@@ -42,7 +43,7 @@ BuildRequires: pkgconfig(libunwind)
 %endif
 
 %description
-service, client libraries (libcynara-client, libcynara-admin),
+service, client libraries (libcynara-client, libcynara-client-async, libcynara-admin),
 helper libraries (libcynara-session, libcynara-creds-common, libcynara-creds-dbus,
 libcynara-creds-socket)
 and tests (cynara-tests)
@@ -64,6 +65,22 @@ Requires:   libcynara-client-commons-devel = %{version}-%{release}
 client library (devel) for checking policies
 
 #######################################################
+%package -n libcynara-client-async
+Summary:    Cynara - asynchronous client library
+Requires:   cynara = %{version}-%{release}
+
+%description -n libcynara-client-async
+asynchronous client library for checking policies
+
+%package -n libcynara-client-async-devel
+Summary:    Cynara - asynchronous client library (devel)
+Requires:   libcynara-client-async = %{version}-%{release}
+Requires:   libcynara-client-commons-devel = %{version}-%{release}
+
+%description -n libcynara-client-async-devel
+asynchronous client library (devel) for checking policies
+
+#######################################################
 %package -n libcynara-client-commons
 Summary:    Cynara - client commons library
 Requires:   cynara = %{version}-%{release}
@@ -214,6 +231,7 @@ cp -a %{SOURCE1008} .
 cp -a %{SOURCE1009} .
 cp -a %{SOURCE1010} .
 cp -a %{SOURCE1011} .
+cp -a %{SOURCE1012} .
 cp -a test/db/db* .
 
 %build
@@ -290,6 +308,10 @@ fi
 
 %postun -n libcynara-client -p /sbin/ldconfig
 
+%post -n libcynara-client-async -p /sbin/ldconfig
+
+%postun -n libcynara-client-async -p /sbin/ldconfig
+
 %post -n libcynara-client-commons -p /sbin/ldconfig
 
 %postun -n libcynara-client-commons -p /sbin/ldconfig
@@ -314,6 +336,10 @@ fi
 
 %postun -n libcynara-client-devel -p /sbin/ldconfig
 
+%post -n libcynara-client-async-devel -p /sbin/ldconfig
+
+%postun -n libcynara-client-async-devel -p /sbin/ldconfig
+
 %post -n libcynara-client-commons-devel -p /sbin/ldconfig
 
 %postun -n libcynara-client-commons-devel -p /sbin/ldconfig
@@ -380,6 +406,16 @@ fi
 %{_libdir}/pkgconfig/cynara-client.pc
 %{_libdir}/libcynara-client.so
 
+%files -n libcynara-client-async
+%manifest libcynara-client-async.manifest
+%license LICENSE
+%{_libdir}/libcynara-client-async.so.*
+
+%files -n libcynara-client-async-devel
+%{_includedir}/cynara/cynara-client-async.h
+%{_libdir}/pkgconfig/cynara-client-async.pc
+%{_libdir}/libcynara-client-async.so
+
 %files -n libcynara-client-commons
 %manifest libcynara-client-commons.manifest
 %license LICENSE
diff --git a/packaging/libcynara-client-async.manifest b/packaging/libcynara-client-async.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
index 0c11631..9d4600f 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 ADD_SUBDIRECTORY(cynara-client)
+ADD_SUBDIRECTORY(cynara-client-async)
 ADD_SUBDIRECTORY(cynara-admin)
 ADD_SUBDIRECTORY(cynara-creds-commons)
 ADD_SUBDIRECTORY(cynara-creds-dbus)
diff --git a/pkgconfig/cynara-client-async/CMakeLists.txt b/pkgconfig/cynara-client-async/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f827ac4
--- /dev/null
@@ -0,0 +1,25 @@
+# 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        CMakeLists.txt
+# @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+#
+
+CONFIGURE_FILE(cynara-client-async.pc.in cynara-client-async.pc @ONLY)
+
+INSTALL(FILES
+    ${CMAKE_BINARY_DIR}/pkgconfig/cynara-client-async/cynara-client-async.pc
+    DESTINATION
+    ${LIB_INSTALL_DIR}/pkgconfig
+    )
diff --git a/pkgconfig/cynara-client-async/cynara-client-async.pc.in b/pkgconfig/cynara-client-async/cynara-client-async.pc.in
new file mode 100644 (file)
index 0000000..cf38a83
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=@LIB_INSTALL_DIR@
+includedir=${prefix}/include
+
+Name: cynara-client-async
+Description: cynara-client-async package
+Version: @CYNARA_VERSION@
+Requires:
+Libs: -L${libdir} -lcynara-client-async
+Cflags: -I${includedir}/cynara
index 66a1186..fe4d096 100644 (file)
@@ -46,6 +46,7 @@ INCLUDE_DIRECTORIES(
 ADD_SUBDIRECTORY(include)
 ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(client)
+ADD_SUBDIRECTORY(client-async)
 ADD_SUBDIRECTORY(client-common)
 ADD_SUBDIRECTORY(admin)
 ADD_SUBDIRECTORY(storage)
diff --git a/src/client-async/CMakeLists.txt b/src/client-async/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3a4ce35
--- /dev/null
@@ -0,0 +1,49 @@
+# 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        CMakeLists.txt
+# @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+#
+
+SET(LIB_CYNARA_ASYNC_VERSION_MAJOR 0)
+SET(LIB_CYNARA_ASYNC_VERSION ${LIB_CYNARA_ASYNC_VERSION_MAJOR}.0.2)
+
+SET(CYNARA_LIB_CYNARA_ASYNC_PATH ${CYNARA_PATH}/client-async)
+
+INCLUDE_DIRECTORIES(
+    ${CYNARA_LIB_CYNARA_ASYNC_PATH}
+    ${CYNARA_PATH}/client-common
+    ${CYNARA_PATH}/common
+    ${CYNARA_PATH}/include
+    )
+
+SET(LIB_CYNARA_ASYNC_SOURCES
+    ${CYNARA_LIB_CYNARA_ASYNC_PATH}/api/client-async-api.cpp
+    ${CYNARA_LIB_CYNARA_ASYNC_PATH}/logic/Logic.cpp
+    )
+
+ADD_LIBRARY(${TARGET_LIB_CYNARA_ASYNC} SHARED ${LIB_CYNARA_ASYNC_SOURCES})
+
+SET_TARGET_PROPERTIES(
+    ${TARGET_LIB_CYNARA_ASYNC}
+    PROPERTIES
+        SOVERSION ${LIB_CYNARA_ASYNC_VERSION_MAJOR}
+        VERSION ${LIB_CYNARA_ASYNC_VERSION}
+    )
+
+TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA_ASYNC}
+    ${TARGET_CYNARA_COMMON}
+    )
+
+INSTALL(TARGETS ${TARGET_LIB_CYNARA_ASYNC} DESTINATION ${LIB_INSTALL_DIR})
diff --git a/src/client-async/api/ApiInterface.h b/src/client-async/api/ApiInterface.h
new file mode 100644 (file)
index 0000000..31478da
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  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/client-async/api/ApiInterface.h
+ * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version     1.0
+ * @brief       This file contains libcynara-client-async API interface definition.
+ */
+
+#ifndef SRC_CLIENT_ASYNC_API_APIINTERFACE_H_
+#define SRC_CLIENT_ASYNC_API_APIINTERFACE_H_
+
+#include <string>
+
+#include <cynara-client-async.h>
+
+namespace Cynara {
+
+class ApiInterface {
+public:
+    ApiInterface() = default;
+    virtual ~ApiInterface() {};
+
+    virtual int checkCache(const std::string &client, const std::string &session,
+                           const std::string &user, const std::string &privilege) = 0;
+    virtual int createRequest(const std::string &client, const std::string &session,
+                              const std::string &user, const std::string &privilege,
+                              cynara_check_id &checkId, cynara_response_callback callback,
+                              void *userResponseData) = 0;
+    virtual int process(void) = 0;
+    virtual int cancelRequest(cynara_check_id checkId) = 0;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_CLIENT_ASYNC_API_APIINTERFACE_H_ */
diff --git a/src/client-async/api/client-async-api.cpp b/src/client-async/api/client-async-api.cpp
new file mode 100644 (file)
index 0000000..d350e10
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ *  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/client-async/api/client-async-api.cpp
+ * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version     1.0
+ * @brief       Implementation of external libcynara-client-async API
+ */
+
+#include <new>
+
+#include <common.h>
+#include <exceptions/TryCatch.h>
+#include <log/log.h>
+
+#include <api/ApiInterface.h>
+#include <cynara-client-async.h>
+#include <logic/Logic.h>
+
+struct cynara_async {
+    Cynara::ApiInterface *impl;
+
+    cynara_async(Cynara::ApiInterface *_impl) : impl(_impl) {
+    }
+
+    ~cynara_async() {
+        delete impl;
+    }
+};
+
+CYNARA_API
+int cynara_async_initialize(cynara_async **pp_cynara,
+                            const cynara_async_configuration *p_conf UNUSED,
+                            cynara_status_callback callback, void *user_status_data) {
+    if (!pp_cynara)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        *pp_cynara = new cynara_async(new Cynara::Logic(callback, user_status_data));
+
+        init_log();
+
+        LOGD("Cynara client async initialized");
+
+        return CYNARA_API_SUCCESS;
+    });
+}
+
+CYNARA_API
+void cynara_async_finish(cynara_async *p_cynara) {
+    delete p_cynara;
+}
+
+CYNARA_API
+int cynara_async_check_cache(cynara_async *p_cynara, const char *client, const char *client_session,
+                             const char *user, const char *privilege) {
+    if (!p_cynara || !p_cynara->impl)
+        return CYNARA_API_INVALID_PARAM;
+    if (!client || !client_session || !user || !privilege)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        std::string clientStr;
+        std::string clientSessionStr;
+        std::string userStr;
+        std::string privilegeStr;
+
+        try {
+            clientStr = client;
+            clientSessionStr = client_session;
+            userStr = user;
+            privilegeStr = privilege;
+        } catch (const std::length_error &e) {
+            LOGE(e.what());
+            return CYNARA_API_INVALID_PARAM;
+        }
+        return p_cynara->impl->checkCache(clientStr, clientSessionStr, userStr, privilegeStr);
+    });
+}
+
+CYNARA_API
+int cynara_async_create_request(cynara_async *p_cynara, const char *client,
+                                const char *client_session, const char *user, const char *privilege,
+                                cynara_check_id *p_check_id, cynara_response_callback callback,
+                                void *user_response_data) {
+    if (!p_cynara || !p_cynara->impl)
+        return CYNARA_API_INVALID_PARAM;
+    if (!client || !client_session || !user || !privilege)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        std::string clientStr;
+        std::string clientSessionStr;
+        std::string userStr;
+        std::string privilegeStr;
+
+        try {
+            clientStr = client;
+            clientSessionStr = client_session;
+            userStr = user;
+            privilegeStr = privilege;
+        } catch (const std::length_error &e) {
+            LOGE(e.what());
+            return CYNARA_API_INVALID_PARAM;
+        }
+        cynara_check_id checkId;
+        int ret = p_cynara->impl->createRequest(clientStr, clientSessionStr, userStr, privilegeStr,
+                                                checkId, callback, user_response_data);
+        if (p_check_id && ret == CYNARA_API_SUCCESS)
+            *p_check_id = checkId;
+        return ret;
+    });
+}
+
+CYNARA_API
+int cynara_async_process(cynara_async *p_cynara) {
+    if (!p_cynara || !p_cynara->impl)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        return p_cynara->impl->process();
+    });
+}
+
+CYNARA_API
+int cynara_async_cancel_request(cynara_async *p_cynara, cynara_check_id check_id) {
+    if (!p_cynara || !p_cynara->impl)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        return p_cynara->impl->cancelRequest(check_id);
+    });
+}
diff --git a/src/client-async/logic/Logic.cpp b/src/client-async/logic/Logic.cpp
new file mode 100644 (file)
index 0000000..f20a216
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  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/client-async/logic/Logic.cpp
+ * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version     1.0
+ * @brief       This file contains implementation of Logic class - main
+ *              libcynara-client-async class
+ */
+
+#include <common.h>
+
+#include "Logic.h"
+
+namespace Cynara {
+
+Logic::Logic(cynara_status_callback callback UNUSED, void *userStatusData UNUSED) {
+    // MOCKUP
+}
+
+int Logic::checkCache(const std::string &client UNUSED, const std::string &session UNUSED,
+                      const std::string &user UNUSED, const std::string &privilege UNUSED) {
+    // MOCKUP
+    return CYNARA_API_CACHE_MISS;
+}
+
+int Logic::createRequest(const std::string &client UNUSED, const std::string &session UNUSED,
+                         const std::string &user UNUSED, const std::string &privilege UNUSED,
+                         cynara_check_id &checkId UNUSED, cynara_response_callback callback UNUSED,
+                         void *userResponseData UNUSED) {
+    // MOCKUP
+    return CYNARA_API_MAX_PENDING_REQUESTS;
+}
+
+
+int Logic::process(void) {
+    // MOCKUP
+    return CYNARA_API_SUCCESS;
+}
+
+int Logic::cancelRequest(cynara_check_id checkId UNUSED) {
+    // MOCKUP
+    return CYNARA_API_SUCCESS;
+}
+
+} // namespace Cynara
diff --git a/src/client-async/logic/Logic.h b/src/client-async/logic/Logic.h
new file mode 100644 (file)
index 0000000..d245501
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  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/client-async/logic/Logic.h
+ * @author      Marcin Niesluchowski <m.niesluchow@samsung.com>
+ * @version     1.0
+ * @brief       This file contains declaration of Logic class - main
+ *              libcynara-client-async class
+ */
+
+#ifndef SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_
+#define SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_
+
+#include <api/ApiInterface.h>
+#include <cynara-client-async.h>
+
+namespace Cynara {
+
+class Logic : public ApiInterface {
+public:
+    Logic(cynara_status_callback callback, void *userStatusData);
+    virtual ~Logic() {};
+
+    virtual int checkCache(const std::string &client, const std::string &session,
+                           const std::string &user, const std::string &privilege);
+    virtual int createRequest(const std::string &client, const std::string &session,
+                              const std::string &user, const std::string &privilege,
+                              cynara_check_id &checkId, cynara_response_callback callback,
+                              void *userResponseData);
+    virtual int process(void);
+    virtual int cancelRequest(cynara_check_id checkId);
+};
+
+} // namespace Cynara
+
+#endif /* SRC_CLIENT_ASYNC_LOGIC_LOGIC_H_ */
index e4c74a4..1be6e10 100644 (file)
@@ -21,6 +21,7 @@ INSTALL(FILES
     ${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
     ${CYNARA_PATH}/include/cynara-client-error.h
     ${CYNARA_PATH}/include/cynara-creds-commons.h
     ${CYNARA_PATH}/include/cynara-creds-dbus.h
index c824124..1e39d9b 100644 (file)
@@ -27,6 +27,8 @@
 
 #include <stdint.h>
 
+#include <cynara-client-error.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif