/* ** Copyright (C) 2015 Eneo Tecnologia S.L. ** Author: Eugenio Perez ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU Affero General Public License as ** published by the Free Software Foundation, either version 3 of the ** License, or (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU Affero General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program. If not, see . */ #define HTTP_UNUSED __attribute__((unused)) #define POSTBUFFERSIZE (10*1024) #define MODE_THREAD_PER_CONNECTION "thread_per_connection" #define MODE_SELECT "select" #define MODE_POLL "poll" #define MODE_EPOLL "epoll" #include "platform.h" #include #include #include #include #include #include #include static int post_handle(void *_cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version HTTP_UNUSED, const char *upload_data, size_t *upload_data_size, void **ptr) { static int a; if (0 != strcmp(method, MHD_HTTP_METHOD_POST)) { return MHD_NO; } if ( NULL == ptr) { return MHD_NO; } if ( NULL == *ptr ) { *ptr = &a; return MHD_YES; } else if ( *upload_data_size > 0 ) { /* middle calls, process string sent */ *upload_data_size = 0; return MHD_YES; } else { struct MHD_Response *http_response = NULL; http_response = MHD_create_response_from_buffer(0,NULL,MHD_RESPMEM_PERSISTENT); const int ret = MHD_queue_response(connection,MHD_HTTP_OK,http_response); MHD_destroy_response(http_response); return ret; } } int main(int argc, char **argv) { struct MHD_OptionItem opts[] = { /* Memory limit per connection */ {MHD_OPTION_CONNECTION_MEMORY_LIMIT, 10*1024, NULL}, { MHD_OPTION_END, 0, NULL } }; struct MHD_Daemon *d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, atoi(argv[1]), NULL, /* Auth callback */ NULL, /* Auth callback parameter */ post_handle, /* Request handler */ NULL, /* Request handler parameter */ MHD_OPTION_ARRAY, opts, MHD_OPTION_END); (void)getc(stdin); MHD_stop_daemon(d); }