summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-07-26 14:31:05 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-07-26 14:31:05 +0300
commitdd4c7ce2e7c55098a90e5b8a265299d10bd52cef (patch)
treee5c60b5b14d3a9aa2b97a955a568ff2a6a30b8bc /src
parent37009e2f98334632b76dbba08712186ae48cfc36 (diff)
Full set of Gemini status codes
Diffstat (limited to 'src')
-rw-r--r--src/gemini.h17
-rw-r--r--src/gmutil.c91
2 files changed, 106 insertions, 2 deletions
diff --git a/src/gemini.h b/src/gemini.h
index 3c00d425..ffe269df 100644
--- a/src/gemini.h
+++ b/src/gemini.h
@@ -1,9 +1,12 @@
1#pragma once 1#pragma once
2 2
3#include <the_Foundation/string.h>
4
3/* Response status codes. */ 5/* Response status codes. */
4enum iGmStatusCode { 6enum iGmStatusCode {
5 failedToOpenFile_GmStatusCode = -2, 7 invalidRedirect_GmStatusCode = -3,
6 invalidHeader_GmStatusCode = -1, 8 invalidHeader_GmStatusCode = -2,
9 failedToOpenFile_GmStatusCode = -1,
7 none_GmStatusCode = 0, 10 none_GmStatusCode = 0,
8 input_GmStatusCode = 10, 11 input_GmStatusCode = 10,
9 sensitiveInput_GmStatusCode = 11, 12 sensitiveInput_GmStatusCode = 11,
@@ -24,3 +27,13 @@ enum iGmStatusCode {
24 certificateNotAuthorized_GmStatusCode = 61, 27 certificateNotAuthorized_GmStatusCode = 61,
25 certificateNotValid_GmStatusCode = 62, 28 certificateNotValid_GmStatusCode = 62,
26}; 29};
30
31iDeclareType(GmError)
32
33struct Impl_GmError {
34 iChar icon;
35 const char *title;
36 const char *info;
37};
38
39const iGmError * get_GmError (enum iGmStatusCode code);
diff --git a/src/gmutil.c b/src/gmutil.c
index ce50f015..0270c2a7 100644
--- a/src/gmutil.c
+++ b/src/gmutil.c
@@ -1,4 +1,5 @@
1#include "gmutil.h" 1#include "gmutil.h"
2#include "gemini.h"
2 3
3#include <the_Foundation/regexp.h> 4#include <the_Foundation/regexp.h>
4#include <the_Foundation/object.h> 5#include <the_Foundation/object.h>
@@ -32,3 +33,93 @@ void urlEncodeSpaces_String(iString *d) {
32 insertData_Block(&d->chars, pos, "%20", 3); 33 insertData_Block(&d->chars, pos, "%20", 3);
33 } 34 }
34} 35}
36
37const iGmError *get_GmError(enum iGmStatusCode code) {
38 static const iGmError none = { 0, "", "" };
39 static const struct {
40 enum iGmStatusCode code;
41 iGmError err;
42 } errors[] = {
43 { failedToOpenFile_GmStatusCode,
44 { 0x1f4c1, /* file folder */
45 "Failed to Open File",
46 "The requested file does not exist or is inaccessible. "
47 "Please check the file path." } },
48 { invalidHeader_GmStatusCode,
49 { 0x1f4a9, /* pile of poo */
50 "Invalid Header",
51 "The received header did not conform to the Gemini specification. "
52 "Perhaps the server is malfunctioning or you tried to contact a "
53 "non-Gemini server." } },
54 { invalidRedirect_GmStatusCode,
55 { 0, /* */
56 "Invalid Redirect",
57 "The server responded with a redirect but did not provide a valid destination URL. "
58 "Perhaps the server is malfunctioning." } },
59 { temporaryFailure_GmStatusCode,
60 { 0x1f50c, /* electric plug */
61 "Temporary Failure",
62 "The request has failed, but may succeed if you try again in the future." } },
63 { serverUnavailable_GmStatusCode,
64 { 0x1f525, /* fire */
65 "Server Unavailable",
66 "The server is unavailable due to overload or maintenance. Check back later." } },
67 { cgiError_GmStatusCode,
68 { 0x1f4a5, /* collision */
69 "CGI Error",
70 "Failure during dynamic content generation on the server. This may be due "
71 "to buggy serverside software." } },
72 { proxyError_GmStatusCode,
73 { 0x1f310, /* globe */
74 "Proxy Error",
75 "A proxy request failed because the server was unable to successfully "
76 "complete a transaction with the remote host. Perhaps there are difficulties "
77 "with network connectivity." } },
78 { slowDown_GmStatusCode,
79 { 0x1f40c, /* snail */
80 "Slow Down",
81 "The server is rate limiting requests. Please wait..." } },
82 { permanentFailure_GmStatusCode,
83 { 0x1f6ab, /* no entry */
84 "Permanent Failure",
85 "Your request has failed and will fail in the future as well if repeated." } },
86 { notFound_GmStatusCode,
87 { 0x1f50d, /* magnifying glass */
88 "Not Found",
89 "The requested resource could not be found at this time." } },
90 { gone_GmStatusCode,
91 { 0x1f47b, /* ghost */
92 "Gone",
93 "The resource requested is no longer available and will not be available again." } },
94 { proxyRequestRefused_GmStatusCode,
95 { 0x1f6c2, /* passport control */
96 "Proxy Request Refused",
97 "The request was for a resource at a domain not served by the server and the "
98 "server does not accept proxy requests." } },
99 { badRequest_GmStatusCode,
100 { 0x1f44e, /* thumbs down */
101 "Bad Request",
102 "The server was unable to parse your request, presumably due to the "
103 "request being malformed. Likely a bug in Lagrange." } },
104 { clientCertificateRequired_GmStatusCode,
105 { 0x1f511, /* key */
106 "Certificate Required",
107 "Access to the requested resource requires identification via "
108 "a client certificate." } },
109 { certificateNotAuthorized_GmStatusCode,
110 { 0x1f512, /* lock */
111 "Certificate Not Authorized",
112 "The provided client certificate is valid but is not authorized for accessing "
113 "the requested resource. " } },
114 { certificateNotValid_GmStatusCode,
115 { 0x1f6a8, /* revolving light */
116 "Invalid Certificate",
117 "The provided client certificate is expired or invalid." } },
118 };
119 iForIndices(i, errors) {
120 if (errors[i].code == code) {
121 return &errors[i].err;
122 }
123 }
124 return &none;
125}