diff options
Diffstat (limited to 'src/examples/refuse_post_example.c')
-rw-r--r-- | src/examples/refuse_post_example.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/examples/refuse_post_example.c b/src/examples/refuse_post_example.c index dc261575..70cfe4b3 100644 --- a/src/examples/refuse_post_example.c +++ b/src/examples/refuse_post_example.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | Copyright (C) 2007, 2008 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2007, 2008 Christian Grothoff (and other contributing authors) |
4 | Copyright (C) 2016-2022 Evgeny Grin (Karlson2k) | ||
4 | 5 | ||
5 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 7 | modify it under the terms of the GNU Lesser General Public |
@@ -20,10 +21,16 @@ | |||
20 | * @file refuse_post_example.c | 21 | * @file refuse_post_example.c |
21 | * @brief example for how to refuse a POST request properly | 22 | * @brief example for how to refuse a POST request properly |
22 | * @author Christian Grothoff and Sebastian Gerhardt | 23 | * @author Christian Grothoff and Sebastian Gerhardt |
24 | * @author Karlson2k (Evgeny Grin) | ||
23 | */ | 25 | */ |
24 | #include "platform.h" | 26 | #include "platform.h" |
25 | #include <microhttpd.h> | 27 | #include <microhttpd.h> |
26 | 28 | ||
29 | struct handler_param | ||
30 | { | ||
31 | const char *response_page; | ||
32 | }; | ||
33 | |||
27 | const char *askpage = | 34 | const char *askpage = |
28 | "<html><body>\n\ | 35 | "<html><body>\n\ |
29 | Upload a file, please!<br>\n\ | 36 | Upload a file, please!<br>\n\ |
@@ -44,7 +51,7 @@ ahc_echo (void *cls, | |||
44 | const char *upload_data, size_t *upload_data_size, void **req_cls) | 51 | const char *upload_data, size_t *upload_data_size, void **req_cls) |
45 | { | 52 | { |
46 | static int aptr; | 53 | static int aptr; |
47 | const char *me = cls; | 54 | struct handler_param *param = (struct handler_param *) cls; |
48 | struct MHD_Response *response; | 55 | struct MHD_Response *response; |
49 | enum MHD_Result ret; | 56 | enum MHD_Result ret; |
50 | (void) cls; /* Unused. Silent compiler warning. */ | 57 | (void) cls; /* Unused. Silent compiler warning. */ |
@@ -63,9 +70,9 @@ ahc_echo (void *cls, | |||
63 | /* always to busy for POST requests */ | 70 | /* always to busy for POST requests */ |
64 | if (0 == strcmp (method, "POST")) | 71 | if (0 == strcmp (method, "POST")) |
65 | { | 72 | { |
66 | response = MHD_create_response_from_buffer (strlen (BUSYPAGE), | 73 | response = |
67 | (void *) BUSYPAGE, | 74 | MHD_create_response_from_buffer_static (strlen (BUSYPAGE), |
68 | MHD_RESPMEM_PERSISTENT); | 75 | (const void *) BUSYPAGE); |
69 | ret = | 76 | ret = |
70 | MHD_queue_response (connection, MHD_HTTP_SERVICE_UNAVAILABLE, | 77 | MHD_queue_response (connection, MHD_HTTP_SERVICE_UNAVAILABLE, |
71 | response); | 78 | response); |
@@ -75,9 +82,10 @@ ahc_echo (void *cls, | |||
75 | } | 82 | } |
76 | 83 | ||
77 | *req_cls = NULL; /* reset when done */ | 84 | *req_cls = NULL; /* reset when done */ |
78 | response = MHD_create_response_from_buffer (strlen (me), | 85 | response = |
79 | (void *) me, | 86 | MHD_create_response_from_buffer_static (strlen (param->response_page), |
80 | MHD_RESPMEM_PERSISTENT); | 87 | (const void *) |
88 | param->response_page); | ||
81 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 89 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
82 | MHD_destroy_response (response); | 90 | MHD_destroy_response (response); |
83 | return ret; | 91 | return ret; |
@@ -89,15 +97,18 @@ main (int argc, char *const *argv) | |||
89 | { | 97 | { |
90 | struct MHD_Daemon *d; | 98 | struct MHD_Daemon *d; |
91 | 99 | ||
100 | struct handler_param data_for_handler; | ||
101 | |||
92 | if (argc != 2) | 102 | if (argc != 2) |
93 | { | 103 | { |
94 | printf ("%s PORT\n", argv[0]); | 104 | printf ("%s PORT\n", argv[0]); |
95 | return 1; | 105 | return 1; |
96 | } | 106 | } |
107 | data_for_handler.response_page = askpage; | ||
97 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 108 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
98 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 109 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, |
99 | atoi (argv[1]), | 110 | atoi (argv[1]), |
100 | NULL, NULL, &ahc_echo, (void *) askpage, | 111 | NULL, NULL, &ahc_echo, &data_for_handler, |
101 | MHD_OPTION_END); | 112 | MHD_OPTION_END); |
102 | if (d == NULL) | 113 | if (d == NULL) |
103 | return 1; | 114 | return 1; |