Adjust libcynara-admin error codes 93/28793/2
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 16 Oct 2014 08:04:15 +0000 (10:04 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 16 Oct 2014 09:08:30 +0000 (11:08 +0200)
Cynara integrates error codes in all libraries.
Release 0.4.0 uses new unified error codes.
Old error codes are removed.

This patch changes old error codes into new ones.
Please do not merge this patch until 0.4.0 is released
or patch "35771f4 Use client error codes in admin libraries"
in cynara repository is merged.

Change-Id: I354bd4a4c3a9adea9308efb8ed6f9025d26f92f1

src/server/service/cynara.cpp

index 6db3e9e..9ca8efc 100644 (file)
@@ -103,16 +103,19 @@ CynaraAdminPolicy::~CynaraAdminPolicy()
     free(this->result_extra);
 }
 
-static void checkCynaraAdminError(int result, const std::string &msg)
+static bool checkCynaraError(int result, const std::string &msg)
 {
     switch (result) {
-        case CYNARA_ADMIN_API_SUCCESS:
-            return;
-        case CYNARA_ADMIN_API_OUT_OF_MEMORY:
+        case CYNARA_API_SUCCESS:
+        case CYNARA_API_ACCESS_ALLOWED:
+            return true;
+        case CYNARA_API_ACCESS_DENIED:
+            return false;
+        case CYNARA_API_OUT_OF_MEMORY:
             ThrowMsg(CynaraException::OutOfMemory, msg);
-        case CYNARA_ADMIN_API_INVALID_PARAM:
+        case CYNARA_API_INVALID_PARAM:
             ThrowMsg(CynaraException::InvalidParam, msg);
-        case CYNARA_ADMIN_API_SERVICE_NOT_AVAILABLE:
+        case CYNARA_API_SERVICE_NOT_AVAILABLE:
             ThrowMsg(CynaraException::ServiceNotAvailable, msg);
         default:
             ThrowMsg(CynaraException::UnknownError, msg);
@@ -121,7 +124,7 @@ static void checkCynaraAdminError(int result, const std::string &msg)
 
 CynaraAdmin::CynaraAdmin()
 {
-    checkCynaraAdminError(
+    checkCynaraError(
         cynara_admin_initialize(&m_CynaraAdmin),
         "Cannot connect to Cynara administrative interface.");
 }
@@ -149,7 +152,7 @@ void CynaraAdmin::SetPolicies(const std::vector<CynaraAdminPolicy> &policies)
 
     pp_policies[policies.size()] = nullptr;
 
-    checkCynaraAdminError(
+    checkCynaraError(
         cynara_admin_set_policies(m_CynaraAdmin, pp_policies.data()),
         "Error while updating Cynara policy.");
 }
@@ -208,26 +211,6 @@ void CynaraAdmin::UpdatePackagePolicy(
     cynaraAdmin.SetPolicies(policies);
 }
 
-static bool checkCynaraError(int result, const std::string &msg)
-{
-    // TODO: Cynara client error codes are being currently refactored
-    // This function must be updated when the refactor is finished.
-    switch (result) {
-        case CYNARA_API_SUCCESS:
-            return true;
-        case CYNARA_API_ACCESS_DENIED:
-            return false;
-        case CYNARA_API_OUT_OF_MEMORY:
-            ThrowMsg(CynaraException::OutOfMemory, msg);
-        case CYNARA_API_INVALID_PARAM:
-            ThrowMsg(CynaraException::InvalidParam, msg);
-        case CYNARA_API_SERVICE_NOT_AVAILABLE:
-            ThrowMsg(CynaraException::ServiceNotAvailable, msg);
-        default:
-            ThrowMsg(CynaraException::UnknownError, msg);
-    }
-}
-
 Cynara::Cynara()
 {
     checkCynaraError(