|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
Route dispatch for in-process dynamic-app request handling. More...
#include "native_dynamic_dispatch.h"#include "native_dispatch_table.h"#include "native_yyjson_helpers.h"#include "native_support.h"#include <stdlib.h>#include <string.h>Go to the source code of this file.
Functions | |
| static char * | construct_packaged_route_fixture_path (const char *artifact_dir) |
| Attempts to locate the route fixture path from the artifact directory. | |
| static char * | construct_direct_route_fixture_path (const char *artifact_dir, const char *app_id) |
| Builds the framework-data route fixture fallback path. | |
| static char * | resolve_route_fixture_path (const char *artifact_dir, const char *app_id) |
| static int | count_segments (const char *path) |
| Counts the number of path segments in a pattern or path. | |
| static const char * | get_segment (const char *path, int index) |
| Extracts the N-th segment (0-indexed) from a path. | |
| static size_t | segment_length (const char *start) |
Returns the length of a segment starting at start. | |
| static int | route_pattern_specificity_score (const char *pattern) |
| Scores a route pattern by match specificity. | |
| static int | pattern_matches (const char *pattern, const char *path) |
| Tests whether a pattern matches a concrete path. | |
| int | native_dynamic_dispatch_match (const char *route_fixture_path, const char *method, const char *path, NativeDynamicRouteMatch **match_out) |
| Matches a request path against the route fixture for an app. | |
| void | native_dynamic_dispatch_free_match (NativeDynamicRouteMatch *match) |
Frees a route match returned by native_dynamic_dispatch_match(). | |
| char * | native_dynamic_dispatch_response_file (const char *artifact_dir, const char *method, const char *path) |
| Resolves the response artifact file for a matched page route. | |
| char * | native_dynamic_dispatch_extract_param (const char *pattern, const char *path, const char *param_name) |
| Returns the URL path parameter value extracted from a matched route. | |
| char * | native_dynamic_dispatch_resolve_route_fixture (const char *artifact_dir, const char *app_id) |
| Resolves the route fixture path from the artifact directory. | |
Route dispatch for in-process dynamic-app request handling.
Reads the app's route fixture JSON, matches an incoming request path against declared routes, and extracts parameterised segments.
Definition in file native_dynamic_dispatch.c.
|
static |
Builds the framework-data route fixture fallback path.
Dynamic-app artifact layouts may also publish route fixtures under data/framework/framework- <app_id>-route-fixture-v1.json.
| artifact_dir | App artifact directory. |
| app_id | App identifier used in the framework fixture name. |
Definition at line 68 of file native_dynamic_dispatch.c.
References path_join().
Referenced by resolve_route_fixture_path().
|
static |
Attempts to locate the route fixture path from the artifact directory.
Reads the finalized artifact-local app manifest from artifact_dir and extracts the route_fixture path. Falls back to the app-root fixture path when the manifest stores a relative value.
| artifact_dir | App artifact directory containing the manifest. |
Builds the conventional packaged-app route fixture path.
Packaged app artifacts place the checked route fixture at fixtures/route-fixture.json under the artifact root.
| artifact_dir | App artifact directory. |
Definition at line 41 of file native_dynamic_dispatch.c.
References path_join().
Referenced by resolve_route_fixture_path().
|
static |
Counts the number of path segments in a pattern or path.
Definition at line 188 of file native_dynamic_dispatch.c.
Referenced by native_dynamic_dispatch_extract_param(), pattern_matches(), and route_pattern_specificity_score().
|
static |
Extracts the N-th segment (0-indexed) from a path.
Definition at line 217 of file native_dynamic_dispatch.c.
Referenced by native_dynamic_dispatch_extract_param(), pattern_matches(), and route_pattern_specificity_score().
| char * native_dynamic_dispatch_extract_param | ( | const char * | pattern, |
| const char * | path, | ||
| const char * | param_name ) |
Returns the URL path parameter value extracted from a matched route.
Given a route pattern like /businesses/:business_slug/ and a concrete path /businesses/foo-bar/, this returns "foo-bar".
| pattern | Route pattern from the fixture. |
| path | Concrete request path. |
| param_name | Name of the parameter segment (without the colon). |
Definition at line 518 of file native_dynamic_dispatch.c.
References count_segments(), dup_range(), get_segment(), and segment_length().
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(), resolve_declared_page_params_json_runtime(), and resolve_invite_accept_page_params_json_runtime().
| void native_dynamic_dispatch_free_match | ( | NativeDynamicRouteMatch * | match | ) |
Frees a route match returned by native_dynamic_dispatch_match().
| match | Match record to free, or NULL. |
Definition at line 488 of file native_dynamic_dispatch.c.
References NativeDynamicRouteMatch::action_id, NativeDynamicRouteMatch::auth_gate, NativeDynamicRouteMatch::kind, NativeDynamicRouteMatch::layout_id, NativeDynamicRouteMatch::page_id, NativeDynamicRouteMatch::path, NativeDynamicRouteMatch::policy_gate, and NativeDynamicRouteMatch::route_id.
Referenced by native_dynamic_dispatch_match(), and native_dynamic_runtime_handle_request().
| int native_dynamic_dispatch_match | ( | const char * | route_fixture_path, |
| const char * | method, | ||
| const char * | path, | ||
| NativeDynamicRouteMatch ** | match_out ) |
Matches a request path against the route fixture for an app.
Reads route_fixture_path and walks the route list looking for a match. Parameterised segments (prefixed with : ) match any non-empty segment in the corresponding position.
| route_fixture_path | File-system path to the route fixture JSON. |
| method | HTTP method (GET, POST, etc.). |
| path | Normalised request path (query string already stripped). |
| match_out | Destination for the allocated match record. Caller must free with native_dynamic_dispatch_free_match(). |
Definition at line 365 of file native_dynamic_dispatch.c.
References NativeDynamicRouteMatch::action_id, NativeDynamicRouteMatch::auth_gate, NativeDynamicRouteMatch::kind, NativeDynamicRouteMatch::layout_id, native_dynamic_dispatch_free_match(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_array(), native_json_obj_get_string_dup(), NativeDynamicRouteMatch::page_id, NativeDynamicRouteMatch::path, pattern_matches(), NativeDynamicRouteMatch::policy_gate, NativeDynamicRouteMatch::route_id, route_pattern_specificity_score(), yyjson_arr_get(), yyjson_arr_size(), yyjson_doc_get_root(), and yyjson_get_str().
Referenced by native_dynamic_runtime_handle_request().
| char * native_dynamic_dispatch_resolve_route_fixture | ( | const char * | artifact_dir, |
| const char * | app_id ) |
Resolves the route fixture path from the artifact directory.
Reads the manifest from artifact_dir and returns the file-system path to the route fixture JSON.
| artifact_dir | App artifact directory. |
Definition at line 565 of file native_dynamic_dispatch.c.
References resolve_route_fixture_path().
Referenced by native_dynamic_runtime_handle_request().
| char * native_dynamic_dispatch_response_file | ( | const char * | artifact_dir, |
| const char * | method, | ||
| const char * | path ) |
Resolves the response artifact file for a matched page route.
Looks up the dispatch table in artifact_dir and returns the pre-built response file for routes whose paths are served as static responses. Returns NULL when no static response file exists for the route.
| artifact_dir | App artifact directory. |
| method | HTTP method. |
| path | Normalised request path. |
Definition at line 503 of file native_dynamic_dispatch.c.
References native_dispatch_response_file_for_request().
Referenced by native_dynamic_runtime_handle_request().
|
static |
Tests whether a pattern matches a concrete path.
Supports:
/accounts/login/ ): (e.g. /businesses/:slug/ )* (matches any single segment) Definition at line 307 of file native_dynamic_dispatch.c.
References count_segments(), get_segment(), and segment_length().
Referenced by native_dynamic_dispatch_match().
|
static |
Definition at line 98 of file native_dynamic_dispatch.c.
References construct_direct_route_fixture_path(), construct_packaged_route_fixture_path(), native_json_doc_free(), native_json_doc_load_text(), native_json_obj_get(), native_json_obj_get_string_dup(), path_exists(), path_join(), read_file_text(), and yyjson_doc_get_root().
Referenced by native_dynamic_dispatch_resolve_route_fixture().
|
static |
Scores a route pattern by match specificity.
Higher scores mean a more specific route. Exact literal segments outrank parameter segments, and parameter segments outrank wildcards. This lets the dispatcher prefer a static route like /appointments/diagnose/ over a broader parameterized route like /appointments/:appointment_id/ when both patterns match the same request path.
| pattern | Route pattern from the fixture. |
-1 when the pattern is missing. Definition at line 269 of file native_dynamic_dispatch.c.
References count_segments(), get_segment(), and segment_length().
Referenced by native_dynamic_dispatch_match().
|
static |
Returns the length of a segment starting at start.
Definition at line 249 of file native_dynamic_dispatch.c.
Referenced by native_dynamic_dispatch_extract_param(), pattern_matches(), and route_pattern_specificity_score().