Debian Codegraph @

doc/examples/hellobrowser.c

raw
1 /* Feel free to use this example code in any way
2 you see fit (Public Domain) */
3
4 #include <sys/types.h>
5 #ifndef _WIN32
6 #include <sys/select.h>
7 #include <sys/socket.h>
8 #else
9 #include <winsock2.h>
10 #endif
11 #include <string.h>
12 #include <microhttpd.h>
13 #include <stdio.h>
14
15 #define PORT 8888
16
17 static enum MHD_Result
18 answer_to_connection (void *cls, struct MHD_Connection *connection,
19 const char *url, const char *method,
20 const char *version, const char *upload_data,
21 size_t *upload_data_size, void **req_cls)
22 {
23 const char *page = "<html><body>Hello, browser!</body></html>";
24 struct MHD_Response *response;
25 enum MHD_Result ret;
26 (void) cls; /* Unused. Silent compiler warning. */
27 (void) url; /* Unused. Silent compiler warning. */
28 (void) method; /* Unused. Silent compiler warning. */
29 (void) version; /* Unused. Silent compiler warning. */
30 (void) upload_data; /* Unused. Silent compiler warning. */
31 (void) upload_data_size; /* Unused. Silent compiler warning. */
32 (void) req_cls; /* Unused. Silent compiler warning. */
33
34 response = MHD_create_response_from_buffer_static (strlen (page), page);
35 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
36 MHD_destroy_response (response);
37
38 return ret;
39 }
40
41
42 int
43 main (void)
44 {
45 struct MHD_Daemon *daemon;
46
47 daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
48 PORT, NULL, NULL,
49 &answer_to_connection, NULL, MHD_OPTION_END);
50 if (NULL == daemon)
51 return 1;
52
53 (void) getchar ();
54
55 MHD_stop_daemon (daemon);
56 return 0;
57 }