Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_dynamic_config.c
Go to the documentation of this file.
2
3#include "native_app_config.h"
5#include "native_support.h"
6
7#include <stdlib.h>
8#include <string.h>
9
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
20 const char *conf_path,
21 const char *key,
22 const char *raw_value
23) {
24 if (raw_value == NULL) {
25 return NULL;
26 }
28 return resolve_conf_relative_path_native(conf_path, raw_value);
29 }
30 return strdup(raw_value);
31}
32
33char *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
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}
char * app_local_conf_path_native(const char *app_root)
Builds the path to an app-local runtime configuration file.
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.
Declares app-local runtime configuration helpers and the app-local configuration record.
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.
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.
int native_dynamic_config_key_is_path(const char *key)
Returns whether a dynamic config key resolves relative to its config file.
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.
Declares Pharos-owned dynamic runtime config resolution helpers.
char * conf_lookup_value(const char *path, const char *key)
Reads a Pharos conf file and looks up one key.
Declares lightweight JSON and conf value lookup helpers.
int streq(const char *a, const char *b)
Tests whether two strings are exactly equal.
int path_exists(const char *path)
Tests whether a filesystem path currently exists.
Declares shared low-level support helpers used across the Pharos native runtime.