From 82fffd1acebf688f1c082d7a597d68239e8a39cc Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 23 Apr 2023 05:09:53 +0200 Subject: Support URL parameters Now, http_payload includes a list of human-readable parameters that can be read (but not modified) by users. Given the following example link: /test?key1=value1&key2=value2 This will generate two parameters, with the following values: { .args = { [0] = {.key = "key1", .value = "value1"}, [1] = {.key = "key2", .value = "value2"} }, .n_args = 2 } As expected, if any URL parameters are given, struct http_payload member "resource" is accordingly trimmed so as not to include any parameters. Therefore, considering the example above: {.args = {...}, .resource = "/test"} Limitations: - Since the definition of struct http_arg is both shared by http.h (as a read-only pointer within struct http_payload) and http.c (as a read/write pointer within struct ctx), its members (namely key and value) must remain as read/write pointers, even if they must not be modified by users of http.h. --- http.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'http.h') diff --git a/http.h b/http.h index ed0770f..8b3a286 100644 --- a/http.h +++ b/http.h @@ -35,6 +35,13 @@ struct http_payload } *files; } post; } u; + + const struct http_arg + { + char *key, *value; + } *args; + + size_t n_args; }; #define HTTP_STATUSES \ -- cgit v1.2.3