From 82742d5d13dc7b0691a79c79f8e62782fcb16e10 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Thu, 27 Mar 2025 12:52:11 +0300 Subject: Doing SQL (work in progress) --- main.c | 50 -------------------------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 main.c (limited to 'main.c') 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 -#include -#include - -#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 = "Error 404: Page does not exist"; - 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; -} -- cgit v1.2.3-70-g09d2