💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › afd538824be97cc21642912b3a0d0… captured on 2023-12-28 at 15:42:59. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
0 /*
1 * ISC License
2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>
3 */
4 #include <stdlib.h>
5 #include "macro.h"
6 #include "error.h"
7 #include "strlcpy.h"
8 #include "strnstr.h"
9 #include "gemini.h"
10
11 int gemini_status_code(int status) {
12 if (status < 10 || status >= 70) return -1;
13 switch (status) { /* if the code is known, return it as it is */
14 case 10: case 11:
15 case 20:
16 case 30:
17 case 31:
18 case 40: case 41: case 42: case 43: case 44:
19 case 50: case 51: case 52: case 53: case 59:
20 case 60: case 61: case 62:
21 return status;
22 }
23 return status - (status % 10);
24 }
25
26 int gemini_iserror(int status) {
27 return status < 10 || status >= 40;
28 }
29
30 int gemini_isredirect(int status) {
31 return status >= 30 && status < 40;
32 }
33
34 int gemini_isinput(int status) {
35 return status == GMI_INPUT || status == GMI_SECRET;
36 }
37
38 int gemini_status_string(int status, char *out, size_t length) {
39 switch (status) {
40 case 10: return strlcpy(out, "Input", length);
41 case 11: return strlcpy(out, "Sensitive input", length);
42 case 20: return strlcpy(out, "Success", length);
43 case 30: return strlcpy(out, "Temporary redirect", length);
44 case 31: return strlcpy(out, "Permanent redirect", length);
45 case 40: return strlcpy(out, "Temporary failure", length);
46 case 41: return strlcpy(out, "Server unvailable", length);
47 case 42: return strlcpy(out, "CGI error", length);
48 case 43: return strlcpy(out, "Proxy error", length);
49 case 44: return strlcpy(out, "Slow down", length);
50 case 50: return strlcpy(out, "Permanent failure", length);
51 case 51: return strlcpy(out, "Not found", length);
52 case 52: return strlcpy(out, "Gone", length);
53 case 53: return strlcpy(out, "Proxy request refused", length);
54 case 59: return strlcpy(out, "Bad request", length);
55 case 60: return strlcpy(out, "Client certificate required", length);
56 case 61: return strlcpy(out, "Certificate not authorised", length);
57 case 62: return strlcpy(out, "Certificate not valid", length);
58 }
59 return -1;
60 }
61