Skip to content

Commit 3486868

Browse files
committed
Add duplicate config APIs with prefixed names
Unfortunately, the choice of names for the config_set_blah() family of APIs is quite generic and poses the potential to cause C symbol collisions when SciTokens is used by large projects that dynamically load lots of libraries (a la HTCondor). A reasonable plan to address this, since those APIs are in use and changing their names would be API-breaking, seems to be adding a second set of prefixed APIs, with the intention of deprecating the old functions at the next major release.
1 parent c12e0c2 commit 3486868

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

src/scitokens.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,45 @@ int config_set_int(const char *key, int value, char **err_msg) {
994994
}
995995
}
996996

997+
int scitokens_config_set_int(const char *key, int value, char **err_msg) {
998+
if (!key) {
999+
if (err_msg) {
1000+
*err_msg = strdup("A key must be provided.");
1001+
}
1002+
return -1;
1003+
}
1004+
1005+
std::string _key = key;
1006+
if (_key == "keycache.update_interval_s") {
1007+
if (value < 0) {
1008+
if (err_msg) {
1009+
*err_msg = strdup("Update interval must be positive.");
1010+
}
1011+
return -1;
1012+
}
1013+
configurer::Configuration::set_next_update_delta(value);
1014+
return 0;
1015+
}
1016+
1017+
else if (_key == "keycache.expiration_interval_s") {
1018+
if (value < 0) {
1019+
if (err_msg) {
1020+
*err_msg = strdup("Expiry interval must be positive.");
1021+
}
1022+
return -1;
1023+
}
1024+
configurer::Configuration::set_expiry_delta(value);
1025+
return 0;
1026+
}
1027+
1028+
else {
1029+
if (err_msg) {
1030+
*err_msg = strdup("Key not recognized.");
1031+
}
1032+
return -1;
1033+
}
1034+
}
1035+
9971036
int config_get_int(const char *key, char **err_msg) {
9981037
if (!key) {
9991038
if (err_msg) {
@@ -1019,6 +1058,31 @@ int config_get_int(const char *key, char **err_msg) {
10191058
}
10201059
}
10211060

1061+
int scitokens_config_get_int(const char *key, char **err_msg) {
1062+
if (!key) {
1063+
if (err_msg) {
1064+
*err_msg = strdup("A key must be provided.");
1065+
}
1066+
return -1;
1067+
}
1068+
1069+
std::string _key = key;
1070+
if (_key == "keycache.update_interval_s") {
1071+
return configurer::Configuration::get_next_update_delta();
1072+
}
1073+
1074+
else if (_key == "keycache.expiration_interval_s") {
1075+
return configurer::Configuration::get_expiry_delta();
1076+
}
1077+
1078+
else {
1079+
if (err_msg) {
1080+
*err_msg = strdup("Key not recognized.");
1081+
}
1082+
return -1;
1083+
}
1084+
}
1085+
10221086
int config_set_str(const char *key, const char *value, char **err_msg) {
10231087
if (!key) {
10241088
if (err_msg) {
@@ -1047,6 +1111,34 @@ int config_set_str(const char *key, const char *value, char **err_msg) {
10471111
return 0;
10481112
}
10491113

1114+
int scitokens_config_set_str(const char *key, const char *value, char **err_msg) {
1115+
if (!key) {
1116+
if (err_msg) {
1117+
*err_msg = strdup("A key must be provided.");
1118+
}
1119+
return -1;
1120+
}
1121+
1122+
std::string _key = key;
1123+
if (_key == "keycache.cache_home") {
1124+
auto rp = configurer::Configuration::set_cache_home(value);
1125+
if (!rp.first) { // There was an error, pass rp.second to err_msg
1126+
if (err_msg) {
1127+
*err_msg = strdup(rp.second.c_str());
1128+
}
1129+
return -1;
1130+
}
1131+
}
1132+
1133+
else {
1134+
if (err_msg) {
1135+
*err_msg = strdup("Key not recognized.");
1136+
}
1137+
return -1;
1138+
}
1139+
return 0;
1140+
}
1141+
10501142
int config_get_str(const char *key, char **output, char **err_msg) {
10511143
if (!key) {
10521144
if (err_msg) {
@@ -1068,3 +1160,25 @@ int config_get_str(const char *key, char **output, char **err_msg) {
10681160
}
10691161
return 0;
10701162
}
1163+
1164+
int scitokens_config_get_str(const char *key, char **output, char **err_msg) {
1165+
if (!key) {
1166+
if (err_msg) {
1167+
*err_msg = strdup("A key must be provided.");
1168+
}
1169+
return -1;
1170+
}
1171+
1172+
std::string _key = key;
1173+
if (_key == "keycache.cache_home") {
1174+
*output = strdup(configurer::Configuration::get_cache_home().c_str());
1175+
}
1176+
1177+
else {
1178+
if (err_msg) {
1179+
*err_msg = strdup("Key not recognized.");
1180+
}
1181+
return -1;
1182+
}
1183+
return 0;
1184+
}

src/scitokens.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ int keycache_set_jwks(const char *issuer, const char *jwks, char **err_msg);
302302
*/
303303
int config_set_int(const char *key, int value, char **err_msg);
304304

305+
// Prefixed version of the same API to avoid potential symbol collisions
306+
int scitokens_config_set_int(const char *key, int value, char **err_msg);
307+
305308
/**
306309
* Get current scitokens int parameters.
307310
* Returns the value associated with the supplied input key on success, and -1
@@ -310,19 +313,28 @@ int config_set_int(const char *key, int value, char **err_msg);
310313
*/
311314
int config_get_int(const char *key, char **err_msg);
312315

316+
// Prefixed version of the same API to avoid potential symbol collisions
317+
int scitokens_config_get_int(const char *key, char **err_msg);
318+
313319
/**
314320
* Set current scitokens str parameters.
315321
* Returns 0 on success, nonzero on failure
316322
*/
317323
int config_set_str(const char *key, const char *value, char **err_msg);
318324

325+
// Prefixed version of the same API to avoid potential symbol collisions
326+
int scitokens_config_set_str(const char *key, const char *value, char **err_msg);
327+
319328
/**
320329
* Get current scitokens str parameters.
321330
* Returns 0 on success, nonzero on failure, and populates the value associated
322331
* with the input key to output.
323332
*/
324333
int config_get_str(const char *key, char **output, char **err_msg);
325334

335+
// Prefixed version of the same API to avoid potential symbol collisions
336+
int scitokens_config_get_str(const char *key, char **output, char **err_msg);
337+
326338
#ifdef __cplusplus
327339
}
328340
#endif

0 commit comments

Comments
 (0)