Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_dynamic_runtime.c File Reference

In-process dynamic-app request handler for the Pharos native runtime. More...

#include "native_dynamic_runtime.h"
#include "native_dynamic_dispatch.h"
#include "native_dynamic_media.h"
#include "native_dynamic_multipart.h"
#include "native_dynamic_request_fields.h"
#include "native_dynamic_relational.h"
#include "native_dynamic_template.h"
#include "native_yyjson_helpers.h"
#include "native_fs.h"
#include "native_http_response.h"
#include "native_support.h"
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  GeneratedAdminSurfaceDescriptor
struct  ResourceLinkDisplay
struct  Sha256Runtime

Macros

#define DYNAMIC_HOST_PROFILE   "dynamic-app"
 Host profile string that triggers in-process dynamic handling.
#define MAX_QUERY_LEN   4096
 Maximum query string length we process.
#define CSRF_COOKIE_NAME   "pharos_csrf"
 CSRF cookie name used by the Pharos framework.
#define SESSION_COOKIE_NAME   "pharos_session"
 Session cookie name used by the Pharos framework.
#define CSRF_TOKEN_HEX_LEN   48
 Maximum CSRF token length (24 bytes = 48 hex chars).
#define CSRF_COOKIE_MAX_AGE   "7200"
 CSRF cookie max-age in seconds.
#define SHA256_BLOCK_SIZE   64
#define SHA256_DIGEST_SIZE   32

Functions

static yyjson_valstate_array_runtime_local (yyjson_val *root, const char *field_name)
static yyjson_valfind_business_by_slug_runtime_local (yyjson_val *root, const char *business_slug)
static yyjson_valfind_business_by_id_runtime_local (yyjson_val *root, long business_id)
 Finds one business record by numeric id in the runtime state.
static yyjson_valfind_user_by_id_runtime_local (yyjson_val *root, long user_id)
static int long_from_value_runtime_local (yyjson_val *value, long *out_value)
static yyjson_valfind_service_for_business_runtime_local (yyjson_val *root, long service_id, long business_id)
static yyjson_valfind_appointment_by_id_runtime_local (yyjson_val *root, long appointment_id)
static char * page_title_dup_runtime (yyjson_val *page_spec_root, yyjson_val *body_params_root)
static char * generated_surface_fixture_path_dup_runtime (const AppRuntime *app)
 Resolves the generated-surface fixture path for the active app.
static char * request_path_dup_runtime (const HttpRequest *request)
static char * generated_admin_manage_page_params_json_dup_runtime (const char *state_path, const char *business_slug, const char *surface_kind, const char *error_text)
static char * business_availability_edit_page_params_json_dup_runtime (const char *state_path, const char *business_slug, long availability_id, const char *error_text)
static char * profile_page_params_json_dup_runtime_local (const char *state_path, long user_id, const char *payment_preference_options_html)
 Builds profile-page template params directly from runtime state.
static yyjson_valproof_state_root_load_runtime (const char *state_path, yyjson_doc **doc_out)
static char * proof_home_page_params_json_dup_runtime (const char *state_path)
static int write_proof_state_api_response (NativeConnection *connection, const char *state_path)
static int text_append_format_runtime_local (char **buffer, size_t *length, size_t *capacity, const char *format,...)
static char * register_page_params_json_dup_runtime (const char *query_string)
static const GeneratedAdminSurfaceDescriptorgenerated_admin_surface_descriptor_runtime (const char *surface_kind)
 Returns the generated-admin descriptor for one declared manage surface.
static int append_generated_admin_surface_rows_runtime (const GeneratedAdminSurfaceDescriptor *descriptor, yyjson_val *root, long business_id, const char *business_slug, char **row_html, size_t *row_html_length, size_t *row_html_capacity)
 Appends row HTML for one generated-admin manage surface.
static int append_generated_admin_surface_form_fields_runtime (const GeneratedAdminSurfaceDescriptor *descriptor, char **form_fields_html, size_t *form_fields_length, size_t *form_fields_capacity, const char *day_options_html)
 Appends create-form field HTML for one generated-admin surface.
static char * generated_admin_surface_filter_controls_dup_runtime (const GeneratedAdminSurfaceDescriptor *descriptor)
 Duplicates the filter-control HTML for one generated-admin surface.
static void generated_admin_surface_page_copy_runtime (yyjson_mut_doc *doc, yyjson_mut_val *page, const GeneratedAdminSurfaceDescriptor *descriptor, const char *filter_controls_html)
 Writes descriptor-owned page copy into one generated-admin params document.
static char * password_reset_request_page_params_json_dup_runtime (void)
static char * password_reset_sent_page_params_json_dup_runtime (const char *preview_path)
static char * password_reset_complete_page_params_json_dup_runtime (const char *request_path)
 Builds native template params for the password-reset completion page.
static char * invite_created_page_params_json_dup_runtime (const char *invite_email, const char *invite_path, const char *return_path)
 Builds template params for the invite-created confirmation page.
static char * invite_accept_page_params_json_dup_runtime (const char *invite_kind, const char *target_business_name, const char *error_message, const char *invite_email, const char *form_action)
 Builds template params for the invite-accept page.
static char * invite_accept_done_page_params_json_dup_runtime (const char *continue_path)
 Builds template params for the invite-accepted confirmation page.
static char * service_edit_page_params_json_dup_runtime (const char *state_path, const char *business_slug, long service_id)
char * business_landing_render_page_params_json_dup_runtime (const char *state_path, const char *business_slug, long user_id, const char *app_root)
char * business_calendar_render_page_params_json_dup_runtime (const char *state_path, const char *business_slug, const char *app_root, const char *selected_year_text, const char *selected_month_text, const char *selected_date_text)
char * diagnostics_render_page_params_json_dup_runtime (const char *state_path)
static unsigned char * request_body_bytes_dup_runtime (const HttpRequest *request, size_t *out_size)
static int resource_link_display_load_runtime (yyjson_val *root, const char *resource_collection_name, long resource_id, ResourceLinkDisplay *display)
 Loads slug and display-name fields for one linked resource id.
static void resource_link_display_free_runtime (ResourceLinkDisplay *display)
 Frees a linked-resource display record.
static int append_profile_subscription_rows_runtime (yyjson_val *root, long user_id, char **subscriptions_block, size_t *subscriptions_length, size_t *subscriptions_capacity)
 Appends profile subscription rows for one user into an HTML list buffer.
static char * profile_subscriptions_block_dup_runtime (yyjson_val *root, long user_id)
 Builds the profile subscription block for one user.
static int runtime_page_params_add_string_runtime (yyjson_mut_doc *doc, yyjson_mut_val *root, const char *key, const char *value)
 Builds native template params for the password-reset request page.
static int runtime_page_params_add_escaped_string_runtime (yyjson_mut_doc *doc, yyjson_mut_val *root, const char *key, const char *value)
 Adds one HTML-escaped string field to a page-params JSON object.
static char * runtime_page_params_write_runtime (yyjson_mut_doc *doc, yyjson_mut_val *root)
 Finalizes and writes one page-params document as compact JSON.
static char * password_reset_preview_html_dup_runtime (const char *preview_path)
 Builds the optional password-reset preview HTML block.
static char * invite_accept_target_html_dup_runtime (const char *target_business_name)
 Builds the optional invite target HTML fragment.
static char * request_form_value_dup_runtime (const HttpRequest *request, const char *field_name)
static char * password_hash_dup_runtime (const char *password_value)
static char * resolve_declared_page_params_json_runtime (const AppRuntime *app, const HttpRequest *request, const NativeDynamicRouteMatch *match, const char *request_path, const char *query_string, long active_user_id)
 Resolves declared page parameter JSON for the matched page route.
static char * resolve_invite_accept_page_params_json_runtime (const AppRuntime *app, const NativeDynamicRouteMatch *match, const char *request_path)
 Resolves invite-accept page parameters from the current app state.
static int handle_password_reset_request_action_runtime (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request)
 Handles password-reset request action processing.
static int handle_password_reset_complete_action_runtime (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const NativeDynamicRouteMatch *match)
 Handles password-reset completion action processing.
static int handle_issue_business_invite_action_runtime (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const NativeDynamicRouteMatch *match)
 Handles invite creation for tenant-backed business membership flows.
static int handle_accept_invite_action_runtime (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const NativeDynamicRouteMatch *match)
 Handles invite acceptance and initial session creation.
static long state_tenant_id_for_business_runtime_local (yyjson_val *root, long business_id)
 Resolves the tenant id that owns a business record.
static int user_has_active_tenant_membership_runtime_local (yyjson_val *root, long user_id, long tenant_id)
 Checks whether a user has an active membership on a tenant.
static const char * membership_role_id_for_invite_runtime_local (const char *role_hint, const char *account_type)
 Maps invite role hints onto the canonical tenant membership role id.
static int persist_app_state_text_runtime_local (const AppRuntime *app, const char *state_json_text)
 Appends a native auth/rate-limit event row to runtime state.
static int append_rate_limit_event_runtime_local (const AppRuntime *app, const char *policy_key, const char *bucket_key, const char *outcome)
static int render_declared_page_response_runtime (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const char *page_id, const char *request_path, const char *body_params_json)
static void write_json_error (NativeConnection *connection, int status, const char *status_text, const char *error_kind, const char *message)
 Writes a JSON error response to a connection.
static void csrf_generate_random_hex (char *buf, size_t byte_count)
 Generates a random hex token for CSRF protection.
static char * csrf_token_from_cookie (const char *cookie_header)
 Extracts the CSRF token from the request cookie header.
static char * csrf_token_for_response (const char *cookie_header)
 Returns the CSRF token to use for a response.
static int request_has_session_cookie (const char *cookie_header)
static char * request_header_value_dup_runtime (const char *headers, const char *header_name)
static char * csrf_request_token_dup_runtime (const HttpRequest *request, const char *form_body)
static int csrf_request_valid_runtime (const HttpRequest *request, const char *form_body)
static char * payment_preference_options_html_dup_runtime (const char *selected_value)
static char * request_body_text_dup_runtime (const HttpRequest *request)
static char * route_request_path_dup_runtime (const AppRuntime *app, const HttpRequest *request)
static char * proof_state_seed_json_dup_runtime (void)
static char * proof_task_items_html_dup_runtime (yyjson_val *items)
static int text_append_runtime_local (char **buffer, size_t *length, size_t *capacity, const char *text)
static char * day_of_week_options_html_dup_runtime (const char *selected_day)
static int is_business_services_api_list_path_runtime (const char *request_path)
 Tests whether a request path is the exact business services list API path.
static int is_business_availability_api_list_path_runtime (const char *request_path)
 Tests whether a request path is the exact business availability list API path.
static int is_business_services_api_schema_path_runtime (const char *request_path)
 Tests whether a request path is the exact business services schema API path.
static int is_business_availability_api_schema_path_runtime (const char *request_path)
 Tests whether a request path is the exact business availability schema API path.
static int valid_day_of_week_runtime (const char *day_text)
 Resolves the final page title from a declarative page spec and params.
static int time_text_to_minutes_runtime (const char *time_text, int *minutes_out)
static int write_business_services_api_response (NativeConnection *connection, const char *state_path, const char *business_slug)
static int write_business_availability_api_response (NativeConnection *connection, const char *state_path, const char *business_slug)
static int write_generated_surface_schema_response (NativeConnection *connection, const AppRuntime *app, const char *state_path, const char *business_slug, const char *surface_id)
 Writes one generated-surface schema object from the declarative fixture.
static char * login_page_params_json_dup_runtime (const char *query_string, const char *error_message)
static int secure_text_equals (const char *left, const char *right)
static uint32_t sha256_rotr (uint32_t value, uint32_t bits)
static void sha256_transform_runtime (Sha256Runtime *ctx, const uint8_t data[])
static void sha256_init_runtime (Sha256Runtime *ctx)
static void sha256_update_runtime (Sha256Runtime *ctx, const uint8_t *data, size_t len)
static void sha256_final_runtime (Sha256Runtime *ctx, uint8_t hash[SHA256_DIGEST_SIZE])
static void bytes_to_hex_runtime (const uint8_t *bytes, size_t len, char *hex_out)
static void hmac_sha256_runtime (const uint8_t *key, size_t key_len, const uint8_t *data, size_t data_len, uint8_t out[SHA256_DIGEST_SIZE])
static int pbkdf2_sha256_runtime (const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint32_t iterations, uint8_t *out, size_t out_len)
static int verify_password_hash_runtime (const char *stored_hash, const char *password_value, const char *username_value)
static char * sha256_hex_dup_runtime (const char *value)
static char * token_hash_dup_runtime (const char *token_value)
static int now_iso_utc_runtime (char out[21])
static int iso_after_seconds_runtime (long delta_seconds, char out[21])
static yyjson_valfind_user_by_username_runtime_local (yyjson_val *root, const char *username)
static int value_long_equals_runtime_local (yyjson_val *value, long expected_value)
static int parse_ymd_runtime_local (const char *date_value, int *year_out, int *month_out, int *day_out)
static int time_ranges_overlap_runtime_local (int start_a_minutes, int duration_a, int start_b_minutes, int duration_b)
static const char * day_abbrev_for_ymd_runtime_local (int year, int month, int day)
static int business_open_for_slot_runtime_local (yyjson_val *root, long business_id, const char *date_value, const char *time_value, long duration_minutes)
static int technician_booked_for_slot_runtime_local (yyjson_val *root, long technician_id, const char *date_value, const char *time_value, long duration_minutes)
static long assign_technician_for_slot_runtime_local (yyjson_val *root, long business_id, long service_id, const char *date_value, const char *time_value)
static long next_array_id_runtime_local (yyjson_val *rows)
static long active_user_id_from_cookie_runtime (const char *state_path, const char *cookie_header)
static char * session_cookie_header_dup_runtime (const AppRuntime *app, const HttpRequest *request, const char *session_token, int clear_cookie)
static const char * default_signed_in_path_runtime (yyjson_val *user)
static int revoke_session_by_cookie_runtime (const AppRuntime *app, const char *cookie_header)
static int issue_browser_session_runtime (const AppRuntime *app, const HttpRequest *request, long user_id, char **session_token_out, char **session_cookie_header_out)
static char * csrf_inject_hidden_inputs (const char *html, const char *csrf_token)
 Injects CSRF hidden inputs into form tags in an HTML string.
static void write_html_response_with_headers_runtime (NativeConnection *connection, int status, const char *status_text, const char *html, const char *csrf_token, const char *extra_headers)
 Writes an HTML response to a connection, optionally with a CSRF cookie.
static void write_html_response (NativeConnection *connection, int status, const char *status_text, const char *html, const char *csrf_token)
static int render_declared_page_response_with_headers_runtime (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const char *page_id, const char *request_path, const char *body_params_json, const char *extra_headers)
static void extract_query (const char *target, char *dest, size_t dest_size)
 Extracts the query portion from a target string.
static void serve_dynamic_home_page (NativeConnection *connection, const char *app_id, const char *route_id, const char *csrf_token)
 Serves the Pharos dynamic-app home page or a generic landing page.
static int handle_page_route (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const NativeDynamicRouteMatch *match, const char *request_path, const char *query_string, const char *csrf_token)
 Handles a matched page route using dynamic template rendering.
static int handle_action_route (NativeConnection *connection, const AppRuntime *app, const HttpRequest *request, const NativeDynamicRouteMatch *match)
 Handles a matched action route.
const char * native_dynamic_runtime_host_profile (void)
 Returns the canonical host profile string that this module handles.
int native_dynamic_runtime_handle_request (const AppRuntime *app, const HttpRequest *request, NativeConnection *connection)
 Serves one dynamic-app request entirely in-process.

Detailed Description

In-process dynamic-app request handler for the Pharos native runtime.

Replaces the former spawn_app_request() path for apps whose host_profile is "dynamic-app". Instead of forking a child process, the request is handled entirely within the Pharos binary.

Flow:

  1. Resolve the route fixture for the app.
  2. Attempt static-asset serving (static/, media/, well-known JSON).
  3. Match the request path against the declared route fixture.
  4. Dispatch page and action routes through the in-process handler.
  5. Fall back to the dispatch table for API-style routes.
  6. Return a 404 for unmatched paths.

Definition in file native_dynamic_runtime.c.

Macro Definition Documentation

◆ CSRF_COOKIE_MAX_AGE

#define CSRF_COOKIE_MAX_AGE   "7200"

CSRF cookie max-age in seconds.

Definition at line 63 of file native_dynamic_runtime.c.

Referenced by write_html_response_with_headers_runtime().

◆ CSRF_COOKIE_NAME

#define CSRF_COOKIE_NAME   "pharos_csrf"

CSRF cookie name used by the Pharos framework.

Definition at line 54 of file native_dynamic_runtime.c.

Referenced by csrf_token_from_cookie(), and write_html_response_with_headers_runtime().

◆ CSRF_TOKEN_HEX_LEN

#define CSRF_TOKEN_HEX_LEN   48

◆ DYNAMIC_HOST_PROFILE

#define DYNAMIC_HOST_PROFILE   "dynamic-app"

Host profile string that triggers in-process dynamic handling.

Definition at line 48 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_host_profile().

◆ MAX_QUERY_LEN

#define MAX_QUERY_LEN   4096

Maximum query string length we process.

Definition at line 51 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_handle_request().

◆ SESSION_COOKIE_NAME

#define SESSION_COOKIE_NAME   "pharos_session"

Session cookie name used by the Pharos framework.

Definition at line 57 of file native_dynamic_runtime.c.

Referenced by active_user_id_from_cookie_runtime(), request_has_session_cookie(), revoke_session_by_cookie_runtime(), and session_cookie_header_dup_runtime().

◆ SHA256_BLOCK_SIZE

#define SHA256_BLOCK_SIZE   64

Definition at line 2524 of file native_dynamic_runtime.c.

Referenced by hmac_sha256_runtime().

◆ SHA256_DIGEST_SIZE

Function Documentation

◆ active_user_id_from_cookie_runtime()

◆ append_generated_admin_surface_form_fields_runtime()

int append_generated_admin_surface_form_fields_runtime ( const GeneratedAdminSurfaceDescriptor * descriptor,
char ** form_fields_html,
size_t * form_fields_length,
size_t * form_fields_capacity,
const char * day_options_html )
static

Appends create-form field HTML for one generated-admin surface.

Parameters
descriptorSurface descriptor that owns the create-form contract.
form_fields_htmlAccumulated form field output buffer.
form_fields_lengthCurrent form field length.
form_fields_capacityCurrent form field capacity.
day_options_htmlOptional prebuilt day-of-week options for availability surfaces.
Returns
1 on success, or 0 on allocation or formatting failure.

Definition at line 969 of file native_dynamic_runtime.c.

References streq(), GeneratedAdminSurfaceDescriptor::surface_kind, text_append_format_runtime_local(), and text_append_runtime_local().

Referenced by generated_admin_manage_page_params_json_dup_runtime().

◆ append_generated_admin_surface_rows_runtime()

int append_generated_admin_surface_rows_runtime ( const GeneratedAdminSurfaceDescriptor * descriptor,
yyjson_val * root,
long business_id,
const char * business_slug,
char ** row_html,
size_t * row_html_length,
size_t * row_html_capacity )
static

Appends row HTML for one generated-admin manage surface.

Parameters
descriptorSurface descriptor that owns the row contract.
rootLoaded runtime state root.
business_idCurrent business identifier.
business_slugCurrent business slug used in edit links.
row_htmlAccumulated row HTML output buffer.
row_html_lengthCurrent row HTML length.
row_html_capacityCurrent row HTML capacity.
Returns
1 on success, or 0 on allocation or formatting failure.

Definition at line 854 of file native_dynamic_runtime.c.

References GeneratedAdminSurfaceDescriptor::empty_state_row_html, native_json_obj_get(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), GeneratedAdminSurfaceDescriptor::resource_collection_name, state_array_runtime_local(), streq(), GeneratedAdminSurfaceDescriptor::surface_kind, GeneratedAdminSurfaceDescriptor::surface_path_segment, text_append_format_runtime_local(), text_append_runtime_local(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_get_bool(), and yyjson_is_obj().

Referenced by generated_admin_manage_page_params_json_dup_runtime().

◆ append_profile_subscription_rows_runtime()

int append_profile_subscription_rows_runtime ( yyjson_val * root,
long user_id,
char ** subscriptions_block,
size_t * subscriptions_length,
size_t * subscriptions_capacity )
static

Appends profile subscription rows for one user into an HTML list buffer.

Parameters
rootLoaded runtime state root.
user_idActive signed-in user id.
subscriptions_blockAccumulated subscription row HTML.
subscriptions_lengthCurrent subscription row length.
subscriptions_capacityCurrent subscription row capacity.
Returns
1 on success, or 0 on allocation or formatting failure.

Definition at line 1125 of file native_dynamic_runtime.c.

References native_json_obj_get_long_default(), resource_link_display_free_runtime(), resource_link_display_load_runtime(), ResourceLinkDisplay::resource_name, ResourceLinkDisplay::resource_slug, state_array_runtime_local(), text_append_format_runtime_local(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), and yyjson_is_obj().

Referenced by profile_subscriptions_block_dup_runtime().

◆ append_rate_limit_event_runtime_local()

◆ assign_technician_for_slot_runtime_local()

◆ business_availability_edit_page_params_json_dup_runtime()

◆ business_calendar_render_page_params_json_dup_runtime()

◆ business_landing_render_page_params_json_dup_runtime()

◆ business_open_for_slot_runtime_local()

int business_open_for_slot_runtime_local ( yyjson_val * root,
long business_id,
const char * date_value,
const char * time_value,
long duration_minutes )
static

◆ bytes_to_hex_runtime()

void bytes_to_hex_runtime ( const uint8_t * bytes,
size_t len,
char * hex_out )
static

◆ csrf_generate_random_hex()

void csrf_generate_random_hex ( char * buf,
size_t byte_count )
static

Generates a random hex token for CSRF protection.

Produces byte_count random bytes encoded as hex (so the returned string is byte_count * 2 characters long).

Parameters
bufDestination buffer (must be at least byte_count*2+1).
byte_countNumber of random bytes to generate.

Definition at line 280 of file native_dynamic_runtime.c.

Referenced by csrf_token_for_response(), handle_issue_business_invite_action_runtime(), handle_password_reset_request_action_runtime(), issue_browser_session_runtime(), and password_hash_dup_runtime().

◆ csrf_inject_hidden_inputs()

char * csrf_inject_hidden_inputs ( const char * html,
const char * csrf_token )
static

Injects CSRF hidden inputs into form tags in an HTML string.

Scans html for <form ... method="post" ...> tags and inserts a hidden input field carrying the CSRF token after the opening tag.

Parameters
htmlOriginal HTML string.
csrf_tokenCSRF token value to inject.
Returns
Newly allocated modified HTML string, or NULL on failure. Caller must free. If injection is not needed, returns a strdup of the original html.

Definition at line 3654 of file native_dynamic_runtime.c.

Referenced by handle_page_route(), and render_declared_page_response_with_headers_runtime().

◆ csrf_request_token_dup_runtime()

char * csrf_request_token_dup_runtime ( const HttpRequest * request,
const char * form_body )
static

◆ csrf_request_valid_runtime()

int csrf_request_valid_runtime ( const HttpRequest * request,
const char * form_body )
static

◆ csrf_token_for_response()

char * csrf_token_for_response ( const char * cookie_header)
static

Returns the CSRF token to use for a response.

Reads the token from the request cookie. If absent, generates a new random token.

Parameters
cookie_headerRaw Cookie header value, or NULL.
Returns
Newly allocated token string. Caller must free.

Definition at line 326 of file native_dynamic_runtime.c.

References csrf_generate_random_hex(), csrf_token_from_cookie(), and CSRF_TOKEN_HEX_LEN.

Referenced by native_dynamic_runtime_handle_request(), and render_declared_page_response_with_headers_runtime().

◆ csrf_token_from_cookie()

char * csrf_token_from_cookie ( const char * cookie_header)
static

Extracts the CSRF token from the request cookie header.

Parameters
cookie_headerRaw Cookie header value, or NULL.
Returns
Newly allocated token string, or NULL if not found. Caller must free.

Definition at line 313 of file native_dynamic_runtime.c.

References CSRF_COOKIE_NAME, and native_dynamic_cookie_value().

Referenced by csrf_request_valid_runtime(), and csrf_token_for_response().

◆ day_abbrev_for_ymd_runtime_local()

const char * day_abbrev_for_ymd_runtime_local ( int year,
int month,
int day )
static

◆ day_of_week_options_html_dup_runtime()

char * day_of_week_options_html_dup_runtime ( const char * selected_day)
static

◆ default_signed_in_path_runtime()

const char * default_signed_in_path_runtime ( yyjson_val * user)
static

◆ diagnostics_render_page_params_json_dup_runtime()

◆ extract_query()

void extract_query ( const char * target,
char * dest,
size_t dest_size )
static

Extracts the query portion from a target string.

Parameters
targetRaw request target (may contain a ? ).
destDestination buffer.
dest_sizeSize of the destination buffer.

Definition at line 3941 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_handle_request().

◆ find_appointment_by_id_runtime_local()

yyjson_val * find_appointment_by_id_runtime_local ( yyjson_val * root,
long appointment_id )
static

◆ find_business_by_id_runtime_local()

yyjson_val * find_business_by_id_runtime_local ( yyjson_val * root,
long business_id )
static

Finds one business record by numeric id in the runtime state.

Parameters
rootLoaded runtime state root.
business_idBusiness id to match.
Returns
Matching business object, or NULL when not found.

Definition at line 2923 of file native_dynamic_runtime.c.

References native_json_obj_get_long_default(), state_array_runtime_local(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), and yyjson_is_obj().

Referenced by handle_accept_invite_action_runtime(), and resolve_invite_accept_page_params_json_runtime().

◆ find_business_by_slug_runtime_local()

◆ find_service_for_business_runtime_local()

◆ find_user_by_id_runtime_local()

◆ find_user_by_username_runtime_local()

yyjson_val * find_user_by_username_runtime_local ( yyjson_val * root,
const char * username )
static

◆ generated_admin_manage_page_params_json_dup_runtime()

◆ generated_admin_surface_descriptor_runtime()

const GeneratedAdminSurfaceDescriptor * generated_admin_surface_descriptor_runtime ( const char * surface_kind)
static

Returns the generated-admin descriptor for one declared manage surface.

Parameters
surface_kindSurface identifier requested by the page route.
Returns
Matching descriptor, or NULL when the surface is unsupported.

Definition at line 782 of file native_dynamic_runtime.c.

References streq().

Referenced by generated_admin_manage_page_params_json_dup_runtime().

◆ generated_admin_surface_filter_controls_dup_runtime()

char * generated_admin_surface_filter_controls_dup_runtime ( const GeneratedAdminSurfaceDescriptor * descriptor)
static

Duplicates the filter-control HTML for one generated-admin surface.

Parameters
descriptorSurface descriptor that owns the filter-control contract.
Returns
Newly allocated HTML string, or NULL on allocation failure.

Definition at line 1020 of file native_dynamic_runtime.c.

References GeneratedAdminSurfaceDescriptor::default_filter_controls_html.

Referenced by generated_admin_manage_page_params_json_dup_runtime().

◆ generated_admin_surface_page_copy_runtime()

void generated_admin_surface_page_copy_runtime ( yyjson_mut_doc * doc,
yyjson_mut_val * page,
const GeneratedAdminSurfaceDescriptor * descriptor,
const char * filter_controls_html )
static

Writes descriptor-owned page copy into one generated-admin params document.

Parameters
docMutable document that owns the page object.
pageMutable page params object.
descriptorSurface descriptor that owns the page copy.
filter_controls_htmlEffective filter-control HTML for the page.

Definition at line 1037 of file native_dynamic_runtime.c.

References GeneratedAdminSurfaceDescriptor::create_button_label, GeneratedAdminSurfaceDescriptor::create_title, GeneratedAdminSurfaceDescriptor::filter_title, GeneratedAdminSurfaceDescriptor::header_html, GeneratedAdminSurfaceDescriptor::records_title, GeneratedAdminSurfaceDescriptor::sort_options_html, GeneratedAdminSurfaceDescriptor::surface_intro, GeneratedAdminSurfaceDescriptor::surface_title, and yyjson_mut_obj_add_strcpy().

Referenced by generated_admin_manage_page_params_json_dup_runtime().

◆ generated_surface_fixture_path_dup_runtime()

char * generated_surface_fixture_path_dup_runtime ( const AppRuntime * app)
static

Resolves the generated-surface fixture path for the active app.

Prefers the built-artifact copy and falls back to the app-root copy.

Parameters
appActive app runtime.
Returns
Newly allocated path string, or NULL when unavailable. Caller must free.

Definition at line 1856 of file native_dynamic_runtime.c.

References AppRuntime::app_root, AppRuntime::artifact_dir, join_base_relative_path_dup_runtime(), and path_exists().

Referenced by write_generated_surface_schema_response().

◆ handle_accept_invite_action_runtime()

int handle_accept_invite_action_runtime ( NativeConnection * connection,
const AppRuntime * app,
const HttpRequest * request,
const NativeDynamicRouteMatch * match )
static

Handles invite acceptance and initial session creation.

Parameters
connectionActive client connection.
appActive app runtime.
requestActive HTTP request.
matchMatched action route.
Returns
HTTP status code written to the connection.

Definition at line 4690 of file native_dynamic_runtime.c.

References default_signed_in_path_runtime(), find_business_by_id_runtime_local(), find_user_by_id_runtime_local(), find_user_by_username_runtime_local(), invite_accept_done_page_params_json_dup_runtime(), issue_browser_session_runtime(), membership_role_id_for_invite_runtime_local(), native_dynamic_dispatch_extract_param(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), native_send_text_response(), next_array_id_runtime_local(), now_iso_utc_runtime(), password_hash_dup_runtime(), NativeDynamicRouteMatch::path, persist_app_state_text_runtime_local(), render_declared_page_response_with_headers_runtime(), request_form_value_dup_runtime(), request_path_dup_runtime(), state_array_runtime_local(), AppRuntime::state_path, streq(), token_hash_dup_runtime(), write_json_error(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_doc_mut_copy(), yyjson_equals_str(), yyjson_get_str(), yyjson_is_null(), yyjson_is_obj(), yyjson_is_str(), yyjson_mut_arr(), yyjson_mut_arr_append(), yyjson_mut_arr_get(), yyjson_mut_doc_free(), yyjson_mut_doc_get_root(), yyjson_mut_int(), yyjson_mut_is_arr(), yyjson_mut_obj(), yyjson_mut_obj_add_bool(), yyjson_mut_obj_add_int(), yyjson_mut_obj_add_strcpy(), yyjson_mut_obj_get(), yyjson_mut_obj_put(), yyjson_mut_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by handle_action_route().

◆ handle_action_route()

int handle_action_route ( NativeConnection * connection,
const AppRuntime * app,
const HttpRequest * request,
const NativeDynamicRouteMatch * match )
static

Handles a matched action route.

For now, POST actions return a JSON acknowledgement. Full action processing will be added in later slices.

Definition at line 5252 of file native_dynamic_runtime.c.

References NativeDynamicRouteMatch::action_id, active_user_id_from_cookie_runtime(), AppRuntime::app_id, append_rate_limit_event_runtime_local(), AppRuntime::artifact_dir, assign_technician_for_slot_runtime_local(), AppRuntime::base_path, HttpRequest::body_file_path, business_open_for_slot_runtime_local(), HttpRequest::content_type, HttpRequest::cookie, csrf_request_valid_runtime(), default_signed_in_path_runtime(), ensure_business_media_tree(), find_business_by_slug_runtime_local(), find_service_for_business_runtime_local(), find_user_by_username_runtime_local(), handle_accept_invite_action_runtime(), handle_issue_business_invite_action_runtime(), handle_password_reset_complete_action_runtime(), handle_password_reset_request_action_runtime(), HttpRequest::is_multipart, issue_browser_session_runtime(), login_page_params_json_dup_runtime(), HttpRequest::method, native_connection_printf(), native_dynamic_dispatch_extract_param(), native_dynamic_form_value(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), native_send_text_response(), next_array_id_runtime_local(), NativeDynamicRouteMatch::path, persist_app_state_text_runtime_local(), proof_state_root_load_runtime(), remove_media_url_file(), render_declared_page_response_runtime(), request_body_text_dup_runtime(), request_form_value_dup_runtime(), request_path_dup_runtime(), revoke_session_by_cookie_runtime(), session_cookie_header_dup_runtime(), state_array_runtime_local(), AppRuntime::state_path, store_uploaded_media(), streq(), time_text_to_minutes_runtime(), valid_day_of_week_runtime(), verify_password_hash_runtime(), write_json_error(), yyjson_arr_get(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_arr_size(), yyjson_doc_get_root(), yyjson_doc_mut_copy(), yyjson_get_bool(), yyjson_is_arr(), yyjson_is_obj(), yyjson_mut_arr(), yyjson_mut_arr_append(), yyjson_mut_arr_foreach, yyjson_mut_arr_get(), yyjson_mut_arr_remove(), yyjson_mut_doc_free(), yyjson_mut_doc_get_root(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_is_arr(), yyjson_mut_is_obj(), yyjson_mut_obj(), yyjson_mut_obj_add_bool(), yyjson_mut_obj_add_int(), yyjson_mut_obj_add_strcpy(), yyjson_mut_obj_get(), yyjson_mut_obj_put(), yyjson_mut_sint(), yyjson_mut_strcpy(), yyjson_mut_write(), yyjson_val_mut_copy(), and YYJSON_WRITE_NOFLAG.

Referenced by native_dynamic_runtime_handle_request().

◆ handle_issue_business_invite_action_runtime()

int handle_issue_business_invite_action_runtime ( NativeConnection * connection,
const AppRuntime * app,
const HttpRequest * request,
const NativeDynamicRouteMatch * match )
static

Handles invite creation for tenant-backed business membership flows.

Parameters
connectionActive client connection.
appActive app runtime.
requestActive HTTP request.
matchMatched action route.
Returns
HTTP status code written to the connection.

Definition at line 4521 of file native_dynamic_runtime.c.

References active_user_id_from_cookie_runtime(), HttpRequest::cookie, csrf_generate_random_hex(), CSRF_TOKEN_HEX_LEN, find_business_by_slug_runtime_local(), invite_created_page_params_json_dup_runtime(), iso_after_seconds_runtime(), membership_role_id_for_invite_runtime_local(), native_dynamic_dispatch_extract_param(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get_long_default(), native_send_text_response(), next_array_id_runtime_local(), now_iso_utc_runtime(), NativeDynamicRouteMatch::path, persist_app_state_text_runtime_local(), render_declared_page_response_runtime(), request_form_value_dup_runtime(), request_path_dup_runtime(), state_array_runtime_local(), AppRuntime::state_path, state_tenant_id_for_business_runtime_local(), token_hash_dup_runtime(), user_has_active_tenant_membership_runtime_local(), write_json_error(), yyjson_doc_get_root(), yyjson_doc_mut_copy(), yyjson_mut_arr(), yyjson_mut_arr_append(), yyjson_mut_doc_free(), yyjson_mut_doc_get_root(), yyjson_mut_is_arr(), yyjson_mut_is_obj(), yyjson_mut_null(), yyjson_mut_obj(), yyjson_mut_obj_add_int(), yyjson_mut_obj_add_strcpy(), yyjson_mut_obj_get(), yyjson_mut_obj_put(), yyjson_mut_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by handle_action_route().

◆ handle_page_route()

int handle_page_route ( NativeConnection * connection,
const AppRuntime * app,
const HttpRequest * request,
const NativeDynamicRouteMatch * match,
const char * request_path,
const char * query_string,
const char * csrf_token )
static

◆ handle_password_reset_complete_action_runtime()

◆ handle_password_reset_request_action_runtime()

◆ hmac_sha256_runtime()

void hmac_sha256_runtime ( const uint8_t * key,
size_t key_len,
const uint8_t * data,
size_t data_len,
uint8_t out[SHA256_DIGEST_SIZE] )
static

◆ invite_accept_done_page_params_json_dup_runtime()

char * invite_accept_done_page_params_json_dup_runtime ( const char * continue_path)
static

Builds template params for the invite-accepted confirmation page.

Parameters
continue_pathPost-accept landing path.
Returns
Newly allocated compact JSON string, or NULL on failure.

Definition at line 2286 of file native_dynamic_runtime.c.

References runtime_page_params_add_escaped_string_runtime(), runtime_page_params_write_runtime(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), and yyjson_mut_obj().

Referenced by handle_accept_invite_action_runtime().

◆ invite_accept_page_params_json_dup_runtime()

char * invite_accept_page_params_json_dup_runtime ( const char * invite_kind,
const char * target_business_name,
const char * error_message,
const char * invite_email,
const char * form_action )
static

Builds template params for the invite-accept page.

Parameters
invite_kindInvite kind label.
target_business_nameOptional business name attached to the invite.
error_messageOptional error text.
invite_emailInvite email.
form_actionForm POST target.
Returns
Newly allocated compact JSON string, or NULL on failure.

Definition at line 2256 of file native_dynamic_runtime.c.

References error_alert_html_dup_runtime(), invite_accept_target_html_dup_runtime(), runtime_page_params_add_escaped_string_runtime(), runtime_page_params_add_string_runtime(), runtime_page_params_write_runtime(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), and yyjson_mut_obj().

Referenced by resolve_invite_accept_page_params_json_runtime().

◆ invite_accept_target_html_dup_runtime()

char * invite_accept_target_html_dup_runtime ( const char * target_business_name)
static

Builds the optional invite target HTML fragment.

Parameters
target_business_nameOptional invite-associated business display name.
Returns
Newly allocated HTML fragment, or an empty string when no target exists.

Definition at line 2143 of file native_dynamic_runtime.c.

References html_escaped_dup_runtime(), and text_append_runtime_local().

Referenced by invite_accept_page_params_json_dup_runtime().

◆ invite_created_page_params_json_dup_runtime()

char * invite_created_page_params_json_dup_runtime ( const char * invite_email,
const char * invite_path,
const char * return_path )
static

Builds template params for the invite-created confirmation page.

Parameters
invite_emailInvite target email.
invite_pathNative preview path for the invite token.
return_pathBusiness return path.
Returns
Newly allocated compact JSON string, or NULL on failure.

Definition at line 2230 of file native_dynamic_runtime.c.

References runtime_page_params_add_escaped_string_runtime(), runtime_page_params_write_runtime(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), and yyjson_mut_obj().

Referenced by handle_issue_business_invite_action_runtime().

◆ is_business_availability_api_list_path_runtime()

int is_business_availability_api_list_path_runtime ( const char * request_path)
static

Tests whether a request path is the exact business availability list API path.

Matches only /api/businesses/{business_slug}/availability/.

Parameters
request_pathNormalized request path without query string.
Returns
1 when the path is the exact availability list API path, else 0.

Definition at line 1516 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_handle_request().

◆ is_business_availability_api_schema_path_runtime()

int is_business_availability_api_schema_path_runtime ( const char * request_path)
static

Tests whether a request path is the exact business availability schema API path.

Parameters
request_pathNormalized request path without query string.
Returns
1 when the path is the exact availability schema API path, else 0.

Definition at line 1594 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_handle_request().

◆ is_business_services_api_list_path_runtime()

int is_business_services_api_list_path_runtime ( const char * request_path)
static

Tests whether a request path is the exact business services list API path.

Matches only /api/businesses/{business_slug}/services/ and avoids hijacking other four-segment paths that happen to contain a slug-like segment in the same position.

Parameters
request_pathNormalized request path without query string.
Returns
1 when the path is the exact services list API path, else 0.

Definition at line 1474 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_handle_request().

◆ is_business_services_api_schema_path_runtime()

int is_business_services_api_schema_path_runtime ( const char * request_path)
static

Tests whether a request path is the exact business services schema API path.

Parameters
request_pathNormalized request path without query string.
Returns
1 when the path is the exact services schema API path, else 0.

Definition at line 1555 of file native_dynamic_runtime.c.

Referenced by native_dynamic_runtime_handle_request().

◆ iso_after_seconds_runtime()

int iso_after_seconds_runtime ( long delta_seconds,
char out[21] )
static

◆ issue_browser_session_runtime()

◆ login_page_params_json_dup_runtime()

◆ long_from_value_runtime_local()

int long_from_value_runtime_local ( yyjson_val * value,
long * out_value )
static

◆ membership_role_id_for_invite_runtime_local()

const char * membership_role_id_for_invite_runtime_local ( const char * role_hint,
const char * account_type )
static

Maps invite role hints onto the canonical tenant membership role id.

Parameters
role_hintRequested invite role hint.
account_typeRequested invite account type.
Returns
Canonical role id string.

Definition at line 3265 of file native_dynamic_runtime.c.

References streq().

Referenced by handle_accept_invite_action_runtime(), and handle_issue_business_invite_action_runtime().

◆ native_dynamic_runtime_handle_request()

int native_dynamic_runtime_handle_request ( const AppRuntime * app,
const HttpRequest * request,
NativeConnection * connection )

Serves one dynamic-app request entirely in-process.

This is the canonical entry point that replaces the former spawn_app_request() path for apps whose host_profile is "dynamic-app". The function reads the app's route fixture, resolves the appropriate handler, and writes the HTTP response directly to connection.

Static-only and non-dynamic host profiles continue to use their existing code paths; this function is called only for dynamic-app requests.

Parameters
appFinalized app runtime metadata (artifact dir, state, etc.).
requestParsed HTTP request record.
connectionConnection to write the response to.
Returns
0 on success, or a non-zero native status code on failure.

Definition at line 6494 of file native_dynamic_runtime.c.

References AppRuntime::app_id, AppRuntime::artifact_dir, HttpRequest::cookie, csrf_token_for_response(), extract_query(), handle_action_route(), handle_page_route(), is_business_availability_api_list_path_runtime(), is_business_availability_api_schema_path_runtime(), is_business_services_api_list_path_runtime(), is_business_services_api_schema_path_runtime(), NativeDynamicRouteMatch::kind, load_root_from_text_runtime(), MAX_QUERY_LEN, HttpRequest::method, native_connection_printf(), native_dynamic_dispatch_extract_param(), native_dynamic_dispatch_free_match(), native_dynamic_dispatch_match(), native_dynamic_dispatch_resolve_route_fixture(), native_dynamic_dispatch_response_file(), native_dynamic_media_is_static_path(), native_dynamic_media_serve_asset(), native_dynamic_relational_prepare_request_state(), native_dynamic_relational_request_sync_free(), native_dynamic_relational_sync_back_if_changed(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_send_text_response(), path_exists(), read_file_text(), request_body_text_dup_runtime(), route_request_path_dup_runtime(), AppRuntime::state_path, streq(), HttpRequest::target, time_text_to_minutes_runtime(), valid_day_of_week_runtime(), write_business_availability_api_response(), write_business_services_api_response(), write_generated_surface_schema_response(), write_json_error(), write_proof_state_api_response(), yyjson_get_str(), yyjson_is_str(), yyjson_write(), and YYJSON_WRITE_NOFLAG.

Referenced by handle_app_or_runtime_request().

◆ native_dynamic_runtime_host_profile()

const char * native_dynamic_runtime_host_profile ( void )

Returns the canonical host profile string that this module handles.

Useful for callers that need to decide which request path to use without duplicating the profile name string.

Returns
Pointer to a string literal; never NULL.

Definition at line 6490 of file native_dynamic_runtime.c.

References DYNAMIC_HOST_PROFILE.

◆ next_array_id_runtime_local()

◆ now_iso_utc_runtime()

◆ page_title_dup_runtime()

char * page_title_dup_runtime ( yyjson_val * page_spec_root,
yyjson_val * body_params_root )
static

◆ parse_ymd_runtime_local()

int parse_ymd_runtime_local ( const char * date_value,
int * year_out,
int * month_out,
int * day_out )
static

◆ password_hash_dup_runtime()

char * password_hash_dup_runtime ( const char * password_value)
static

◆ password_reset_complete_page_params_json_dup_runtime()

char * password_reset_complete_page_params_json_dup_runtime ( const char * request_path)
static

Builds native template params for the password-reset completion page.

Parameters
request_pathMatched request path that contains the reset token.
Returns
Newly allocated compact JSON string, or NULL on failure.

Definition at line 2204 of file native_dynamic_runtime.c.

References error_alert_html_dup_runtime(), runtime_page_params_add_escaped_string_runtime(), runtime_page_params_add_string_runtime(), runtime_page_params_write_runtime(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), and yyjson_mut_obj().

Referenced by resolve_declared_page_params_json_runtime().

◆ password_reset_preview_html_dup_runtime()

char * password_reset_preview_html_dup_runtime ( const char * preview_path)
static

Builds the optional password-reset preview HTML block.

Parameters
preview_pathLocal preview path to expose.
Returns
Newly allocated HTML fragment, or an empty string when no preview path exists.

Definition at line 2116 of file native_dynamic_runtime.c.

Referenced by password_reset_sent_page_params_json_dup_runtime().

◆ password_reset_request_page_params_json_dup_runtime()

◆ password_reset_sent_page_params_json_dup_runtime()

char * password_reset_sent_page_params_json_dup_runtime ( const char * preview_path)
static

◆ payment_preference_options_html_dup_runtime()

char * payment_preference_options_html_dup_runtime ( const char * selected_value)
static

Definition at line 392 of file native_dynamic_runtime.c.

References streq().

Referenced by resolve_declared_page_params_json_runtime().

◆ pbkdf2_sha256_runtime()

int pbkdf2_sha256_runtime ( const uint8_t * password,
size_t password_len,
const uint8_t * salt,
size_t salt_len,
uint32_t iterations,
uint8_t * out,
size_t out_len )
static

◆ persist_app_state_text_runtime_local()

int persist_app_state_text_runtime_local ( const AppRuntime * app,
const char * state_json_text )
static

◆ profile_page_params_json_dup_runtime_local()

char * profile_page_params_json_dup_runtime_local ( const char * state_path,
long user_id,
const char * payment_preference_options_html )
static

Builds profile-page template params directly from runtime state.

This local builder keeps the profile page on the native dynamic render path without depending on the older shared profile params helper.

Parameters
state_pathRuntime state JSON path.
user_idActive signed-in user id.
payment_preference_options_htmlPre-rendered select option HTML.
Returns
Newly allocated compact JSON string, or NULL on failure.

Definition at line 1323 of file native_dynamic_runtime.c.

References find_user_by_id_runtime_local(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get_string_dup(), profile_subscriptions_block_dup_runtime(), yyjson_doc_get_root(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_obj(), yyjson_mut_obj_add_strcpy(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

◆ profile_subscriptions_block_dup_runtime()

char * profile_subscriptions_block_dup_runtime ( yyjson_val * root,
long user_id )
static

Builds the profile subscription block for one user.

Parameters
rootLoaded runtime state root.
user_idActive signed-in user id.
Returns
Newly allocated HTML block, or NULL on failure.

Definition at line 1180 of file native_dynamic_runtime.c.

References append_profile_subscription_rows_runtime(), and text_append_runtime_local().

Referenced by profile_page_params_json_dup_runtime_local().

◆ proof_home_page_params_json_dup_runtime()

◆ proof_state_root_load_runtime()

◆ proof_state_seed_json_dup_runtime()

char * proof_state_seed_json_dup_runtime ( void )
static

Definition at line 553 of file native_dynamic_runtime.c.

Referenced by proof_state_root_load_runtime().

◆ proof_task_items_html_dup_runtime()

◆ register_page_params_json_dup_runtime()

◆ render_declared_page_response_runtime()

int render_declared_page_response_runtime ( NativeConnection * connection,
const AppRuntime * app,
const HttpRequest * request,
const char * page_id,
const char * request_path,
const char * body_params_json )
static

◆ render_declared_page_response_with_headers_runtime()

◆ request_body_bytes_dup_runtime()

unsigned char * request_body_bytes_dup_runtime ( const HttpRequest * request,
size_t * out_size )
static

◆ request_body_text_dup_runtime()

char * request_body_text_dup_runtime ( const HttpRequest * request)
static

◆ request_form_value_dup_runtime()

◆ request_has_session_cookie()

int request_has_session_cookie ( const char * cookie_header)
static

Definition at line 341 of file native_dynamic_runtime.c.

References native_dynamic_cookie_value(), and SESSION_COOKIE_NAME.

◆ request_header_value_dup_runtime()

char * request_header_value_dup_runtime ( const char * headers,
const char * header_name )
static

Definition at line 348 of file native_dynamic_runtime.c.

References dup_range().

Referenced by csrf_request_token_dup_runtime().

◆ request_path_dup_runtime()

◆ resolve_declared_page_params_json_runtime()

char * resolve_declared_page_params_json_runtime ( const AppRuntime * app,
const HttpRequest * request,
const NativeDynamicRouteMatch * match,
const char * request_path,
const char * query_string,
long active_user_id )
static

Resolves declared page parameter JSON for the matched page route.

Parameters
appActive app runtime.
requestActive HTTP request.
matchMatched page route.
request_pathRequest path used for route-param extraction.
query_stringRaw query string.
active_user_idAuthenticated user id, or 0 when anonymous.
Returns
Newly allocated page-params JSON string.

Definition at line 4056 of file native_dynamic_runtime.c.

References AppRuntime::app_id, AppRuntime::app_root, appointments_render_page_params_json_dup_runtime(), business_availability_edit_page_params_json_dup_runtime(), business_calendar_render_page_params_json_dup_runtime(), business_dashboard_render_page_params_json_dup_runtime(), business_detail_admin_render_page_params_json_dup_runtime(), business_edit_page_params_json_dup_runtime(), business_landing_render_page_params_json_dup_runtime(), diagnostics_render_page_params_json_dup_runtime(), explore_render_page_params_json_dup_runtime(), find_user_by_id_runtime_local(), generated_admin_manage_page_params_json_dup_runtime(), login_page_params_json_dup_runtime(), native_dynamic_dispatch_extract_param(), native_dynamic_query_value(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get_string_dup(), NativeDynamicRouteMatch::page_id, password_reset_complete_page_params_json_dup_runtime(), password_reset_request_page_params_json_dup_runtime(), NativeDynamicRouteMatch::path, payment_preference_options_html_dup_runtime(), profile_render_page_params_json_dup_runtime(), proof_home_page_params_json_dup_runtime(), register_page_params_json_dup_runtime(), resolve_invite_accept_page_params_json_runtime(), NativeDynamicRouteMatch::route_id, service_book_form_page_params_json_dup_runtime(), service_edit_page_params_json_dup_runtime(), AppRuntime::state_path, streq(), and yyjson_doc_get_root().

Referenced by handle_page_route().

◆ resolve_invite_accept_page_params_json_runtime()

char * resolve_invite_accept_page_params_json_runtime ( const AppRuntime * app,
const NativeDynamicRouteMatch * match,
const char * request_path )
static

Resolves invite-accept page parameters from the current app state.

Parameters
appActive app runtime.
matchMatched route used to extract path parameters.
request_pathRequest path for parameter extraction.
Returns
Newly allocated page-params JSON string, or NULL when no active invite can be resolved.

Definition at line 3966 of file native_dynamic_runtime.c.

References find_business_by_id_runtime_local(), invite_accept_page_params_json_dup_runtime(), native_dynamic_dispatch_extract_param(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), now_iso_utc_runtime(), NativeDynamicRouteMatch::path, state_array_runtime_local(), AppRuntime::state_path, token_hash_dup_runtime(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_equals_str(), yyjson_is_null(), yyjson_is_obj(), and yyjson_is_str().

Referenced by resolve_declared_page_params_json_runtime().

◆ resource_link_display_free_runtime()

void resource_link_display_free_runtime ( ResourceLinkDisplay * display)
static

Frees a linked-resource display record.

Parameters
displayDisplay record to release.

Definition at line 1105 of file native_dynamic_runtime.c.

References ResourceLinkDisplay::resource_name, and ResourceLinkDisplay::resource_slug.

Referenced by append_profile_subscription_rows_runtime().

◆ resource_link_display_load_runtime()

int resource_link_display_load_runtime ( yyjson_val * root,
const char * resource_collection_name,
long resource_id,
ResourceLinkDisplay * display )
static

Loads slug and display-name fields for one linked resource id.

Parameters
rootLoaded runtime state root.
resource_collection_nameState collection that owns the linked resource.
resource_idResource identifier to resolve.
displayOutput record that receives duplicated slug and name values.
Returns
1 on success, or 0 when the resource cannot be resolved.

Definition at line 1067 of file native_dynamic_runtime.c.

References native_json_obj_get_long_default(), native_json_obj_get_string_dup(), ResourceLinkDisplay::resource_name, ResourceLinkDisplay::resource_slug, state_array_runtime_local(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), and yyjson_is_obj().

Referenced by append_profile_subscription_rows_runtime().

◆ revoke_session_by_cookie_runtime()

◆ route_request_path_dup_runtime()

char * route_request_path_dup_runtime ( const AppRuntime * app,
const HttpRequest * request )
static

◆ runtime_page_params_add_escaped_string_runtime()

int runtime_page_params_add_escaped_string_runtime ( yyjson_mut_doc * doc,
yyjson_mut_val * root,
const char * key,
const char * value )
static

Adds one HTML-escaped string field to a page-params JSON object.

Parameters
docMutable params document.
rootMutable params object.
keyField name to populate.
valueRaw string value to escape before storing.
Returns
1 on success, or 0 on allocation or escaping failure.

Definition at line 2075 of file native_dynamic_runtime.c.

References html_escaped_dup_runtime(), and yyjson_mut_obj_add_strcpy().

Referenced by invite_accept_done_page_params_json_dup_runtime(), invite_accept_page_params_json_dup_runtime(), invite_created_page_params_json_dup_runtime(), and password_reset_complete_page_params_json_dup_runtime().

◆ runtime_page_params_add_string_runtime()

int runtime_page_params_add_string_runtime ( yyjson_mut_doc * doc,
yyjson_mut_val * root,
const char * key,
const char * value )
static

Builds native template params for the password-reset request page.

Returns
Newly allocated compact JSON string, or NULL on failure.

Adds one literal string field to a page-params JSON object.

Parameters
docMutable params document.
rootMutable params object.
keyField name to populate.
valueRaw string value to store.
Returns
1 on success, or 0 on allocation failure.

Definition at line 2054 of file native_dynamic_runtime.c.

References yyjson_mut_obj_add_strcpy().

Referenced by invite_accept_page_params_json_dup_runtime(), password_reset_complete_page_params_json_dup_runtime(), password_reset_request_page_params_json_dup_runtime(), and password_reset_sent_page_params_json_dup_runtime().

◆ runtime_page_params_write_runtime()

char * runtime_page_params_write_runtime ( yyjson_mut_doc * doc,
yyjson_mut_val * root )
static

Finalizes and writes one page-params document as compact JSON.

Parameters
docMutable params document.
rootMutable params object.
Returns
Newly allocated compact JSON string, or NULL on failure.

Definition at line 2102 of file native_dynamic_runtime.c.

References yyjson_mut_doc_set_root(), yyjson_mut_write(), and YYJSON_WRITE_NOFLAG.

Referenced by invite_accept_done_page_params_json_dup_runtime(), invite_accept_page_params_json_dup_runtime(), invite_created_page_params_json_dup_runtime(), password_reset_complete_page_params_json_dup_runtime(), password_reset_request_page_params_json_dup_runtime(), and password_reset_sent_page_params_json_dup_runtime().

◆ secure_text_equals()

int secure_text_equals ( const char * left,
const char * right )
static

Definition at line 2505 of file native_dynamic_runtime.c.

Referenced by verify_password_hash_runtime().

◆ serve_dynamic_home_page()

void serve_dynamic_home_page ( NativeConnection * connection,
const char * app_id,
const char * route_id,
const char * csrf_token )
static

Serves the Pharos dynamic-app home page or a generic landing page.

This is a placeholder that will be replaced by full template rendering in later Phase 3 slices. For now it provides a functional HTML page so the app is browsable.

Definition at line 5030 of file native_dynamic_runtime.c.

References len, native_send_text_response(), and write_html_response().

Referenced by handle_page_route().

◆ service_edit_page_params_json_dup_runtime()

◆ session_cookie_header_dup_runtime()

char * session_cookie_header_dup_runtime ( const AppRuntime * app,
const HttpRequest * request,
const char * session_token,
int clear_cookie )
static

◆ sha256_final_runtime()

void sha256_final_runtime ( Sha256Runtime * ctx,
uint8_t hash[SHA256_DIGEST_SIZE] )
static

◆ sha256_hex_dup_runtime()

char * sha256_hex_dup_runtime ( const char * value)
static

◆ sha256_init_runtime()

void sha256_init_runtime ( Sha256Runtime * ctx)
static

◆ sha256_rotr()

uint32_t sha256_rotr ( uint32_t value,
uint32_t bits )
static

Definition at line 2534 of file native_dynamic_runtime.c.

Referenced by sha256_transform_runtime().

◆ sha256_transform_runtime()

void sha256_transform_runtime ( Sha256Runtime * ctx,
const uint8_t data[] )
static

Definition at line 2538 of file native_dynamic_runtime.c.

References sha256_rotr(), and Sha256Runtime::state.

Referenced by sha256_final_runtime(), and sha256_update_runtime().

◆ sha256_update_runtime()

void sha256_update_runtime ( Sha256Runtime * ctx,
const uint8_t * data,
size_t len )
static

◆ state_array_runtime_local()

◆ state_tenant_id_for_business_runtime_local()

long state_tenant_id_for_business_runtime_local ( yyjson_val * root,
long business_id )
static

Resolves the tenant id that owns a business record.

Parameters
rootLoaded runtime state root.
business_idBusiness id to map.
Returns
Matching tenant id, or 0 when not found.

Definition at line 3208 of file native_dynamic_runtime.c.

References native_json_obj_get_long_default(), state_array_runtime_local(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), and yyjson_is_obj().

Referenced by handle_issue_business_invite_action_runtime().

◆ technician_booked_for_slot_runtime_local()

◆ text_append_format_runtime_local()

int text_append_format_runtime_local ( char ** buffer,
size_t * length,
size_t * capacity,
const char * format,
... )
static

◆ text_append_runtime_local()

◆ time_ranges_overlap_runtime_local()

int time_ranges_overlap_runtime_local ( int start_a_minutes,
int duration_a,
int start_b_minutes,
int duration_b )
static

Definition at line 3009 of file native_dynamic_runtime.c.

Referenced by technician_booked_for_slot_runtime_local().

◆ time_text_to_minutes_runtime()

int time_text_to_minutes_runtime ( const char * time_text,
int * minutes_out )
static

◆ token_hash_dup_runtime()

◆ user_has_active_tenant_membership_runtime_local()

int user_has_active_tenant_membership_runtime_local ( yyjson_val * root,
long user_id,
long tenant_id )
static

Checks whether a user has an active membership on a tenant.

Parameters
rootLoaded runtime state root.
user_idUser id to test.
tenant_idTenant id to test.
Returns
1 when active, otherwise 0.

Definition at line 3234 of file native_dynamic_runtime.c.

References native_json_obj_get(), native_json_obj_get_long_default(), state_array_runtime_local(), streq(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_get_str(), and yyjson_is_obj().

Referenced by handle_issue_business_invite_action_runtime().

◆ valid_day_of_week_runtime()

int valid_day_of_week_runtime ( const char * day_text)
static

Resolves the final page title from a declarative page spec and params.

Prefers an explicit title value from the page spec. When the spec uses title_mode instead, this treats the title-mode value as the params field name whose string value should supply the page title.

Parameters
page_spec_rootLoaded page-spec JSON root.
body_params_rootLoaded page-params JSON root.
Returns
Newly allocated page title string, or an empty string on fallback. Caller must free.

Definition at line 1640 of file native_dynamic_runtime.c.

References streq().

Referenced by handle_action_route(), and native_dynamic_runtime_handle_request().

◆ value_long_equals_runtime_local()

int value_long_equals_runtime_local ( yyjson_val * value,
long expected_value )
static

◆ verify_password_hash_runtime()

int verify_password_hash_runtime ( const char * stored_hash,
const char * password_value,
const char * username_value )
static

◆ write_business_availability_api_response()

◆ write_business_services_api_response()

◆ write_generated_surface_schema_response()

int write_generated_surface_schema_response ( NativeConnection * connection,
const AppRuntime * app,
const char * state_path,
const char * business_slug,
const char * surface_id )
static

Writes one generated-surface schema object from the declarative fixture.

Parameters
connectionConnection to write to.
appActive app runtime for fixture resolution.
state_pathRuntime state path used to validate the business slug.
business_slugBusiness slug from the request path.
surface_idSchema surface id to emit.
Returns
HTTP status code written to the client.

Definition at line 1888 of file native_dynamic_runtime.c.

References find_business_by_slug_runtime_local(), generated_surface_fixture_path_dup_runtime(), native_connection_printf(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_send_text_response(), write_json_error(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_equals_str(), yyjson_is_arr(), yyjson_is_str(), yyjson_mut_doc_free(), yyjson_mut_doc_new(), yyjson_mut_doc_set_root(), yyjson_mut_write(), yyjson_val_mut_copy(), and YYJSON_WRITE_NOFLAG.

Referenced by native_dynamic_runtime_handle_request().

◆ write_html_response()

void write_html_response ( NativeConnection * connection,
int status,
const char * status_text,
const char * html,
const char * csrf_token )
static

◆ write_html_response_with_headers_runtime()

void write_html_response_with_headers_runtime ( NativeConnection * connection,
int status,
const char * status_text,
const char * html,
const char * csrf_token,
const char * extra_headers )
static

Writes an HTML response to a connection, optionally with a CSRF cookie.

Parameters
connectionConnection to write to.
statusHTTP status code.
status_textHTTP reason phrase.
htmlHTML body content.
csrf_tokenCSRF token to set as cookie, or NULL to skip.

Definition at line 3795 of file native_dynamic_runtime.c.

References CSRF_COOKIE_MAX_AGE, CSRF_COOKIE_NAME, native_connection_printf(), and native_send_text_response().

Referenced by render_declared_page_response_with_headers_runtime(), and write_html_response().

◆ write_json_error()

void write_json_error ( NativeConnection * connection,
int status,
const char * status_text,
const char * error_kind,
const char * message )
static

Writes a JSON error response to a connection.

Parameters
connectionConnection to write to.
statusHTTP status code.
status_textHTTP reason phrase.
error_kindMachine-readable error kind.
messageHuman-readable error message.

Definition at line 238 of file native_dynamic_runtime.c.

References native_connection_printf(), and native_send_text_response().

Referenced by handle_accept_invite_action_runtime(), handle_action_route(), handle_issue_business_invite_action_runtime(), handle_password_reset_complete_action_runtime(), native_dynamic_runtime_handle_request(), write_business_availability_api_response(), write_business_services_api_response(), and write_generated_surface_schema_response().

◆ write_proof_state_api_response()

int write_proof_state_api_response ( NativeConnection * connection,
const char * state_path )
static