summaryrefslogtreecommitdiff
path: root/src/libtipidee
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-10-06 00:13:28 +0000
committerLaurent Bercot <ska@appnovation.com>2023-10-06 00:13:28 +0000
commitd9f5cb7a28ee79e299e41d3ce325171f01e1a3d7 (patch)
treec13af66675cbd2ed3de340ab139297e4dcdbd199 /src/libtipidee
parent8d66c8c5cac310958fa64e3f62b828ea960202ba (diff)
downloadtipidee-d9f5cb7a28ee79e299e41d3ce325171f01e1a3d7.tar.xz
Some fixes, preparation for changes in error responses
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee')
-rw-r--r--src/libtipidee/deps-lib/tipidee1
-rw-r--r--src/libtipidee/tipidee_util_defaulttext.c59
2 files changed, 60 insertions, 0 deletions
diff --git a/src/libtipidee/deps-lib/tipidee b/src/libtipidee/deps-lib/tipidee
index 81cc5f7..b7f88cc 100644
--- a/src/libtipidee/deps-lib/tipidee
+++ b/src/libtipidee/deps-lib/tipidee
@@ -23,5 +23,6 @@ tipidee_response_status.o
tipidee_rql_read.o
tipidee_uri_parse.o
tipidee_util_chunked_read.o
+tipidee_util_defaulttext.o
tipidee_util_httpdate.o
-lskarnet
diff --git a/src/libtipidee/tipidee_util_defaulttext.c b/src/libtipidee/tipidee_util_defaulttext.c
new file mode 100644
index 0000000..d464e48
--- /dev/null
+++ b/src/libtipidee/tipidee_util_defaulttext.c
@@ -0,0 +1,59 @@
+/* ISC license. */
+
+#include <stdlib.h>
+
+#include <tipidee/util.h>
+
+struct blah_s
+{
+ unsigned int status ;
+ char const *reason ;
+ char const *text ;
+} ;
+
+static struct blah_s const data[] =
+{
+ { .status = 200, .reason = "OK", .text = 0 },
+ { .status = 206, .reason = "Partial Content", .text = 0 },
+ { .status = 301, .reason = "Moved Permanently", .text = 0 },
+ { .status = 302, .reason = "Found", .text = 0 },
+ { .status = 304, .reason = "Not Modified", .text = 0 },
+ { .status = 307, .reason = "Temporary Redirect", .text = 0 },
+ { .status = 308, .reason = "Permanent Redirect", .text = 0 },
+ { .status = 400, .reason = "Bad Request", .text = "Bad HTTP request." },
+ { .status = 401, .reason = "Unauthorized", .text = "You need to be authenticated to access this resource." },
+ { .status = 403, .reason = "Forbidden", .text = "Missing credentials to access the resource." },
+ { .status = 404, .reason = "Not Found", .text = "The requested resource was not found." },
+ { .status = 405, .reason = "Method Not Allowed", .text = "This method is not allowed on this resource." },
+ { .status = 408, .reason = "Request Timeout", .text = "The client took too long to formulate its request." },
+ { .status = 412, .reason = "Precondition Failed", .text = 0 },
+ { .status = 413, .reason = "Content Too Large", .text = "Too much data in the request body." },
+ { .status = 414, .reason = "URI Too Long", .text = "The request URI had an oversized component." },
+ { .status = 416, .reason = "Range Not Satisfiable", .text = 0 },
+ { .status = 500, .reason = "Internal Server Error", .text = "There was a server-side issue while processing your request. Sorry." },
+ { .status = 501, .reason = "Not Implemented", .text = "The server does not implement this method." },
+ { .status = 502, .reason = "Bad Gateway", .text = "There was an issue with the backend while processing your request. Sorry." },
+ { .status = 504, .reason = "Gateway Timeout", .text = "The backend took too long to answer. Sorry." },
+ { .status = 505, .reason = "HTTP Version Not Supported", .text = "The server does not implement this version of the protocol." },
+} ;
+
+static int blah_cmp (void const *key, void const *el)
+{
+ unsigned int a = *(unsigned int const *)key ;
+ unsigned int b = ((struct blah_s *)el)->status ;
+ return a < b ? -1 : a > b ;
+}
+
+int tipidee_util_defaulttext (unsigned int status, tipidee_defaulttext *dt)
+{
+ struct blah_s const *p = bsearch(
+ &status,
+ data,
+ sizeof(data) / sizeof(struct blah_s),
+ sizeof(struct blah_s),
+ &blah_cmp) ;
+ if (!p) return 0 ;
+ dt->reason = p->reason ;
+ dt->text = p->text ;
+ return 1 ;
+}