1 // SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: GPL-2.0-only
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´.)
10 #ifndef CGIRLS_REQUEST_H
11 #define CGIRLS_REQUEST_H
15 **////////////////////////////////////////////////////////////////////
17 ** ❦ `enum cgirls_mtype´
19 ** The `cgirls_mtype´ enumeration is used to indicate recognized
20 ** mediatype extensions.
22 enum cgirls_mtype
: unsigned char {
24 ** The value `cgirls_mtype_any´ indicates no mediatype preference.
29 ** The value `cgirls_mtype_txt´ indicates a preference for
30 ** `text/plain´ content.
35 ** The value `cgirls_mtype_htm´ indicates a preference for
36 ** `text/html´ content.
41 ** The value `cgirls_mtype_xml´ indicates a preference for
42 ** `application/xml´ content, ideally with an `<?xml-stylesheet?>´
43 ** processing instruction.
48 ** The value `cgirls_mtype_rdf´ indicates a preference for
49 ** `application/rdf+xml´ content.
54 typedef enum cgirls_mtype cgirls_mtype
;
59 ** The `cgirls_vb´ enumeration is used to indicate recognized verbs
62 enum cgirls_vb
: unsigned char {
65 ** The value `cgirls_vb_unknown´ indicates an unknown or unspecified
68 cgirls_vb_unknown
= 0,
71 ** The value `cgirls_vb_index´ indicates a request for an index of
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.
81 // cgirls_vb_branches = ??,
82 // cgirls_vb_tags = ??,
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.
91 // cgirls_vb_raw = ??,
92 // cgirls_vb_blame = ??,
95 ** The value `cgirls_vb_index´ indicates a request for a diff between
98 // cgirls_vb_diff = ??,
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.
105 // cgirls_vb_log = ??,
106 // cgirls_vb_shortlog = ??,
107 // cgirls_vb_atom = ??,
108 // cgirls_vb_patch = ??,
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.
115 ** Verbs can be categorized into a few distinct classes :—
117 ** • Verbs which do not require a project :— `cgirls_vb_index´.
119 ** • Verbs which require a project, but not a revspec :—
120 ** `cgirls_vb_branches´, `cgirls_vb_tags´.
122 ** • Verbs which request information about a single object :—
123 ** `cgirls_vb_show´, `cgirls_vb_raw´, `cgirls_vb_blame´.
125 ** • Verbs which compare two commits :— `cgirls_vb_diff´.
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´.
132 typedef enum cgirls_vb cgirls_vb
;
135 ** ❦ `struct cgirls_req_status´
137 ** The struct `cgirls_req_status´ wraps a status code and message for
140 ** The `.message´ is only significant if `.code´ is not `200´.
142 typedef struct cgirls_req_status cgirls_req_status
;
143 struct cgirls_req_status
{
145 char* message
; // if `code´ is not ok
149 ** ❦ `struct cgirls_req´
151 ** The struct `cgirls_req´ represents a request.
153 ** Requests must have a verb, may specify a mediatype extension, and
154 ** might also reference a project, revspec, and subpath.
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.
160 typedef struct cgirls_req cgirls_req
;
165 char* id_THIS_WILL_CHANGE
;
167 char* baseid_THIS_WILL_CHANGE
;
168 cgirls_req_status status
;
173 **////////////////////////////////////////////////////////////////////
175 ** ❦ `cgirls_req cgirls_path·to·req(char const*const)´
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.
181 ** This resulting struct contains a lot of dynamically‐allocated data,
182 ** so it ☞︎must☜︎ be freed with `cgirls_req·free´ after use.
184 ** Maximally, the path string is processed according to the following
187 ** |`{project}/{action}/{revspec}/{subpath}´
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.
194 ** In case of an error, `.status.code´ on the returned `cgirls_req´
195 ** will be some·thing other than `200´.
197 cgirls_req cgirls_path·to·
req(char const*const);
200 ** ❦ `void cgirls_req·free(cgirls_req)´
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.
206 void cgirls_req·
free(cgirls_req
);
209 ** ❦ `char* cgirls_req·to·path(cgirls_req)´
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.
215 ** All possible `cgirls_req´s have a canonical string representation;
216 ** `cgirls_req·to·path´ will only return `nullptr´ if it
218 ** It is worth noting that, if the `.project´ is the null pointer, the
219 ** canonical path string will always be the empty string.
221 char* cgirls_req·to·
path(cgirls_req
);
223 #endif /* CGIRLS_REQUEST_H */