First version of the refactor

This commit is contained in:
2025-11-21 12:53:03 +01:00
parent 7be22fed4b
commit 879dc74e34
55 changed files with 4929 additions and 10370 deletions
-3
View File
@@ -1,3 +0,0 @@
(The following are thoughts that came to mind that I didn't have the time to add to docs but don't want to forget.)
The immediate mode API allows writing directly to the library's output buffer avoiding intermediate allocations
-8
View File
@@ -1,8 +0,0 @@
Allow resolving requests from different threads
Find a way to make sure chttp.h and chttp.c are always up to date
Find a way to compile OpenSSL on windows
handle 3xx client redirections
add discussion on string management
add discussion on error management
add timers
add debug and release builds
+51 -26
View File
@@ -6,56 +6,81 @@ class Amalgamator:
self.out += text
def append_file(self, file):
self.out += "\n"
self.out += "////////////////////////////////////////////////////////////////////////////////////////\n"
self.out += "// " + file + "\n"
self.out += "////////////////////////////////////////////////////////////////////////////////////////\n"
self.out += "\n"
self.out += "#line 1 \"" + file + "\"\n"
self.out += open(file).read()
if len(self.out) > 0 and self.out[len(self.out)-1] != '\n':
if len(self.out) > 0 and self.out[len(self.out) - 1] != "\n":
self.out += "\n"
def save(self, file):
open(file, 'w').write(self.out)
open(file, "w").write(self.out)
desc = """
// This file was generated automatically. Do not modify directly!
desc = """// cHTTP, an HTTP client and server library!
//
// This file was generated automatically. Do not modify directly.
//
// Refer to the end of this file for the license"""
license = """
////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2025 Francesco Cozzuto
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall
// be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////
"""
header = Amalgamator()
header.append_text("#ifndef HTTP_AMALGAMATION\n")
header.append_text("#define HTTP_AMALGAMATION\n")
header.append_text(desc)
header.append_file("src/includes.h")
header.append_file("src/basic.h")
header.append_file("src/parse.h")
header.append_file("src/engine.h")
header.append_file("src/secure_context.h")
header.append_file("src/socket.h")
header.append_file("src/thread.h")
header.append_file("src/byte_queue.h")
header.append_file("src/cert.h")
header.append_file("src/client.h")
header.append_file("src/parse.h")
header.append_file("src/server.h")
header.append_text("#endif // HTTP_AMALGAMATION\n")
header.append_text(license)
header.save("chttp.h")
source = Amalgamator()
source.append_text("#ifndef HTTP_NOINCLUDE\n")
source.append_text("#include \"chttp.h\"\n")
source.append_text(desc)
source.append_text("\n")
source.append_text("#ifndef HTTP_DONT_INCLUDE\n")
source.append_text('#include "chttp.h"\n')
source.append_text("#endif\n")
source.append_file("src/sec.h")
source.append_file("src/socket_raw.h")
source.append_file("src/socket.h")
source.append_file("src/socket_pool.h")
source.append_file("src/basic.c")
source.append_file("src/parse.c")
source.append_file("src/engine.c")
source.append_file("src/cert.c")
source.append_file("src/sec.c")
source.append_file("src/socket_raw.c")
source.append_file("src/secure_context.c")
source.append_file("src/socket.c")
source.append_file("src/socket_pool.c")
source.append_file("src/thread.c")
source.append_file("src/byte_queue.c")
source.append_file("src/cert.c")
source.append_file("src/client.c")
source.append_file("src/parse.c")
source.append_file("src/server.c")
header.append_text(license)
source.save("chttp.c")