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