diff --git a/.gitignore b/.gitignore index 716887a..71b980b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ *.out .DS_Store +pagezero.txt +sortedlinks.txt +ysortedlinks.txt +.vscode/ +restful_server.dSYM/ \ No newline at end of file diff --git a/mongoose/restful_server b/mongoose/restful_server deleted file mode 100755 index b1b6deb..0000000 Binary files a/mongoose/restful_server and /dev/null differ diff --git a/mongoose/restful_server.c b/mongoose/restful_server.c deleted file mode 100644 index 1be00cd..0000000 --- a/mongoose/restful_server.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2014 Cesanta Software Limited - * All rights reserved - */ - -#include "mongoose.h" - -static const char *s_http_port = "8000"; -static struct mg_serve_http_opts s_http_server_opts; - -static void handle_sum_call(struct mg_connection *nc, struct http_message *hm) { - char word[100]; - - - /* Get form variables */ - mg_get_http_var(&hm->query_string, "word", word, sizeof(word)); - - - - /* Send headers */ - mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); - - /* Compute the result and send it back as a JSON object */ - //result = word; - //printf("hello"); - mg_printf_http_chunk(nc, "{ \"result\": [\"%s\",\"%s\"] }", word, word); - mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */ -} - -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - struct http_message *hm = (struct http_message *) ev_data; - - switch (ev) { - case MG_EV_HTTP_REQUEST: - if (mg_vcmp(&hm->uri, "/api/v1/sum") == 0) { - handle_sum_call(nc, hm); /* Handle RESTful call */ - } else if (mg_vcmp(&hm->uri, "/printcontent") == 0) { - char buf[100] = {0}; - memcpy(buf, hm->body.p, - sizeof(buf) - 1 < hm->body.len ? sizeof(buf) - 1 : hm->body.len); - printf("%s\n", buf); - } else { - mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */ - } - break; - default: - break; - } -} - -int main(int argc, char *argv[]) { - struct mg_mgr mgr; - struct mg_connection *nc; - struct mg_bind_opts bind_opts; - int i; - char *cp; - const char *err_str; -#if MG_ENABLE_SSL - const char *ssl_cert = NULL; -#endif - - mg_mgr_init(&mgr, NULL); - - /* Use current binary directory as document root */ - if (argc > 0 && ((cp = strrchr(argv[0], DIRSEP)) != NULL)) { - *cp = '\0'; - s_http_server_opts.document_root = argv[0]; - } - - /* Process command line options to customize HTTP server */ - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-D") == 0 && i + 1 < argc) { - mgr.hexdump_file = argv[++i]; - } else if (strcmp(argv[i], "-d") == 0 && i + 1 < argc) { - s_http_server_opts.document_root = argv[++i]; - } else if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) { - s_http_port = argv[++i]; - } else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) { - s_http_server_opts.auth_domain = argv[++i]; - } else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) { - s_http_server_opts.global_auth_file = argv[++i]; - } else if (strcmp(argv[i], "-A") == 0 && i + 1 < argc) { - s_http_server_opts.per_directory_auth_file = argv[++i]; - } else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) { - s_http_server_opts.url_rewrites = argv[++i]; -#if MG_ENABLE_HTTP_CGI - } else if (strcmp(argv[i], "-i") == 0 && i + 1 < argc) { - s_http_server_opts.cgi_interpreter = argv[++i]; -#endif -#if MG_ENABLE_SSL - } else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) { - ssl_cert = argv[++i]; -#endif - } else { - fprintf(stderr, "Unknown option: [%s]\n", argv[i]); - exit(1); - } - } - - /* Set HTTP server options */ - memset(&bind_opts, 0, sizeof(bind_opts)); - bind_opts.error_string = &err_str; -#if MG_ENABLE_SSL - if (ssl_cert != NULL) { - bind_opts.ssl_cert = ssl_cert; - } -#endif - nc = mg_bind_opt(&mgr, s_http_port, ev_handler, bind_opts); - if (nc == NULL) { - fprintf(stderr, "Error starting server on port %s: %s\n", s_http_port, - *bind_opts.error_string); - exit(1); - } - - mg_set_protocol_http_websocket(nc); - s_http_server_opts.enable_directory_listing = "yes"; - - printf("Starting RESTful server on port %s, serving %s\n", s_http_port, - s_http_server_opts.document_root); - - for(int i = 0;i < 1000000;i++){ - //nop - } - - for (;;) { - mg_mgr_poll(&mgr, 1000); - } - mg_mgr_free(&mgr); - - return 0; -} diff --git a/mongoose/restful_server.cpp b/mongoose/restful_server.cpp index 665c956..07ba5be 100644 --- a/mongoose/restful_server.cpp +++ b/mongoose/restful_server.cpp @@ -107,7 +107,9 @@ static void handle_sum_call(struct mg_connection *nc, struct http_message *hm) { string str = "{ \"result\": ["; for(int i = 0;i < result.size() && i < 8;i++){ if(i != 0)str += ","; - str += "\"" + v[result[i].second] + "\""; + string se = v[result[i].second]; + se = se.substr(1,se.size()-2); + str += "\"" + se + "\""; } str += "] }"; mg_printf_http_chunk(nc, "%s", str.c_str()); diff --git a/mongoose/restful_server.dSYM/Contents/Resources/DWARF/restful_server b/mongoose/restful_server.dSYM/Contents/Resources/DWARF/restful_server deleted file mode 100644 index f3a3c9d..0000000 Binary files a/mongoose/restful_server.dSYM/Contents/Resources/DWARF/restful_server and /dev/null differ