]> Lady’s Gitweb - CGirls/blob - request.h
3ff77e20773b4c7e2e05ed7f9071170b979d487a
[CGirls] / request.h
1 // SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: GPL-2.0-only
3
4 /**
5 ** This file defines types, constants, and function signatures
6 ** necessary for dealing with the ⹐semantics⹑ of C·Girls requests.
7 ** (Implementations of these functions are provided in `request.c´.)
8 **/
9
10 #ifndef CGIRLS_REQUEST_H
11 #define CGIRLS_REQUEST_H
12
13 /**
14 ** § Types
15 **////////////////////////////////////////////////////////////////////
16 /**
17 ** ❦ `enum cgirls_mtype´
18 **
19 ** The `cgirls_mtype´ enumeration is used to indicate recognized
20 ** mediatype extensions.
21 **/
22 enum cgirls_mtype : unsigned char {
23 /**
24 ** The value `cgirls_mtype_any´ indicates no mediatype preference.
25 **/
26 cgirls_mtype_any = 0,
27
28 /**
29 ** The value `cgirls_mtype_txt´ indicates a preference for
30 ** `text/plain´ content.
31 **/
32 cgirls_mtype_txt = 1,
33
34 /**
35 ** The value `cgirls_mtype_htm´ indicates a preference for
36 ** `text/html´ content.
37 **/
38 cgirls_mtype_htm = 2,
39
40 /**
41 ** The value `cgirls_mtype_xml´ indicates a preference for
42 ** `application/xml´ content, ideally with an `<?xml-stylesheet?>´
43 ** processing instruction.
44 **/
45 cgirls_mtype_xml = 3,
46
47 /**
48 ** The value `cgirls_mtype_rdf´ indicates a preference for
49 ** `application/rdf+xml´ content.
50 **/
51 cgirls_mtype_rdf = 4,
52
53 };
54 typedef enum cgirls_mtype cgirls_mtype;
55
56 /**
57 ** ❦ `enum cgirls_vb´
58 **
59 ** The `cgirls_vb´ enumeration is used to indicate recognized verbs
60 ** for requests.
61 **/
62 enum cgirls_vb : unsigned char {
63
64 /**
65 ** The value `cgirls_vb_unknown´ indicates an unknown or unspecified
66 ** verb.
67 **/
68 cgirls_vb_unknown = 0,
69
70 /**
71 ** The value `cgirls_vb_index´ indicates a request for an index of
72 ** projects.
73 **/
74 cgirls_vb_index = 1,
75
76 /**
77 ** The value `cgirls_vb_branches´ indicates a request for an index of
78 ** branches in a given project. The value `cgirls_vb_tags´ indicates a
79 ** request for an index of tags.
80 **/
81 // cgirls_vb_branches = ??,
82 // cgirls_vb_tags = ??,
83
84 /**
85 ** The value `cgirls_vb_show´ indicates a request for an object in a
86 ** human‐readable manner. The value `cgirls_vb_raw´ indicates a
87 ** request for the raw contents of an object. The value
88 ** `cgirls_vb_blame´ indicates a request for a blame of a commit.
89 **/
90 cgirls_vb_show = 2,
91 // cgirls_vb_raw = ??,
92 // cgirls_vb_blame = ??,
93
94 /**
95 ** The value `cgirls_vb_index´ indicates a request for a diff between
96 ** two commits.
97 **/
98 // cgirls_vb_diff = ??,
99
100 /**
101 ** The values `cgirls_vb_log´, `cgirls_vb_shortlog´, `cgirls_vb_atom´,
102 ** and `cgirls_vb_patch´ indicate requests for logs of a number of
103 ** commits in various formats.
104 **/
105 // cgirls_vb_log = ??,
106 // cgirls_vb_shortlog = ??,
107 // cgirls_vb_atom = ??,
108 // cgirls_vb_patch = ??,
109
110 /**
111 ** Note that the numbering for verbs does not follow their order in
112 ** the above list, but rather is fixed to when they were first
113 ** supported. New verbs may be added in the future.
114 **
115 ** Verbs can be categorized into a few distinct classes :—
116 **
117 ** • Verbs which do not require a project :— `cgirls_vb_index´.
118 **
119 ** • Verbs which require a project, but not a revspec :—
120 ** `cgirls_vb_branches´, `cgirls_vb_tags´.
121 **
122 ** • Verbs which request information about a single object :—
123 ** `cgirls_vb_show´, `cgirls_vb_raw´, `cgirls_vb_blame´.
124 **
125 ** • Verbs which compare two commits :— `cgirls_vb_diff´.
126 **
127 ** • Verbs which produce information about an open‐ended number of
128 ** commits :— `cgirls_vb_log´, `cgirls_vb_shortlog´,
129 ** `cgirls_vb_atom´, `cgirls_vb_patch´.
130 **/
131 };
132 typedef enum cgirls_vb cgirls_vb;
133
134 /**
135 ** ❦ `struct cgirls_req_status´
136 **
137 ** The struct `cgirls_req_status´ wraps a status code and message for
138 ** a response.
139 **
140 ** The `.message´ is only significant if `.code´ is not `200´.
141 **/
142 typedef struct cgirls_req_status cgirls_req_status;
143 struct cgirls_req_status {
144 unsigned short code;
145 char* message; // if `code´ is not ok
146 };
147
148 /**
149 ** ❦ `struct cgirls_req´
150 **
151 ** The struct `cgirls_req´ represents a request.
152 **
153 ** Requests must have a verb, may specify a mediatype extension, and
154 ** might also reference a project, revspec, and subpath.
155 **
156 ** All requests have a status, which is used to express request
157 ** validity. If `.status.code´ is not `200´, the request is invalid
158 ** and a response with the associated code and message is recommended.
159 **/
160 typedef struct cgirls_req cgirls_req;
161 struct cgirls_req {
162 cgirls_vb verb;
163 cgirls_mtype mtype;
164 char* project;
165 char* id_THIS_WILL_CHANGE;
166 char** subpath;
167 char* baseid_THIS_WILL_CHANGE;
168 cgirls_req_status status;
169 };
170
171 /**
172 ** § Functions
173 **////////////////////////////////////////////////////////////////////
174 /**
175 ** ❦ `cgirls_req cgirls_path·to·req(char const*const)´
176 **
177 ** The `cgirls_path·to·req´ function takes a path string (such as one
178 ** provided by the C·G·I `PATH_INFO´ environment variable) and returns
179 ** a `cgirls_req´ which represents its semantics.
180 **
181 ** This resulting struct contains a lot of dynamically‐allocated data,
182 ** so it ☞︎must☜︎ be freed with `cgirls_req·free´ after use.
183 **
184 ** Maximally, the path string is processed according to the following
185 ** form :—
186 **
187 ** |`{project}/{action}/{revspec}/{subpath}´
188 **
189 ** —: (where `{subpath}´ can contain additional slashes, and
190 ** `{action}´ consists of a verb and optionally a supported mediatype
191 ** extension). Not all components necessarily need to be specified,
192 ** and not all possible values are valid or meaningful.
193 **
194 ** In case of an error, `.status.code´ on the returned `cgirls_req´
195 ** will be some·thing other than `200´.
196 **/
197 cgirls_req cgirls_path·to·req(char const*const);
198
199 /**
200 ** ❦ `void cgirls_req·free(cgirls_req)´
201 **
202 ** The `cgirls_req·free´ function frees up any dynamically‐allocated
203 ** memory in the provided `cgirls_req´, assuming that it was created
204 ** with `cgirls_path·to·req´ or similar.
205 **/
206 void cgirls_req·free(cgirls_req);
207
208 /**
209 ** ❦ `char* cgirls_req·to·path(cgirls_req)´
210 **
211 ** The `cgirls_req·to·path´ function does the reverse of
212 ** `cgirls_path·to·req´: It takes in a `cgirls_req´ structure and
213 ** returns the canonical path string which represents it.
214 **
215 ** All possible `cgirls_req´s have a canonical string representation;
216 ** `cgirls_req·to·path´ will only return `nullptr´ if it
217 **
218 ** It is worth noting that, if the `.project´ is the null pointer, the
219 ** canonical path string will always be the empty string.
220 **/
221 char* cgirls_req·to·path(cgirls_req);
222
223 #endif /* CGIRLS_REQUEST_H */
This page took 0.0582 seconds and 3 git commands to generate.