| Directory: | cvmfs/ |
|---|---|
| File: | cvmfs/libcvmfs_options.cc |
| Date: | 2025-11-09 02:35:23 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 21 | 34 | 61.8% |
| Branches: | 13 | 42 | 31.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * This file is part of the CernVM File System. | ||
| 3 | * | ||
| 4 | * Implements the C wrapper of the OptionsManager | ||
| 5 | */ | ||
| 6 | |||
| 7 | |||
| 8 | #include <cassert> | ||
| 9 | #include <cstdlib> | ||
| 10 | #include <cstring> | ||
| 11 | #include <string> | ||
| 12 | |||
| 13 | #include "libcvmfs.h" | ||
| 14 | #include "options.h" | ||
| 15 | |||
| 16 | using namespace std; // NOLINT | ||
| 17 | |||
| 18 | |||
| 19 | 36 | SimpleOptionsParser *cvmfs_options_clone(SimpleOptionsParser *opts) { | |
| 20 | SimpleOptionsParser *result = new SimpleOptionsParser( | ||
| 21 |
1/2✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
|
36 | *reinterpret_cast<SimpleOptionsParser *>(opts)); |
| 22 | 36 | return result; | |
| 23 | } | ||
| 24 | |||
| 25 | |||
| 26 |
1/2✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
|
214 | void cvmfs_options_fini(SimpleOptionsParser *opts) { delete opts; } |
| 27 | |||
| 28 | |||
| 29 | ✗ | void cvmfs_options_free(char *value) { free(value); } | |
| 30 | |||
| 31 | |||
| 32 | 36 | char *cvmfs_options_get(SimpleOptionsParser *opts, const char *key) { | |
| 33 | 36 | string arg; | |
| 34 |
2/4✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 36 times.
✗ Branch 6 not taken.
|
36 | const bool retval = opts->GetValue(key, &arg); |
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!retval) |
| 36 | ✗ | return NULL; | |
| 37 | 36 | char *result = strdup(arg.c_str()); | |
| 38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | assert(result != NULL); |
| 39 | 36 | return result; | |
| 40 | 36 | } | |
| 41 | |||
| 42 | |||
| 43 | ✗ | char *cvmfs_options_dump(SimpleOptionsParser *opts) { | |
| 44 | ✗ | char *result = strdup(opts->Dump().c_str()); | |
| 45 | ✗ | assert(result != NULL); | |
| 46 | ✗ | return result; | |
| 47 | } | ||
| 48 | |||
| 49 | |||
| 50 | 342 | SimpleOptionsParser *cvmfs_options_init() { return cvmfs_options_init_v2(0); } | |
| 51 | |||
| 52 | |||
| 53 | 342 | SimpleOptionsParser *cvmfs_options_init_v2(int taint_environ) { | |
| 54 |
1/2✓ Branch 2 taken 342 times.
✗ Branch 3 not taken.
|
342 | SimpleOptionsParser *result = new SimpleOptionsParser(); |
| 55 | // In contrast to the fuse module, we don't want to taint the process' | ||
| 56 | // environment with parameters from the cvmfs configuration in libcvmfs | ||
| 57 | 342 | result->set_taint_environment(taint_environ); | |
| 58 | // Not strictly necessary but avoids a failure log message | ||
| 59 |
3/6✓ Branch 2 taken 342 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 342 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 342 times.
✗ Branch 10 not taken.
|
342 | result->SetValue("CVMFS_MOUNT_DIR", "/cvmfs"); |
| 60 | 342 | return result; | |
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | 924 | void cvmfs_options_set(SimpleOptionsParser *opts, const char *key, | |
| 65 | const char *value) { | ||
| 66 |
3/6✓ Branch 2 taken 924 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 924 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 924 times.
✗ Branch 10 not taken.
|
924 | opts->SetValue(key, value); |
| 67 | 924 | } | |
| 68 | |||
| 69 | |||
| 70 | ✗ | int cvmfs_options_parse(SimpleOptionsParser *opts, const char *path) { | |
| 71 | ✗ | const bool result = opts->TryParsePath(path); | |
| 72 | ✗ | return result ? 0 : -1; | |
| 73 | } | ||
| 74 | |||
| 75 | ✗ | void cvmfs_options_parse_default(SimpleOptionsParser *opts, const char *fqrn) { | |
| 76 | ✗ | opts->ParseDefault(fqrn); | |
| 77 | } | ||
| 78 | |||
| 79 | ✗ | void cvmfs_options_unset(SimpleOptionsParser *opts, const char *key) { | |
| 80 | ✗ | opts->UnsetValue(key); | |
| 81 | } | ||
| 82 |