diff options
author | silvioprog <silvioprog@gmail.com> | 2020-04-10 13:50:12 -0300 |
---|---|---|
committer | silvioprog <silvioprog@gmail.com> | 2020-04-10 13:50:12 -0300 |
commit | 08134cf85ade4eb39b6a384af1df58db7af9266b (patch) | |
tree | c7dc970ba1ccb981d8ccb2c598059216cfc1aea9 | |
parent | 100cf4ae10eccfd691a706987a80e3ab97f6ed42 (diff) | |
download | libmicrohttpd-08134cf85ade4eb39b6a384af1df58db7af9266b.tar.gz libmicrohttpd-08134cf85ade4eb39b6a384af1df58db7af9266b.zip |
Fixed websocket example.
-rw-r--r-- | src/examples/websocket_threaded_example.c | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/examples/websocket_threaded_example.c b/src/examples/websocket_threaded_example.c index 449b9aba..ac4bb839 100644 --- a/src/examples/websocket_threaded_example.c +++ b/src/examples/websocket_threaded_example.c | |||
@@ -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 | char message_block[64]; | 136 | unsigned char message_block[64]; |
137 | int computed; | 137 | int computed; |
138 | int corrupted; | 138 | int corrupted; |
139 | }; | 139 | }; |
@@ -269,7 +269,8 @@ SHA1Reset (struct SHA1Context *context) | |||
269 | 269 | ||
270 | 270 | ||
271 | static enum SHA1_RESULT | 271 | static enum SHA1_RESULT |
272 | SHA1Result (struct SHA1Context *context, char Message_Digest[SHA1HashSize]) | 272 | SHA1Result (struct SHA1Context *context, unsigned char |
273 | Message_Digest[SHA1HashSize]) | ||
273 | { | 274 | { |
274 | int i; | 275 | int i; |
275 | 276 | ||
@@ -302,7 +303,7 @@ SHA1Result (struct SHA1Context *context, char Message_Digest[SHA1HashSize]) | |||
302 | 303 | ||
303 | 304 | ||
304 | static enum SHA1_RESULT | 305 | static enum SHA1_RESULT |
305 | SHA1Input (struct SHA1Context *context, const char *message_array, | 306 | SHA1Input (struct SHA1Context *context, const unsigned char *message_array, |
306 | unsigned length) | 307 | unsigned length) |
307 | { | 308 | { |
308 | if (! length) | 309 | if (! length) |
@@ -477,7 +478,7 @@ static enum MHD_Result | |||
477 | ws_get_accept_value (const char *key, char **val) | 478 | ws_get_accept_value (const char *key, char **val) |
478 | { | 479 | { |
479 | struct SHA1Context ctx; | 480 | struct SHA1Context ctx; |
480 | char hash[SHA1HashSize]; | 481 | unsigned char hash[SHA1HashSize]; |
481 | char *str; | 482 | char *str; |
482 | ssize_t len; | 483 | ssize_t len; |
483 | 484 | ||
@@ -493,7 +494,7 @@ ws_get_accept_value (const char *key, char **val) | |||
493 | strcpy (str, key); | 494 | strcpy (str, key); |
494 | strcat (str, WS_GUID); | 495 | strcat (str, WS_GUID); |
495 | SHA1Reset (&ctx); | 496 | SHA1Reset (&ctx); |
496 | SHA1Input (&ctx, (const char *) str, WS_KEY_GUID_LEN); | 497 | SHA1Input (&ctx, (const unsigned char *) str, WS_KEY_GUID_LEN); |
497 | SHA1Result (&ctx, hash); | 498 | SHA1Result (&ctx, hash); |
498 | free (str); | 499 | free (str); |
499 | len = BASE64Encode (hash, SHA1HashSize, val); | 500 | len = BASE64Encode (hash, SHA1HashSize, val); |
@@ -527,7 +528,7 @@ make_blocking (MHD_socket fd) | |||
527 | 528 | ||
528 | 529 | ||
529 | static size_t | 530 | static size_t |
530 | send_all (MHD_socket sock, const char *buf, size_t len) | 531 | send_all (MHD_socket sock, const unsigned char *buf, size_t len) |
531 | { | 532 | { |
532 | ssize_t ret; | 533 | ssize_t ret; |
533 | size_t off; | 534 | size_t off; |
@@ -556,8 +557,8 @@ send_all (MHD_socket sock, const char *buf, size_t len) | |||
556 | static int | 557 | static int |
557 | ws_send_frame (int sock, const char *msg, size_t length) | 558 | ws_send_frame (int sock, const char *msg, size_t length) |
558 | { | 559 | { |
559 | char *response; | 560 | unsigned char *response; |
560 | char frame[10]; | 561 | unsigned char frame[10]; |
561 | unsigned char idx_first_rdata; | 562 | unsigned char idx_first_rdata; |
562 | int idx_response; | 563 | int idx_response; |
563 | int output; | 564 | int output; |
@@ -580,14 +581,14 @@ ws_send_frame (int sock, const char *msg, size_t length) | |||
580 | else | 581 | else |
581 | { | 582 | { |
582 | frame[1] = 127; | 583 | frame[1] = 127; |
583 | frame[2] = (char) ((length >> 56) & 0xFF); | 584 | frame[2] = (unsigned char) ((length >> 56) & 0xFF); |
584 | frame[3] = (char) ((length >> 48) & 0xFF); | 585 | frame[3] = (unsigned char) ((length >> 48) & 0xFF); |
585 | frame[4] = (char) ((length >> 40) & 0xFF); | 586 | frame[4] = (unsigned char) ((length >> 40) & 0xFF); |
586 | frame[5] = (char) ((length >> 32) & 0xFF); | 587 | frame[5] = (unsigned char) ((length >> 32) & 0xFF); |
587 | frame[6] = (char) ((length >> 24) & 0xFF); | 588 | frame[6] = (unsigned char) ((length >> 24) & 0xFF); |
588 | frame[7] = (char) ((length >> 16) & 0xFF); | 589 | frame[7] = (unsigned char) ((length >> 16) & 0xFF); |
589 | frame[8] = (char) ((length >> 8) & 0xFF); | 590 | frame[8] = (unsigned char) ((length >> 8) & 0xFF); |
590 | frame[9] = (char) (length & 0xFF); | 591 | frame[9] = (unsigned char) (length & 0xFF); |
591 | idx_first_rdata = 10; | 592 | idx_first_rdata = 10; |
592 | } | 593 | } |
593 | idx_response = 0; | 594 | idx_response = 0; |
@@ -626,12 +627,12 @@ ws_send_frame (int sock, const char *msg, size_t length) | |||
626 | static unsigned char * | 627 | static unsigned char * |
627 | ws_receive_frame (unsigned char *frame, ssize_t *length, int *type) | 628 | ws_receive_frame (unsigned char *frame, ssize_t *length, int *type) |
628 | { | 629 | { |
630 | unsigned char masks[4]; | ||
631 | unsigned char mask; | ||
629 | unsigned char *msg; | 632 | unsigned char *msg; |
630 | char masks[4]; | 633 | unsigned char flength; |
631 | char mask; | 634 | unsigned char idx_first_mask; |
632 | char flength; | 635 | unsigned char idx_first_data; |
633 | char idx_first_mask; | ||
634 | char idx_first_data; | ||
635 | ssize_t data_length; | 636 | ssize_t data_length; |
636 | int i; | 637 | int i; |
637 | int j; | 638 | int j; |