Skip to content

Commit 7bf99da

Browse files
committed
first implementation.
1 parent 6af145d commit 7bf99da

10 files changed

+879
-0
lines changed

build.c

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <_string.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#include "arena.h"
6+
#include "csv.h"
7+
#include "fs.h"
8+
#include "strchrepl.h"
9+
10+
void render_methods(struct csv_t *csv) {
11+
FILE* output = fs_open("./http_method.h", "w");
12+
13+
fprintf(output, "#ifndef __HTTP_TYPES_METHODS__\n");
14+
fprintf(output, "#define __HTTP_TYPES_METHODS__ 1\n\n");
15+
16+
for (size_t i = 1; i < csv->row_count - 1; ++i) {
17+
char** row = csv_row(csv, i);
18+
fprintf(output, "#define HTTP_METHODS_%s \"%s\"\n", row[0], row[0]);
19+
}
20+
21+
fprintf(output, "\n#endif // __HTTP_TYPES_METHODS__\n");
22+
23+
fclose(output);
24+
}
25+
26+
// http-status-codes-1.csv
27+
28+
void render_headers(struct csv_t *csv) {
29+
FILE* output = fs_open("./http_headers.h", "w");
30+
31+
fprintf(output, "#ifndef __HTTP_TYPES_HEADERS__\n");
32+
fprintf(output, "#define __HTTP_TYPES_HEADERS__ 1\n\n");
33+
34+
for (size_t i = 1; i < csv->row_count - 1; ++i) {
35+
char** row = csv_row(csv, i);
36+
char* name = strdup(row[0]);
37+
(void)strchrepl(name, '-', '_');
38+
fprintf(output, "#define HTTP_HEADER_%s \"%s\"\n", name, row[0]);
39+
// free(name);
40+
}
41+
42+
fprintf(output, "\n#endif // __HTTP_TYPES_HEADERS__\n");
43+
44+
fclose(output);
45+
}
46+
47+
void render_statuses(struct csv_t *csv) {
48+
FILE* output = fs_open("./http_statuses.h", "w");
49+
50+
fprintf(output, "#ifndef __HTTP_TYPES_STATUSES__\n");
51+
fprintf(output, "#define __HTTP_TYPES_STATUSES__ 1\n\n");
52+
53+
for (size_t i = 1; i < csv->row_count - 1; ++i) {
54+
char** row = csv_row(csv, i);
55+
if (memcmp(row[1], "Unassigned", strlen("Unassigned")) == 0) {
56+
fprintf(output, "// #define HTTP_STATUS_%s \"%s\"\n", row[0], row[0]);
57+
} else {
58+
fprintf(output, "#define HTTP_STATUS_%s \"%s\"\n", row[0], row[0]);
59+
}
60+
}
61+
62+
fprintf(output, "\n#endif // __HTTP_TYPES_STATUSES__\n");
63+
64+
fclose(output);
65+
}
66+
67+
int build(char* filename, void (*render)(struct csv_t*)) {
68+
arena_t arena = {0};
69+
arena_create(&arena, 4096 * 8);
70+
71+
struct csv_t csv = {0};
72+
73+
const char *content = fs_read(filename);
74+
75+
(void)csv_parse(&arena, &csv, content);
76+
77+
render(&csv);
78+
79+
free((char*)content);
80+
81+
// csv_free(&csv);
82+
arena_free(&arena);
83+
84+
return 0;
85+
}
86+
87+
int main(void) {
88+
build("methods.csv", render_methods);
89+
build("field-names.csv", render_headers);
90+
build("http-status-codes-1.csv", render_statuses);
91+
return 0;
92+
}

clib.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "http_types",
3+
"version": "0.1.0",
4+
"repo": "c-sdk/http_types",
5+
"description": "HTTP types available on the IANA.org.",
6+
"license": "unlicense",
7+
"keyworkds": ["http", "methods", "fields", "headers", "types", "statuses", "http status", "http methods", "http header field names"],
8+
"src": ["./http_statuses.h", "./http_fields.h", "./http_methods.h", "./http_types.h"],
9+
"dependencies": {
10+
"jwerle/fs.c": "*",
11+
"c-sdk/csv": "*",
12+
"c-sdk/arena": "*",
13+
"c-sdk/strchrepl": "*"
14+
}
15+
}

compile_flags.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-std=c17
2+
-I.
3+
-I./deps/arena
4+
-I./deps/fs
5+
-I./deps/csv
6+
-I./deps/strchrepl
7+

field-names.csv

+248
Large diffs are not rendered by default.

http-status-codes-1.csv

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Value,Description,Reference
2+
100,Continue,"[RFC9110, Section 15.2.1]"
3+
101,Switching Protocols,"[RFC9110, Section 15.2.2]"
4+
102,Processing,[RFC2518]
5+
103,Early Hints,[RFC8297]
6+
104,"Upload Resumption Supported (TEMPORARY - registered 2024-11-13, expires 2025-11-13)",[draft-ietf-httpbis-resumable-upload-05]
7+
105-199,Unassigned,
8+
200,OK,"[RFC9110, Section 15.3.1]"
9+
201,Created,"[RFC9110, Section 15.3.2]"
10+
202,Accepted,"[RFC9110, Section 15.3.3]"
11+
203,Non-Authoritative Information,"[RFC9110, Section 15.3.4]"
12+
204,No Content,"[RFC9110, Section 15.3.5]"
13+
205,Reset Content,"[RFC9110, Section 15.3.6]"
14+
206,Partial Content,"[RFC9110, Section 15.3.7]"
15+
207,Multi-Status,[RFC4918]
16+
208,Already Reported,[RFC5842]
17+
209-225,Unassigned,
18+
226,IM Used,[RFC3229]
19+
227-299,Unassigned,
20+
300,Multiple Choices,"[RFC9110, Section 15.4.1]"
21+
301,Moved Permanently,"[RFC9110, Section 15.4.2]"
22+
302,Found,"[RFC9110, Section 15.4.3]"
23+
303,See Other,"[RFC9110, Section 15.4.4]"
24+
304,Not Modified,"[RFC9110, Section 15.4.5]"
25+
305,Use Proxy,"[RFC9110, Section 15.4.6]"
26+
306,(Unused),"[RFC9110, Section 15.4.7]"
27+
307,Temporary Redirect,"[RFC9110, Section 15.4.8]"
28+
308,Permanent Redirect,"[RFC9110, Section 15.4.9]"
29+
309-399,Unassigned,
30+
400,Bad Request,"[RFC9110, Section 15.5.1]"
31+
401,Unauthorized,"[RFC9110, Section 15.5.2]"
32+
402,Payment Required,"[RFC9110, Section 15.5.3]"
33+
403,Forbidden,"[RFC9110, Section 15.5.4]"
34+
404,Not Found,"[RFC9110, Section 15.5.5]"
35+
405,Method Not Allowed,"[RFC9110, Section 15.5.6]"
36+
406,Not Acceptable,"[RFC9110, Section 15.5.7]"
37+
407,Proxy Authentication Required,"[RFC9110, Section 15.5.8]"
38+
408,Request Timeout,"[RFC9110, Section 15.5.9]"
39+
409,Conflict,"[RFC9110, Section 15.5.10]"
40+
410,Gone,"[RFC9110, Section 15.5.11]"
41+
411,Length Required,"[RFC9110, Section 15.5.12]"
42+
412,Precondition Failed,"[RFC9110, Section 15.5.13]"
43+
413,Content Too Large,"[RFC9110, Section 15.5.14]"
44+
414,URI Too Long,"[RFC9110, Section 15.5.15]"
45+
415,Unsupported Media Type,"[RFC9110, Section 15.5.16]"
46+
416,Range Not Satisfiable,"[RFC9110, Section 15.5.17]"
47+
417,Expectation Failed,"[RFC9110, Section 15.5.18]"
48+
418,(Unused),"[RFC9110, Section 15.5.19]"
49+
419-420,Unassigned,
50+
421,Misdirected Request,"[RFC9110, Section 15.5.20]"
51+
422,Unprocessable Content,"[RFC9110, Section 15.5.21]"
52+
423,Locked,[RFC4918]
53+
424,Failed Dependency,[RFC4918]
54+
425,Too Early,[RFC8470]
55+
426,Upgrade Required,"[RFC9110, Section 15.5.22]"
56+
427,Unassigned,
57+
428,Precondition Required,[RFC6585]
58+
429,Too Many Requests,[RFC6585]
59+
430,Unassigned,
60+
431,Request Header Fields Too Large,[RFC6585]
61+
432-450,Unassigned,
62+
451,Unavailable For Legal Reasons,[RFC7725]
63+
452-499,Unassigned,
64+
500,Internal Server Error,"[RFC9110, Section 15.6.1]"
65+
501,Not Implemented,"[RFC9110, Section 15.6.2]"
66+
502,Bad Gateway,"[RFC9110, Section 15.6.3]"
67+
503,Service Unavailable,"[RFC9110, Section 15.6.4]"
68+
504,Gateway Timeout,"[RFC9110, Section 15.6.5]"
69+
505,HTTP Version Not Supported,"[RFC9110, Section 15.6.6]"
70+
506,Variant Also Negotiates,[RFC2295]
71+
507,Insufficient Storage,[RFC4918]
72+
508,Loop Detected,[RFC5842]
73+
509,Unassigned,
74+
510,Not Extended (OBSOLETED),[RFC2774][Status change of HTTP experiments to Historic]
75+
511,Network Authentication Required,[RFC6585]
76+
512-599,Unassigned,

0 commit comments

Comments
 (0)