aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-06-12 07:45:50 +0000
committerChristian Grothoff <christian@grothoff.org>2015-06-12 07:45:50 +0000
commit4f9c53c222ce07b4f02474ddcc45000d6638250f (patch)
treec920266242ffc45ccf0c224adf8a1bfb4db18723 /doc
parentc461ee5489068066b9752ef9de179f3ccf75015b (diff)
downloadlibmicrohttpd-4f9c53c222ce07b4f02474ddcc45000d6638250f.tar.gz
libmicrohttpd-4f9c53c222ce07b4f02474ddcc45000d6638250f.zip
-fix compiler warnings
Diffstat (limited to 'doc')
-rw-r--r--doc/examples/sessions.c71
1 files changed, 35 insertions, 36 deletions
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index 0fd27666..6b7b797f 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -98,7 +98,7 @@ struct Session
98 struct Session *next; 98 struct Session *next;
99 99
100 /** 100 /**
101 * Unique ID for this session. 101 * Unique ID for this session.
102 */ 102 */
103 char sid[33]; 103 char sid[33];
104 104
@@ -144,7 +144,7 @@ struct Request
144 struct MHD_PostProcessor *pp; 144 struct MHD_PostProcessor *pp;
145 145
146 /** 146 /**
147 * URL to serve in response to this POST (if this request 147 * URL to serve in response to this POST (if this request
148 * was a 'POST') 148 * was a 'POST')
149 */ 149 */
150 const char *post_url; 150 const char *post_url;
@@ -162,7 +162,7 @@ static struct Session *sessions;
162 162
163 163
164/** 164/**
165 * Return the session handle for this connection, or 165 * Return the session handle for this connection, or
166 * create one if this is a new user. 166 * create one if this is a new user.
167 */ 167 */
168static struct Session * 168static struct Session *
@@ -193,9 +193,9 @@ get_session (struct MHD_Connection *connection)
193 /* create fresh session */ 193 /* create fresh session */
194 ret = calloc (1, sizeof (struct Session)); 194 ret = calloc (1, sizeof (struct Session));
195 if (NULL == ret) 195 if (NULL == ret)
196 { 196 {
197 fprintf (stderr, "calloc error: %s\n", strerror (errno)); 197 fprintf (stderr, "calloc error: %s\n", strerror (errno));
198 return NULL; 198 return NULL;
199 } 199 }
200 /* not a super-secure way to generate a random session ID, 200 /* not a super-secure way to generate a random session ID,
201 but should do for a simple example... */ 201 but should do for a simple example... */
@@ -206,7 +206,7 @@ get_session (struct MHD_Connection *connection)
206 (unsigned int) rand (), 206 (unsigned int) rand (),
207 (unsigned int) rand (), 207 (unsigned int) rand (),
208 (unsigned int) rand ()); 208 (unsigned int) rand ());
209 ret->rc++; 209 ret->rc++;
210 ret->start = time (NULL); 210 ret->start = time (NULL);
211 ret->next = sessions; 211 ret->next = sessions;
212 sessions = ret; 212 sessions = ret;
@@ -231,7 +231,7 @@ typedef int (*PageHandler)(const void *cls,
231 231
232/** 232/**
233 * Entry we generate for each page served. 233 * Entry we generate for each page served.
234 */ 234 */
235struct Page 235struct Page
236{ 236{
237 /** 237 /**
@@ -251,7 +251,7 @@ struct Page
251 251
252 /** 252 /**
253 * Extra argument to handler. 253 * Extra argument to handler.
254 */ 254 */
255 const void *handler_cls; 255 const void *handler_cls;
256}; 256};
257 257
@@ -261,7 +261,7 @@ struct Page
261 * 261 *
262 * @param session session to use 262 * @param session session to use
263 * @param response response to modify 263 * @param response response to modify
264 */ 264 */
265static void 265static void
266add_session_cookie (struct Session *session, 266add_session_cookie (struct Session *session,
267 struct MHD_Response *response) 267 struct MHD_Response *response)
@@ -272,12 +272,12 @@ add_session_cookie (struct Session *session,
272 "%s=%s", 272 "%s=%s",
273 COOKIE_NAME, 273 COOKIE_NAME,
274 session->sid); 274 session->sid);
275 if (MHD_NO == 275 if (MHD_NO ==
276 MHD_add_response_header (response, 276 MHD_add_response_header (response,
277 MHD_HTTP_HEADER_SET_COOKIE, 277 MHD_HTTP_HEADER_SET_COOKIE,
278 cstr)) 278 cstr))
279 { 279 {
280 fprintf (stderr, 280 fprintf (stderr,
281 "Failed to set session cookie header!\n"); 281 "Failed to set session cookie header!\n");
282 } 282 }
283} 283}
@@ -289,7 +289,7 @@ add_session_cookie (struct Session *session,
289 * 289 *
290 * @param cls a 'const char *' with the HTML webpage to return 290 * @param cls a 'const char *' with the HTML webpage to return
291 * @param mime mime type to use 291 * @param mime mime type to use
292 * @param session session handle 292 * @param session session handle
293 * @param connection connection to use 293 * @param connection connection to use
294 */ 294 */
295static int 295static int
@@ -310,8 +310,8 @@ serve_simple_form (const void *cls,
310 MHD_add_response_header (response, 310 MHD_add_response_header (response,
311 MHD_HTTP_HEADER_CONTENT_ENCODING, 311 MHD_HTTP_HEADER_CONTENT_ENCODING,
312 mime); 312 mime);
313 ret = MHD_queue_response (connection, 313 ret = MHD_queue_response (connection,
314 MHD_HTTP_OK, 314 MHD_HTTP_OK,
315 response); 315 response);
316 MHD_destroy_response (response); 316 MHD_destroy_response (response);
317 return ret; 317 return ret;
@@ -323,7 +323,7 @@ serve_simple_form (const void *cls,
323 * 323 *
324 * @param cls a 'const char *' with the HTML webpage to return 324 * @param cls a 'const char *' with the HTML webpage to return
325 * @param mime mime type to use 325 * @param mime mime type to use
326 * @param session session handle 326 * @param session session handle
327 * @param connection connection to use 327 * @param connection connection to use
328 */ 328 */
329static int 329static int
@@ -352,8 +352,8 @@ fill_v1_form (const void *cls,
352 MHD_add_response_header (response, 352 MHD_add_response_header (response,
353 MHD_HTTP_HEADER_CONTENT_ENCODING, 353 MHD_HTTP_HEADER_CONTENT_ENCODING,
354 mime); 354 mime);
355 ret = MHD_queue_response (connection, 355 ret = MHD_queue_response (connection,
356 MHD_HTTP_OK, 356 MHD_HTTP_OK,
357 response); 357 response);
358 MHD_destroy_response (response); 358 MHD_destroy_response (response);
359 return ret; 359 return ret;
@@ -365,7 +365,7 @@ fill_v1_form (const void *cls,
365 * 365 *
366 * @param cls a 'const char *' with the HTML webpage to return 366 * @param cls a 'const char *' with the HTML webpage to return
367 * @param mime mime type to use 367 * @param mime mime type to use
368 * @param session session handle 368 * @param session session handle
369 * @param connection connection to use 369 * @param connection connection to use
370 */ 370 */
371static int 371static int
@@ -395,8 +395,8 @@ fill_v1_v2_form (const void *cls,
395 MHD_add_response_header (response, 395 MHD_add_response_header (response,
396 MHD_HTTP_HEADER_CONTENT_ENCODING, 396 MHD_HTTP_HEADER_CONTENT_ENCODING,
397 mime); 397 mime);
398 ret = MHD_queue_response (connection, 398 ret = MHD_queue_response (connection,
399 MHD_HTTP_OK, 399 MHD_HTTP_OK,
400 response); 400 response);
401 MHD_destroy_response (response); 401 MHD_destroy_response (response);
402 return ret; 402 return ret;
@@ -408,7 +408,7 @@ fill_v1_v2_form (const void *cls,
408 * 408 *
409 * @param cls a 'const char *' with the HTML webpage to return 409 * @param cls a 'const char *' with the HTML webpage to return
410 * @param mime mime type to use 410 * @param mime mime type to use
411 * @param session session handle 411 * @param session session handle
412 * @param connection connection to use 412 * @param connection connection to use
413 */ 413 */
414static int 414static int
@@ -424,8 +424,8 @@ not_found_page (const void *cls,
424 response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR), 424 response = MHD_create_response_from_buffer (strlen (NOT_FOUND_ERROR),
425 (void *) NOT_FOUND_ERROR, 425 (void *) NOT_FOUND_ERROR,
426 MHD_RESPMEM_PERSISTENT); 426 MHD_RESPMEM_PERSISTENT);
427 ret = MHD_queue_response (connection, 427 ret = MHD_queue_response (connection,
428 MHD_HTTP_NOT_FOUND, 428 MHD_HTTP_NOT_FOUND,
429 response); 429 response);
430 MHD_add_response_header (response, 430 MHD_add_response_header (response,
431 MHD_HTTP_HEADER_CONTENT_ENCODING, 431 MHD_HTTP_HEADER_CONTENT_ENCODING,
@@ -438,7 +438,7 @@ not_found_page (const void *cls,
438/** 438/**
439 * List of all pages served by this HTTP server. 439 * List of all pages served by this HTTP server.
440 */ 440 */
441static struct Page pages[] = 441static struct Page pages[] =
442 { 442 {
443 { "/", "text/html", &fill_v1_form, MAIN_PAGE }, 443 { "/", "text/html", &fill_v1_form, MAIN_PAGE },
444 { "/2", "text/html", &fill_v1_v2_form, SECOND_PAGE }, 444 { "/2", "text/html", &fill_v1_v2_form, SECOND_PAGE },
@@ -556,7 +556,7 @@ create_response (void *cls,
556 const char *url, 556 const char *url,
557 const char *method, 557 const char *method,
558 const char *version, 558 const char *version,
559 const char *upload_data, 559 const char *upload_data,
560 size_t *upload_data_size, 560 size_t *upload_data_size,
561 void **ptr) 561 void **ptr)
562{ 562{
@@ -602,7 +602,7 @@ create_response (void *cls,
602 session = request->session; 602 session = request->session;
603 session->start = time (NULL); 603 session->start = time (NULL);
604 if (0 == strcmp (method, MHD_HTTP_METHOD_POST)) 604 if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
605 { 605 {
606 /* evaluate POST data */ 606 /* evaluate POST data */
607 MHD_post_process (request->pp, 607 MHD_post_process (request->pp,
608 upload_data, 608 upload_data,
@@ -628,7 +628,7 @@ create_response (void *cls,
628 while ( (pages[i].url != NULL) && 628 while ( (pages[i].url != NULL) &&
629 (0 != strcmp (pages[i].url, url)) ) 629 (0 != strcmp (pages[i].url, url)) )
630 i++; 630 i++;
631 ret = pages[i].handler (pages[i].handler_cls, 631 ret = pages[i].handler (pages[i].handler_cls,
632 pages[i].mime, 632 pages[i].mime,
633 session, connection); 633 session, connection);
634 if (ret != MHD_YES) 634 if (ret != MHD_YES)
@@ -640,8 +640,8 @@ create_response (void *cls,
640 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR), 640 response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
641 (void *) METHOD_ERROR, 641 (void *) METHOD_ERROR,
642 MHD_RESPMEM_PERSISTENT); 642 MHD_RESPMEM_PERSISTENT);
643 ret = MHD_queue_response (connection, 643 ret = MHD_queue_response (connection,
644 MHD_HTTP_METHOD_NOT_ACCEPTABLE, 644 MHD_HTTP_NOT_ACCEPTABLE,
645 response); 645 response);
646 MHD_destroy_response (response); 646 MHD_destroy_response (response);
647 return ret; 647 return ret;
@@ -705,7 +705,7 @@ expire_sessions ()
705 else 705 else
706 prev = pos; 706 prev = pos;
707 pos = next; 707 pos = next;
708 } 708 }
709} 709}
710 710
711 711
@@ -734,8 +734,8 @@ main (int argc, char *const *argv)
734 srand ((unsigned int) time (NULL)); 734 srand ((unsigned int) time (NULL));
735 d = MHD_start_daemon (MHD_USE_DEBUG, 735 d = MHD_start_daemon (MHD_USE_DEBUG,
736 atoi (argv[1]), 736 atoi (argv[1]),
737 NULL, NULL, 737 NULL, NULL,
738 &create_response, NULL, 738 &create_response, NULL,
739 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, 739 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
740 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, 740 MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL,
741 MHD_OPTION_END); 741 MHD_OPTION_END);
@@ -750,18 +750,18 @@ main (int argc, char *const *argv)
750 FD_ZERO (&es); 750 FD_ZERO (&es);
751 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 751 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
752 break; /* fatal internal error */ 752 break; /* fatal internal error */
753 if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES) 753 if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES)
754 { 754 {
755 tv.tv_sec = mhd_timeout / 1000; 755 tv.tv_sec = mhd_timeout / 1000;
756 tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000; 756 tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000;
757 tvp = &tv; 757 tvp = &tv;
758 } 758 }
759 else 759 else
760 tvp = NULL; 760 tvp = NULL;
761 if (-1 == select (max + 1, &rs, &ws, &es, tvp)) 761 if (-1 == select (max + 1, &rs, &ws, &es, tvp))
762 { 762 {
763 if (EINTR != errno) 763 if (EINTR != errno)
764 fprintf (stderr, 764 fprintf (stderr,
765 "Aborting due to error during select: %s\n", 765 "Aborting due to error during select: %s\n",
766 strerror (errno)); 766 strerror (errno));
767 break; 767 break;
@@ -771,4 +771,3 @@ main (int argc, char *const *argv)
771 MHD_stop_daemon (d); 771 MHD_stop_daemon (d);
772 return 0; 772 return 0;
773} 773}
774