Handlers in another function

This commit is contained in:
Senad Uka
2022-11-19 23:18:44 +01:00
parent faebd267ca
commit ee1eb89e9a
6 changed files with 77 additions and 44 deletions

44
main.c
View File

@@ -1,46 +1,8 @@
#include <microhttpd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define PAGE "<html><head><title>nasuh search engine</title>"\
"</head><body>all your programming needs</body></html>"
static enum MHD_Result
ahc_echo(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 ** ptr) {
static int dummy;
const char * page = cls;
struct MHD_Response * response;
int ret;
if (0 != strcmp(method, "GET"))
return MHD_NO; /* unexpected method */
if (&dummy != *ptr)
{
/* The first time only the headers are valid,
do not respond in the first round... */
*ptr = &dummy;
return MHD_YES;
}
if (0 != *upload_data_size)
return MHD_NO; /* upload data in a GET!? */
*ptr = NULL; /* clear context pointer */
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;
}
#include <stdlib.h>
#include "handlers.h"
int main(int argc,
char ** argv) {
@@ -54,7 +16,7 @@ int main(int argc,
atoi(argv[1]),
NULL,
NULL,
&ahc_echo,
&handle_all,
PAGE,
MHD_OPTION_END);
if (d == NULL)