Rename http.c/.h to chttp.c/.h and improve amalgamation formatting
This commit is contained in:
@@ -6,16 +6,10 @@ LFLAGS = -lssl -lcrypto
|
||||
CFILES = $(shell find src -name "*.c")
|
||||
HFILES = $(shell find src -name "*.h")
|
||||
|
||||
all: client_example server_example http.c http.h
|
||||
all: chttp.c chttp.h
|
||||
|
||||
http.c http.h: $(HFILES) $(CFILES)
|
||||
chttp.c chttp.h: $(HFILES) $(CFILES)
|
||||
python misc/amalg.py
|
||||
|
||||
client_example: examples/client_example.c http.c http.h
|
||||
$(CC) examples/client_example.c http.c $(CFLAGS) -o $@ $(LFLAGS)
|
||||
|
||||
server_example: examples/server_example.c http.c http.h
|
||||
$(CC) examples/server_example.c http.c $(CFLAGS) -o $@ $(LFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f client_example server_example
|
||||
|
||||
+36
-6
@@ -30,9 +30,17 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/cert.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
int http_create_test_certificate(HTTP_String C, HTTP_String O, HTTP_String CN,
|
||||
HTTP_String cert_file, HTTP_String key_file);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/socket.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This is a socket abstraction module for non-blocking TCP and TLS sockets.
|
||||
//
|
||||
// Sockets may be in a number of states based on if they are plain TCP or TLS
|
||||
@@ -156,6 +164,10 @@ void socket_close (Socket *sock);
|
||||
void socket_free (Socket *sock);
|
||||
int socket_wait (Socket **socks, int num_socks);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/basic.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
int http_streq(HTTP_String s1, HTTP_String s2)
|
||||
{
|
||||
if (s1.len != s2.len)
|
||||
@@ -246,7 +258,10 @@ void print_bytes(HTTP_String prefix, HTTP_String src)
|
||||
cur++;
|
||||
}
|
||||
putc('\n', stream);
|
||||
}
|
||||
}//////////////////////////////////////////////////////////////////////
|
||||
// src/parse.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// From RFC 9112
|
||||
// request-target = origin-form
|
||||
// / absolute-form
|
||||
@@ -1276,7 +1291,10 @@ HTTP_String http_getcookie(HTTP_Request *req, HTTP_String name)
|
||||
{
|
||||
// TODO
|
||||
return (HTTP_String) {NULL, 0};
|
||||
}
|
||||
}//////////////////////////////////////////////////////////////////////
|
||||
// src/engine.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This is the implementation of a byte queue useful
|
||||
// for systems that need to process engs of bytes.
|
||||
//
|
||||
@@ -2260,7 +2278,10 @@ void http_engine_undo(HTTP_Engine *eng)
|
||||
eng->state = HTTP_ENGINE_STATE_CLIENT_PREP_URL;
|
||||
else
|
||||
eng->state = HTTP_ENGINE_STATE_SERVER_PREP_STATUS;
|
||||
}
|
||||
}//////////////////////////////////////////////////////////////////////
|
||||
// src/socket.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void socket_global_init(void)
|
||||
{
|
||||
SSL_library_init();
|
||||
@@ -3023,7 +3044,10 @@ int socket_wait(Socket **socks, int num_socks)
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}//////////////////////////////////////////////////////////////////////
|
||||
// src/client.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO
|
||||
#define ERROR printf("error at %s:%d\n", __FILE__, __LINE__);
|
||||
|
||||
@@ -3387,7 +3411,10 @@ void http_request_free(HTTP_RequestHandle handle)
|
||||
socket_free(&conn->socket);
|
||||
conn->state = CLIENT_CONNECTION_FREE;
|
||||
client->num_conns--;
|
||||
}
|
||||
}//////////////////////////////////////////////////////////////////////
|
||||
// src/server.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define MAX_CONNS (1<<10)
|
||||
|
||||
typedef struct {
|
||||
@@ -3825,7 +3852,10 @@ void http_response_done(HTTP_ResponseHandle res)
|
||||
http_engine_free(&conn->engine);
|
||||
server->num_conns--;
|
||||
}
|
||||
}
|
||||
}//////////////////////////////////////////////////////////////////////
|
||||
// src/router.c
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WIN32
|
||||
#endif
|
||||
|
||||
@@ -13,6 +13,10 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/basic.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define HTTP_STR(X) ((HTTP_String) {(X), sizeof(X)-1})
|
||||
#define HTTP_CEIL(X, Y) (((X) + (Y) - 1) / (Y))
|
||||
|
||||
@@ -28,6 +32,10 @@ HTTP_String http_trim (HTTP_String s);
|
||||
#define HTTP_COUNT(X) (sizeof(X) / sizeof((X)[0]))
|
||||
#define HTTP_ASSERT(X) {if (!(X)) { __builtin_trap(); }}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/parse.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define HTTP_MAX_HEADERS 32
|
||||
|
||||
typedef struct {
|
||||
@@ -116,6 +124,10 @@ HTTP_String http_getqueryparam (HTTP_Request *req, HTTP_String name);
|
||||
HTTP_String http_getbodyparam (HTTP_Request *req, HTTP_String name);
|
||||
HTTP_String http_getcookie (HTTP_Request *req, HTTP_String name);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/engine.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef enum {
|
||||
HTTP_MEMFUNC_MALLOC,
|
||||
HTTP_MEMFUNC_FREE,
|
||||
@@ -229,6 +241,11 @@ char* http_engine_bodybuf (HTTP_Engine *eng, int *cap);
|
||||
void http_engine_bodyack (HTTP_Engine *eng, int num);
|
||||
void http_engine_done (HTTP_Engine *eng);
|
||||
void http_engine_undo (HTTP_Engine *eng);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/client.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
void http_global_init(void);
|
||||
void http_global_free(void);
|
||||
|
||||
@@ -252,6 +269,10 @@ void http_request_submit (HTTP_RequestHandle handle);
|
||||
HTTP_Response* http_request_result (HTTP_RequestHandle handle);
|
||||
void http_request_free (HTTP_RequestHandle handle);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/server.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct {
|
||||
void *data0;
|
||||
int data1;
|
||||
@@ -277,9 +298,17 @@ void http_response_bodyack (HTTP_ResponseHandle res, int num);
|
||||
void http_response_undo (HTTP_ResponseHandle res);
|
||||
void http_response_done (HTTP_ResponseHandle res);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/cert.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
int http_create_test_certificate(HTTP_String C, HTTP_String O, HTTP_String CN,
|
||||
HTTP_String cert_file, HTTP_String key_file);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// src/router.h
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct HTTP_Router HTTP_Router;
|
||||
typedef void (*HTTP_RouterFunc)(HTTP_Request*, HTTP_ResponseHandle, void*);;
|
||||
|
||||
+9
-4
@@ -26,6 +26,11 @@ class AmalgamationBuilder:
|
||||
skipped_lines = 0
|
||||
first_content_line = True
|
||||
|
||||
self.body += "//////////////////////////////////////////////////////////////////////\n"
|
||||
self.body += "// " + filepath + "\n"
|
||||
self.body += "//////////////////////////////////////////////////////////////////////\n"
|
||||
self.body += "\n"
|
||||
|
||||
for line in lines:
|
||||
# Check if the line is an include
|
||||
if self._is_include_line(line):
|
||||
@@ -190,8 +195,8 @@ def main():
|
||||
source = source_builder.result()
|
||||
|
||||
# Write results
|
||||
print("Writing http.h...")
|
||||
with open("http.h", 'w', encoding='utf-8') as f:
|
||||
print("Writing chttp.h...")
|
||||
with open("chttp.h", 'w', encoding='utf-8') as f:
|
||||
f.write('/*\n')
|
||||
f.write(' * HTTP Library - Amalgamated Header\n')
|
||||
f.write(' * Generated automatically - do not edit manually\n')
|
||||
@@ -207,8 +212,8 @@ def main():
|
||||
f.write('#endif\n\n')
|
||||
f.write('#endif /* HTTP_AMALGAMATION_H */\n')
|
||||
|
||||
print("Writing http.c...")
|
||||
with open("http.c", 'w', encoding='utf-8') as f:
|
||||
print("Writing chttp.c...")
|
||||
with open("chttp.c", 'w', encoding='utf-8') as f:
|
||||
f.write('/*\n')
|
||||
f.write(' * HTTP Library - Amalgamated Source\n')
|
||||
f.write(' * Generated automatically - do not edit manually\n')
|
||||
|
||||
@@ -115,4 +115,5 @@ char* http_engine_bodybuf (HTTP_Engine *eng, int *cap);
|
||||
void http_engine_bodyack (HTTP_Engine *eng, int num);
|
||||
void http_engine_done (HTTP_Engine *eng);
|
||||
void http_engine_undo (HTTP_Engine *eng);
|
||||
|
||||
#endif // HTTP_ENGINE_INCLUDED
|
||||
Reference in New Issue
Block a user