diff options
author | silvioprog <silvioprog@gmail.com> | 2020-04-09 23:54:28 -0300 |
---|---|---|
committer | silvioprog <silvioprog@gmail.com> | 2020-04-09 23:54:28 -0300 |
commit | 275d6fed80cc0bbc55dc0de05a970a38e510e334 (patch) | |
tree | 042ce83dc43af1536f592016acb29dfdd3709c03 /src/examples | |
parent | 61227ed72d3278d4ee196dcfa4243913a125d9d3 (diff) | |
download | libmicrohttpd-275d6fed80cc0bbc55dc0de05a970a38e510e334.tar.gz libmicrohttpd-275d6fed80cc0bbc55dc0de05a970a38e510e334.zip |
Fixed compiler warnings.
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/minimal_example_empty.c | 1 | ||||
-rw-r--r-- | src/examples/minimal_example_empty_tls.c | 1 | ||||
-rw-r--r-- | src/examples/websocket_threaded_example.c | 100 |
3 files changed, 63 insertions, 39 deletions
diff --git a/src/examples/minimal_example_empty.c b/src/examples/minimal_example_empty.c index 986a2504..d692e0d8 100644 --- a/src/examples/minimal_example_empty.c +++ b/src/examples/minimal_example_empty.c | |||
@@ -40,6 +40,7 @@ ahc_echo (void *cls, | |||
40 | struct MHD_Response *response; | 40 | struct MHD_Response *response; |
41 | enum MHD_Result ret; | 41 | enum MHD_Result ret; |
42 | 42 | ||
43 | (void) cls; /* Unused. Silent compiler warning. */ | ||
43 | (void) url; /* Unused. Silent compiler warning. */ | 44 | (void) url; /* Unused. Silent compiler warning. */ |
44 | (void) version; /* Unused. Silent compiler warning. */ | 45 | (void) version; /* Unused. Silent compiler warning. */ |
45 | (void) upload_data; /* Unused. Silent compiler warning. */ | 46 | (void) upload_data; /* Unused. Silent compiler warning. */ |
diff --git a/src/examples/minimal_example_empty_tls.c b/src/examples/minimal_example_empty_tls.c index 0b9a0e25..f7e36802 100644 --- a/src/examples/minimal_example_empty_tls.c +++ b/src/examples/minimal_example_empty_tls.c | |||
@@ -40,6 +40,7 @@ ahc_echo (void *cls, | |||
40 | struct MHD_Response *response; | 40 | struct MHD_Response *response; |
41 | enum MHD_Result ret; | 41 | enum MHD_Result ret; |
42 | 42 | ||
43 | (void) cls; /* Unused. Silent compiler warning. */ | ||
43 | (void) url; /* Unused. Silent compiler warning. */ | 44 | (void) url; /* Unused. Silent compiler warning. */ |
44 | (void) version; /* Unused. Silent compiler warning. */ | 45 | (void) version; /* Unused. Silent compiler warning. */ |
45 | (void) upload_data; /* Unused. Silent compiler warning. */ | 46 | (void) upload_data; /* Unused. Silent compiler warning. */ |
diff --git a/src/examples/websocket_threaded_example.c b/src/examples/websocket_threaded_example.c index 98796767..449b9aba 100644 --- a/src/examples/websocket_threaded_example.c +++ b/src/examples/websocket_threaded_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) 2020 Christian Grothoff (and other contributing authors) | 3 | Copyright (C) 2020 Christian Grothoff, Silvio Clecio (and other |
4 | contributing authors) | ||
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 |
@@ -14,8 +15,7 @@ | |||
14 | 15 | ||
15 | You should have received a copy of the GNU Lesser General Public | 16 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library; if not, write to the Free Software | 17 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | USA | ||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
@@ -133,7 +133,7 @@ struct SHA1Context | |||
133 | uint32_t length_low; | 133 | uint32_t length_low; |
134 | uint32_t length_high; | 134 | uint32_t length_high; |
135 | int_least16_t message_block_index; | 135 | int_least16_t message_block_index; |
136 | uint8_t message_block[64]; | 136 | char message_block[64]; |
137 | int computed; | 137 | int computed; |
138 | int corrupted; | 138 | int corrupted; |
139 | }; | 139 | }; |
@@ -146,6 +146,7 @@ SHA1ProcessMessageBlock (struct SHA1Context *context) | |||
146 | uint32_t temp; | 146 | uint32_t temp; |
147 | uint32_t W[80]; | 147 | uint32_t W[80]; |
148 | uint32_t A, B, C, D, E; | 148 | uint32_t A, B, C, D, E; |
149 | |||
149 | for (i = 0; i < 16; i++) | 150 | for (i = 0; i < 16; i++) |
150 | { | 151 | { |
151 | W[i] = context->message_block[i * 4] << 24; | 152 | W[i] = context->message_block[i * 4] << 24; |
@@ -268,9 +269,10 @@ SHA1Reset (struct SHA1Context *context) | |||
268 | 269 | ||
269 | 270 | ||
270 | static enum SHA1_RESULT | 271 | static enum SHA1_RESULT |
271 | SHA1Result (struct SHA1Context *context, uint8_t Message_Digest[SHA1HashSize]) | 272 | SHA1Result (struct SHA1Context *context, char Message_Digest[SHA1HashSize]) |
272 | { | 273 | { |
273 | int i; | 274 | int i; |
275 | |||
274 | if (! context || ! Message_Digest) | 276 | if (! context || ! Message_Digest) |
275 | { | 277 | { |
276 | return SHA1_RESULT_NULL; | 278 | return SHA1_RESULT_NULL; |
@@ -300,7 +302,7 @@ SHA1Result (struct SHA1Context *context, uint8_t Message_Digest[SHA1HashSize]) | |||
300 | 302 | ||
301 | 303 | ||
302 | static enum SHA1_RESULT | 304 | static enum SHA1_RESULT |
303 | SHA1Input (struct SHA1Context *context, const uint8_t *message_array, | 305 | SHA1Input (struct SHA1Context *context, const char *message_array, |
304 | unsigned length) | 306 | unsigned length) |
305 | { | 307 | { |
306 | if (! length) | 308 | if (! length) |
@@ -359,9 +361,10 @@ BASE64Encode (const void *in, size_t len, char **output) | |||
359 | const char *data = in; | 361 | const char *data = in; |
360 | char *opt; | 362 | char *opt; |
361 | ssize_t ret; | 363 | ssize_t ret; |
362 | ssize_t i; | 364 | size_t i; |
363 | char c; | 365 | char c; |
364 | ret = 0; | 366 | ret = 0; |
367 | |||
365 | opt = malloc (2 + (len * 4 / 3) + 8); | 368 | opt = malloc (2 + (len * 4 / 3) + 8); |
366 | if (NULL == opt) | 369 | if (NULL == opt) |
367 | { | 370 | { |
@@ -413,6 +416,9 @@ static enum MHD_Result | |||
413 | is_websocket_request (struct MHD_Connection *con, const char *upg_header, | 416 | is_websocket_request (struct MHD_Connection *con, const char *upg_header, |
414 | const char *con_header) | 417 | const char *con_header) |
415 | { | 418 | { |
419 | |||
420 | (void) con; /* Unused. Silent compiler warning. */ | ||
421 | |||
416 | return (upg_header != NULL) && (con_header != NULL) | 422 | return (upg_header != NULL) && (con_header != NULL) |
417 | && (0 == strcmp (upg_header, WS_UPGRADE_VALUE)) | 423 | && (0 == strcmp (upg_header, WS_UPGRADE_VALUE)) |
418 | && (NULL != strstr (con_header, "Upgrade")) | 424 | && (NULL != strstr (con_header, "Upgrade")) |
@@ -422,10 +428,11 @@ is_websocket_request (struct MHD_Connection *con, const char *upg_header, | |||
422 | 428 | ||
423 | 429 | ||
424 | static enum MHD_Result | 430 | static enum MHD_Result |
425 | send_chat_page (struct MHD_Connection *con, uint16_t port) | 431 | send_chat_page (struct MHD_Connection *con) |
426 | { | 432 | { |
427 | struct MHD_Response *res; | 433 | struct MHD_Response *res; |
428 | enum MHD_Result ret; | 434 | enum MHD_Result ret; |
435 | |||
429 | res = MHD_create_response_from_buffer (strlen (CHAT_PAGE), (void *) CHAT_PAGE, | 436 | res = MHD_create_response_from_buffer (strlen (CHAT_PAGE), (void *) CHAT_PAGE, |
430 | MHD_RESPMEM_PERSISTENT); | 437 | MHD_RESPMEM_PERSISTENT); |
431 | ret = MHD_queue_response (con, MHD_HTTP_OK, res); | 438 | ret = MHD_queue_response (con, MHD_HTTP_OK, res); |
@@ -439,6 +446,7 @@ send_bad_request (struct MHD_Connection *con) | |||
439 | { | 446 | { |
440 | struct MHD_Response *res; | 447 | struct MHD_Response *res; |
441 | enum MHD_Result ret; | 448 | enum MHD_Result ret; |
449 | |||
442 | res = MHD_create_response_from_buffer (strlen (BAD_REQUEST_PAGE), | 450 | res = MHD_create_response_from_buffer (strlen (BAD_REQUEST_PAGE), |
443 | (void *) BAD_REQUEST_PAGE, | 451 | (void *) BAD_REQUEST_PAGE, |
444 | MHD_RESPMEM_PERSISTENT); | 452 | MHD_RESPMEM_PERSISTENT); |
@@ -453,6 +461,7 @@ send_upgrade_required (struct MHD_Connection *con) | |||
453 | { | 461 | { |
454 | struct MHD_Response *res; | 462 | struct MHD_Response *res; |
455 | enum MHD_Result ret; | 463 | enum MHD_Result ret; |
464 | |||
456 | res = MHD_create_response_from_buffer (strlen (UPGRADE_REQUIRED_PAGE), | 465 | res = MHD_create_response_from_buffer (strlen (UPGRADE_REQUIRED_PAGE), |
457 | (void *) UPGRADE_REQUIRED_PAGE, | 466 | (void *) UPGRADE_REQUIRED_PAGE, |
458 | MHD_RESPMEM_PERSISTENT); | 467 | MHD_RESPMEM_PERSISTENT); |
@@ -471,6 +480,7 @@ ws_get_accept_value (const char *key, char **val) | |||
471 | char hash[SHA1HashSize]; | 480 | char hash[SHA1HashSize]; |
472 | char *str; | 481 | char *str; |
473 | ssize_t len; | 482 | ssize_t len; |
483 | |||
474 | if (NULL == key) | 484 | if (NULL == key) |
475 | { | 485 | { |
476 | return MHD_NO; | 486 | return MHD_NO; |
@@ -483,7 +493,7 @@ ws_get_accept_value (const char *key, char **val) | |||
483 | strcpy (str, key); | 493 | strcpy (str, key); |
484 | strcat (str, WS_GUID); | 494 | strcat (str, WS_GUID); |
485 | SHA1Reset (&ctx); | 495 | SHA1Reset (&ctx); |
486 | SHA1Input (&ctx, (const uint8_t *) str, WS_KEY_GUID_LEN); | 496 | SHA1Input (&ctx, (const char *) str, WS_KEY_GUID_LEN); |
487 | SHA1Result (&ctx, hash); | 497 | SHA1Result (&ctx, hash); |
488 | free (str); | 498 | free (str); |
489 | len = BASE64Encode (hash, SHA1HashSize, val); | 499 | len = BASE64Encode (hash, SHA1HashSize, val); |
@@ -501,6 +511,7 @@ make_blocking (MHD_socket fd) | |||
501 | { | 511 | { |
502 | #if defined(MHD_POSIX_SOCKETS) | 512 | #if defined(MHD_POSIX_SOCKETS) |
503 | int flags; | 513 | int flags; |
514 | |||
504 | flags = fcntl (fd, F_GETFL); | 515 | flags = fcntl (fd, F_GETFL); |
505 | if (-1 == flags) | 516 | if (-1 == flags) |
506 | return; | 517 | return; |
@@ -509,6 +520,7 @@ make_blocking (MHD_socket fd) | |||
509 | abort (); | 520 | abort (); |
510 | #elif defined(MHD_WINSOCK_SOCKETS) | 521 | #elif defined(MHD_WINSOCK_SOCKETS) |
511 | unsigned long flags = 1; | 522 | unsigned long flags = 1; |
523 | |||
512 | ioctlsocket (fd, FIONBIO, &flags); | 524 | ioctlsocket (fd, FIONBIO, &flags); |
513 | #endif /* MHD_WINSOCK_SOCKETS */ | 525 | #endif /* MHD_WINSOCK_SOCKETS */ |
514 | } | 526 | } |
@@ -519,6 +531,7 @@ send_all (MHD_socket sock, const char *buf, size_t len) | |||
519 | { | 531 | { |
520 | ssize_t ret; | 532 | ssize_t ret; |
521 | size_t off; | 533 | size_t off; |
534 | |||
522 | for (off = 0; off < len; off += ret) | 535 | for (off = 0; off < len; off += ret) |
523 | { | 536 | { |
524 | ret = send (sock, &buf[off], len - off, 0); | 537 | ret = send (sock, &buf[off], len - off, 0); |
@@ -543,13 +556,14 @@ send_all (MHD_socket sock, const char *buf, size_t len) | |||
543 | static int | 556 | static int |
544 | ws_send_frame (int sock, const char *msg, size_t length) | 557 | ws_send_frame (int sock, const char *msg, size_t length) |
545 | { | 558 | { |
546 | unsigned char *response; | 559 | char *response; |
547 | unsigned char frame[10]; | 560 | char frame[10]; |
548 | uint8_t idx_first_rdata; | 561 | unsigned char idx_first_rdata; |
549 | int idx_response; | 562 | int idx_response; |
550 | int output; | 563 | int output; |
551 | int isock; | 564 | int isock; |
552 | int i; | 565 | size_t i; |
566 | |||
553 | frame[0] = (WS_FIN | WS_OPCODE_TEXT_FRAME); | 567 | frame[0] = (WS_FIN | WS_OPCODE_TEXT_FRAME); |
554 | if (length <= 125) | 568 | if (length <= 125) |
555 | { | 569 | { |
@@ -566,14 +580,14 @@ ws_send_frame (int sock, const char *msg, size_t length) | |||
566 | else | 580 | else |
567 | { | 581 | { |
568 | frame[1] = 127; | 582 | frame[1] = 127; |
569 | frame[2] = (unsigned char) ((length >> 56) & 0xFF); | 583 | frame[2] = (char) ((length >> 56) & 0xFF); |
570 | frame[3] = (unsigned char) ((length >> 48) & 0xFF); | 584 | frame[3] = (char) ((length >> 48) & 0xFF); |
571 | frame[4] = (unsigned char) ((length >> 40) & 0xFF); | 585 | frame[4] = (char) ((length >> 40) & 0xFF); |
572 | frame[5] = (unsigned char) ((length >> 32) & 0xFF); | 586 | frame[5] = (char) ((length >> 32) & 0xFF); |
573 | frame[6] = (unsigned char) ((length >> 24) & 0xFF); | 587 | frame[6] = (char) ((length >> 24) & 0xFF); |
574 | frame[7] = (unsigned char) ((length >> 16) & 0xFF); | 588 | frame[7] = (char) ((length >> 16) & 0xFF); |
575 | frame[8] = (unsigned char) ((length >> 8) & 0xFF); | 589 | frame[8] = (char) ((length >> 8) & 0xFF); |
576 | frame[9] = (unsigned char) (length & 0xFF); | 590 | frame[9] = (char) (length & 0xFF); |
577 | idx_first_rdata = 10; | 591 | idx_first_rdata = 10; |
578 | } | 592 | } |
579 | idx_response = 0; | 593 | idx_response = 0; |
@@ -613,14 +627,15 @@ static unsigned char * | |||
613 | ws_receive_frame (unsigned char *frame, ssize_t *length, int *type) | 627 | ws_receive_frame (unsigned char *frame, ssize_t *length, int *type) |
614 | { | 628 | { |
615 | unsigned char *msg; | 629 | unsigned char *msg; |
616 | uint8_t masks[4]; | 630 | char masks[4]; |
617 | uint8_t mask; | 631 | char mask; |
618 | uint8_t flength; | 632 | char flength; |
619 | uint8_t idx_first_mask; | 633 | char idx_first_mask; |
620 | uint8_t idx_first_data; | 634 | char idx_first_data; |
621 | ssize_t data_length; | 635 | ssize_t data_length; |
622 | int i; | 636 | int i; |
623 | int j; | 637 | int j; |
638 | |||
624 | msg = NULL; | 639 | msg = NULL; |
625 | if (frame[0] == (WS_FIN | WS_OPCODE_TEXT_FRAME)) | 640 | if (frame[0] == (WS_FIN | WS_OPCODE_TEXT_FRAME)) |
626 | { | 641 | { |
@@ -670,15 +685,16 @@ run_usock (void *cls) | |||
670 | { | 685 | { |
671 | struct WsData *ws = cls; | 686 | struct WsData *ws = cls; |
672 | struct MHD_UpgradeResponseHandle *urh = ws->urh; | 687 | struct MHD_UpgradeResponseHandle *urh = ws->urh; |
688 | unsigned char buf[2048]; | ||
673 | unsigned char *msg; | 689 | unsigned char *msg; |
674 | unsigned char *text; | 690 | char client[20]; |
675 | unsigned char client[20]; | 691 | char *text; |
676 | char buf[2048]; | ||
677 | ssize_t got; | 692 | ssize_t got; |
678 | size_t size; | 693 | size_t size; |
679 | int type; | 694 | int type; |
680 | int sent; | 695 | int sent; |
681 | int i; | 696 | int i; |
697 | |||
682 | make_blocking (ws->sock); | 698 | make_blocking (ws->sock); |
683 | while (1) | 699 | while (1) |
684 | { | 700 | { |
@@ -747,11 +763,13 @@ uh_cb (void *cls, struct MHD_Connection *con, void *con_cls, | |||
747 | pthread_t pt; | 763 | pthread_t pt; |
748 | int sock_overflow; | 764 | int sock_overflow; |
749 | int i; | 765 | int i; |
750 | (void) cls; | 766 | |
751 | (void) con; | 767 | (void) cls; /* Unused. Silent compiler warning. */ |
752 | (void) con_cls; | 768 | (void) con; /* Unused. Silent compiler warning. */ |
753 | (void) extra_in; | 769 | (void) con_cls; /* Unused. Silent compiler warning. */ |
754 | (void) extra_in_size; | 770 | (void) extra_in; /* Unused. Silent compiler warning. */ |
771 | (void) extra_in_size; /* Unused. Silent compiler warning. */ | ||
772 | |||
755 | sock_overflow = MHD_YES; | 773 | sock_overflow = MHD_YES; |
756 | ws = malloc (sizeof (struct WsData)); | 774 | ws = malloc (sizeof (struct WsData)); |
757 | if (NULL == ws) | 775 | if (NULL == ws) |
@@ -759,6 +777,7 @@ uh_cb (void *cls, struct MHD_Connection *con, void *con_cls, | |||
759 | memset (ws, 0, sizeof (struct WsData)); | 777 | memset (ws, 0, sizeof (struct WsData)); |
760 | ws->sock = sock; | 778 | ws->sock = sock; |
761 | ws->urh = urh; | 779 | ws->urh = urh; |
780 | |||
762 | pthread_mutex_lock (&MUTEX); | 781 | pthread_mutex_lock (&MUTEX); |
763 | for (i = 0; i < MAX_CLIENTS; i++) | 782 | for (i = 0; i < MAX_CLIENTS; i++) |
764 | { | 783 | { |
@@ -795,12 +814,14 @@ ahc_cb (void *cls, struct MHD_Connection *con, const char *url, | |||
795 | const char *con_header; | 814 | const char *con_header; |
796 | const char *ws_version_header; | 815 | const char *ws_version_header; |
797 | const char *ws_key_header; | 816 | const char *ws_key_header; |
798 | char ws_ac_header[60]; | ||
799 | char *ws_ac_value; | 817 | char *ws_ac_value; |
800 | enum MHD_Result ret; | 818 | enum MHD_Result ret; |
801 | (void) url; | 819 | |
802 | (void) upload_data; | 820 | (void) cls; /* Unused. Silent compiler warning. */ |
803 | (void) upload_data_size; | 821 | (void) url; /* Unused. Silent compiler warning. */ |
822 | (void) upload_data; /* Unused. Silent compiler warning. */ | ||
823 | (void) upload_data_size; /* Unused. Silent compiler warning. */ | ||
824 | |||
804 | if (NULL == *ptr) | 825 | if (NULL == *ptr) |
805 | { | 826 | { |
806 | *ptr = (void *) 1; | 827 | *ptr = (void *) 1; |
@@ -813,7 +834,7 @@ ahc_cb (void *cls, struct MHD_Connection *con, const char *url, | |||
813 | MHD_HTTP_HEADER_CONNECTION); | 834 | MHD_HTTP_HEADER_CONNECTION); |
814 | if (MHD_NO == is_websocket_request (con, upg_header, con_header)) | 835 | if (MHD_NO == is_websocket_request (con, upg_header, con_header)) |
815 | { | 836 | { |
816 | return send_chat_page (con, *(uint16_t *) cls); | 837 | return send_chat_page (con); |
817 | } | 838 | } |
818 | if ((0 != strcmp (method, MHD_HTTP_METHOD_GET)) | 839 | if ((0 != strcmp (method, MHD_HTTP_METHOD_GET)) |
819 | || (0 != strcmp (version, MHD_HTTP_VERSION_1_1))) | 840 | || (0 != strcmp (version, MHD_HTTP_VERSION_1_1))) |
@@ -854,6 +875,7 @@ main (int argc, char *const *argv) | |||
854 | { | 875 | { |
855 | struct MHD_Daemon *d; | 876 | struct MHD_Daemon *d; |
856 | uint16_t port; | 877 | uint16_t port; |
878 | |||
857 | if (argc != 2) | 879 | if (argc != 2) |
858 | { | 880 | { |
859 | printf ("%s PORT\n", argv[0]); | 881 | printf ("%s PORT\n", argv[0]); |