12#ifndef PHAROS_RUNTIME_STACK_VERSION
13#define PHAROS_RUNTIME_STACK_VERSION "0.7.23"
22#define native_runtime_stack_strdup _strdup
25#define native_runtime_stack_strdup strdup
36 for (cursor = value; *cursor !=
'\0'; cursor++) {
37 if (*cursor ==
'\'') {
43 quoted = (
char *)malloc(
len + 1);
49 for (cursor = value; *cursor !=
'\0'; cursor++) {
50 if (*cursor ==
'\'') {
51 memcpy(out,
"'\\''", 4);
64 char *resolved = NULL;
65 if (conf_path == NULL || conf_path[0] ==
'\0') {
69 if (raw == NULL || raw[0] ==
'\0') {
80 char *quoted_apps_dir = NULL;
84 char *fingerprint = NULL;
85 if (apps_dir == NULL || apps_dir[0] ==
'\0') {
89 if (quoted_apps_dir == NULL) {
95 "find %s -mindepth 1 -maxdepth 2 \\( -name pharos.app.json -o -name app.conf -o -path '*/runtime/*' \\) -type f -print 2>/dev/null | sort | xargs cat 2>/dev/null | shasum -a 256",
98 free(quoted_apps_dir);
99 pipe = popen(command,
"r");
103 if (fgets(buffer,
sizeof(buffer), pipe) != NULL) {
104 size_t len = strcspn(buffer,
" \t\r\n");
117 const char *context = mount;
118 if (context[0] ==
'/') {
121 if (context[0] ==
'\0') {
122 context = app != NULL && app->
app_id != NULL ? app->
app_id :
"";
124 snprintf(buffer, buffer_len,
"%s", context);
130 time_t now = time(NULL);
136 gmtime_s(&tm_utc, &now);
138 gmtime_r(&now, &tm_utc);
140 strftime(timestamp,
sizeof(timestamp),
"%Y-%m-%dT%H:%M:%SZ", &tm_utc);
141 for (i = 0; i < stack->
count; i++) {
143 if (context[0] ==
'\0') {
146 if (loaded_apps.
len > 0) {
152 printf(
"%s INFO app_count: %zu\n", timestamp, stack->
count);
153 printf(
"%s INFO loaded_apps: %s\n", timestamp, loaded_apps.
data != NULL ? loaded_apps.
data :
"");
154 printf(
"%s STATUS listening_on: %s started in: %ldms\n",
166 for (index = 0; index < stack->
count; index++) {
169 size_t mount_len = strlen(mount);
170 if (mount_len == 0) {
176 if (strcmp(path, mount) == 0 || (
starts_with(path, mount) && (path[mount_len] ==
'/' || path[mount_len] ==
'\0' || path[mount_len] ==
'?'))) {
177 if (mount_len > best_len) {
179 best_len = mount_len;
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 * 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.
char * runtime_apps_dir_native(const char *conf_path)
Resolves the apps directory configured for a runtime config file.
#define PHAROS_RUNTIME_STACK_VERSION
char * runtime_apps_fingerprint_native(const char *apps_dir)
Builds a fingerprint string describing the current runtime apps directory state.
static void runtime_loaded_app_context_native(const AppRuntime *app, char *buffer, size_t buffer_len)
static char * shell_quote_runtime_stack_native(const char *value)
#define native_runtime_stack_strdup
void runtime_log_banner_native(const RuntimeStack *stack, const ServeConfig *config, long load_ms)
Emits a startup banner describing the loaded runtime stack.
AppRuntime * runtime_match_app_native(RuntimeStack *stack, const char *path)
Finds the loaded app runtime that should handle a request path.
Declares runtime stack helpers for app discovery, reload detection, and request matching.
void buffer_init(Buffer *buffer)
Initializes a growable buffer to an empty state.
char * dup_range(const char *start, size_t len)
Duplicates a byte range into a newly allocated NUL-terminated string.
void buffer_free(Buffer *buffer)
Releases memory owned by a growable buffer.
char * current_working_directory(void)
Returns the current working directory.
int buffer_append(Buffer *buffer, const void *data, size_t len)
Appends bytes to a growable buffer and maintains a trailing NUL byte.
int starts_with(const char *value, const char *prefix)
Tests whether one string starts with another string.
Declares shared low-level support helpers used across the Pharos native runtime.
Loaded runtime metadata for one Pharos app artifact.
Growable byte buffer used by parsing and string assembly helpers.
In-memory collection of loaded app runtimes served by one listener.
AppRuntime apps[MAX_APPS]
Parsed native serve configuration used to bootstrap the runtime listener.