Pharos
0.7.23
Modern Web Framework & Web App Hosting Service.
Toggle main menu visibility
Loading...
Searching...
No Matches
native_dynamic_dispatch.h
Go to the documentation of this file.
1
/**
2
* @file
3
* @brief Route dispatch for in-process dynamic-app request handling.
4
*
5
* This module reads the app's route fixture JSON and matches an incoming
6
* request path against the declared routes. It supports both exact
7
* segment matches and parameterised segment patterns (e.g.
8
* @c /businesses/:business_slug/).
9
*
10
* The dispatch layer also resolves the response artifact file for
11
* API-style routes that have pre-built static responses in the
12
* dispatch table.
13
*
14
* @see native_dynamic_runtime.h for the higher-level entry point.
15
*/
16
17
#ifndef PHAROS_NATIVE_DYNAMIC_DISPATCH_H
18
#define PHAROS_NATIVE_DYNAMIC_DISPATCH_H
19
20
#include "
native_runtime_types.h
"
21
#include "
native_http_request.h
"
22
#include "
native_connection.h
"
23
24
/**
25
* @brief Describes one matched route from the route fixture.
26
*/
27
typedef
struct
{
28
char
*
route_id
;
/**< Unique route identifier from the fixture. */
29
char
*
path
;
/**< Route path pattern (may contain parameter segments). */
30
char
*
kind
;
/**< Route kind: @c "page" or @c "action". */
31
char
*
page_id
;
/**< Page identifier (for page routes), or NULL. */
32
char
*
action_id
;
/**< Action identifier (for action routes), or NULL. */
33
char
*
layout_id
;
/**< Layout identifier, or NULL. */
34
char
*
auth_gate
;
/**< Auth gate constraint, or NULL. */
35
char
*
policy_gate
;
/**< Policy gate constraint, or NULL. */
36
}
NativeDynamicRouteMatch
;
37
38
/** @name Dispatch helpers
39
* @{
40
*/
41
42
/**
43
* @brief Matches a request path against the route fixture for an app.
44
*
45
* Reads @p route_fixture_path and walks the route list looking for a
46
* match. Parameterised segments (prefixed with @c : ) match any
47
* non-empty segment in the corresponding position.
48
*
49
* @param route_fixture_path File-system path to the route fixture JSON.
50
* @param method HTTP method (GET, POST, etc.).
51
* @param path Normalised request path (query string already stripped).
52
* @param match_out Destination for the allocated match record. Caller
53
* must free with @c native_dynamic_dispatch_free_match().
54
* @return 0 when a match is found, 1 when no route matches, or a
55
* negative value on I/O or parse failure.
56
*/
57
int
native_dynamic_dispatch_match
(
58
const
char
*route_fixture_path,
59
const
char
*method,
60
const
char
*path,
61
NativeDynamicRouteMatch
**match_out
62
);
63
64
/**
65
* @brief Frees a route match returned by @c native_dynamic_dispatch_match().
66
* @param match Match record to free, or NULL.
67
*/
68
void
native_dynamic_dispatch_free_match
(
NativeDynamicRouteMatch
*match);
69
70
/**
71
* @brief Resolves the response artifact file for a matched page route.
72
*
73
* Looks up the dispatch table in @p artifact_dir and returns the
74
* pre-built response file for routes whose paths are served as
75
* static responses. Returns NULL when no static response file
76
* exists for the route.
77
*
78
* @param artifact_dir App artifact directory.
79
* @param method HTTP method.
80
* @param path Normalised request path.
81
* @return Newly allocated file path, or NULL. Caller must free.
82
*/
83
char
*
native_dynamic_dispatch_response_file
(
84
const
char
*artifact_dir,
85
const
char
*method,
86
const
char
*path
87
);
88
89
/**
90
* @brief Resolves the route fixture path from the artifact directory.
91
*
92
* Reads the manifest from @p artifact_dir and returns the file-system
93
* path to the route fixture JSON.
94
*
95
* @param artifact_dir App artifact directory.
96
* @return Newly allocated route fixture path, or NULL. Caller must free.
97
*/
98
char
*
native_dynamic_dispatch_resolve_route_fixture
(
99
const
char
*artifact_dir,
100
const
char
*app_id
101
);
102
103
/**
104
* @brief Returns the URL path parameter value extracted from a matched route.
105
*
106
* Given a route pattern like @c /businesses/:business_slug/ and a
107
* concrete path @c /businesses/foo-bar/, this returns @c "foo-bar".
108
*
109
* @param pattern Route pattern from the fixture.
110
* @param path Concrete request path.
111
* @param param_name Name of the parameter segment (without the colon).
112
* @return Newly allocated parameter value, or NULL if not found.
113
* Caller must free.
114
*/
115
char
*
native_dynamic_dispatch_extract_param
(
116
const
char
*pattern,
117
const
char
*path,
118
const
char
*param_name
119
);
120
121
/** @} */
122
123
#endif
native_connection.h
Declares the native connection abstraction and transport metadata helpers.
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.
Definition
native_dynamic_dispatch.c:503
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.
Definition
native_dynamic_dispatch.c:365
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.
Definition
native_dynamic_dispatch.c:565
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.
Definition
native_dynamic_dispatch.c:518
native_dynamic_dispatch_free_match
void native_dynamic_dispatch_free_match(NativeDynamicRouteMatch *match)
Frees a route match returned by native_dynamic_dispatch_match().
Definition
native_dynamic_dispatch.c:488
native_http_request.h
Declares the parsed HTTP request record and request parsing helpers.
native_runtime_types.h
Defines shared native runtime data structures used across the Pharos C runtime.
NativeDynamicRouteMatch
Describes one matched route from the route fixture.
Definition
native_dynamic_dispatch.h:27
NativeDynamicRouteMatch::layout_id
char * layout_id
Definition
native_dynamic_dispatch.h:33
NativeDynamicRouteMatch::page_id
char * page_id
Definition
native_dynamic_dispatch.h:31
NativeDynamicRouteMatch::kind
char * kind
Definition
native_dynamic_dispatch.h:30
NativeDynamicRouteMatch::policy_gate
char * policy_gate
Definition
native_dynamic_dispatch.h:35
NativeDynamicRouteMatch::action_id
char * action_id
Definition
native_dynamic_dispatch.h:32
NativeDynamicRouteMatch::path
char * path
Definition
native_dynamic_dispatch.h:29
NativeDynamicRouteMatch::auth_gate
char * auth_gate
Definition
native_dynamic_dispatch.h:34
NativeDynamicRouteMatch::route_id
char * route_id
Definition
native_dynamic_dispatch.h:28
src
native_runtime
c
native_dynamic_dispatch.h
Generated by
1.17.0