Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_app_runtime_finalize.c
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Finalizes loaded app runtime records by applying serve overrides and resolving effective runtime paths.
4 */
5
7
9#include "native_app_config.h"
10#include "native_support.h"
11
12#include <stdlib.h>
13#include <string.h>
14
15#ifdef _WIN32
16#define native_runtime_finalize_strdup _strdup
17#else
18#define native_runtime_finalize_strdup strdup
19#endif
20
22 char *app_root,
23 char *build_dir,
24 char *state_path,
25 char *base_path,
26 char *log_path,
27 char *log_format,
28 char *error_report_path,
29 char *debug,
30 char *runtime_conf_path
31) {
32 free(app_root);
33 free(build_dir);
34 free(state_path);
35 free(base_path);
36 free(log_path);
37 free(log_format);
38 free(error_report_path);
39 free(debug);
40 free(runtime_conf_path);
41}
42
43static char *clone_or_empty_finalize(const char *value) {
44 if (value == NULL) {
46 }
48}
49
50static int has_override_value(const char *value) {
51 return value != NULL && value[0] != '\0';
52}
53
54static char *finalize_state_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root, const char *build_dir) {
55 if (config != NULL && has_override_value(config->state_path)) {
57 }
58 if (config != NULL && has_override_value(config->state_dir)) {
59 return effective_app_state_path_native(app_root, build_dir, app->app_id, NULL, config->state_dir);
60 }
63 }
64 return effective_app_state_path_native(app_root, build_dir, app->app_id, NULL, NULL);
65}
66
67static char *finalize_base_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root) {
68 if (config != NULL && has_override_value(config->base_path)) {
69 return effective_app_base_path_native(app_root, config->base_path);
70 }
71 if (app != NULL && has_override_value(app->base_path)) {
73 }
74 return effective_app_base_path_native(app_root, NULL);
75}
76
77static char *finalize_log_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root) {
78 if (config != NULL && has_override_value(config->log_path)) {
79 return effective_app_log_path_native(app_root, app->app_id, config->log_path);
80 }
81 if (has_override_value(app->log_path)) {
83 }
84 return effective_app_log_path_native(app_root, app->app_id, NULL);
85}
86
87static char *finalize_log_format_native(const AppRuntime *app, const char *app_root) {
90 }
91 return effective_app_log_format_native(app_root);
92}
93
94static char *finalize_error_report_path_native(const AppRuntime *app, const char *app_root) {
95 if (app->error_report_path != NULL) {
97 }
99}
100
101static char *finalize_debug_native(const AppRuntime *app, const ServeConfig *config, const char *app_root) {
102 if (config != NULL && has_override_value(config->debug)) {
103 return effective_app_debug_native(app_root, config->debug);
104 }
105 if (has_override_value(app->debug)) {
107 }
108 return effective_app_debug_native(app_root, NULL);
109}
110
111static char *finalize_runtime_conf_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root) {
112 if (config != NULL && has_override_value(config->conf_path)) {
113 return resolved_runtime_conf_path_from_config_native(config, app_root);
114 }
117 }
118 return resolved_runtime_conf_path_from_config_native(config, app_root);
119}
120
121char *resolved_runtime_conf_path_from_config_native(const ServeConfig *config, const char *app_root) {
122 char *cwd;
123 char *resolved;
124 char *local_conf_path;
125 if (config != NULL && config->conf_path != NULL && config->conf_path[0] != '\0') {
127 if (cwd == NULL) {
129 }
130 resolved = resolve_relative_to(cwd, config->conf_path);
131 free(cwd);
132 return resolved;
133 }
134 local_conf_path = app_local_conf_path_native(app_root);
135 if (local_conf_path != NULL) {
136 return local_conf_path;
137 }
138 return NULL;
139}
140
141int finalize_loaded_app_runtime_native(AppRuntime *app, const ServeConfig *config, const char *app_root_override, const char *build_dir_override) {
142 char *app_root = NULL;
143 char *build_dir = NULL;
144 char *state_path = NULL;
145 char *base_path = NULL;
146 char *log_path = NULL;
147 char *log_format = NULL;
148 char *error_report_path = NULL;
149 char *debug = NULL;
150 char *runtime_conf_path = NULL;
151
152 if (app == NULL) {
153 return -1;
154 }
155
156 app_root = native_runtime_finalize_strdup(app_root_override != NULL ? app_root_override : app->app_root);
157 build_dir = native_runtime_finalize_strdup(build_dir_override != NULL ? build_dir_override : app->build_dir);
158 state_path = finalize_state_path_native(app, config, app_root != NULL ? app_root : app->app_root, build_dir != NULL ? build_dir : app->build_dir);
159 base_path = finalize_base_path_native(app, config, app_root != NULL ? app_root : app->app_root);
160 log_path = finalize_log_path_native(app, config, app_root != NULL ? app_root : app->app_root);
161 log_format = finalize_log_format_native(app, app_root != NULL ? app_root : app->app_root);
162 error_report_path = finalize_error_report_path_native(app, app_root != NULL ? app_root : app->app_root);
163 debug = finalize_debug_native(app, config, app_root != NULL ? app_root : app->app_root);
164 if (debug == NULL) {
165 debug = native_runtime_finalize_strdup("false");
166 }
167 runtime_conf_path = finalize_runtime_conf_path_native(app, config, app_root != NULL ? app_root : app->app_root);
168 if (base_path == NULL) {
169 base_path = clone_or_empty_finalize("");
170 }
171
172 if (((app_root_override != NULL || app->app_root != NULL) && app_root == NULL) ||
173 ((build_dir_override != NULL || app->build_dir != NULL) && build_dir == NULL) ||
174 state_path == NULL ||
175 base_path == NULL ||
176 log_path == NULL ||
177 log_format == NULL ||
178 error_report_path == NULL ||
179 debug == NULL) {
180 free_finalize_fields(app_root, build_dir, state_path, base_path, log_path, log_format, error_report_path, debug, runtime_conf_path);
181 return -1;
182 }
183
184 free(app->app_root);
185 free(app->build_dir);
186 free(app->state_path);
187 free(app->base_path);
188 free(app->log_path);
189 free(app->log_format);
190 free(app->error_report_path);
191 free(app->debug);
192 free(app->runtime_conf_path);
193
194 app->app_root = app_root;
195 app->build_dir = build_dir;
196 app->state_path = state_path;
197 app->base_path = base_path;
198 app->log_path = log_path;
199 app->log_format = log_format;
200 app->error_report_path = error_report_path;
201 app->debug = debug;
202 app->runtime_conf_path = runtime_conf_path;
203
204 return 0;
205}
char * app_local_conf_path_native(const char *app_root)
Builds the path to an app-local runtime configuration file.
Declares app-local runtime configuration helpers and the app-local configuration record.
static void free_finalize_fields(char *app_root, char *build_dir, char *state_path, char *base_path, char *log_path, char *log_format, char *error_report_path, char *debug, char *runtime_conf_path)
static char * finalize_log_format_native(const AppRuntime *app, const char *app_root)
static char * finalize_debug_native(const AppRuntime *app, const ServeConfig *config, const char *app_root)
static char * finalize_base_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root)
static char * finalize_state_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root, const char *build_dir)
static char * finalize_error_report_path_native(const AppRuntime *app, const char *app_root)
#define native_runtime_finalize_strdup
char * resolved_runtime_conf_path_from_config_native(const ServeConfig *config, const char *app_root)
Resolves the runtime configuration path that should apply to an app.
int finalize_loaded_app_runtime_native(AppRuntime *app, const ServeConfig *config, const char *app_root_override, const char *build_dir_override)
Applies overrides and derived runtime paths to a loaded app runtime record.
static char * finalize_runtime_conf_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root)
static int has_override_value(const char *value)
static char * clone_or_empty_finalize(const char *value)
static char * finalize_log_path_native(const AppRuntime *app, const ServeConfig *config, const char *app_root)
Declares helpers that finalize loaded app runtime configuration.
char * effective_app_log_path_native(const char *app_root, const char *app_id, const char *log_path_override)
Resolves the effective log file path for an app.
char * effective_app_log_format_native(const char *app_root)
Resolves the effective log format for an app.
char * effective_app_debug_native(const char *app_root, const char *debug_override)
Resolves the effective debug setting for an app.
char * effective_app_error_report_path_native(const char *app_root, const char *app_id)
Resolves the effective error report path for an app.
char * effective_app_state_path_native(const char *app_root, const char *build_dir, const char *app_id, const char *state_path_override, const char *state_dir_override)
Resolves the effective state file path for an app.
char * effective_app_base_path_native(const char *app_root, const char *base_path_override)
Resolves the effective URL base path for an app.
Declares helpers for locating app roots and deriving runtime paths.
char * current_working_directory(void)
Returns the current working directory.
char * resolve_relative_to(const char *base_dir, const char *value)
Resolves a path value relative to a base directory when needed.
Declares shared low-level support helpers used across the Pharos native runtime.
Loaded runtime metadata for one Pharos app artifact.
Parsed native serve configuration used to bootstrap the runtime listener.