From cb839af1c8160a1576003c982340c29409b06e82 Mon Sep 17 00:00:00 2001 From: keqingmoe Date: Thu, 19 Dec 2024 22:10:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=9D=E5=A7=8B=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=BB=93=E6=9E=84=EF=BC=8C=E5=8C=85=E6=8B=AC=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96=E9=85=8D=E7=BD=AE=E3=80=81?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E6=96=87=E4=BB=B6=E3=80=81=E5=A4=B4=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AE=9A=E4=B9=89=E3=80=81=E4=B8=BB=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=92=8C=E6=9E=84=E5=BB=BA=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .clang-format | 57 +++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 5 ++++ include/kqm/defs.h | 8 +++++++ include/kqm/types.h | 11 +++++++++ src/main.c | 31 ++++++++++++++++++++++++ xmake.lua | 15 ++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 include/kqm/defs.h create mode 100644 include/kqm/types.h create mode 100644 src/main.c create mode 100644 xmake.lua diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..5ee97e7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,57 @@ +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: Left +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + PadOperators: true +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false +AlignOperands: Align +AllowAllParametersOfDeclarationOnNextLine: true +AllowAllArgumentsOnNextLine: false +AllowShortLambdasOnASingleLine: Empty +AllowShortFunctionsOnASingleLine: Empty +AllowShortBlocksOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakTemplateDeclarations: "Yes" +BinPackArguments: false +BinPackParameters: false +BreakBeforeBraces: Custom +BreakBeforeBinaryOperators: NonAssignment +ColumnLimit: 120 +CommentPragmas: "^ IWYU pragma:" +ConstructorInitializerIndentWidth: 4 +IndentWidth: 4 +Language: Cpp +MaxEmptyLinesToKeep: 2 +PointerAlignment: Left +TabWidth: 4 +UseTab: Never +SortIncludes: CaseSensitive +BraceWrapping: + AfterEnum: true + AfterStruct: true + AfterClass: true + AfterUnion: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true +IndentRequires: true +FixNamespaceComments: false +NamespaceIndentation: None +BreakBeforeConceptDeclarations: Always +RequiresClausePosition: OwnLine +IndentRequiresClause: true +AllowBreakBeforeNoexceptSpecifier: OnlyWithParen diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39e9a10 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.cache/ +.vscode/ +.xmake/ +build/ +compile_commands.json diff --git a/include/kqm/defs.h b/include/kqm/defs.h new file mode 100644 index 0000000..b37f67a --- /dev/null +++ b/include/kqm/defs.h @@ -0,0 +1,8 @@ +#ifndef DEFS_H +#define DEFS_H + +#define CR "\r" +#define LF "\n" +#define CRLF "\r\n" + +#endif // DEFS_H diff --git a/include/kqm/types.h b/include/kqm/types.h new file mode 100644 index 0000000..64232fc --- /dev/null +++ b/include/kqm/types.h @@ -0,0 +1,11 @@ +#ifndef TYPES_H +#define TYPES_H + +#include + +typedef struct mg_callbacks mg_callbacks; +typedef struct mg_context mg_context; +typedef struct mg_connection mg_connection; +typedef struct mg_request_info mg_request_info; + +#endif // TYPES_H diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..471974d --- /dev/null +++ b/src/main.c @@ -0,0 +1,31 @@ +#include + +#include +#include + +#include +#include + +static int request_handler(mg_connection* conn, void* cbdata) +{ + mg_printf(conn, + "HTTP/1.1 200 OK" CRLF "Content-Type: text/plain" CRLF "Connection: close" CRLF CRLF "Hello, World!"); + return 200; +} + +int main(int argc, char** argv) +{ + const char* options[] = {"document_root", ".", "listening_ports", "8080", NULL}; + mg_callbacks callbacks; + mg_context* ctx; + + memset(&callbacks, 0, sizeof(callbacks)); + ctx = mg_start(&callbacks, NULL, options); + + mg_set_request_handler(ctx, "/", request_handler, NULL); + + printf("Server started on port(s) %s\n", mg_get_option(ctx, "listening_ports")); + getchar(); + mg_stop(ctx); + +} diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..d149017 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") +add_rules("plugin.compile_commands.autoupdate") + +set_languages("c23") + +set_warnings("all") +set_warnings("error") + +add_requires("civetweb") + +target("math") + set_kind("binary") + add_packages("civetweb") + add_includedirs("include") + add_files("src/main.c")