]> Lady’s Gitweb - CGirls/blob - request.h
Add request parsing and related tests
[CGirls] / request.h
1 // SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: GPL-2.0-only
3
4 #ifndef CGIRLS_REQUEST_H
5 #define CGIRLS_REQUEST_H
6
7 enum cgirls_mediatype : unsigned char {
8 // Unspecified media type
9 cgirls_mediatype_any = 0x00,
10 // Text media types
11 cgirls_mediatype_txt = 0x10,
12 cgirls_mediatype_htm = 0x11,
13 // X·M·L media types
14 cgirls_mediatype_xml = 0x20,
15 cgirls_mediatype_rdf = 0x21,
16 };
17 typedef enum cgirls_mediatype cgirls_mediatype;
18
19 enum cgirls_vb : unsigned char {
20 // Actions in general
21 cgirls_vb_index = 0x00,
22 // Actions on projects
23 cgirls_vb_branches = 0x10,
24 cgirls_vb_tags = 0x11,
25 // Actions on single objects
26 cgirls_vb_show = 0x20,
27 cgirls_vb_raw = 0x21,
28 cgirls_vb_blame = 0x22,
29 // Actions on ranges of objects
30 cgirls_vb_log = 0x30,
31 cgirls_vb_shortlog = 0x31,
32 cgirls_vb_atom = 0x32,
33 cgirls_vb_patch = 0x33,
34 // Unknown verb
35 cgirls_vb_unknown = 0xFF,
36 };
37 typedef enum cgirls_vb cgirls_vb;
38
39 typedef struct cgirls_req_status cgirls_req_status;
40 struct cgirls_req_status {
41 unsigned short cgirls_code;
42 char* cgirls_message; // if `cgirls_code´ is not ok
43 };
44
45 typedef struct cgirls_req cgirls_req;
46 struct cgirls_req {
47 cgirls_vb cgirls_action;
48 cgirls_mediatype cgirls_type;
49 char* cgirls_project;
50 char* cgirls_id;
51 char** cgirls_subpath;
52 char* cgirls_baseid;
53 cgirls_req_status cgirls_status;
54 };
55
56 /*
57 Frees up any dynamically‐allocated memory which was allocated by
58 `cgirls_path2req´.
59 */
60 void cgirls_freereq (cgirls_req req);
61
62 /*
63 Converts the provided “path info” string into a `cgirls_req´ struct
64 and returns the result.
65
66 This struct contains dynamically‐allocated strings which must be freed
67 by calling `cgirls_freereq´.
68
69 Maximally, a “path info” string has the following form :—
70
71 {project}/{action}/{baseid}..{id}/{subpath}
72
73 —: (where subpath can contain additional slashes, and action may
74 optionally include one of a small number of supported extensions).
75 `baseid´ is optional; if omitted, the dots preceding `id´ are also
76 dropped. For all other components, all preceding components must be
77 provided if a given component is provided.
78 */
79 cgirls_req cgirls_path2req(char const*const pathinfo);
80
81 /*
82 Returns the canonical “path info” string which represents the provided
83 `cgirls_req´.
84
85 Note that if `cgirls_req.cgirls_project´ is the null pointer, the
86 canonical “path info” string is always the empty string.
87 */
88 char* cgirls_req2path(cgirls_req);
89
90 #endif /* CGIRLS_REQUEST_H */
This page took 0.274827 seconds and 5 git commands to generate.