Pharos
0.7.23
Modern Web Framework & Web App Hosting Service.
Toggle main menu visibility
Loading...
Searching...
No Matches
native_dynamic_config.c
Go to the documentation of this file.
1
#include "
native_dynamic_config.h
"
2
3
#include "
native_app_config.h
"
4
#include "
native_json_config.h
"
5
#include "
native_support.h
"
6
7
#include <stdlib.h>
8
#include <string.h>
9
10
int
native_dynamic_config_key_is_path
(
const
char
*key) {
11
return
key != NULL && (
12
streq
(key,
"db_path"
) ||
13
streq
(key,
"db_tls_root_cert"
) ||
14
streq
(key,
"db_tls_cert"
) ||
15
streq
(key,
"db_tls_key"
)
16
);
17
}
18
19
char
*
native_dynamic_config_resolve_value_dup
(
20
const
char
*conf_path,
21
const
char
*key,
22
const
char
*raw_value
23
) {
24
if
(raw_value == NULL) {
25
return
NULL;
26
}
27
if
(
native_dynamic_config_key_is_path
(key)) {
28
return
resolve_conf_relative_path_native
(conf_path, raw_value);
29
}
30
return
strdup(raw_value);
31
}
32
33
char
*
native_dynamic_config_lookup_raw_dup
(
const
char
*conf_path,
const
char
*key) {
34
if
(conf_path == NULL || conf_path[0] ==
'\0'
|| key == NULL || key[0] ==
'\0'
|| !
path_exists
(conf_path)) {
35
return
NULL;
36
}
37
return
conf_lookup_value
(conf_path, key);
38
}
39
40
char
*
native_dynamic_config_merged_value_dup
(
41
const
char
*app_root,
42
const
char
*runtime_conf_path,
43
const
char
*key
44
) {
45
char
*raw_value = NULL;
46
char
*resolved_value = NULL;
47
char
*app_conf_path = NULL;
48
49
if
(key == NULL || key[0] ==
'\0'
) {
50
return
NULL;
51
}
52
53
raw_value =
native_dynamic_config_lookup_raw_dup
(runtime_conf_path, key);
54
if
(raw_value != NULL) {
55
resolved_value =
native_dynamic_config_resolve_value_dup
(runtime_conf_path, key, raw_value);
56
free(raw_value);
57
return
resolved_value;
58
}
59
60
app_conf_path =
app_local_conf_path_native
(app_root);
61
raw_value =
native_dynamic_config_lookup_raw_dup
(app_conf_path, key);
62
if
(raw_value != NULL) {
63
resolved_value =
native_dynamic_config_resolve_value_dup
(app_conf_path, key, raw_value);
64
free(raw_value);
65
}
66
free(app_conf_path);
67
return
resolved_value;
68
}
app_local_conf_path_native
char * app_local_conf_path_native(const char *app_root)
Builds the path to an app-local runtime configuration file.
Definition
native_app_config.c:44
resolve_conf_relative_path_native
char * resolve_conf_relative_path_native(const char *conf_path, const char *raw_value)
Resolves a config value relative to the directory that owns a config file.
Definition
native_app_config.c:20
native_app_config.h
Declares app-local runtime configuration helpers and the app-local configuration record.
native_dynamic_config_lookup_raw_dup
char * native_dynamic_config_lookup_raw_dup(const char *conf_path, const char *key)
Loads one raw dynamic config value from a config file when it exists.
Definition
native_dynamic_config.c:33
native_dynamic_config_merged_value_dup
char * native_dynamic_config_merged_value_dup(const char *app_root, const char *runtime_conf_path, const char *key)
Loads one merged dynamic config value with runtime-conf precedence over app-local config.
Definition
native_dynamic_config.c:40
native_dynamic_config_key_is_path
int native_dynamic_config_key_is_path(const char *key)
Returns whether a dynamic config key resolves relative to its config file.
Definition
native_dynamic_config.c:10
native_dynamic_config_resolve_value_dup
char * native_dynamic_config_resolve_value_dup(const char *conf_path, const char *key, const char *raw_value)
Resolves one raw dynamic config value against its owning config file.
Definition
native_dynamic_config.c:19
native_dynamic_config.h
Declares Pharos-owned dynamic runtime config resolution helpers.
conf_lookup_value
char * conf_lookup_value(const char *path, const char *key)
Reads a Pharos conf file and looks up one key.
Definition
native_json_config.c:179
native_json_config.h
Declares lightweight JSON and conf value lookup helpers.
streq
int streq(const char *a, const char *b)
Tests whether two strings are exactly equal.
Definition
native_support.c:111
path_exists
int path_exists(const char *path)
Tests whether a filesystem path currently exists.
Definition
native_support.c:168
native_support.h
Declares shared low-level support helpers used across the Pharos native runtime.
src
native_runtime
c
native_dynamic_config.c
Generated by
1.17.0