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

Route dispatch for in-process dynamic-app request handling. More...

Go to the source code of this file.

Data Structures

struct  NativeDynamicRouteMatch
 Describes one matched route from the route fixture. More...

Functions

Dispatch helpers
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_resolve_route_fixture (const char *artifact_dir, const char *app_id)
 Resolves the route fixture path from the artifact directory.
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.

Detailed Description

Route dispatch for in-process dynamic-app request handling.

This module reads the app's route fixture JSON and matches an incoming request path against the declared routes. It supports both exact segment matches and parameterised segment patterns (e.g. /businesses/:business_slug/).

The dispatch layer also resolves the response artifact file for API-style routes that have pre-built static responses in the dispatch table.

See also
native_dynamic_runtime.h for the higher-level entry point.

Definition in file native_dynamic_dispatch.h.

Function Documentation

◆ native_dynamic_dispatch_extract_param()

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".

Parameters
patternRoute pattern from the fixture.
pathConcrete request path.
param_nameName of the parameter segment (without the colon).
Returns
Newly allocated parameter value, or NULL if not found. Caller must free.

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().

◆ native_dynamic_dispatch_free_match()

◆ native_dynamic_dispatch_match()

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.

Parameters
route_fixture_pathFile-system path to the route fixture JSON.
methodHTTP method (GET, POST, etc.).
pathNormalised request path (query string already stripped).
match_outDestination for the allocated match record. Caller must free with native_dynamic_dispatch_free_match().
Returns
0 when a match is found, 1 when no route matches, or a negative value on I/O or parse failure.

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().

◆ native_dynamic_dispatch_resolve_route_fixture()

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.

Parameters
artifact_dirApp artifact directory.
Returns
Newly allocated route fixture path, or NULL. Caller must free.

Definition at line 565 of file native_dynamic_dispatch.c.

References resolve_route_fixture_path().

Referenced by native_dynamic_runtime_handle_request().

◆ native_dynamic_dispatch_response_file()

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.

Parameters
artifact_dirApp artifact directory.
methodHTTP method.
pathNormalised request path.
Returns
Newly allocated file path, or NULL. Caller must free.

Definition at line 503 of file native_dynamic_dispatch.c.

References native_dispatch_response_file_for_request().

Referenced by native_dynamic_runtime_handle_request().