1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
* |
4 |
|
|
* Implements the C wrapper of the OptionsManager |
5 |
|
|
*/ |
6 |
|
|
|
7 |
|
|
#include "cvmfs_config.h" |
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 |
|
3 |
SimpleOptionsParser *cvmfs_options_clone(SimpleOptionsParser *opts) { |
21 |
|
|
SimpleOptionsParser *result = new SimpleOptionsParser( |
22 |
|
3 |
*reinterpret_cast<SimpleOptionsParser *>(opts)); |
23 |
|
3 |
return result; |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
|
27 |
|
12 |
void cvmfs_options_fini(SimpleOptionsParser *opts) { |
28 |
✓✗ |
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 |
bool retval = opts->GetValue(key, &arg); |
40 |
✗✓ |
2 |
if (!retval) |
41 |
|
|
return NULL; |
42 |
|
2 |
char *result = strdup(arg.c_str()); |
43 |
✗✓ |
2 |
assert(result != NULL); |
44 |
|
2 |
return result; |
45 |
|
|
} |
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 |
|
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 |
|
21 |
result->SetValue("CVMFS_MOUNT_DIR", "/cvmfs"); |
67 |
|
21 |
return result; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
|
71 |
|
45 |
void cvmfs_options_set( |
72 |
|
|
SimpleOptionsParser *opts, |
73 |
|
|
const char *key, const |
74 |
|
|
char *value) |
75 |
|
|
{ |
76 |
|
45 |
opts->SetValue(key, value); |
77 |
|
45 |
} |
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 |
|
|
|
86 |
|
|
void cvmfs_options_unset(SimpleOptionsParser *opts, const char *key) { |
87 |
|
|
opts->UnsetValue(key); |
88 |
|
|
} |