From d43e9ed60fc7052e193a4f0207fc04ee3d646432 Mon Sep 17 00:00:00 2001 From: Sebastian Grabowski Date: Mon, 1 Dec 2014 16:26:56 +0100 Subject: [PATCH 1/1] Added security_manager_strerror function. This function translates lib_retcode(s) to a string describing given error that occured in security-manager. Change-Id: Ied57ff8c27a972123b28714ebc25efe143c6d64c Signed-off-by: Sebastian Grabowski --- src/client/client-security-manager.cpp | 21 +++++++++++++++++++++ src/cmd/security-manager-cmd.cpp | 11 ++++++----- src/include/security-manager.h | 8 ++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/client/client-security-manager.cpp b/src/client/client-security-manager.cpp index a4fa36a..1e03d36 100644 --- a/src/client/client-security-manager.cpp +++ b/src/client/client-security-manager.cpp @@ -49,7 +49,28 @@ #include +/** + * Mapping of lib_retcode error codes to theirs strings equivalents + */ +static std::map lib_retcode_string_map = { + {SECURITY_MANAGER_SUCCESS, "Success"}, + {SECURITY_MANAGER_ERROR_UNKNOWN, "Unknown error"}, + {SECURITY_MANAGER_ERROR_INPUT_PARAM, "Invalid function parameter was given"}, + {SECURITY_MANAGER_ERROR_MEMORY, "Memory allocation error"}, + {SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE, "Incomplete data in application request"}, + {SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED, "User does not have sufficient " + "rigths to perform an operation"} +}; +SECURITY_MANAGER_API +const char *security_manager_strerror(enum lib_retcode rc) +{ + try { + return lib_retcode_string_map.at(rc).c_str(); + } catch (const std::out_of_range &e) { + return "Unknown error code"; + } +} SECURITY_MANAGER_API int security_manager_app_inst_req_new(app_inst_req **pp_req) diff --git a/src/cmd/security-manager-cmd.cpp b/src/cmd/security-manager-cmd.cpp index ec7b680..c615d12 100644 --- a/src/cmd/security-manager-cmd.cpp +++ b/src/cmd/security-manager-cmd.cpp @@ -248,11 +248,12 @@ static int installApp(const struct app_inst_req &req) LogDebug("Application " << req.appId << " installed successfully."); } else { - std::cout << "Failed to install " << req.appId << - " application. Return code: " << ret << - std::endl; - LogDebug("Failed to install " << req.appId << - " application. Return code: " << ret); + std::cout << "Failed to install " << req.appId << " application: " << + security_manager_strerror(static_cast(ret)) << + " (" << ret << ")." << std::endl; + LogError("Failed to install " << req.appId << " application: " << + security_manager_strerror(static_cast(ret)) << + " (" << ret << ")." << std::endl); } return ret; } diff --git a/src/include/security-manager.h b/src/include/security-manager.h index c06b2fb..36028c2 100644 --- a/src/include/security-manager.h +++ b/src/include/security-manager.h @@ -60,6 +60,14 @@ enum app_install_path_type { struct app_inst_req; typedef struct app_inst_req app_inst_req; +/** + * This function translates lib_retcode error codes to strings describing + * errors. + * @param[in] rc error code of lib_retcode type + * @return string describing error for error code + */ +const char *security_manager_strerror(enum lib_retcode rc); + /* * This function is responsible for initialize app_inst_req data structure * It uses dynamic allocation inside and user responsibility is to call -- 2.7.4