]> Lady’s Gitweb - CGirls/blobdiff - request.h
Add request parsing and related tests
[CGirls] / request.h
diff --git a/request.h b/request.h
new file mode 100644 (file)
index 0000000..2ab70e0
--- /dev/null
+++ b/request.h
@@ -0,0 +1,90 @@
+// SPDX-FileCopyrightText: 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: GPL-2.0-only
+
+#ifndef CGIRLS_REQUEST_H
+#define CGIRLS_REQUEST_H
+
+enum cgirls_mediatype : unsigned char {
+       // Unspecified media type
+       cgirls_mediatype_any = 0x00,
+       // Text media types
+       cgirls_mediatype_txt = 0x10,
+       cgirls_mediatype_htm = 0x11,
+       // X·M·L media types
+       cgirls_mediatype_xml = 0x20,
+       cgirls_mediatype_rdf = 0x21,
+};
+typedef enum cgirls_mediatype cgirls_mediatype;
+
+enum cgirls_vb : unsigned char {
+       // Actions in general
+       cgirls_vb_index = 0x00,
+       // Actions on projects
+       cgirls_vb_branches = 0x10,
+       cgirls_vb_tags = 0x11,
+       // Actions on single objects
+       cgirls_vb_show = 0x20,
+       cgirls_vb_raw = 0x21,
+       cgirls_vb_blame = 0x22,
+       // Actions on ranges of objects
+       cgirls_vb_log = 0x30,
+       cgirls_vb_shortlog = 0x31,
+       cgirls_vb_atom = 0x32,
+       cgirls_vb_patch = 0x33,
+       // Unknown verb
+       cgirls_vb_unknown = 0xFF,
+};
+typedef enum cgirls_vb cgirls_vb;
+
+typedef struct cgirls_req_status cgirls_req_status;
+struct cgirls_req_status {
+       unsigned short cgirls_code;
+       char* cgirls_message; // if `cgirls_code´ is not ok
+};
+
+typedef struct cgirls_req cgirls_req;
+struct cgirls_req {
+       cgirls_vb cgirls_action;
+       cgirls_mediatype cgirls_type;
+       char* cgirls_project;
+       char* cgirls_id;
+       char** cgirls_subpath;
+       char* cgirls_baseid;
+       cgirls_req_status cgirls_status;
+};
+
+/*
+Frees up any dynamically‐allocated memory which was allocated by
+`cgirls_path2req´.
+*/
+void cgirls_freereq (cgirls_req req);
+
+/*
+Converts the provided “path info” string into a `cgirls_req´ struct
+and returns the result.
+
+This struct contains dynamically‐allocated strings which must be freed
+by calling `cgirls_freereq´.
+
+Maximally, a “path info” string has the following form :—
+
+       {project}/{action}/{baseid}..{id}/{subpath}
+
+—: (where subpath can contain additional slashes, and action may
+optionally include one of a small number of supported extensions).
+`baseid´ is optional; if omitted, the dots preceding `id´ are also
+dropped. For all other components, all preceding components must be
+provided if a given component is provided.
+*/
+cgirls_req cgirls_path2req(char const*const pathinfo);
+
+/*
+Returns the canonical “path info” string which represents the provided
+`cgirls_req´.
+
+Note that if `cgirls_req.cgirls_project´ is the null pointer, the
+canonical “path info” string is always the empty string.
+*/
+char* cgirls_req2path(cgirls_req);
+
+#endif /* CGIRLS_REQUEST_H */
This page took 0.267388 seconds and 4 git commands to generate.