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
;
57 ** ❦ `enum ⸤cgirls_vb⸥´
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
78 ** of branches in a given project. The value `⟨cgirls_vb_tags⟩´
79 ** indicates a 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
96 ** between two commits.
98 // cgirls_vb_diff = ??,
101 ** The values `⟨cgirls_vb_log⟩´, `⟨cgirls_vb_shortlog⟩´,
102 ** `⟨cgirls_vb_atom⟩´, and `⟨cgirls_vb_patch⟩´ indicate requests for
103 ** logs of a number of 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
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. The value of
155 ** `⟨.subpath⟩´, if not `⟨nullptr⟩´, must be a `⟨nullptr⟩´‐terminated
158 ** All requests have a status, which is used to express request
159 ** validity. If `⟨.status⟩⟨.code⟩´ is not `200´, the request is
160 ** invalid and a response with the associated code and message is
163 typedef struct cgirls_req cgirls_req
;
168 char* id_THIS_WILL_CHANGE
;
170 char* baseid_THIS_WILL_CHANGE
;
171 cgirls_req_status status
;
176 **////////////////////////////////////////////////////////////////////
178 ** ❦ `⸤cgirls_req⸥ ⟨cgirls_path·to·req⟩(⸤char const*const⸥)´
180 ** The `⟨cgirls_path·to·req⟩´ function takes a path string (such as
181 ** one provided by the C·G·I `⟨PATH_INFO⟩´ environment variable) and
182 ** returns a `⸤cgirls_req⸥´ which represents its semantics.
184 ** This resulting struct contains a lot of dynamically‐allocated data,
185 ** so it ☞︎must☜︎ be freed with `⟨cgirls_req·free⟩´ after use.
187 ** Maximally, the path string is processed according to the following
190 ** |`{project}/{action}/{revspec}/{subpath}´
192 ** —: (where `{subpath}´ can contain additional slashes, and
193 ** `{action}´ consists of a verb and optionally a supported mediatype
194 ** extension). Not all components necessarily need to be specified,
195 ** and not all possible values are valid or meaningful.
197 ** In case of an error, `⟨.status⟩⟨.code⟩´ on the returned
198 ** `⸤cgirls_req⸥´ will be some·thing other than `200´.
200 cgirls_req cgirls_path·to·
req(char const*const);
203 ** ❦ `⸤void⸥ ⟨cgirls_req·free⟩(⸤cgirls_req⸥)´
205 ** The `⟨cgirls_req·free⟩´ function frees up any dynamically‐allocated
206 ** memory in the provided `⸤cgirls_req⸥´, assuming that it was created
207 ** with `⟨cgirls_path·to·req⟩´ or similar.
209 void cgirls_req·
free(cgirls_req
);
212 ** ❦ `⸤char*⸥ ⟨cgirls_req·to·path⟩(⸤cgirls_req⸥)´
214 ** The `⟨cgirls_req·to·path⟩´ function does the reverse of
215 ** `⟨cgirls_path·to·req⟩´: It takes in a `⸤cgirls_req⸥´ struct and
216 ** returns the canonical path string which represents it.
218 ** All possible `⸤cgirls_req⸥´s have a canonical string
219 ** representation; `⟨cgirls_req·to·path⟩´ will only return `⟨nullptr⟩´
220 ** if it fails to allocate memory while constructing the resulting
221 ** string. Return values are dynamically allocated and must be
222 ** manually freed with `⟨free⟩´.
224 ** It is worth noting that, if the `⟨.project⟩´ is the null pointer,
225 ** the canonical path string will always be the empty string.
227 char* cgirls_req·to·
path(cgirls_req
);
229 #endif /* CGIRLS_REQUEST_H */