/* Feel free to use this example code in any way you see fit (Public Domain) */ #include //#ifndef _WIN32 #include #include //#else //#include //#endif #include #include #include #include "web.h" #include "pebblisp.h" int routeCount = 0; struct Route routes[10]; int addRoute(struct Route route) { routes[routeCount] = route; routeCount += 1; return 0; } static enum MHD_Result answer_to_connection(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { const char *page = NULL; printf("%s URL: '%s' :: ", method, url); for (int i = 0; i < routeCount; i++) { if (strcmp(url, routes[i].path) == 0) { printf("route[%d]\n", i); //page = routes[i].routeAction(url); Object emptyList = listObject(); nf_addToList(&emptyList, numberObject(0)); Object route = cloneObject(routes[i].routeAction); Object result = listEvalLambda(&route, &emptyList, routes[i].env); page = result.string; break; } } if (!page) { printf("no route found!\n"); page = "

404, Dumbass.

"; } struct MHD_Response *response; enum MHD_Result ret; (void) cls; /* Unused. Silent compiler warning. */ (void) url; /* Unused. Silent compiler warning. */ (void) method; /* Unused. Silent compiler warning. */ (void) version; /* Unused. Silent compiler warning. */ (void) upload_data; /* Unused. Silent compiler warning. */ (void) upload_data_size; /* Unused. Silent compiler warning. */ (void) con_cls; /* Unused. Silent compiler warning. */ response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); return ret; } int start(int port) { struct MHD_Daemon *daemon = MHD_start_daemon( MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD, port, NULL, NULL, &answer_to_connection, NULL, MHD_OPTION_END); if (NULL == daemon) return 1; // (void) getchar(); // MHD_stop_daemon(daemon); return 0; }