11#include < atomic>
22#include < exception>
33#include < string.h>
4-
4+ # include < sys/stat.h >
55
66#include " scitokens.h"
77#include " scitokens_internal.h"
88
99/* *
1010 * GLOBALS
1111 */
12+
13+ // Cache timeout config
1214std::atomic_int configurer::Configuration::m_next_update_delta{600 };
1315std::atomic_int configurer::Configuration::m_expiry_delta{4 * 24 * 3600 };
1416
17+ // SciTokens cache home config
18+ std::shared_ptr<std::string> configurer::Configuration::m_cache_home =
19+ std::make_shared<std::string>(" " );
20+
1521SciTokenKey scitoken_key_create (const char *key_id, const char *alg,
1622 const char *public_contents,
1723 const char *private_contents, char **err_msg) {
@@ -950,6 +956,10 @@ int keycache_set_jwks(const char *issuer, const char *jwks, char **err_msg) {
950956}
951957
952958int config_set_int (const char *key, int value, char **err_msg) {
959+ return scitoken_config_set_int (key, value, err_msg);
960+ }
961+
962+ int scitoken_config_set_int (const char *key, int value, char **err_msg) {
953963 if (!key) {
954964 if (err_msg) {
955965 *err_msg = strdup (" A key must be provided." );
@@ -958,7 +968,6 @@ int config_set_int(const char *key, int value, char **err_msg) {
958968 }
959969
960970 std::string _key = key;
961-
962971 if (_key == " keycache.update_interval_s" ) {
963972 if (value < 0 ) {
964973 if (err_msg) {
@@ -970,8 +979,8 @@ int config_set_int(const char *key, int value, char **err_msg) {
970979 return 0 ;
971980 }
972981
973- if (_key == " keycache.expiration_interval_s" ) {
974- if (value < 0 ) {
982+ else if (_key == " keycache.expiration_interval_s" ) {
983+ if (value < 0 ) {
975984 if (err_msg) {
976985 *err_msg = strdup (" Expiry interval must be positive." );
977986 }
@@ -990,6 +999,10 @@ int config_set_int(const char *key, int value, char **err_msg) {
990999}
9911000
9921001int config_get_int (const char *key, char **err_msg) {
1002+ return scitoken_config_get_int (key, err_msg);
1003+ }
1004+
1005+ int scitoken_config_get_int (const char *key, char **err_msg) {
9931006 if (!key) {
9941007 if (err_msg) {
9951008 *err_msg = strdup (" A key must be provided." );
@@ -998,12 +1011,11 @@ int config_get_int(const char *key, char **err_msg) {
9981011 }
9991012
10001013 std::string _key = key;
1001-
10021014 if (_key == " keycache.update_interval_s" ) {
10031015 return configurer::Configuration::get_next_update_delta ();
10041016 }
10051017
1006- if (_key == " keycache.expiration_interval_s" ) {
1018+ else if (_key == " keycache.expiration_interval_s" ) {
10071019 return configurer::Configuration::get_expiry_delta ();
10081020 }
10091021
@@ -1013,4 +1025,55 @@ int config_get_int(const char *key, char **err_msg) {
10131025 }
10141026 return -1 ;
10151027 }
1016- }
1028+ }
1029+
1030+ int scitoken_config_set_str (const char *key, const char *value,
1031+ char **err_msg) {
1032+ if (!key) {
1033+ if (err_msg) {
1034+ *err_msg = strdup (" A key must be provided." );
1035+ }
1036+ return -1 ;
1037+ }
1038+
1039+ std::string _key = key;
1040+ if (_key == " keycache.cache_home" ) {
1041+ auto rp = configurer::Configuration::set_cache_home (value);
1042+ if (!rp.first ) { // There was an error, pass rp.second to err_msg
1043+ if (err_msg) {
1044+ *err_msg = strdup (rp.second .c_str ());
1045+ }
1046+ return -1 ;
1047+ }
1048+ }
1049+
1050+ else {
1051+ if (err_msg) {
1052+ *err_msg = strdup (" Key not recognized." );
1053+ }
1054+ return -1 ;
1055+ }
1056+ return 0 ;
1057+ }
1058+
1059+ int scitoken_config_get_str (const char *key, char **output, char **err_msg) {
1060+ if (!key) {
1061+ if (err_msg) {
1062+ *err_msg = strdup (" A key must be provided." );
1063+ }
1064+ return -1 ;
1065+ }
1066+
1067+ std::string _key = key;
1068+ if (_key == " keycache.cache_home" ) {
1069+ *output = strdup (configurer::Configuration::get_cache_home ().c_str ());
1070+ }
1071+
1072+ else {
1073+ if (err_msg) {
1074+ *err_msg = strdup (" Key not recognized." );
1075+ }
1076+ return -1 ;
1077+ }
1078+ return 0 ;
1079+ }
0 commit comments