aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorjustanothercatgirl <sotov@twistea.su>2025-03-27 12:52:11 +0300
committerjustanothercatgirl <sotov@twistea.su>2025-03-27 12:52:11 +0300
commit82742d5d13dc7b0691a79c79f8e62782fcb16e10 (patch)
tree48d077549ed667d2a54171b82eb7608cb8edaf3e /main.c
parent8542ec17d3df989f3df9fd03af7a447bf730dc13 (diff)
Doing SQL (work in progress)
Diffstat (limited to 'main.c')
-rw-r--r--main.c50
1 files changed, 0 insertions, 50 deletions
diff --git a/main.c b/main.c
deleted file mode 100644
index 3d8f57d..0000000
--- a/main.c
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <dlfcn.h>
-
-#include "microhttpd.h"
-
-typedef char*(*endpoint)(struct MHD_Connection*);
-
-enum MHD_Result process_connection(void *dylib, struct MHD_Connection *connection, const char *url,
- const char *method, const char *version, const char *upload_data,
- size_t *upload_data_size, void **req_cls)
-{
- printf("\nurl: %s\nmethod:%s\nversion:%s\nupload_data:%s\nsize:%zu\n",
- url, method, version, upload_data, *upload_data_size);
- /* Load function with the name of the url from shared library */
- endpoint handler = dlsym(dylib, url);
- struct MHD_Response *res; int status;
- if (handler != NULL) {
- fprintf(stderr, "Accessed at url\t%s\n", url);
- char* response = handler(connection);
- res = MHD_create_response_from_buffer(strlen(response), response, MHD_RESPMEM_MUST_FREE);
- status = MHD_HTTP_OK;
- } else {
- fprintf(stderr, "Failed to access at url\t%s\n", url);
- const char* error = "<html><body>Error 404: Page does not exist</body></html>";
- res = MHD_create_response_from_buffer(strlen(error), (void*)error, MHD_RESPMEM_PERSISTENT);
- status = MHD_HTTP_NOT_FOUND;
- }
- MHD_queue_response(connection, status, res);
- MHD_destroy_response(res);
- return MHD_YES;
-}
-
-
-int main(){
- void* dylib = dlopen("./endpoints.so", RTLD_NOW);
- if (!dylib) {
- fprintf(stderr, "Could not open dynamic library: %s\n", dlerror());
- return 1;
- }
- struct MHD_Daemon *daemon = MHD_start_daemon(MHD_USE_POLL | MHD_USE_INTERNAL_POLLING_THREAD, 8080, NULL, NULL, process_connection, dylib, MHD_OPTION_END);
- if (daemon == NULL) {
- perror("daemon");
- fprintf(stderr, "could not initialize daemon\n");
- return 1;
- }
- getchar();
- MHD_stop_daemon(daemon);
- return 0;
-}