1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #include <klib/namelist.h>
28 #include <klib/printf.h>
29 #include <klib/strings.h> /* KFG_USER_ACCEPT_GCP_CHARGES etc */
30 #include <klib/rc.h>
31 #include <klib/text.h>
32 #include <klib/vector.h>
33
34 #include <kfs/directory.h>
35 #include <kfs/file.h>
36
37 #include <kfg/config.h>
38 #include <kfg/repository.h>
39 #include <kfg/ngc.h>
40 #include "ngc-priv.h"
41
42 #include <va_copy.h>
43
44 /* ---------------------------------------------------------------------------------------------------- */
45
KConfig_Get_Repository_State(const KConfig * self,bool * state,bool negate,bool dflt,const char * path,...)46 static rc_t KConfig_Get_Repository_State( const KConfig *self,
47 bool * state, bool negate, bool dflt, const char * path, ... )
48 {
49 rc_t rc = 0;
50 if ( self == NULL )
51 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
52 else if ( state == NULL || path == NULL )
53 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
54 else {
55 va_list args;
56 char tmp[ 4096 ];
57 size_t num_writ;
58
59 *state = dflt;
60 va_start ( args, path );
61 rc = string_vprintf ( tmp, sizeof tmp, & num_writ, path, args );
62 va_end ( args );
63
64 if ( rc == 0 )
65 {
66 bool rd_state;
67 rc = KConfigReadBool ( self, tmp, &rd_state );
68 if ( rc == 0 )
69 {
70 if ( negate )
71 *state = !rd_state;
72 else
73 *state = rd_state;
74 }
75 else
76 rc = 0; /* it is OK to not find the node, return the default then... */
77 }
78 }
79 return rc;
80 }
81
82
KConfig_Set_Repository_State(KConfig * self,bool state,bool negate,const char * path,...)83 static rc_t KConfig_Set_Repository_State( KConfig *self,
84 bool state, bool negate, const char * path, ... )
85 {
86 rc_t rc = 0;
87 if ( self == NULL )
88 rc = RC ( rcKFG, rcNode, rcWriting, rcSelf, rcNull );
89 else if ( path == NULL )
90 rc = RC ( rcKFG, rcNode, rcWriting, rcParam, rcNull );
91 else
92 {
93 va_list args;
94 char tmp[ 4096 ];
95 size_t num_writ;
96
97 va_start ( args, path );
98 rc = string_vprintf ( tmp, sizeof tmp, & num_writ, path, args );
99 va_end ( args );
100
101 if ( rc == 0 )
102 {
103 if ( negate )
104 rc = KConfigWriteBool( self, tmp, !state );
105 else
106 rc = KConfigWriteBool( self, tmp, state );
107 }
108 }
109 return rc;
110 }
111
112
113 /* ---------------------------------------------------------------------------------------------------- */
114
KConfig_Get_Repository_String(const KConfig * self,char * buffer,size_t buffer_size,size_t * written,const char * path,...)115 static rc_t KConfig_Get_Repository_String( const KConfig *self,
116 char * buffer, size_t buffer_size, size_t * written, const char * path, ... )
117 {
118 rc_t rc = 0;
119 if ( self == NULL )
120 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
121 else if ( buffer == NULL || path == NULL )
122 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
123 {
124 va_list args;
125 char tmp[ 4096 ];
126 size_t num_writ;
127
128 va_start ( args, path );
129 rc = string_vprintf ( tmp, sizeof tmp, & num_writ, path, args );
130 va_end ( args );
131
132 if ( rc == 0 )
133 {
134 struct String * res;
135 rc = KConfigReadString ( self, tmp, &res );
136 if ( rc == 0 )
137 {
138 rc = string_printf( buffer, buffer_size, written, "%S", res );
139 StringWhack ( res );
140 }
141 else
142 {
143 * buffer = 0;
144 if ( written != NULL )
145 {
146 * written = 0;
147 }
148 }
149 }
150 }
151 return rc;
152 }
153
154
KConfig_Set_Repository_String(KConfig * self,const char * value,const char * path,...)155 static rc_t KConfig_Set_Repository_String( KConfig *self,
156 const char * value, const char * path, ... )
157 {
158 rc_t rc = 0;
159 if ( self == NULL )
160 rc = RC ( rcKFG, rcNode, rcWriting, rcSelf, rcNull );
161 else if ( path == NULL )
162 rc = RC ( rcKFG, rcNode, rcWriting, rcParam, rcNull );
163 else
164 {
165 va_list args;
166 char tmp[ 4096 ];
167 size_t num_writ;
168
169 va_start ( args, path );
170 rc = string_vprintf ( tmp, sizeof tmp, & num_writ, path, args );
171 va_end ( args );
172
173 if ( rc == 0 )
174 rc = KConfigWriteString( self, tmp, value );
175 }
176 return rc;
177 }
178
179 /* -------------------------------------------------------------------------- */
180
181 /* get/set HTTP proxy path */
KConfig_Get_Http_Proxy_Path(const KConfig * self,char * buffer,size_t buffer_size,size_t * written)182 LIB_EXPORT rc_t CC KConfig_Get_Http_Proxy_Path( const KConfig *self,
183 char *buffer, size_t buffer_size, size_t *written )
184 {
185 return KConfig_Get_Repository_String
186 (self, buffer, buffer_size, written, "http/proxy/path");
187 }
188
KConfig_Set_Http_Proxy_Path(KConfig * self,const char * value)189 LIB_EXPORT rc_t CC KConfig_Set_Http_Proxy_Path
190 ( KConfig *self, const char *value )
191 {
192 return KConfig_Set_Repository_String(self, value, "http/proxy/path");
193 }
194
195 /* get/set enabled-state for HTTP proxy */
KConfig_Get_Http_Proxy_Enabled(const KConfig * self,bool * enabled,bool dflt)196 LIB_EXPORT rc_t CC KConfig_Get_Http_Proxy_Enabled
197 ( const KConfig *self, bool *enabled, bool dflt )
198 {
199 rc_t rc = 0;
200
201 if ( self == NULL ) {
202 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
203 }
204 else if ( enabled == NULL ) {
205 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
206 }
207 else {
208 *enabled = dflt;
209 KConfigReadBool ( self, "http/proxy/enabled", enabled );
210 /* errors are ignored - then default value is returned */
211 }
212
213 return rc;
214 }
215
KConfig_Set_Http_Proxy_Enabled(KConfig * self,bool enabled)216 LIB_EXPORT rc_t CC KConfig_Set_Http_Proxy_Enabled
217 ( KConfig *self, bool enabled )
218 {
219 rc_t rc = 0;
220
221 if ( self == NULL ) {
222 rc = RC ( rcKFG, rcNode, rcWriting, rcSelf, rcNull );
223 }
224 else {
225 rc = KConfigWriteBool( self, "http/proxy/enabled", enabled );
226 }
227
228 return rc;
229 }
230
231 /* -------------------------------------------------------------------------- */
232 /* get/set priority of environmnet vs. configuration for HTTP proxy */
KConfig_Has_Http_Proxy_Env_Higher_Priority(const KConfig * self,bool * enabled)233 LIB_EXPORT rc_t CC KConfig_Has_Http_Proxy_Env_Higher_Priority
234 ( const KConfig *self, bool *enabled )
235 {
236 rc_t rc = 0;
237
238 if ( self == NULL ) {
239 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
240 }
241 else if ( enabled == NULL ) {
242 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
243 }
244 else {
245 String * res = NULL;
246 * enabled = false;
247 rc = KConfigReadString ( self, "/http/proxy/use", &res );
248 if ( rc == 0 ) {
249 String v;
250 CONST_STRING ( & v, "env,kfg" );
251 if ( StringEqual ( res, & v ) ) {
252 * enabled = true;
253 }
254 } else {
255 rc = 0;
256 }
257 free ( res );
258 }
259
260 return rc;
261 }
KConfig_Set_Http_Proxy_Env_Higher_Priority(KConfig * self,bool enabled)262 LIB_EXPORT rc_t CC KConfig_Set_Http_Proxy_Env_Higher_Priority
263 ( KConfig *self, bool enabled )
264 {
265 rc_t rc = 0;
266
267 if ( self == NULL ) {
268 rc = RC ( rcKFG, rcNode, rcWriting, rcSelf, rcNull );
269 }
270 else {
271 rc = KConfigWriteString
272 ( self, "/http/proxy/use", enabled ? "env,kfg" : "kfg,env" );
273 }
274
275 return rc;
276 }
277
278 /* -------------------------------------------------------------------------- */
279
KConfig_Get_Home(const KConfig * self,char * buffer,size_t buffer_size,size_t * written)280 LIB_EXPORT rc_t CC KConfig_Get_Home( const KConfig *self, char * buffer, size_t buffer_size, size_t * written )
281 { return KConfig_Get_Repository_String( self, buffer, buffer_size, written, "HOME" ); }
282
283 #define USER_DEFAULT_PATH "/repository/user/default-path"
KConfig_Get_Default_User_Path(const KConfig * self,char * buffer,size_t buffer_size,size_t * written)284 LIB_EXPORT rc_t CC KConfig_Get_Default_User_Path( const KConfig *self, char * buffer, size_t buffer_size, size_t * written )
285 { return KConfig_Get_Repository_String( self, buffer, buffer_size, written, USER_DEFAULT_PATH ); }
KConfig_Set_Default_User_Path(KConfig * self,const char * value)286 LIB_EXPORT rc_t CC KConfig_Set_Default_User_Path( KConfig *self, const char * value )
287 { return KConfig_Set_Repository_String( self, value, USER_DEFAULT_PATH ); }
288
289 /* -------------------------------------------------------------------------- */
290
291 #define PATH_REPOSITORY_REMOTE_DISABLED "/repository/remote/disabled"
KConfig_Get_Remote_Access_Enabled(const KConfig * self,bool * enabled)292 LIB_EXPORT rc_t CC KConfig_Get_Remote_Access_Enabled
293 ( const KConfig *self, bool * enabled )
294 {
295 return KConfig_Get_Repository_State( self, enabled,
296 true, true, PATH_REPOSITORY_REMOTE_DISABLED );
297 }
KConfig_Set_Remote_Access_Enabled(KConfig * self,bool enabled)298 LIB_EXPORT rc_t CC KConfig_Set_Remote_Access_Enabled
299 ( KConfig *self, bool enabled )
300 {
301 return KConfig_Set_Repository_State( self, enabled,
302 true, PATH_REPOSITORY_REMOTE_DISABLED );
303 }
304
305 #define PATH_REPOSITORY_REMOTE_MAIN_CGI_DISABLED \
306 "/repository/remote/main/CGI/disabled"
KConfig_Get_Remote_Main_Cgi_Access_Enabled(const KConfig * self,bool * enabled)307 LIB_EXPORT rc_t CC KConfig_Get_Remote_Main_Cgi_Access_Enabled
308 ( const KConfig *self, bool * enabled )
309 {
310 return KConfig_Get_Repository_State( self, enabled,
311 true, true, PATH_REPOSITORY_REMOTE_MAIN_CGI_DISABLED );
312 }
313
314 #define PATH_REPOSITORY_REMOTE_AUX_NCBI_DISABLED \
315 "/repository/remote/aux/NCBI/disabled"
KConfig_Get_Remote_Aux_Ncbi_Access_Enabled(const KConfig * self,bool * enabled)316 LIB_EXPORT rc_t CC KConfig_Get_Remote_Aux_Ncbi_Access_Enabled
317 ( const KConfig *self, bool * enabled )
318 {
319 return KConfig_Get_Repository_State( self, enabled,
320 true, true, PATH_REPOSITORY_REMOTE_DISABLED );
321 }
322
323 #define PATH_REPOSITORY_SITE_DISABLED "/repository/site/disabled"
324 #define PATH_REPOSITORY_USER_DISABLED "/repository/user/disabled"
KConfig_Get_Site_Access_Enabled(const KConfig * self,bool * enabled)325 LIB_EXPORT rc_t CC KConfig_Get_Site_Access_Enabled( const KConfig *self, bool * enabled )
326 { return KConfig_Get_Repository_State( self, enabled, true, true, PATH_REPOSITORY_SITE_DISABLED ); }
KConfig_Set_Site_Access_Enabled(KConfig * self,bool enabled)327 LIB_EXPORT rc_t CC KConfig_Set_Site_Access_Enabled( KConfig *self, bool enabled )
328 { return KConfig_Set_Repository_State( self, enabled, true, PATH_REPOSITORY_SITE_DISABLED ); }
329
KConfig_Get_User_Access_Enabled(const KConfig * self,bool * enabled)330 LIB_EXPORT rc_t CC KConfig_Get_User_Access_Enabled( const KConfig *self, bool * enabled )
331 { return KConfig_Get_Repository_State( self, enabled, true, true, PATH_REPOSITORY_USER_DISABLED ); }
KConfig_Set_User_Access_Enabled(KConfig * self,bool enabled)332 LIB_EXPORT rc_t CC KConfig_Set_User_Access_Enabled( KConfig *self, bool enabled )
333 { return KConfig_Set_Repository_State( self, enabled, true, PATH_REPOSITORY_USER_DISABLED ); }
334
335 #define PATH_ALLOW_ALL_CERTS "/tls/allow-all-certs"
KConfig_Get_Allow_All_Certs(const KConfig * self,bool * enabled)336 LIB_EXPORT rc_t CC KConfig_Get_Allow_All_Certs( const KConfig *self, bool * enabled )
337 { return KConfig_Get_Repository_State( self, enabled, false, false, PATH_ALLOW_ALL_CERTS ); }
KConfig_Set_Allow_All_Certs(KConfig * self,bool enabled)338 LIB_EXPORT rc_t CC KConfig_Set_Allow_All_Certs( KConfig *self, bool enabled )
339 { return KConfig_Set_Repository_State( self, enabled, false, PATH_ALLOW_ALL_CERTS ); }
340
341 #define PATH_REPOSITORY_USER_PUBLIC_DISABLED "/repository/user/main/public/disabled"
KConfig_Get_User_Public_Enabled(const KConfig * self,bool * enabled)342 LIB_EXPORT rc_t CC KConfig_Get_User_Public_Enabled( const KConfig *self, bool * enabled )
343 { return KConfig_Get_Repository_State( self, enabled, true, true, PATH_REPOSITORY_USER_PUBLIC_DISABLED ); }
KConfig_Set_User_Public_Enabled(KConfig * self,bool enabled)344 LIB_EXPORT rc_t CC KConfig_Set_User_Public_Enabled( KConfig *self, bool enabled )
345 { return KConfig_Set_Repository_State( self, enabled, true, PATH_REPOSITORY_USER_PUBLIC_DISABLED ); }
346
347 #define PATH_REPOSITORY_USER_PUBLIC_CACHE_DISABLED "/repository/user/main/public/cache-disabled"
KConfig_Get_User_Public_Cached(const KConfig * self,bool * enabled)348 LIB_EXPORT rc_t CC KConfig_Get_User_Public_Cached( const KConfig *self, bool * enabled )
349 { return KConfig_Get_Repository_State( self, enabled, true, true, PATH_REPOSITORY_USER_PUBLIC_CACHE_DISABLED ); }
KConfig_Set_User_Public_Cached(KConfig * self,bool enabled)350 LIB_EXPORT rc_t CC KConfig_Set_User_Public_Cached( KConfig *self, bool enabled )
351 { return KConfig_Set_Repository_State( self, enabled, true, PATH_REPOSITORY_USER_PUBLIC_CACHE_DISABLED ); }
352
353 #define PATH_REPOSITORY_USER_PROTECTED_CACHE_ENABLED "/repository/user/protected/%s/cache-enabled"
KConfig_Get_User_Protected_Cached(const KConfig * self,bool * enabled,const char * name)354 LIB_EXPORT rc_t CC KConfig_Get_User_Protected_Cached( const KConfig *self, bool * enabled, const char * name )
355 { return KConfig_Get_Repository_State( self, enabled, false, false, PATH_REPOSITORY_USER_PROTECTED_CACHE_ENABLED, name ); }
KConfig_Set_User_Protected_Cached(KConfig * self,bool enabled,const char * name)356 LIB_EXPORT rc_t CC KConfig_Set_User_Protected_Cached( KConfig *self, bool enabled, const char * name )
357 { return KConfig_Set_Repository_State( self, enabled, false, PATH_REPOSITORY_USER_PROTECTED_CACHE_ENABLED, name ); }
358
359 #define PATH_REPOSITORY_USER_PUBLIC_CACHE_LOCATION "/repository/user/main/public/root"
KConfig_Get_User_Public_Cache_Location(const KConfig * self,char * value,size_t value_size,size_t * written)360 LIB_EXPORT rc_t CC KConfig_Get_User_Public_Cache_Location( const KConfig *self,
361 char * value, size_t value_size, size_t * written )
362 { return KConfig_Get_Repository_String( self, value, value_size, written, PATH_REPOSITORY_USER_PUBLIC_CACHE_LOCATION ); }
KConfig_Set_User_Public_Cache_Location(KConfig * self,const char * value)363 LIB_EXPORT rc_t CC KConfig_Set_User_Public_Cache_Location( KConfig *self, const char * value )
364 { return KConfig_Set_Repository_String( self, value, PATH_REPOSITORY_USER_PUBLIC_CACHE_LOCATION ); }
365
366 /* ---------------------------------------------------------------------------------------------------- */
367
KConfigGetProtectedRepositoryCount(const KConfig * self,uint32_t * count)368 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryCount( const KConfig *self, uint32_t * count )
369 {
370 rc_t rc = 0;
371 if ( self == NULL )
372 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
373 else if ( count == NULL )
374 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
375 else
376 {
377 const struct KConfigNode * node;
378 rc = KConfigOpenNodeRead ( self, &node, "/repository/user/protected" );
379 if ( rc == 0 )
380 {
381 struct KNamelist * names;
382 rc = KConfigNodeListChildren ( node, &names );
383 if ( rc == 0 )
384 {
385 rc = KNamelistCount ( names, count );
386 KNamelistRelease ( names );
387 }
388 KConfigNodeRelease ( node );
389 }
390 }
391 return rc;
392 }
393
394
KConfigGetProtectedRepositoryName(const KConfig * self,uint32_t id,char * buffer,size_t buffer_size,size_t * written)395 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryName( const KConfig *self,
396 uint32_t id, char * buffer, size_t buffer_size, size_t * written )
397 {
398 rc_t rc = 0;
399 if ( self == NULL )
400 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
401 else if ( buffer == NULL )
402 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
403 else
404 {
405 const struct KConfigNode * node;
406 rc = KConfigOpenNodeRead ( self, &node, "/repository/user/protected" );
407 if ( rc == 0 )
408 {
409 struct KNamelist * names;
410 rc = KConfigNodeListChildren ( node, &names );
411 if ( rc == 0 )
412 {
413 const char * name;
414 rc = KNamelistGet ( names, id, &name );
415 if ( rc == 0 )
416 rc = string_printf( buffer, buffer_size, written, "%s", name );
417 KNamelistRelease ( names );
418 }
419 KConfigNodeRelease ( node );
420 }
421 }
422 return rc;
423 }
424
425
get_root_dir_of_repository(const struct KConfigNode * node,const char * name,char * buffer,size_t buffer_size,size_t * written)426 static rc_t get_root_dir_of_repository( const struct KConfigNode * node,
427 const char * name, char * buffer, size_t buffer_size, size_t * written )
428 {
429 const struct KConfigNode * sub_node;
430 rc_t rc = KConfigNodeOpenNodeRead ( node, &sub_node, "%s/root", name );
431 if ( rc == 0 )
432 {
433 struct String * S;
434 rc = KConfigNodeReadString ( sub_node, &S );
435 if ( rc == 0 )
436 {
437 rc = string_printf( buffer, buffer_size, written, "%S", S );
438 StringWhack ( S );
439 }
440 KConfigNodeRelease ( sub_node );
441 }
442 return rc;
443 }
444
445
get_description_of_repository(const struct KConfigNode * node,const char * name,char * buffer,size_t buffer_size,size_t * written)446 static rc_t get_description_of_repository( const struct KConfigNode * node,
447 const char * name, char * buffer, size_t buffer_size, size_t * written )
448 {
449 const struct KConfigNode * sub_node;
450 rc_t rc = KConfigNodeOpenNodeRead (node, &sub_node, "%s/description", name);
451 if ( rc == 0 )
452 {
453 struct String * S;
454 rc = KConfigNodeReadString ( sub_node, &S );
455 if ( rc == 0 )
456 {
457 rc = string_printf( buffer, buffer_size, written, "%S", S );
458 StringWhack ( S );
459 }
460 KConfigNodeRelease ( sub_node );
461 }
462 return rc;
463 }
464
465
KConfigGetProtectedRepositoryPathById(const KConfig * self,uint32_t id,char * buffer,size_t buffer_size,size_t * written)466 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryPathById( const KConfig *self,
467 uint32_t id, char * buffer, size_t buffer_size, size_t * written )
468 {
469 rc_t rc = 0;
470 if ( self == NULL )
471 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
472 else if ( buffer == NULL )
473 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
474 else
475 {
476 const struct KConfigNode * node;
477 rc = KConfigOpenNodeRead ( self, &node, "/repository/user/protected" );
478 if ( rc == 0 )
479 {
480 struct KNamelist * names;
481 rc = KConfigNodeListChildren ( node, &names );
482 if ( rc == 0 )
483 {
484 const char * name;
485 rc = KNamelistGet ( names, id, &name );
486 if ( rc == 0 )
487 rc = get_root_dir_of_repository( node, name, buffer, buffer_size, written );
488 KNamelistRelease ( names );
489 }
490 KConfigNodeRelease ( node );
491 }
492 }
493 return rc;
494 }
495
KConfigSetProtectedRepositoryPathById(KConfig * self,uint32_t id,const char * value)496 LIB_EXPORT rc_t CC KConfigSetProtectedRepositoryPathById( KConfig *self, uint32_t id, const char * value )
497 {
498 char repo_name[ 1024 ];
499 size_t written;
500 rc_t rc = KConfigGetProtectedRepositoryName( self, id, repo_name, sizeof repo_name, &written );
501 if ( rc == 0 )
502 rc = KConfig_Set_Repository_String( self, value, "/repository/user/protected/%s/root", repo_name );
503 return rc;
504 }
505
506
KConfigGetProtectedRepositoryIdByName(const KConfig * self,const char * name,uint32_t * id)507 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryIdByName
508 (const KConfig *self, const char *name, uint32_t *id)
509 {
510 if (self == NULL)
511 return RC(rcKFG, rcNode, rcReading, rcSelf, rcNull);
512 else if (name == NULL || id == NULL)
513 return RC(rcKFG, rcNode, rcReading, rcParam, rcNull);
514 else {
515 const struct KConfigNode *node = NULL;
516 rc_t rc
517 = KConfigOpenNodeRead(self, &node, "/repository/user/protected");
518 if (rc == 0) {
519 struct KNamelist *names = NULL;
520 rc = KConfigNodeListChildren(node, &names);
521 if (rc == 0) {
522 uint32_t count = 0;
523 rc = KNamelistCount(names, &count);
524 if (rc == 0) {
525 if (count == 0)
526 rc = RC(rcKFG, rcNode, rcReading, rcName, rcNotFound);
527 else { /* loop through the names to find the one */
528 uint32_t i = 0; /* which matches the name parameter */
529 bool found = false;
530 size_t name_size = string_size(name);
531 for (i = 0; i < count && rc == 0; ++i) {
532 const char *s = NULL;
533 rc = KNamelistGet(names, i, &s);
534 if ( rc == 0 && s != NULL ) {
535 size_t s_size = string_size(s);
536 if (name_size == s_size) {
537 int cmp = string_cmp(name, name_size,
538 s, s_size, (uint32_t)s_size);
539 found = (cmp == 0);
540 if (found) {
541 *id = i;
542 break;
543 }
544 }
545 }
546 }
547 if (rc == 0 && !found) {
548 rc = RC
549 (rcKFG, rcNode, rcReading, rcName, rcNotFound);
550 }
551 }
552 }
553 KNamelistRelease(names);
554 }
555 KConfigNodeRelease(node);
556 }
557 return rc;
558 }
559 }
560
KConfigGetProtectedRepositoryPathByName(const KConfig * self,const char * name,char * buffer,size_t buffer_size,size_t * written)561 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryPathByName( const KConfig *self,
562 const char * name, char * buffer, size_t buffer_size, size_t * written )
563 {
564 rc_t rc = 0;
565 if ( self == NULL )
566 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
567 else if ( buffer == NULL )
568 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
569 else
570 {
571 const struct KConfigNode * node;
572 rc = KConfigOpenNodeRead ( self, &node, "/repository/user/protected" );
573 if ( rc == 0 )
574 {
575 struct KNamelist * names;
576 rc = KConfigNodeListChildren ( node, &names );
577 if ( rc == 0 )
578 {
579 uint32_t count;
580 rc = KNamelistCount ( names, &count );
581 if ( rc == 0 )
582 {
583 if ( count == 0 )
584 rc = RC ( rcKFG, rcNode, rcReading, rcName, rcNotFound );
585 else
586 {
587 /* loop through the names to find the one which matches the name parameter */
588 uint32_t i;
589 bool found = false;
590 size_t name_size = string_size( name );
591 for ( i = 0; !found && i < count && rc == 0; ++i )
592 {
593 const char * s = NULL;
594 rc = KNamelistGet ( names, i, &s );
595 if ( rc == 0 && s != NULL )
596 {
597 size_t s_size = string_size( s );
598 if ( name_size == s_size )
599 {
600 int cmp = string_cmp ( name, name_size,
601 s, s_size, (uint32_t)s_size);
602 found = ( cmp == 0 );
603 if ( found )
604 rc = get_root_dir_of_repository( node, s, buffer, buffer_size, written );
605 }
606 }
607 }
608 if ( rc == 0 && !found )
609 rc = RC ( rcKFG, rcNode, rcReading, rcName, rcNotFound );
610 }
611 }
612 KNamelistRelease ( names );
613 }
614 KConfigNodeRelease ( node );
615 }
616 }
617 return rc;
618 }
619
620
KConfigGetProtectedRepositoryDescriptionByName(const KConfig * self,const char * name,char * buffer,size_t buffer_size,size_t * written)621 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryDescriptionByName(
622 const KConfig *self,
623 const char * name, char * buffer, size_t buffer_size, size_t * written )
624 {
625 rc_t rc = 0;
626 if ( self == NULL )
627 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
628 else if ( buffer == NULL )
629 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
630 else
631 {
632 const struct KConfigNode * node;
633 rc = KConfigOpenNodeRead ( self, &node, "/repository/user/protected" );
634 if ( rc == 0 )
635 {
636 struct KNamelist * names;
637 rc = KConfigNodeListChildren ( node, &names );
638 if ( rc == 0 )
639 {
640 uint32_t count;
641 rc = KNamelistCount ( names, &count );
642 if ( rc == 0 )
643 {
644 if ( count == 0 )
645 rc = RC( rcKFG, rcNode, rcReading, rcName, rcNotFound );
646 else
647 {
648 /* loop through the names to find the one which matches the name parameter */
649 uint32_t i;
650 bool found = false;
651 size_t name_size = string_size( name );
652 for ( i = 0; !found && i < count && rc == 0; ++i )
653 {
654 const char * s = NULL;
655 rc = KNamelistGet ( names, i, &s );
656 if ( rc == 0 && s != NULL )
657 {
658 size_t s_size = string_size( s );
659 if ( name_size == s_size )
660 {
661 int cmp = string_cmp ( name, name_size,
662 s, s_size, (uint32_t)s_size);
663 found = ( cmp == 0 );
664 if ( found )
665 rc = get_description_of_repository(node,
666 s, buffer, buffer_size, written );
667 }
668 }
669 }
670 if ( rc == 0 && !found )
671 rc = RC
672 (rcKFG, rcNode, rcReading, rcName, rcNotFound);
673 }
674 }
675 KNamelistRelease ( names );
676 }
677 KConfigNodeRelease ( node );
678 }
679 }
680 return rc;
681 }
682
683
KConfigDoesProtectedRepositoryExist(const KConfig * self,const char * name,bool * res)684 LIB_EXPORT rc_t CC KConfigDoesProtectedRepositoryExist( const KConfig *self, const char * name, bool * res )
685 {
686 rc_t rc = 0;
687 if ( self == NULL )
688 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
689 else if ( res == NULL )
690 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
691 else
692 {
693 const struct KConfigNode * node;
694 *res = false;
695 rc = KConfigOpenNodeRead ( self, &node, "/repository/user/protected" );
696 if ( rc == 0 )
697 {
698 struct KNamelist * names;
699 rc = KConfigNodeListChildren ( node, &names );
700 if ( rc == 0 )
701 {
702 uint32_t count;
703 rc = KNamelistCount ( names, &count );
704 if ( rc == 0 )
705 {
706 if ( count == 0 )
707 rc = RC ( rcKFG, rcNode, rcReading, rcName, rcNotFound );
708 else
709 {
710 /* loop through the names to find the one which matches the name parameter */
711 uint32_t i;
712 bool found = false;
713 size_t name_size = string_size( name );
714 for ( i = 0; !found && i < count && rc == 0; ++i )
715 {
716 const char * s = NULL;
717 rc = KNamelistGet ( names, i, &s );
718 if ( rc == 0 && s != NULL )
719 {
720 size_t s_size = string_size( s );
721 if ( name_size == s_size )
722 {
723 int cmp = string_cmp ( name, name_size,
724 s, s_size, (uint32_t)s_size);
725 found = ( cmp == 0 );
726 }
727 }
728 }
729 if ( rc == 0 && found )
730 *res = true;
731 }
732 }
733 KNamelistRelease ( names );
734 }
735 KConfigNodeRelease ( node );
736 }
737 }
738 return rc;
739 }
740
KConfigGetProtectedRepositoryEnabledById(const KConfig * self,uint32_t id,bool * enabled)741 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryEnabledById( const KConfig *self, uint32_t id, bool * enabled )
742 {
743 char repo_name[ 1024 ];
744 size_t written;
745 rc_t rc = KConfigGetProtectedRepositoryName( self, id, repo_name, sizeof repo_name, &written );
746 if ( rc == 0 )
747 rc = KConfig_Get_Repository_State( self, enabled, true, true, "/repository/user/protected/%s/disabled", repo_name );
748 return rc;
749 }
750
751
KConfigSetProtectedRepositoryEnabledById(KConfig * self,uint32_t id,bool enabled)752 LIB_EXPORT rc_t CC KConfigSetProtectedRepositoryEnabledById( KConfig *self, uint32_t id, bool enabled )
753 {
754 char repo_name[ 1024 ];
755 size_t written;
756 rc_t rc = KConfigGetProtectedRepositoryName( self, id, repo_name, sizeof repo_name, &written );
757 if ( rc == 0 )
758 rc = KConfig_Set_Repository_State( self, enabled, true, "/repository/user/protected/%s/disabled", repo_name );
759 return rc;
760 }
761
762
KConfigGetProtectedRepositoryCachedById(const KConfig * self,uint32_t id,bool * enabled)763 LIB_EXPORT rc_t CC KConfigGetProtectedRepositoryCachedById( const KConfig *self, uint32_t id, bool * enabled )
764 {
765 char repo_name[ 1024 ];
766 size_t written;
767 rc_t rc = KConfigGetProtectedRepositoryName( self, id, repo_name, sizeof repo_name, &written );
768 if ( rc == 0 )
769 rc = KConfig_Get_Repository_State( self, enabled, false, false, "/repository/user/protected/%s/cache-enabled", repo_name );
770 return rc;
771 }
772
773
KConfigSetProtectedRepositoryCachedById(KConfig * self,uint32_t id,bool enabled)774 LIB_EXPORT rc_t CC KConfigSetProtectedRepositoryCachedById( KConfig *self, uint32_t id, bool enabled )
775 {
776 char repo_name[ 1024 ];
777 size_t written;
778 rc_t rc = KConfigGetProtectedRepositoryName( self, id, repo_name, sizeof repo_name, &written );
779 if ( rc == 0 )
780 rc = KConfig_Set_Repository_State( self, enabled, false, "/repository/user/protected/%s/cache-enabled", repo_name );
781 return rc;
782 }
783
784 /* ---------------------------------------------------------------------------------------------------- */
785
786 #define PREFETCH_DOWNLOAD_TO_CACHE "/tools/prefetch/download_to_cache"
KConfig_Get_Prefetch_Download_To_Cache(const KConfig * self,bool * value)787 LIB_EXPORT rc_t CC KConfig_Get_Prefetch_Download_To_Cache ( const KConfig *self, bool * value )
788 {
789 rc_t rc = KConfigReadBool ( self, PREFETCH_DOWNLOAD_TO_CACHE, value );
790 if ( GetRCState ( rc ) == rcNotFound)
791 {
792 * value = true;
793 rc = 0;
794 }
795 return rc;
796 }
KConfig_Set_Prefetch_Download_To_Cache(KConfig * self,bool value)797 LIB_EXPORT rc_t CC KConfig_Set_Prefetch_Download_To_Cache ( KConfig *self, bool value )
798 {
799 return KConfigWriteBool( self, PREFETCH_DOWNLOAD_TO_CACHE, value );
800 }
801
802 #define USER_ACCEPT_AWS_CHARGES "/libs/cloud/accept_aws_charges"
KConfig_Get_User_Accept_Aws_Charges(const KConfig * self,bool * value)803 LIB_EXPORT rc_t CC KConfig_Get_User_Accept_Aws_Charges ( const KConfig *self, bool * value )
804 {
805 rc_t rc = KConfigReadBool ( self, USER_ACCEPT_AWS_CHARGES, value );
806 if ( GetRCState ( rc ) == rcNotFound)
807 {
808 * value = false;
809 rc = 0;
810 }
811 return rc;
812 }
KConfig_Set_User_Accept_Aws_Charges(KConfig * self,bool value)813 LIB_EXPORT rc_t CC KConfig_Set_User_Accept_Aws_Charges ( KConfig *self, bool value )
814 {
815 return KConfigWriteBool( self, USER_ACCEPT_AWS_CHARGES, value );
816 }
817
818 #define USER_ACCEPT_GCP_CHARGES "/libs/cloud/accept_gcp_charges"
KConfig_Get_User_Accept_Gcp_Charges(const KConfig * self,bool * value)819 LIB_EXPORT rc_t CC KConfig_Get_User_Accept_Gcp_Charges ( const KConfig *self, bool * value )
820 {
821 rc_t rc = KConfigReadBool ( self, USER_ACCEPT_GCP_CHARGES, value );
822 if ( GetRCState ( rc ) == rcNotFound)
823 {
824 * value = false;
825 rc = 0;
826 }
827 return rc;
828 }
KConfig_Set_User_Accept_Gcp_Charges(KConfig * self,bool value)829 LIB_EXPORT rc_t CC KConfig_Set_User_Accept_Gcp_Charges ( KConfig *self, bool value )
830 {
831 return KConfigWriteBool( self, USER_ACCEPT_GCP_CHARGES, value );
832 }
833
834 #define REPORT_CLOUD_INSTANCE_IDENTITY "/libs/cloud/report_instance_identity"
KConfig_Get_Report_Cloud_Instance_Identity(const KConfig * self,bool * value)835 LIB_EXPORT rc_t CC KConfig_Get_Report_Cloud_Instance_Identity ( const KConfig *self, bool * value )
836 {
837 rc_t rc = KConfigReadBool ( self, REPORT_CLOUD_INSTANCE_IDENTITY, value );
838 if ( GetRCState ( rc ) == rcNotFound)
839 {
840 * value = false;
841 rc = 0;
842 }
843 return rc;
844 }
KConfig_Set_Report_Cloud_Instance_Identity(KConfig * self,bool value)845 LIB_EXPORT rc_t CC KConfig_Set_Report_Cloud_Instance_Identity ( KConfig *self, bool value )
846 {
847 return KConfigWriteBool( self, REPORT_CLOUD_INSTANCE_IDENTITY, value );
848 }
849
850 #define TEMP_CACHE "/libs/temp_cache"
851 LIB_EXPORT rc_t CC
KConfig_Get_Temp_Cache(const KConfig * self,char * value,size_t value_size,size_t * written)852 KConfig_Get_Temp_Cache( const KConfig *self,
853 char * value, size_t value_size, size_t * written )
854 {
855 return KConfig_Get_Repository_String( self, value, value_size, written, TEMP_CACHE );
856 }
857 LIB_EXPORT rc_t CC
KConfig_Set_Temp_Cache(KConfig * self,const char * value)858 KConfig_Set_Temp_Cache( KConfig *self, const char * value )
859 {
860 return KConfig_Set_Repository_String( self, value, TEMP_CACHE );
861 }
862
863 #define GCP_CREDENTIAL_FILE "/gcp/credential_file"
864 LIB_EXPORT rc_t CC
KConfig_Get_Gcp_Credential_File(const KConfig * self,char * value,size_t value_size,size_t * written)865 KConfig_Get_Gcp_Credential_File( const KConfig *self,
866 char * value, size_t value_size, size_t * written )
867 {
868 return KConfig_Get_Repository_String( self, value, value_size, written, GCP_CREDENTIAL_FILE );
869 }
870 LIB_EXPORT rc_t CC
KConfig_Set_Gcp_Credential_File(KConfig * self,const char * value)871 KConfig_Set_Gcp_Credential_File( KConfig *self, const char * value )
872 {
873 return KConfig_Set_Repository_String( self, value, GCP_CREDENTIAL_FILE );
874 }
875
876 #define AWS_CREDENTIAL_FILE "/aws/credential_file"
877 LIB_EXPORT rc_t CC
KConfig_Get_Aws_Credential_File(const KConfig * self,char * value,size_t value_size,size_t * written)878 KConfig_Get_Aws_Credential_File( const KConfig *self,
879 char * value, size_t value_size, size_t * written )
880 {
881 return KConfig_Get_Repository_String( self, value, value_size, written, AWS_CREDENTIAL_FILE );
882 }
883 LIB_EXPORT rc_t CC
KConfig_Set_Aws_Credential_File(KConfig * self,const char * value)884 KConfig_Set_Aws_Credential_File( KConfig *self, const char * value )
885 {
886 return KConfig_Set_Repository_String( self, value, AWS_CREDENTIAL_FILE );
887 }
888
889 #define AWS_PROFILE "/aws/profile"
890 LIB_EXPORT rc_t CC
KConfig_Get_Aws_Profile(const KConfig * self,char * value,size_t value_size,size_t * written)891 KConfig_Get_Aws_Profile( const KConfig *self,
892 char * value, size_t value_size, size_t * written )
893 {
894 rc_t rc = 0;
895
896 size_t dummy = 0;
897 if (written == NULL)
898 written = &dummy;
899
900 rc = KConfig_Get_Repository_String( self, value, value_size, written,
901 AWS_PROFILE );
902 if ( GetRCState ( rc ) == rcNotFound || ( rc == 0 && * written == 0 ) )
903 {
904 * written = string_copy_measure ( value, value_size, "default" );
905 rc = 0;
906 }
907
908 return rc;
909 }
910 LIB_EXPORT rc_t CC
KConfig_Set_Aws_Profile(KConfig * self,const char * value)911 KConfig_Set_Aws_Profile( KConfig *self, const char * value )
912 {
913 return KConfig_Set_Repository_String( self, value, AWS_PROFILE );
914 }
915
916 #define CACHE_AMOUNT "/libs/cache_amount"
KConfig_Get_Cache_Amount(const KConfig * self,uint32_t * value)917 LIB_EXPORT rc_t CC KConfig_Get_Cache_Amount ( const KConfig *self, uint32_t * value )
918 {
919 rc_t rc;
920 if ( self == NULL )
921 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
922 else if ( value == NULL )
923 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
924 else
925 {
926 uint64_t long_value = 0;
927 rc = KConfigReadU64 ( self, CACHE_AMOUNT, &long_value );
928 if ( rc == 0 || GetRCState ( rc ) == rcNotFound )
929 {
930 * value = long_value & 0xFFFFFFFF;
931 rc = 0;
932 }
933 }
934 return rc;
935 }
936
KConfig_Set_Cache_Amount(KConfig * self,uint32_t value)937 LIB_EXPORT rc_t CC KConfig_Set_Cache_Amount( KConfig *self, uint32_t value )
938 {
939 rc_t rc;
940 if ( self == NULL )
941 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
942 else
943 {
944 char buff[ 128 ];
945 size_t num_writ;
946 rc = string_printf ( buff, sizeof buff, &num_writ, "%u", value );
947 if ( rc == 0 )
948 rc = KConfigWriteString( self, CACHE_AMOUNT, buff );
949 }
950 return rc;
951 }
952
953 /* ------------------------------------------------------------------------ */
get_uint32_t_value(const KConfig * self,const char * key,uint32_t * value,uint32_t dflt)954 static rc_t get_uint32_t_value( const KConfig *self, const char * key, uint32_t * value, uint32_t dflt )
955 {
956 rc_t rc;
957 if ( self == NULL )
958 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
959 else if ( value == NULL )
960 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
961 else
962 {
963 uint64_t long_value = dflt;
964 rc = KConfigReadU64 ( self, key, &long_value );
965 if ( rc == 0 )
966 * value = ( long_value & 0xFFFFFFFF );
967 rc = 0;
968 }
969 return rc;
970 }
971
set_uint32_t_value(KConfig * self,const char * key,uint32_t value)972 static rc_t set_uint32_t_value( KConfig *self, const char * key, uint32_t value )
973 {
974 rc_t rc;
975 if ( self == NULL )
976 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
977 else
978 {
979 char buff[ 128 ];
980 size_t num_writ;
981 rc = string_printf ( buff, sizeof buff, &num_writ, "%u", value );
982 if ( rc == 0 )
983 rc = KConfigWriteString( self, key, buff );
984 }
985 return rc;
986 }
987
get_bool_value(const KConfig * self,const char * key,bool * value,bool dflt)988 static rc_t get_bool_value( const KConfig *self, const char * key, bool * value, bool dflt )
989 {
990 rc_t rc;
991 if ( self == NULL )
992 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
993 else if ( value == NULL )
994 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
995 else
996 {
997 bool res = dflt;
998 rc = KConfigReadBool ( self, key, &res );
999 if ( rc == 0 )
1000 * value = res;
1001 rc = 0;
1002 }
1003 return rc;
1004 }
1005
set_bool_value(KConfig * self,const char * key,bool value)1006 static rc_t set_bool_value( KConfig *self, const char * key, bool value )
1007 {
1008 rc_t rc;
1009 if ( self == NULL )
1010 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
1011 else
1012 rc = KConfigWriteBool( self, key, value );
1013 return rc;
1014 }
1015
1016 #define CACHE_TEE_VERSION "/CACHINGPARAMS/CACHETEEVER"
KConfig_Get_CacheTeeVersion(const KConfig * self,uint32_t * value,uint32_t dflt)1017 LIB_EXPORT rc_t CC KConfig_Get_CacheTeeVersion ( const KConfig *self, uint32_t * value, uint32_t dflt )
1018 { return get_uint32_t_value( self, CACHE_TEE_VERSION, value, dflt ); }
KConfig_Set_CacheTeeVersion(KConfig * self,uint32_t value)1019 LIB_EXPORT rc_t CC KConfig_Set_CacheTeeVersion( KConfig *self, uint32_t value )
1020 { return set_uint32_t_value( self, CACHE_TEE_VERSION, value ); }
1021
1022 #define CACHE_TEE_CLUSTER_FACTOR "/CACHINGPARAMS/CACHETEECLUSTERFACTOR"
KConfig_Get_CacheClusterFactorBits(const KConfig * self,uint32_t * value,uint32_t dflt)1023 LIB_EXPORT rc_t CC KConfig_Get_CacheClusterFactorBits( const KConfig *self, uint32_t * value, uint32_t dflt )
1024 { return get_uint32_t_value( self, CACHE_TEE_CLUSTER_FACTOR, value, dflt ); }
KConfig_Set_CacheClusterFactorBits(KConfig * self,uint32_t value)1025 LIB_EXPORT rc_t CC KConfig_Set_CacheClusterFactorBits( KConfig *self, uint32_t value )
1026 { return set_uint32_t_value( self, CACHE_TEE_CLUSTER_FACTOR, value ); }
1027
1028 #define CACHE_TEE_PAGE_SIZE "/CACHINGPARAMS/CACHETEEPAGESIZE"
KConfig_Get_CachePageSizeBits(const KConfig * self,uint32_t * value,uint32_t dflt)1029 LIB_EXPORT rc_t CC KConfig_Get_CachePageSizeBits( const KConfig *self, uint32_t * value, uint32_t dflt )
1030 { return get_uint32_t_value( self, CACHE_TEE_PAGE_SIZE, value, dflt ); }
KConfig_Set_CachePageSizeBits(KConfig * self,uint32_t value)1031 LIB_EXPORT rc_t CC KConfig_Set_CachePageSizeBits( KConfig *self, uint32_t value )
1032 { return set_uint32_t_value( self, CACHE_TEE_PAGE_SIZE, value ); }
1033
1034 #define CACHE_BLOCKSIZE "/CACHINGPARAMS/BLOCKSIZE"
KConfig_Get_CacheBlockSize(const KConfig * self,size_t * value,size_t dflt)1035 LIB_EXPORT rc_t CC KConfig_Get_CacheBlockSize ( const KConfig *self, size_t * value, size_t dflt )
1036 {
1037 rc_t rc;
1038 if ( self == NULL )
1039 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
1040 else if ( value == NULL )
1041 rc = RC ( rcKFG, rcNode, rcReading, rcParam, rcNull );
1042 else
1043 {
1044 uint64_t long_value = dflt;
1045 rc = KConfigReadU64 ( self, CACHE_BLOCKSIZE, &long_value );
1046 if ( rc == 0 )
1047 * value = long_value;
1048 rc = 0;
1049 }
1050 return rc;
1051 }
1052
KConfig_Set_CacheBlockSize(KConfig * self,size_t value)1053 LIB_EXPORT rc_t CC KConfig_Set_CacheBlockSize( KConfig *self, size_t value )
1054 {
1055 rc_t rc;
1056 if ( self == NULL )
1057 rc = RC ( rcKFG, rcNode, rcReading, rcSelf, rcNull );
1058 else
1059 {
1060 char buff[ 128 ];
1061 size_t num_writ;
1062 rc = string_printf ( buff, sizeof buff, &num_writ, "%u", value );
1063 if ( rc == 0 )
1064 rc = KConfigWriteString( self, CACHE_BLOCKSIZE, buff );
1065 }
1066 return rc;
1067 }
1068
1069 #define CACHE_PAGE_COUNT "/CACHINGPARAMS/PAGECOUNT"
KConfig_Get_CachePageCount(const KConfig * self,uint32_t * value,uint32_t dflt)1070 LIB_EXPORT rc_t CC KConfig_Get_CachePageCount( const KConfig *self, uint32_t * value, uint32_t dflt )
1071 { return get_uint32_t_value( self, CACHE_PAGE_COUNT, value, dflt ); }
KConfig_Set_CachePageCount(KConfig * self,uint32_t value)1072 LIB_EXPORT rc_t CC KConfig_Set_CachePageCount( KConfig *self, uint32_t value )
1073 { return set_uint32_t_value( self, CACHE_PAGE_COUNT, value ); }
1074
1075 #define CACHE_LOG_USE_CWD "/CACHINGPARAMS/LOGUSECWD"
KConfig_Get_CacheLogUseCWD(const KConfig * self,bool * value,bool dflt)1076 LIB_EXPORT rc_t CC KConfig_Get_CacheLogUseCWD( const KConfig *self, bool * value, bool dflt )
1077 { return get_bool_value( self, CACHE_LOG_USE_CWD, value, dflt ); }
KConfig_Set_CacheLogUseCWD(KConfig * self,bool value)1078 LIB_EXPORT rc_t CC KConfig_Set_CacheLogUseCWD( KConfig *self, bool value )
1079 { return set_bool_value( self, CACHE_LOG_USE_CWD, value ); }
1080
1081 #define CACHE_LOG_APPEND "/CACHINGPARAMS/LOGAPPEND"
KConfig_Get_CacheLogAppend(const KConfig * self,bool * value,bool dflt)1082 LIB_EXPORT rc_t CC KConfig_Get_CacheLogAppend( const KConfig *self, bool * value, bool dflt )
1083 { return get_bool_value( self, CACHE_LOG_APPEND, value, dflt ); }
KConfig_Set_CacheLogAppend(KConfig * self,bool value)1084 LIB_EXPORT rc_t CC KConfig_Set_CacheLogAppend( KConfig *self, bool value )
1085 { return set_bool_value( self, CACHE_LOG_APPEND, value ); }
1086
1087 #define CACHE_LOG_TIMED "/CACHINGPARAMS/LOGTIMED"
KConfig_Get_CacheLogTimed(const KConfig * self,bool * value,bool dflt)1088 LIB_EXPORT rc_t CC KConfig_Get_CacheLogTimed( const KConfig *self, bool * value, bool dflt )
1089 { return get_bool_value( self, CACHE_LOG_TIMED, value, dflt ); }
KConfig_Set_CacheLogTimed(KConfig * self,bool value)1090 LIB_EXPORT rc_t CC KConfig_Set_CacheLogTimed( KConfig *self, bool value )
1091 { return set_bool_value( self, CACHE_LOG_TIMED, value ); }
1092
1093 #define CACHE_LOG_OUTER "/CACHINGPARAMS/LOGOUTER"
KConfig_Get_CacheLogOuter(const KConfig * self,bool * value,bool dflt)1094 LIB_EXPORT rc_t CC KConfig_Get_CacheLogOuter( const KConfig *self, bool * value, bool dflt )
1095 { return get_bool_value( self, CACHE_LOG_OUTER, value, dflt ); }
KConfig_Set_CacheLogOuter(KConfig * self,bool value)1096 LIB_EXPORT rc_t CC KConfig_Set_CacheLogOuter( KConfig *self, bool value )
1097 { return set_bool_value( self, CACHE_LOG_OUTER, value ); }
1098
1099 #define CACHE_LOG_INNER "/CACHINGPARAMS/LOGINNER"
KConfig_Get_CacheLogInner(const KConfig * self,bool * value,bool dflt)1100 LIB_EXPORT rc_t CC KConfig_Get_CacheLogInner( const KConfig *self, bool * value, bool dflt )
1101 { return get_bool_value( self, CACHE_LOG_INNER, value, dflt ); }
KConfig_Set_CacheLogInner(KConfig * self,bool value)1102 LIB_EXPORT rc_t CC KConfig_Set_CacheLogInner( KConfig *self, bool value )
1103 { return set_bool_value( self, CACHE_LOG_INNER, value ); }
1104
1105 #define DEBUG_CACHEING "/CACHINGPARAMS/DEBUG"
KConfig_Get_CacheDebug(const KConfig * self,bool * value,bool dflt)1106 LIB_EXPORT rc_t CC KConfig_Get_CacheDebug( const KConfig *self, bool * value, bool dflt )
1107 { return get_bool_value( self, DEBUG_CACHEING, value, dflt ); }
KConfig_Set_CacheDebug(KConfig * self,bool value)1108 LIB_EXPORT rc_t CC KConfig_Set_CacheDebug( KConfig *self, bool value )
1109 { return set_bool_value( self, DEBUG_CACHEING, value ); }
1110
1111 #define GUID_KEY "LIBS/GUID"
KConfig_Get_GUID(const KConfig * self,char * value,size_t value_size,size_t * written)1112 LIB_EXPORT rc_t CC KConfig_Get_GUID( const KConfig *self, char * value, size_t value_size, size_t * written )
1113 {
1114 size_t local_written;
1115 rc_t rc = KConfig_Get_Repository_String( self, value, value_size, &local_written, GUID_KEY );
1116 if ( rc == 0 )
1117 {
1118 if ( written != NULL )
1119 *written = local_written;
1120 }
1121 return rc;
1122 }
1123
KConfig_Set_GUID(KConfig * self,const char * value)1124 LIB_EXPORT rc_t CC KConfig_Set_GUID( KConfig *self, const char * value )
1125 {
1126 return KConfig_Set_Repository_String( self, value, GUID_KEY );
1127 }
1128
1129 #define FULL_QUALITY_KEY "libs/vdb/full-quality"
KConfig_Get_FullQuality(const KConfig * self,bool * value)1130 LIB_EXPORT rc_t CC KConfig_Get_FullQuality( const KConfig *self, bool * value )
1131 { return get_bool_value( self, FULL_QUALITY_KEY, value, false ); }
KConfig_Set_FullQuality(KConfig * self,bool value)1132 LIB_EXPORT rc_t CC KConfig_Set_FullQuality( KConfig *self, bool value )
1133 { return set_bool_value( self, FULL_QUALITY_KEY, value ); }
1134