/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 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.
* @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
* @author Radoslaw Bartosiak <r.bartosiak@samsung.com>
* @author Aleksander Zdyb <a.zdyb@samsung.com>
+ * @author Jacek Bukarewicz <j.bukarewicz@samsung.com>
* @version 1.0
* @brief Implementation of external libcynara-creds-commons API
*/
CYNARA_API
int cynara_creds_get_default_client_method(enum cynara_client_creds *method) {
- return Cynara::tryCatch([&] () {
- int methodCode, ret;
- static const Cynara::CredentialsMap clientCredsMap{{"smack", CLIENT_METHOD_SMACK},
- {"pid", CLIENT_METHOD_PID}};
+ static int cachedMethodCode = -1;
+ static const Cynara::CredentialsMap clientCredsMap{{"smack", CLIENT_METHOD_SMACK},
+ {"pid", CLIENT_METHOD_PID}};
- if ((ret = Cynara::CredsCommonsInnerBackend::
- getMethodFromConfigurationFile(clientCredsMap,
- "client_default",
- methodCode))
- != CYNARA_API_SUCCESS)
+ if (cachedMethodCode == -1) {
+ int ret = Cynara::tryCatch([&] () {
+ return Cynara::CredsCommonsInnerBackend::
+ getMethodFromConfigurationFile(clientCredsMap, "client_default",
+ cachedMethodCode);
+ });
+ if (ret != CYNARA_API_SUCCESS)
return ret;
+ }
+ *method = static_cast<enum cynara_client_creds>(cachedMethodCode);
+ return CYNARA_API_SUCCESS;
- *method = static_cast<enum cynara_client_creds>(methodCode);
- return CYNARA_API_SUCCESS;
- });
}
CYNARA_API
int cynara_creds_get_default_user_method(enum cynara_user_creds *method) {
- return Cynara::tryCatch([&] () {
- int methodCode, ret;
- static const Cynara::CredentialsMap userCredsMap{{"uid", USER_METHOD_UID},
- {"gid", USER_METHOD_GID}};
- if ((ret = Cynara::CredsCommonsInnerBackend::
- getMethodFromConfigurationFile(userCredsMap,
- "user_default",
- methodCode))
- != CYNARA_API_SUCCESS)
+ static int cachedMethodCode = -1;
+ static const Cynara::CredentialsMap userCredsMap{{"uid", USER_METHOD_UID},
+ {"gid", USER_METHOD_GID}};
+
+ if (cachedMethodCode == -1) {
+ int ret = Cynara::tryCatch([&] () {
+ return Cynara::CredsCommonsInnerBackend::
+ getMethodFromConfigurationFile(userCredsMap,
+ "user_default",
+ cachedMethodCode);
+ });
+ if (ret != CYNARA_API_SUCCESS)
return ret;
+ }
- *method = static_cast<enum cynara_user_creds>(methodCode);
- return CYNARA_API_SUCCESS;
- });
+ *method = static_cast<enum cynara_user_creds>(cachedMethodCode);
+ return CYNARA_API_SUCCESS;
}
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2015 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.
* value of method parameter.
*
* \par Method of function operation:
- * The function will read and return the value of parameter client_default set
- * in /etc/cynara/creds.conf file (the path is determined by CYNARA_CONFIGURATION_DIR).
+ * When this function is called for the first time it reads and returns the value of client_default
+ * parameter from /etc/cynara/creds.conf file (the path is determined by CYNARA_CONFIGURATION_DIR).
+ * Returned value is cached so subsequent calls will not consult file again but use cached value.
+ * This also means that after the initial call any changes in the file will be ignored for the
+ * remaining lifetime of the process.
*
* \par Sync (or) Async:
* This is a synchronous API.
* value of method parameter.
*
* \par Method of function operation:
- * The function will read and return the value of parameter user_default set
- * in /etc/cynara/creds.conf file (the path is determined by CYNARA_CONFIGURATION_DIR).
+ * When this function is called for the first time it reads and returns the value of user_default
+ * parameter from /etc/cynara/creds.conf file (the path is determined by CYNARA_CONFIGURATION_DIR).
+ * Returned value is cached so subsequent calls will not consult file again but use cached value.
+ * This also means that after the initial call any changes in the file will be ignored for the
+ * remaining lifetime of the process.
*
* \par Sync (or) Async:
* This is a synchronous API.