aboutsummaryrefslogtreecommitdiff
path: root/doc/examples
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-01-18 15:17:21 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-01-18 15:18:40 +0300
commitbd41946e8f4f2086f7b2fcacc468a668c0676aff (patch)
tree151e103d07dc210f8365bbef0c26361d29873850 /doc/examples
parent17c22c2c3b8e2b56874ff701be58e7c10d1d41f4 (diff)
downloadlibmicrohttpd-bd41946e8f4f2086f7b2fcacc468a668c0676aff.tar.gz
libmicrohttpd-bd41946e8f4f2086f7b2fcacc468a668c0676aff.zip
Renamed 'con_cls' -> 'req_cls' for access handler callback
The argument is actually request-specific, not connection specific. The name was confusing. Fixed related documentation and clarified usage. Also fixed code where argument named 'unused' was actually used.
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/basicauthentication.c6
-rw-r--r--doc/examples/hellobrowser.c4
-rw-r--r--doc/examples/largepost.c14
-rw-r--r--doc/examples/logging.c4
-rw-r--r--doc/examples/responseheaders.c4
-rw-r--r--doc/examples/sessions.c16
-rw-r--r--doc/examples/simplepost.c14
-rw-r--r--doc/examples/tlsauthentication.c6
-rw-r--r--doc/examples/websocket.c10
9 files changed, 39 insertions, 39 deletions
diff --git a/doc/examples/basicauthentication.c b/doc/examples/basicauthentication.c
index fffc728f..3b105a1d 100644
--- a/doc/examples/basicauthentication.c
+++ b/doc/examples/basicauthentication.c
@@ -21,7 +21,7 @@ static enum MHD_Result
21answer_to_connection (void *cls, struct MHD_Connection *connection, 21answer_to_connection (void *cls, struct MHD_Connection *connection,
22 const char *url, const char *method, 22 const char *url, const char *method,
23 const char *version, const char *upload_data, 23 const char *version, const char *upload_data,
24 size_t *upload_data_size, void **con_cls) 24 size_t *upload_data_size, void **req_cls)
25{ 25{
26 char *user; 26 char *user;
27 char *pass; 27 char *pass;
@@ -36,9 +36,9 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
36 36
37 if (0 != strcmp (method, "GET")) 37 if (0 != strcmp (method, "GET"))
38 return MHD_NO; 38 return MHD_NO;
39 if (NULL == *con_cls) 39 if (NULL == *req_cls)
40 { 40 {
41 *con_cls = connection; 41 *req_cls = connection;
42 return MHD_YES; 42 return MHD_YES;
43 } 43 }
44 pass = NULL; 44 pass = NULL;
diff --git a/doc/examples/hellobrowser.c b/doc/examples/hellobrowser.c
index 0c13c24d..b14ea6d8 100644
--- a/doc/examples/hellobrowser.c
+++ b/doc/examples/hellobrowser.c
@@ -18,7 +18,7 @@ static enum MHD_Result
18answer_to_connection (void *cls, struct MHD_Connection *connection, 18answer_to_connection (void *cls, struct MHD_Connection *connection,
19 const char *url, const char *method, 19 const char *url, const char *method,
20 const char *version, const char *upload_data, 20 const char *version, const char *upload_data,
21 size_t *upload_data_size, void **con_cls) 21 size_t *upload_data_size, void **req_cls)
22{ 22{
23 const char *page = "<html><body>Hello, browser!</body></html>"; 23 const char *page = "<html><body>Hello, browser!</body></html>";
24 struct MHD_Response *response; 24 struct MHD_Response *response;
@@ -29,7 +29,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
29 (void) version; /* Unused. Silent compiler warning. */ 29 (void) version; /* Unused. Silent compiler warning. */
30 (void) upload_data; /* Unused. Silent compiler warning. */ 30 (void) upload_data; /* Unused. Silent compiler warning. */
31 (void) upload_data_size; /* Unused. Silent compiler warning. */ 31 (void) upload_data_size; /* Unused. Silent compiler warning. */
32 (void) con_cls; /* Unused. Silent compiler warning. */ 32 (void) req_cls; /* Unused. Silent compiler warning. */
33 33
34 response = 34 response =
35 MHD_create_response_from_buffer (strlen (page), (void *) page, 35 MHD_create_response_from_buffer (strlen (page), (void *) page,
diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c
index dc685745..58649508 100644
--- a/doc/examples/largepost.c
+++ b/doc/examples/largepost.c
@@ -181,10 +181,10 @@ iterate_post (void *coninfo_cls,
181static void 181static void
182request_completed (void *cls, 182request_completed (void *cls,
183 struct MHD_Connection *connection, 183 struct MHD_Connection *connection,
184 void **con_cls, 184 void **req_cls,
185 enum MHD_RequestTerminationCode toe) 185 enum MHD_RequestTerminationCode toe)
186{ 186{
187 struct connection_info_struct *con_info = *con_cls; 187 struct connection_info_struct *con_info = *req_cls;
188 (void) cls; /* Unused. Silent compiler warning. */ 188 (void) cls; /* Unused. Silent compiler warning. */
189 (void) connection; /* Unused. Silent compiler warning. */ 189 (void) connection; /* Unused. Silent compiler warning. */
190 (void) toe; /* Unused. Silent compiler warning. */ 190 (void) toe; /* Unused. Silent compiler warning. */
@@ -205,7 +205,7 @@ request_completed (void *cls,
205 } 205 }
206 206
207 free (con_info); 207 free (con_info);
208 *con_cls = NULL; 208 *req_cls = NULL;
209} 209}
210 210
211 211
@@ -217,13 +217,13 @@ answer_to_connection (void *cls,
217 const char *version, 217 const char *version,
218 const char *upload_data, 218 const char *upload_data,
219 size_t *upload_data_size, 219 size_t *upload_data_size,
220 void **con_cls) 220 void **req_cls)
221{ 221{
222 (void) cls; /* Unused. Silent compiler warning. */ 222 (void) cls; /* Unused. Silent compiler warning. */
223 (void) url; /* Unused. Silent compiler warning. */ 223 (void) url; /* Unused. Silent compiler warning. */
224 (void) version; /* Unused. Silent compiler warning. */ 224 (void) version; /* Unused. Silent compiler warning. */
225 225
226 if (NULL == *con_cls) 226 if (NULL == *req_cls)
227 { 227 {
228 /* First call, setup data structures */ 228 /* First call, setup data structures */
229 struct connection_info_struct *con_info; 229 struct connection_info_struct *con_info;
@@ -262,7 +262,7 @@ answer_to_connection (void *cls,
262 con_info->connectiontype = GET; 262 con_info->connectiontype = GET;
263 } 263 }
264 264
265 *con_cls = (void *) con_info; 265 *req_cls = (void *) con_info;
266 266
267 return MHD_YES; 267 return MHD_YES;
268 } 268 }
@@ -283,7 +283,7 @@ answer_to_connection (void *cls,
283 283
284 if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST)) 284 if (0 == strcasecmp (method, MHD_HTTP_METHOD_POST))
285 { 285 {
286 struct connection_info_struct *con_info = *con_cls; 286 struct connection_info_struct *con_info = *req_cls;
287 287
288 if (0 != *upload_data_size) 288 if (0 != *upload_data_size)
289 { 289 {
diff --git a/doc/examples/logging.c b/doc/examples/logging.c
index 22ff7e62..0db2e2ef 100644
--- a/doc/examples/logging.c
+++ b/doc/examples/logging.c
@@ -29,13 +29,13 @@ static enum MHD_Result
29answer_to_connection (void *cls, struct MHD_Connection *connection, 29answer_to_connection (void *cls, struct MHD_Connection *connection,
30 const char *url, const char *method, 30 const char *url, const char *method,
31 const char *version, const char *upload_data, 31 const char *version, const char *upload_data,
32 size_t *upload_data_size, void **con_cls) 32 size_t *upload_data_size, void **req_cls)
33{ 33{
34 (void) cls; /* Unused. Silent compiler warning. */ 34 (void) cls; /* Unused. Silent compiler warning. */
35 (void) version; /* Unused. Silent compiler warning. */ 35 (void) version; /* Unused. Silent compiler warning. */
36 (void) upload_data; /* Unused. Silent compiler warning. */ 36 (void) upload_data; /* Unused. Silent compiler warning. */
37 (void) upload_data_size; /* Unused. Silent compiler warning. */ 37 (void) upload_data_size; /* Unused. Silent compiler warning. */
38 (void) con_cls; /* Unused. Silent compiler warning. */ 38 (void) req_cls; /* Unused. Silent compiler warning. */
39 printf ("New %s request for %s using version %s\n", method, url, version); 39 printf ("New %s request for %s using version %s\n", method, url, version);
40 40
41 MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key, 41 MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key,
diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c
index f1cf939c..80eebbe9 100644
--- a/doc/examples/responseheaders.c
+++ b/doc/examples/responseheaders.c
@@ -23,7 +23,7 @@ static enum MHD_Result
23answer_to_connection (void *cls, struct MHD_Connection *connection, 23answer_to_connection (void *cls, struct MHD_Connection *connection,
24 const char *url, const char *method, 24 const char *url, const char *method,
25 const char *version, const char *upload_data, 25 const char *version, const char *upload_data,
26 size_t *upload_data_size, void **con_cls) 26 size_t *upload_data_size, void **req_cls)
27{ 27{
28 struct MHD_Response *response; 28 struct MHD_Response *response;
29 int fd; 29 int fd;
@@ -34,7 +34,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
34 (void) version; /* Unused. Silent compiler warning. */ 34 (void) version; /* Unused. Silent compiler warning. */
35 (void) upload_data; /* Unused. Silent compiler warning. */ 35 (void) upload_data; /* Unused. Silent compiler warning. */
36 (void) upload_data_size; /* Unused. Silent compiler warning. */ 36 (void) upload_data_size; /* Unused. Silent compiler warning. */
37 (void) con_cls; /* Unused. Silent compiler warning. */ 37 (void) req_cls; /* Unused. Silent compiler warning. */
38 38
39 if (0 != strcmp (method, "GET")) 39 if (0 != strcmp (method, "GET"))
40 return MHD_NO; 40 return MHD_NO;
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index db311bd4..5dd74e2c 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -548,7 +548,7 @@ post_iterator (void *cls,
548 * @param upload_data_size set initially to the size of the 548 * @param upload_data_size set initially to the size of the
549 * upload_data provided; the method must update this 549 * upload_data provided; the method must update this
550 * value to the number of bytes NOT processed; 550 * value to the number of bytes NOT processed;
551 * @param ptr pointer that the callback can set to some 551 * @param req_cls pointer that the callback can set to some
552 * address and that will be preserved by MHD for future 552 * address and that will be preserved by MHD for future
553 * calls for this request; since the access handler may 553 * calls for this request; since the access handler may
554 * be called many times (i.e., for a PUT/POST operation 554 * be called many times (i.e., for a PUT/POST operation
@@ -557,7 +557,7 @@ post_iterator (void *cls,
557 * If necessary, this state can be cleaned up in the 557 * If necessary, this state can be cleaned up in the
558 * global "MHD_RequestCompleted" callback (which 558 * global "MHD_RequestCompleted" callback (which
559 * can be set with the MHD_OPTION_NOTIFY_COMPLETED). 559 * can be set with the MHD_OPTION_NOTIFY_COMPLETED).
560 * Initially, <tt>*con_cls</tt> will be NULL. 560 * Initially, <tt>*req_cls</tt> will be NULL.
561 * @return MHS_YES if the connection was handled successfully, 561 * @return MHS_YES if the connection was handled successfully,
562 * MHS_NO if the socket must be closed due to a serious 562 * MHS_NO if the socket must be closed due to a serious
563 * error while handling the request 563 * error while handling the request
@@ -570,7 +570,7 @@ create_response (void *cls,
570 const char *version, 570 const char *version,
571 const char *upload_data, 571 const char *upload_data,
572 size_t *upload_data_size, 572 size_t *upload_data_size,
573 void **ptr) 573 void **req_cls)
574{ 574{
575 struct MHD_Response *response; 575 struct MHD_Response *response;
576 struct Request *request; 576 struct Request *request;
@@ -580,7 +580,7 @@ create_response (void *cls,
580 (void) cls; /* Unused. Silent compiler warning. */ 580 (void) cls; /* Unused. Silent compiler warning. */
581 (void) version; /* Unused. Silent compiler warning. */ 581 (void) version; /* Unused. Silent compiler warning. */
582 582
583 request = *ptr; 583 request = *req_cls;
584 if (NULL == request) 584 if (NULL == request)
585 { 585 {
586 request = calloc (1, sizeof (struct Request)); 586 request = calloc (1, sizeof (struct Request));
@@ -589,7 +589,7 @@ create_response (void *cls,
589 fprintf (stderr, "calloc error: %s\n", strerror (errno)); 589 fprintf (stderr, "calloc error: %s\n", strerror (errno));
590 return MHD_NO; 590 return MHD_NO;
591 } 591 }
592 *ptr = request; 592 *req_cls = request;
593 if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) 593 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
594 { 594 {
595 request->pp = MHD_create_post_processor (connection, 1024, 595 request->pp = MHD_create_post_processor (connection, 1024,
@@ -668,16 +668,16 @@ create_response (void *cls,
668 * 668 *
669 * @param cls not used 669 * @param cls not used
670 * @param connection connection that completed 670 * @param connection connection that completed
671 * @param con_cls session handle 671 * @param req_cls session handle
672 * @param toe status code 672 * @param toe status code
673 */ 673 */
674static void 674static void
675request_completed_callback (void *cls, 675request_completed_callback (void *cls,
676 struct MHD_Connection *connection, 676 struct MHD_Connection *connection,
677 void **con_cls, 677 void **req_cls,
678 enum MHD_RequestTerminationCode toe) 678 enum MHD_RequestTerminationCode toe)
679{ 679{
680 struct Request *request = *con_cls; 680 struct Request *request = *req_cls;
681 (void) cls; /* Unused. Silent compiler warning. */ 681 (void) cls; /* Unused. Silent compiler warning. */
682 (void) connection; /* Unused. Silent compiler warning. */ 682 (void) connection; /* Unused. Silent compiler warning. */
683 (void) toe; /* Unused. Silent compiler warning. */ 683 (void) toe; /* Unused. Silent compiler warning. */
diff --git a/doc/examples/simplepost.c b/doc/examples/simplepost.c
index 1e52e5dd..ea3899d1 100644
--- a/doc/examples/simplepost.c
+++ b/doc/examples/simplepost.c
@@ -105,9 +105,9 @@ iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key,
105 105
106static void 106static void
107request_completed (void *cls, struct MHD_Connection *connection, 107request_completed (void *cls, struct MHD_Connection *connection,
108 void **con_cls, enum MHD_RequestTerminationCode toe) 108 void **req_cls, enum MHD_RequestTerminationCode toe)
109{ 109{
110 struct connection_info_struct *con_info = *con_cls; 110 struct connection_info_struct *con_info = *req_cls;
111 (void) cls; /* Unused. Silent compiler warning. */ 111 (void) cls; /* Unused. Silent compiler warning. */
112 (void) connection; /* Unused. Silent compiler warning. */ 112 (void) connection; /* Unused. Silent compiler warning. */
113 (void) toe; /* Unused. Silent compiler warning. */ 113 (void) toe; /* Unused. Silent compiler warning. */
@@ -123,7 +123,7 @@ request_completed (void *cls, struct MHD_Connection *connection,
123 } 123 }
124 124
125 free (con_info); 125 free (con_info);
126 *con_cls = NULL; 126 *req_cls = NULL;
127} 127}
128 128
129 129
@@ -131,13 +131,13 @@ static enum MHD_Result
131answer_to_connection (void *cls, struct MHD_Connection *connection, 131answer_to_connection (void *cls, struct MHD_Connection *connection,
132 const char *url, const char *method, 132 const char *url, const char *method,
133 const char *version, const char *upload_data, 133 const char *version, const char *upload_data,
134 size_t *upload_data_size, void **con_cls) 134 size_t *upload_data_size, void **req_cls)
135{ 135{
136 (void) cls; /* Unused. Silent compiler warning. */ 136 (void) cls; /* Unused. Silent compiler warning. */
137 (void) url; /* Unused. Silent compiler warning. */ 137 (void) url; /* Unused. Silent compiler warning. */
138 (void) version; /* Unused. Silent compiler warning. */ 138 (void) version; /* Unused. Silent compiler warning. */
139 139
140 if (NULL == *con_cls) 140 if (NULL == *req_cls)
141 { 141 {
142 struct connection_info_struct *con_info; 142 struct connection_info_struct *con_info;
143 143
@@ -163,7 +163,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
163 else 163 else
164 con_info->connectiontype = GET; 164 con_info->connectiontype = GET;
165 165
166 *con_cls = (void *) con_info; 166 *req_cls = (void *) con_info;
167 167
168 return MHD_YES; 168 return MHD_YES;
169 } 169 }
@@ -175,7 +175,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
175 175
176 if (0 == strcmp (method, "POST")) 176 if (0 == strcmp (method, "POST"))
177 { 177 {
178 struct connection_info_struct *con_info = *con_cls; 178 struct connection_info_struct *con_info = *req_cls;
179 179
180 if (*upload_data_size != 0) 180 if (*upload_data_size != 0)
181 { 181 {
diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c
index b31eab43..4db00b7f 100644
--- a/doc/examples/tlsauthentication.c
+++ b/doc/examples/tlsauthentication.c
@@ -225,7 +225,7 @@ static enum MHD_Result
225answer_to_connection (void *cls, struct MHD_Connection *connection, 225answer_to_connection (void *cls, struct MHD_Connection *connection,
226 const char *url, const char *method, 226 const char *url, const char *method,
227 const char *version, const char *upload_data, 227 const char *version, const char *upload_data,
228 size_t *upload_data_size, void **con_cls) 228 size_t *upload_data_size, void **req_cls)
229{ 229{
230 (void) cls; /* Unused. Silent compiler warning. */ 230 (void) cls; /* Unused. Silent compiler warning. */
231 (void) url; /* Unused. Silent compiler warning. */ 231 (void) url; /* Unused. Silent compiler warning. */
@@ -235,9 +235,9 @@ answer_to_connection (void *cls, struct MHD_Connection *connection,
235 235
236 if (0 != strcmp (method, "GET")) 236 if (0 != strcmp (method, "GET"))
237 return MHD_NO; 237 return MHD_NO;
238 if (NULL == *con_cls) 238 if (NULL == *req_cls)
239 { 239 {
240 *con_cls = connection; 240 *req_cls = connection;
241 return MHD_YES; 241 return MHD_YES;
242 } 242 }
243 243
diff --git a/doc/examples/websocket.c b/doc/examples/websocket.c
index 4fa6f4ed..5cdf0423 100644
--- a/doc/examples/websocket.c
+++ b/doc/examples/websocket.c
@@ -80,7 +80,7 @@ make_blocking (MHD_socket fd);
80static void 80static void
81upgrade_handler (void *cls, 81upgrade_handler (void *cls,
82 struct MHD_Connection *connection, 82 struct MHD_Connection *connection,
83 void *con_cls, 83 void *req_cls,
84 const char *extra_in, 84 const char *extra_in,
85 size_t extra_in_size, 85 size_t extra_in_size,
86 MHD_socket fd, 86 MHD_socket fd,
@@ -307,7 +307,7 @@ access_handler (void *cls,
307 const char *version, 307 const char *version,
308 const char *upload_data, 308 const char *upload_data,
309 size_t *upload_data_size, 309 size_t *upload_data_size,
310 void **ptr) 310 void **req_cls)
311{ 311{
312 static int aptr; 312 static int aptr;
313 struct MHD_Response *response; 313 struct MHD_Response *response;
@@ -319,13 +319,13 @@ access_handler (void *cls,
319 319
320 if (0 != strcmp (method, "GET")) 320 if (0 != strcmp (method, "GET"))
321 return MHD_NO; /* unexpected method */ 321 return MHD_NO; /* unexpected method */
322 if (&aptr != *ptr) 322 if (&aptr != *req_cls)
323 { 323 {
324 /* do never respond on first call */ 324 /* do never respond on first call */
325 *ptr = &aptr; 325 *req_cls = &aptr;
326 return MHD_YES; 326 return MHD_YES;
327 } 327 }
328 *ptr = NULL; /* reset when done */ 328 *req_cls = NULL; /* reset when done */
329 329
330 if (0 == strcmp (url, "/")) 330 if (0 == strcmp (url, "/"))
331 { 331 {