Kaynağa Gözat

websockets: fixed code style

Evgeny Grin (Karlson2k) 4 yıl önce
ebeveyn
işleme
f44e4bf896

+ 22 - 17
doc/examples/websocket.c

@@ -73,6 +73,7 @@ static void
 send_all (MHD_socket fd,
           const char *buf,
           size_t len);
+
 static void
 make_blocking (MHD_socket fd);
 
@@ -89,7 +90,7 @@ upgrade_handler (void *cls,
   make_blocking (fd);
 
   /* create a websocket stream for this connection */
-  struct MHD_WebSocketStream* ws;
+  struct MHD_WebSocketStream *ws;
   int result = MHD_websocket_stream_init (&ws,
                                           0,
                                           0);
@@ -241,6 +242,7 @@ upgrade_handler (void *cls,
                       MHD_UPGRADE_ACTION_CLOSE);
 }
 
+
 /* This helper function is used for the case that
  * we need to resend some data
  */
@@ -272,6 +274,7 @@ send_all (MHD_socket fd,
   }
 }
 
+
 /* This helper function contains operating-system-dependent code and
  * is used to make a socket blocking.
  */
@@ -294,6 +297,7 @@ make_blocking (MHD_socket fd)
 #endif
 }
 
+
 static enum MHD_Result
 access_handler (void *cls,
                 struct MHD_Connection *connection,
@@ -326,9 +330,9 @@ access_handler (void *cls,
   {
     /* Default page for visiting the server */
     struct MHD_Response *response = MHD_create_response_from_buffer (
-                                      strlen (PAGE),
-                                      PAGE,
-                                      MHD_RESPMEM_PERSISTENT);
+      strlen (PAGE),
+      PAGE,
+      MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_OK,
                               response);
@@ -337,7 +341,7 @@ access_handler (void *cls,
   else if (0 == strcmp (url, "/chat"))
   {
     char is_valid = 1;
-    const char* value = NULL;
+    const char *value = NULL;
     char sec_websocket_accept[29];
 
     if (0 != MHD_websocket_check_http_version (version))
@@ -395,10 +399,10 @@ access_handler (void *cls,
     else
     {
       /* return error page */
-      struct MHD_Response*response = MHD_create_response_from_buffer (
-                                       strlen (PAGE_INVALID_WEBSOCKET_REQUEST),
-                                       PAGE_INVALID_WEBSOCKET_REQUEST,
-                                       MHD_RESPMEM_PERSISTENT);
+      struct MHD_Response *response = MHD_create_response_from_buffer (
+        strlen (PAGE_INVALID_WEBSOCKET_REQUEST),
+        PAGE_INVALID_WEBSOCKET_REQUEST,
+        MHD_RESPMEM_PERSISTENT);
       ret = MHD_queue_response (connection,
                                 MHD_HTTP_BAD_REQUEST,
                                 response);
@@ -407,10 +411,10 @@ access_handler (void *cls,
   }
   else
   {
-    struct MHD_Response*response = MHD_create_response_from_buffer (
-                                     strlen (PAGE_NOT_FOUND),
-                                     PAGE_NOT_FOUND,
-                                     MHD_RESPMEM_PERSISTENT);
+    struct MHD_Response *response = MHD_create_response_from_buffer (
+      strlen (PAGE_NOT_FOUND),
+      PAGE_NOT_FOUND,
+      MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_NOT_FOUND,
                               response);
@@ -420,6 +424,7 @@ access_handler (void *cls,
   return ret;
 }
 
+
 int
 main (int argc,
       char *const *argv)
@@ -428,10 +433,10 @@ main (int argc,
   (void) argv;               /* Unused. Silent compiler warning. */
   struct MHD_Daemon *daemon;
 
-  daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD |
-                             MHD_USE_THREAD_PER_CONNECTION |
-                             MHD_ALLOW_UPGRADE |
-                             MHD_USE_ERROR_LOG,
+  daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD
+                             | MHD_USE_THREAD_PER_CONNECTION
+                             | MHD_ALLOW_UPGRADE
+                             | MHD_USE_ERROR_LOG,
                              PORT, NULL, NULL,
                              &access_handler, NULL,
                              MHD_OPTION_END);

+ 61 - 60
src/examples/websocket_chatserver_example.c

@@ -629,14 +629,14 @@ struct ConnectedUser
   /* the UpgradeResponseHandle of libmicrohttpd (needed for closing the socket) */
   struct MHD_UpgradeResponseHandle *urh;
   /* the websocket encode/decode stream */
-  struct MHD_WebSocketStream*ws;
+  struct MHD_WebSocketStream *ws;
   /* the possibly read data at the start (only used once) */
   char *extra_in;
   size_t extra_in_size;
   /* the unique user id (counting from 1, ids will never be re-used) */
   size_t user_id;
   /* the current user name */
-  char*user_name;
+  char *user_name;
   size_t user_name_len;
   /* the zero-based index of the next message;
      may be decremented when old messages are deleted */
@@ -673,7 +673,7 @@ struct Message
   /* The user id of the recipient. This is 0 if every connected user shall receive it */
   size_t to_user_id;
   /* The data of the message. */
-  char*data;
+  char *data;
   size_t data_len;
   /* Specifies whether the data is UTF-8 encoded text (0) or binary data (1) */
   int is_binary;
@@ -684,9 +684,9 @@ size_t unique_user_id = 0;
 
 /* the chat data (users and messages; may be accessed by all threads, but is protected by mutex) */
 pthread_mutex_t chat_mutex;
-struct ConnectedUser**users = NULL;
+struct ConnectedUser **users = NULL;
 size_t user_count = 0;
-struct Message**messages = NULL;
+struct Message **messages = NULL;
 size_t message_count = 0;
 /* specifies whether all websockets must close (1) or not (0) */
 volatile int disconnect_all = 0;
@@ -728,7 +728,7 @@ make_blocking (MHD_socket fd)
  * @param len The length in bytes of the data in the buffer
  */
 static void
-send_all (struct ConnectedUser*cu,
+send_all (struct ConnectedUser *cu,
           const char *buf,
           size_t len)
 {
@@ -776,13 +776,13 @@ send_all (struct ConnectedUser*cu,
 static int
 chat_addmessage (size_t from_user_id,
                  size_t to_user_id,
-                 char*data,
+                 char *data,
                  size_t data_len,
                  int is_binary,
                  int needs_lock)
 {
   /* allocate the buffer and fill it with data */
-  struct Message*message = (struct Message*) malloc (sizeof (struct Message));
+  struct Message *message = (struct Message *) malloc (sizeof (struct Message));
   if (NULL == message)
     return 1;
 
@@ -809,10 +809,10 @@ chat_addmessage (size_t from_user_id,
 
   /* add the new message to the global message list */
   size_t message_count_ = message_count + 1;
-  struct Message**messages_ = (struct Message**) realloc (messages,
-                                                          message_count_
-                                                          * sizeof (struct
-                                                                    Message*));
+  struct Message **messages_ = (struct Message **) realloc (messages,
+                                                            message_count_
+                                                            * sizeof (struct
+                                                                      Message *));
   if (NULL == messages_)
   {
     free (message);
@@ -928,14 +928,14 @@ chat_clearmessages (int needs_lock)
  * @return   0 on success, other values on error
  */
 static int
-chat_adduser (struct ConnectedUser*cu)
+chat_adduser (struct ConnectedUser *cu)
 {
   /* initialize the notification message of the new user */
   char user_index[32];
   snprintf (user_index, 32, "%d", (int) cu->user_id);
   size_t user_index_len = strlen (user_index);
   size_t data_len = user_index_len + cu->user_name_len + 9;
-  char*data = (char*) malloc (data_len + 1);
+  char *data = (char *) malloc (data_len + 1);
   if (NULL == data)
     return 1;
   strcpy (data, "useradd|");
@@ -965,12 +965,12 @@ chat_adduser (struct ConnectedUser*cu)
 
   /* add the new user to the list */
   size_t user_count_ = user_count + 1;
-  struct ConnectedUser**users_ = (struct ConnectedUser**) realloc (users,
-                                                                   user_count_
-                                                                   * sizeof (
-                                                                     struct
-                                                                     ConnectedUser
-                                                                     *));
+  struct ConnectedUser **users_ = (struct ConnectedUser **) realloc (users,
+                                                                     user_count_
+                                                                     * sizeof (
+                                                                       struct
+                                                                       ConnectedUser
+                                                                       *));
   if (NULL == users_)
   {
     /* realloc failed */
@@ -998,7 +998,7 @@ chat_adduser (struct ConnectedUser*cu)
  * @return   0 on success, other values on error
  */
 static int
-chat_removeuser (struct ConnectedUser*cu)
+chat_removeuser (struct ConnectedUser *cu)
 {
   char user_index[32];
 
@@ -1006,7 +1006,7 @@ chat_removeuser (struct ConnectedUser*cu)
   snprintf (user_index, 32, "%d", (int) cu->user_id);
   size_t user_index_len = strlen (user_index);
   size_t data_len = user_index_len + 9;
-  char*data = (char*) malloc (data_len + 1);
+  char *data = (char *) malloc (data_len + 1);
   if (NULL == data)
     return 1;
   strcpy (data, "userdel|");
@@ -1061,8 +1061,8 @@ chat_removeuser (struct ConnectedUser*cu)
  * @return             0 on success, other values on error. 2 means name already in use.
  */
 static int
-chat_renameuser (struct ConnectedUser*cu,
-                 char*new_name,
+chat_renameuser (struct ConnectedUser *cu,
+                 char *new_name,
                  size_t new_name_len)
 {
   /* lock the mutex */
@@ -1090,7 +1090,7 @@ chat_renameuser (struct ConnectedUser*cu,
   snprintf (user_index, 32, "%d", (int) cu->user_id);
   size_t user_index_len = strlen (user_index);
   size_t data_len = user_index_len + new_name_len + 10;
-  char*data = (char*) malloc (data_len + 1);
+  char *data = (char *) malloc (data_len + 1);
   if (NULL == data)
     return 1;
   strcpy (data, "username|");
@@ -1128,8 +1128,8 @@ chat_renameuser (struct ConnectedUser*cu,
 * @return             0 on success, other values on error
 */
 static int
-connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
-                                               char*buf,
+connecteduser_parse_received_websocket_stream (struct ConnectedUser *cu,
+                                               char *buf,
                                                size_t buf_len)
 {
   size_t buf_offset = 0;
@@ -1270,7 +1270,7 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
                   snprintf (user_index, 32, "%d", (int) cu->user_id);
                   size_t user_index_len = strlen (user_index);
                   size_t data_len = user_index_len + frame_len - j + 9;
-                  char*data = (char*) malloc (data_len + 1);
+                  char *data = (char *) malloc (data_len + 1);
                   if (NULL != data)
                   {
                     strcpy (data, "regular|");
@@ -1307,7 +1307,7 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
                   snprintf (user_index, 32, "%d", (int) cu->user_id);
                   size_t user_index_len = strlen (user_index);
                   size_t data_len = user_index_len + frame_len - j + 9;
-                  char*data = (char*) malloc (data_len + 1);
+                  char *data = (char *) malloc (data_len + 1);
                   if (NULL != data)
                   {
 
@@ -1347,7 +1347,7 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
                                      1);
                     break;
                   }
-                  char*new_name = (char*) malloc (new_name_len + 1);
+                  char *new_name = (char *) malloc (new_name_len + 1);
                   if (NULL == new_name)
                   {
                     chat_addmessage (0,
@@ -1415,7 +1415,7 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
                   if (0 == pthread_mutex_lock (&chat_mutex))
                   {
                     /* check whether the to_user exists */
-                    struct ConnectedUser*ping_user = NULL;
+                    struct ConnectedUser *ping_user = NULL;
                     for (size_t k = 0; k < user_count; ++k)
                     {
                       if (users[k]->user_id == to_user_id)
@@ -1478,7 +1478,7 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
           MHD_websocket_free (cu->ws,
                               frame_data);
           {
-            char*result = NULL;
+            char *result = NULL;
             size_t result_len = 0;
             int er = MHD_websocket_encode_close (cu->ws,
                                                  MHD_WEBSOCKET_CLOSEREASON_REGULAR,
@@ -1545,7 +1545,8 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
               snprintf (result_text + 5, 235, "%d", (int) cu->user_id);
               strcat (result_text,
                       "|");
-              snprintf (result_text + strlen (result_text), 240 - strlen (result_text), "%d", (int) ping);
+              snprintf (result_text + strlen (result_text), 240 - strlen (
+                          result_text), "%d", (int) ping);
               chat_addmessage (0,
                                0,
                                result_text,
@@ -1586,7 +1587,7 @@ connecteduser_parse_received_websocket_stream (struct ConnectedUser*cu,
  * @return             Always NULL
  */
 static void *
-connecteduser_send_messages (void*cls)
+connecteduser_send_messages (void *cls)
 {
   struct ConnectedUser *cu = cls;
 
@@ -1602,7 +1603,7 @@ connecteduser_send_messages (void*cls)
         if (1 == disconnect_all)
         {
           /* the application closes and want that we disconnect all users */
-          struct MHD_UpgradeResponseHandle*urh = cu->urh;
+          struct MHD_UpgradeResponseHandle *urh = cu->urh;
           if (NULL != urh)
           {
             /* Close the TCP/IP socket. */
@@ -1629,7 +1630,7 @@ connecteduser_send_messages (void*cls)
                   "libmicrohttpdchatserverpingdata");
           snprintf (cu->ping_message + 31, 97, "%d", (int) cu->ping_counter);
           cu->ping_message_len = strlen (cu->ping_message);
-          char*frame_data = NULL;
+          char *frame_data = NULL;
           size_t frame_len = 0;
           int er = MHD_websocket_encode_ping (cu->ws,
                                               cu->ping_message,
@@ -1657,11 +1658,11 @@ connecteduser_send_messages (void*cls)
         else if (cu->next_message_index < message_count)
         {
           /* a chat message or command is pending */
-          char*frame_data = NULL;
+          char *frame_data = NULL;
           size_t frame_len = 0;
           int er = 0;
           {
-            struct Message*msg = messages[cu->next_message_index];
+            struct Message *msg = messages[cu->next_message_index];
             if ((0 == msg->to_user_id) ||
                 (cu->user_id == msg->to_user_id) ||
                 (cu->user_id == msg->from_user_id) )
@@ -1810,10 +1811,10 @@ connecteduser_receive_messages (void *cls)
   {
     struct UserInit
     {
-      char*user_init;
+      char *user_init;
       size_t user_init_len;
     };
-    struct UserInit*init_users = NULL;
+    struct UserInit *init_users = NULL;
     size_t init_users_len = 0;
 
     /* first collect all users without sending (so the mutex isn't locked too long) */
@@ -1821,8 +1822,8 @@ connecteduser_receive_messages (void *cls)
     {
       if (0 < user_count)
       {
-        init_users = (struct UserInit*) malloc (user_count * sizeof (struct
-                                                                     UserInit));
+        init_users = (struct UserInit *) malloc (user_count * sizeof (struct
+                                                                      UserInit));
         if (NULL != init_users)
         {
           init_users_len = user_count;
@@ -1833,7 +1834,7 @@ connecteduser_receive_messages (void *cls)
             size_t user_index_len = strlen (user_index);
             struct UserInit iu;
             iu.user_init_len = user_index_len + users[i]->user_name_len + 10;
-            iu.user_init = (char*) malloc (iu.user_init_len + 1);
+            iu.user_init = (char *) malloc (iu.user_init_len + 1);
             if (NULL != iu.user_init)
             {
               strcpy (iu.user_init, "userinit|");
@@ -1929,7 +1930,7 @@ connecteduser_receive_messages (void *cls)
         pthread_mutex_unlock (&chat_mutex);
         pthread_join (pt, NULL);
       }
-      struct MHD_UpgradeResponseHandle*urh = cu->urh;
+      struct MHD_UpgradeResponseHandle *urh = cu->urh;
       if (NULL != urh)
       {
         cu->urh = NULL;
@@ -1974,7 +1975,7 @@ connecteduser_receive_messages (void *cls)
           pthread_mutex_unlock (&chat_mutex);
           pthread_join (pt, NULL);
         }
-        struct MHD_UpgradeResponseHandle*urh = cu->urh;
+        struct MHD_UpgradeResponseHandle *urh = cu->urh;
         if (NULL != urh)
         {
           cu->urh = NULL;
@@ -2000,7 +2001,7 @@ connecteduser_receive_messages (void *cls)
     pthread_mutex_unlock (&chat_mutex);
     pthread_join (pt, NULL);
   }
-  struct MHD_UpgradeResponseHandle*urh = cu->urh;
+  struct MHD_UpgradeResponseHandle *urh = cu->urh;
   if (NULL != urh)
   {
     cu->urh = NULL;
@@ -2161,10 +2162,10 @@ access_handler (void *cls,
   if (0 == strcmp (url, "/"))
   {
     /* Default page for visiting the server */
-    struct MHD_Response*response = MHD_create_response_from_buffer (strlen (
-                                                                      PAGE),
-                                                                    PAGE,
-                                                                    MHD_RESPMEM_PERSISTENT);
+    struct MHD_Response *response = MHD_create_response_from_buffer (strlen (
+                                                                       PAGE),
+                                                                     PAGE,
+                                                                     MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_OK,
                               response);
@@ -2188,7 +2189,7 @@ access_handler (void *cls,
      */
 
     char is_valid = 1;
-    const char* value = NULL;
+    const char *value = NULL;
     char sec_websocket_accept[29];
 
     /* check whether an websocket upgrade is requested */
@@ -2257,10 +2258,10 @@ access_handler (void *cls,
     else
     {
       /* return error page */
-      struct MHD_Response*response = MHD_create_response_from_buffer (strlen (
-                                                                        PAGE_INVALID_WEBSOCKET_REQUEST),
-                                                                      PAGE_INVALID_WEBSOCKET_REQUEST,
-                                                                      MHD_RESPMEM_PERSISTENT);
+      struct MHD_Response *response = MHD_create_response_from_buffer (strlen (
+                                                                         PAGE_INVALID_WEBSOCKET_REQUEST),
+                                                                       PAGE_INVALID_WEBSOCKET_REQUEST,
+                                                                       MHD_RESPMEM_PERSISTENT);
       ret = MHD_queue_response (connection,
                                 MHD_HTTP_BAD_REQUEST,
                                 response);
@@ -2269,10 +2270,10 @@ access_handler (void *cls,
   }
   else
   {
-    struct MHD_Response*response = MHD_create_response_from_buffer (strlen (
-                                                                      PAGE_NOT_FOUND),
-                                                                    PAGE_NOT_FOUND,
-                                                                    MHD_RESPMEM_PERSISTENT);
+    struct MHD_Response *response = MHD_create_response_from_buffer (strlen (
+                                                                       PAGE_NOT_FOUND),
+                                                                     PAGE_NOT_FOUND,
+                                                                     MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_NOT_FOUND,
                               response);
@@ -2338,7 +2339,7 @@ main (int argc,
   {
     for (size_t i = 0; i < user_count; ++i)
     {
-      struct MHD_UpgradeResponseHandle*urh = users[i]->urh;
+      struct MHD_UpgradeResponseHandle *urh = users[i]->urh;
       if (NULL != urh)
       {
         users[i]->urh = NULL;

+ 2 - 2
src/examples/websocket_threaded_example.c

@@ -539,7 +539,7 @@ send_all (MHD_socket sock, const unsigned char *buf, size_t len)
 
   for (off = 0; off < len; off += ret)
   {
-    ret = send (sock, (const void*) &buf[off], len - off, 0);
+    ret = send (sock, (const void *) &buf[off], len - off, 0);
     if (0 > ret)
     {
       if (EAGAIN == errno)
@@ -705,7 +705,7 @@ run_usock (void *cls)
   make_blocking (ws->sock);
   while (1)
   {
-    got = recv (ws->sock, (void*) buf, sizeof (buf), 0);
+    got = recv (ws->sock, (void *) buf, sizeof (buf), 0);
     if (0 >= got)
     {
       break;

+ 53 - 53
src/include/microhttpd_ws.h

@@ -547,7 +547,7 @@ enum MHD_WEBSOCKET_VALIDITY
  * @return allocated memory
  * @ingroup websocket
  */
-typedef void*
+typedef void *
 (*MHD_WebSocketMallocCallback) (size_t buf_len);
 /**
  * This callback function is used internally by many websocket
@@ -565,7 +565,7 @@ typedef void*
  * @return reallocated memory
  * @ingroup websocket
  */
-typedef void*
+typedef void *
 (*MHD_WebSocketReallocCallback) (void *buf, size_t new_buf_len);
 /**
  * This callback function is used internally by many websocket
@@ -600,7 +600,7 @@ typedef void
  * @ingroup websocket
  */
 typedef size_t
-(*MHD_WebSocketRandomNumberGenerator) (void *cls, void* buf, size_t buf_len);
+(*MHD_WebSocketRandomNumberGenerator) (void *cls, void *buf, size_t buf_len);
 
 /**
  * Checks the HTTP version of the incoming request.
@@ -615,7 +615,7 @@ typedef size_t
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_http_version (const char* http_version);
+MHD_websocket_check_http_version (const char *http_version);
 
 /**
  * Checks the value of the 'Connection' HTTP request header.
@@ -634,7 +634,7 @@ MHD_websocket_check_http_version (const char* http_version);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_connection_header (const char* connection_header);
+MHD_websocket_check_connection_header (const char *connection_header);
 
 /**
  * Checks the value of the 'Upgrade' HTTP request header.
@@ -653,7 +653,7 @@ MHD_websocket_check_connection_header (const char* connection_header);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_upgrade_header (const char* upgrade_header);
+MHD_websocket_check_upgrade_header (const char *upgrade_header);
 
 /**
  * Checks the value of the 'Sec-WebSocket-Version' HTTP request header.
@@ -673,7 +673,7 @@ MHD_websocket_check_upgrade_header (const char* upgrade_header);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_version_header (const char* version_header);
+MHD_websocket_check_version_header (const char *version_header);
 
 /**
  * Creates the response value for the 'Sec-WebSocket-Key' HTTP request header.
@@ -695,8 +695,8 @@ MHD_websocket_check_version_header (const char* version_header);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_create_accept_header (const char* sec_websocket_key,
-                                    char* sec_websocket_accept);
+MHD_websocket_create_accept_header (const char *sec_websocket_key,
+                                    char *sec_websocket_accept);
 
 /**
  * Creates a new websocket stream, used for decoding/encoding.
@@ -711,7 +711,7 @@ MHD_websocket_create_accept_header (const char* sec_websocket_key,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_init (struct MHD_WebSocketStream**ws,
+MHD_websocket_stream_init (struct MHD_WebSocketStream **ws,
                            int flags,
                            size_t max_payload_size);
 
@@ -746,13 +746,13 @@ MHD_websocket_stream_init (struct MHD_WebSocketStream**ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_init2 (struct MHD_WebSocketStream**ws,
+MHD_websocket_stream_init2 (struct MHD_WebSocketStream **ws,
                             int flags,
                             size_t max_payload_size,
                             MHD_WebSocketMallocCallback callback_malloc,
                             MHD_WebSocketReallocCallback callback_realloc,
                             MHD_WebSocketFreeCallback callback_free,
-                            void* cls_rng,
+                            void *cls_rng,
                             MHD_WebSocketRandomNumberGenerator callback_rng);
 
 /**
@@ -764,7 +764,7 @@ MHD_websocket_stream_init2 (struct MHD_WebSocketStream**ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_free (struct MHD_WebSocketStream*ws);
+MHD_websocket_stream_free (struct MHD_WebSocketStream *ws);
 
 /**
  * Invalidates a websocket stream.
@@ -777,7 +777,7 @@ MHD_websocket_stream_free (struct MHD_WebSocketStream*ws);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_invalidate (struct MHD_WebSocketStream*ws);
+MHD_websocket_stream_invalidate (struct MHD_WebSocketStream *ws);
 
 /**
  * Queries whether a websocket stream is valid.
@@ -789,7 +789,7 @@ MHD_websocket_stream_invalidate (struct MHD_WebSocketStream*ws);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_VALIDITY
-MHD_websocket_stream_is_valid (struct MHD_WebSocketStream*ws);
+MHD_websocket_stream_is_valid (struct MHD_WebSocketStream *ws);
 
 /**
  * Decodes a byte sequence for a websocket stream.
@@ -836,12 +836,12 @@ MHD_websocket_stream_is_valid (struct MHD_WebSocketStream*ws);
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_decode (struct MHD_WebSocketStream* ws,
-                      const char* streambuf,
+MHD_websocket_decode (struct MHD_WebSocketStream *ws,
+                      const char *streambuf,
                       size_t streambuf_len,
-                      size_t* streambuf_read_len,
-                      char** payload,
-                      size_t* payload_len);
+                      size_t *streambuf_read_len,
+                      char **payload,
+                      size_t *payload_len);
 
 /**
  * Splits the payload of a decoded close frame.
@@ -871,11 +871,11 @@ MHD_websocket_decode (struct MHD_WebSocketStream* ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_split_close_reason (const char* payload,
+MHD_websocket_split_close_reason (const char *payload,
                                   size_t payload_len,
-                                  unsigned short* reason_code,
-                                  const char** reason_utf8,
-                                  size_t* reason_utf8_len);
+                                  unsigned short *reason_code,
+                                  const char **reason_utf8,
+                                  size_t *reason_utf8_len);
 
 /**
  * Encodes an UTF-8 encoded text into websocket text frame.
@@ -913,13 +913,13 @@ MHD_websocket_split_close_reason (const char* payload,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_text (struct MHD_WebSocketStream* ws,
-                           const char* payload_utf8,
+MHD_websocket_encode_text (struct MHD_WebSocketStream *ws,
+                           const char *payload_utf8,
                            size_t payload_utf8_len,
                            int fragmentation,
-                           char** frame,
-                           size_t* frame_len,
-                           int* utf8_step);
+                           char **frame,
+                           size_t *frame_len,
+                           int *utf8_step);
 
 /**
  * Encodes binary data into websocket binary frame.
@@ -948,12 +948,12 @@ MHD_websocket_encode_text (struct MHD_WebSocketStream* ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_binary (struct MHD_WebSocketStream* ws,
-                             const char* payload,
+MHD_websocket_encode_binary (struct MHD_WebSocketStream *ws,
+                             const char *payload,
                              size_t payload_len,
                              int fragmentation,
-                             char** frame,
-                             size_t* frame_len);
+                             char **frame,
+                             size_t *frame_len);
 
 /**
  * Encodes a websocket ping frame
@@ -977,11 +977,11 @@ MHD_websocket_encode_binary (struct MHD_WebSocketStream* ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_ping (struct MHD_WebSocketStream* ws,
-                           const char* payload,
+MHD_websocket_encode_ping (struct MHD_WebSocketStream *ws,
+                           const char *payload,
                            size_t payload_len,
-                           char** frame,
-                           size_t* frame_len);
+                           char **frame,
+                           size_t *frame_len);
 
 /**
  * Encodes a websocket pong frame
@@ -1010,11 +1010,11 @@ MHD_websocket_encode_ping (struct MHD_WebSocketStream* ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_pong (struct MHD_WebSocketStream* ws,
-                           const char* payload,
-                           size_t  payload_len,
-                           char** frame,
-                           size_t* frame_len);
+MHD_websocket_encode_pong (struct MHD_WebSocketStream *ws,
+                           const char *payload,
+                           size_t payload_len,
+                           char **frame,
+                           size_t *frame_len);
 
 /**
  * Encodes a websocket close frame
@@ -1052,12 +1052,12 @@ MHD_websocket_encode_pong (struct MHD_WebSocketStream* ws,
  * @ingroup websocket
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_close (struct MHD_WebSocketStream* ws,
+MHD_websocket_encode_close (struct MHD_WebSocketStream *ws,
                             unsigned short reason_code,
-                            const char* reason_utf8,
+                            const char *reason_utf8,
                             size_t reason_utf8_len,
-                            char** frame,
-                            size_t* frame_len);
+                            char **frame,
+                            size_t *frame_len);
 
 /**
  * Allocates memory with the associated 'malloc' function
@@ -1069,8 +1069,8 @@ MHD_websocket_encode_close (struct MHD_WebSocketStream* ws,
  * @return The allocated memory on success or NULL on failure.
  * @ingroup websocket
  */
-_MHD_EXTERN void*
-MHD_websocket_malloc (struct MHD_WebSocketStream* ws,
+_MHD_EXTERN void *
+MHD_websocket_malloc (struct MHD_WebSocketStream *ws,
                       size_t buf_len);
 
 /**
@@ -1086,9 +1086,9 @@ MHD_websocket_malloc (struct MHD_WebSocketStream* ws,
  *         remains valid.
  * @ingroup websocket
  */
-_MHD_EXTERN void*
-MHD_websocket_realloc (struct MHD_WebSocketStream* ws,
-                       void* buf,
+_MHD_EXTERN void *
+MHD_websocket_realloc (struct MHD_WebSocketStream *ws,
+                       void *buf,
                        size_t new_buf_len);
 
 /**
@@ -1104,8 +1104,8 @@ MHD_websocket_realloc (struct MHD_WebSocketStream* ws,
  * @ingroup websocket
  */
 _MHD_EXTERN int
-MHD_websocket_free (struct MHD_WebSocketStream* ws,
-                    void* buf);
+MHD_websocket_free (struct MHD_WebSocketStream *ws,
+                    void *buf);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {

+ 188 - 185
src/microhttpd_ws/mhd_websocket.c

@@ -37,7 +37,7 @@ struct MHD_WebSocketStream
   /* The function pointer to free for payload (can be used to use different memory management) */
   MHD_WebSocketFreeCallback free;
   /* A closure for the random number generator (only used for client mode; usually not required) */
-  void* cls_rng;
+  void *cls_rng;
   /* The random number generator (only used for client mode; usually not required) */
   MHD_WebSocketRandomNumberGenerator rng;
   /* The flags specified upon initialization. It may alter the behavior of decoding/encoding */
@@ -54,11 +54,11 @@ struct MHD_WebSocketStream
   /* if != 0 means that we expect a CONTINUATION frame */
   char data_type;
   /* The start of the current frame (may differ from data_payload for CONTINUATION frames) */
-  char*data_payload_start;
+  char *data_payload_start;
   /* The buffer for the data frame */
-  char*data_payload;
+  char *data_payload;
   /* The buffer for the control frame */
-  char*control_payload;
+  char *control_payload;
   /* Configuration for the maximum allowed buffer size for payload data */
   size_t max_payload_size;
   /* The current frame header size */
@@ -127,27 +127,27 @@ enum MHD_WebSocket_UTF8Result
 };
 
 static void
-MHD_websocket_copy_payload (char*dst,
-                            const char*src,
+MHD_websocket_copy_payload (char *dst,
+                            const char *src,
                             size_t len,
                             uint32_t mask,
                             unsigned long mask_offset);
 
 static int
-MHD_websocket_check_utf8 (const char*buf,
+MHD_websocket_check_utf8 (const char *buf,
                           size_t buf_len,
-                          int*utf8_step,
-                          size_t*buf_offset);
+                          int *utf8_step,
+                          size_t *buf_offset);
 
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_decode_header_complete (struct MHD_WebSocketStream*ws,
-                                      char**payload,
-                                      size_t*payload_len);
+MHD_websocket_decode_header_complete (struct MHD_WebSocketStream *ws,
+                                      char **payload,
+                                      size_t *payload_len);
 
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_decode_payload_complete (struct MHD_WebSocketStream*ws,
-                                       char**payload,
-                                       size_t*payload_len);
+MHD_websocket_decode_payload_complete (struct MHD_WebSocketStream *ws,
+                                       char **payload,
+                                       size_t *payload_len);
 
 static char
 MHD_websocket_encode_is_masked (struct MHD_WebSocketStream *ws);
@@ -156,24 +156,24 @@ MHD_websocket_encode_overhead_size (struct MHD_WebSocketStream *ws,
                                     size_t payload_len);
 
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_data (struct MHD_WebSocketStream*ws,
-                           const char*payload,
+MHD_websocket_encode_data (struct MHD_WebSocketStream *ws,
+                           const char *payload,
                            size_t payload_len,
                            int fragmentation,
-                           char**frame,
-                           size_t*frame_len,
+                           char **frame,
+                           size_t *frame_len,
                            char opcode);
 
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_ping_pong (struct MHD_WebSocketStream*ws,
-                                const char*payload,
+MHD_websocket_encode_ping_pong (struct MHD_WebSocketStream *ws,
+                                const char *payload,
                                 size_t payload_len,
-                                char**frame,
-                                size_t*frame_len,
+                                char **frame,
+                                size_t *frame_len,
                                 char opcode);
 
 static uint32_t
-MHD_websocket_generate_mask (struct MHD_WebSocketStream*ws);
+MHD_websocket_generate_mask (struct MHD_WebSocketStream *ws);
 
 static uint16_t
 MHD_htons (uint16_t value);
@@ -186,7 +186,7 @@ MHD_htonll (uint64_t value);
  * Checks whether the HTTP version is 1.1 or above.
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_http_version (const char* http_version)
+MHD_websocket_check_http_version (const char *http_version)
 {
   /* validate parameters */
   if (NULL == http_version)
@@ -199,11 +199,11 @@ MHD_websocket_check_http_version (const char* http_version)
   /* Check whether the version has a valid format */
   /* RFC 1945 3.1: The format must be "HTTP/x.x" where x is */
   /* any digit and must appear at least once */
-  if ('H' != http_version[0] ||
-      'T' != http_version[1] ||
-      'T' != http_version[2] ||
-      'P' != http_version[3] ||
-      '/' != http_version[4])
+  if (('H' != http_version[0]) ||
+      ('T' != http_version[1]) ||
+      ('T' != http_version[2]) ||
+      ('P' != http_version[3]) ||
+      ('/' != http_version[4]))
   {
     return MHD_WEBSOCKET_STATUS_NO_WEBSOCKET_HANDSHAKE_HEADER;
   }
@@ -211,16 +211,16 @@ MHD_websocket_check_http_version (const char* http_version)
   /* Find the major and minor part of the version */
   /* RFC 1945 3.1: Both numbers must be threated as separate integers. */
   /* Leading zeros must be ignored and both integers may have multiple digits */
-  const char* major = NULL;
-  const char* dot   = NULL;
+  const char *major = NULL;
+  const char *dot   = NULL;
   size_t i = 5;
   for (;;)
   {
     char c = http_version[i];
-    if ('0' <= c && '9' >= c)
+    if (('0' <= c) && ('9' >= c))
     {
-      if (NULL == major ||
-          (http_version + i == major + 1 && '0' == *major) )
+      if ((NULL == major) ||
+          ((http_version + i == major + 1) && ('0' == *major)) )
       {
         major = http_version + i;
       }
@@ -237,15 +237,15 @@ MHD_websocket_check_http_version (const char* http_version)
       return MHD_WEBSOCKET_STATUS_NO_WEBSOCKET_HANDSHAKE_HEADER;
     }
   }
-  const char* minor = NULL;
-  const char* end   = NULL;
+  const char *minor = NULL;
+  const char *end   = NULL;
   for (;;)
   {
     char c = http_version[i];
-    if ('0' <= c && '9' >= c)
+    if (('0' <= c) && ('9' >= c))
     {
-      if (NULL == minor ||
-          (http_version + i == minor + 1 && '0' == *minor) )
+      if ((NULL == minor) ||
+          ((http_version + i == minor + 1) && ('0' == *minor)) )
       {
         minor = http_version + i;
       }
@@ -261,12 +261,12 @@ MHD_websocket_check_http_version (const char* http_version)
       return MHD_WEBSOCKET_STATUS_NO_WEBSOCKET_HANDSHAKE_HEADER;
     }
   }
-  if (NULL == major || NULL == dot || NULL == minor || NULL == end)
+  if ((NULL == major) || (NULL == dot) || (NULL == minor) || (NULL == end))
   {
     return MHD_WEBSOCKET_STATUS_NO_WEBSOCKET_HANDSHAKE_HEADER;
   }
-  if (2 <= dot - major || '2' <= *major ||
-      ('1' == *major && (2 <= end - minor || '1' <= *minor)) )
+  if ((2 <= dot - major) || ('2' <= *major) ||
+      (('1' == *major) && ((2 <= end - minor) || ('1' <= *minor))) )
   {
     return MHD_WEBSOCKET_STATUS_OK;
   }
@@ -279,7 +279,7 @@ MHD_websocket_check_http_version (const char* http_version)
  * Checks whether the "Connection" request header has the 'Upgrade' token.
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_connection_header (const char* connection_header)
+MHD_websocket_check_connection_header (const char *connection_header)
 {
   /* validate parameters */
   if (NULL == connection_header)
@@ -293,9 +293,9 @@ MHD_websocket_check_connection_header (const char* connection_header)
   /* Check whether the Connection includes an Upgrade token */
   /* RFC 7230 6.1: Multiple tokens may appear. */
   /* RFC 7230 3.2.6: Tokens are comma separated */
-  const char* token_start = NULL;
-  const char* token_end   = NULL;
-  for(size_t i = 0; ; ++i)
+  const char *token_start = NULL;
+  const char *token_end   = NULL;
+  for (size_t i = 0; ; ++i)
   {
     char c = connection_header[i];
 
@@ -303,12 +303,12 @@ MHD_websocket_check_connection_header (const char* connection_header)
     /* "!" / "#" / "$" / "%" / "&" / "'" / "*" / */
     /* "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" */
     /* DIGIT / ALPHA */
-    if ('!' == c || '#' == c || '$' == c || '%' == c ||
-        '&' == c || '\'' == c || '*' == c ||
-        '+' == c || '-' == c || '.' == c || '^' == c ||
-        '_' == c || '`' == c || '|' == c || '~' == c ||
-        ('0' <= c && '9' >= c) ||
-        ('A' <= c && 'Z' >= c) || ('a' <= c && 'z' >= c) )
+    if (('!' == c) || ('#' == c) || ('$' == c) || ('%' == c) ||
+        ('&' == c) || ('\'' == c) || ('*' == c) ||
+        ('+' == c) || ('-' == c) || ('.' == c) || ('^' == c) ||
+        ('_' == c) || ('`' == c) || ('|' == c) || ('~' == c) ||
+        (('0' <= c) && ('9' >= c)) ||
+        (('A' <= c) && ('Z' >= c)) || (('a' <= c) && ('z' >= c)) )
     {
       /* This is a valid token character */
       if (NULL == token_start)
@@ -317,24 +317,24 @@ MHD_websocket_check_connection_header (const char* connection_header)
       }
       token_end = connection_header + i + 1;
     }
-    else if (' ' == c || '\t' == c)
+    else if ((' ' == c) || ('\t' == c))
     {
       /* White-spaces around tokens will be ignored */
     }
-    else if (',' == c || 0 == c)
+    else if ((',' == c) || (0 == c))
     {
       /* Check the token (case-insensitive) */
       if (NULL != token_start)
       {
-        if ( 7 == (token_end - token_start) )
+        if (7 == (token_end - token_start) )
         {
-          if ( ('U' == token_start[0] || 'u' == token_start[0]) &&
-               ('P' == token_start[1] || 'p' == token_start[1]) &&
-               ('G' == token_start[2] || 'g' == token_start[2]) &&
-               ('R' == token_start[3] || 'r' == token_start[3]) &&
-               ('A' == token_start[4] || 'a' == token_start[4]) &&
-               ('D' == token_start[5] || 'd' == token_start[5]) &&
-               ('E' == token_start[6] || 'e' == token_start[6]) )
+          if ( (('U' == token_start[0]) || ('u' == token_start[0])) &&
+               (('P' == token_start[1]) || ('p' == token_start[1])) &&
+               (('G' == token_start[2]) || ('g' == token_start[2])) &&
+               (('R' == token_start[3]) || ('r' == token_start[3])) &&
+               (('A' == token_start[4]) || ('a' == token_start[4])) &&
+               (('D' == token_start[5]) || ('d' == token_start[5])) &&
+               (('E' == token_start[6]) || ('e' == token_start[6])) )
           {
             /* The token equals to "Upgrade" */
             return MHD_WEBSOCKET_STATUS_OK;
@@ -362,7 +362,7 @@ MHD_websocket_check_connection_header (const char* connection_header)
  * Checks whether the "Upgrade" request header has the "websocket" keyword.
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_upgrade_header (const char* upgrade_header)
+MHD_websocket_check_upgrade_header (const char *upgrade_header)
 {
   /* validate parameters */
   if (NULL == upgrade_header)
@@ -376,9 +376,9 @@ MHD_websocket_check_upgrade_header (const char* upgrade_header)
   /* Check whether the Connection includes an Upgrade token */
   /* RFC 7230 6.1: Multiple tokens may appear. */
   /* RFC 7230 3.2.6: Tokens are comma separated */
-  const char* keyword_start = NULL;
-  const char* keyword_end   = NULL;
-  for(size_t i = 0; ; ++i)
+  const char *keyword_start = NULL;
+  const char *keyword_end   = NULL;
+  for (size_t i = 0; ; ++i)
   {
     char c = upgrade_header[i];
 
@@ -387,13 +387,13 @@ MHD_websocket_check_upgrade_header (const char* upgrade_header)
     /* "+" / "-" / "." / "^" / "_" / "`" / "|" / "~" */
     /* DIGIT / ALPHA */
     /* We also allow "/" here as the sub-delimiter for the protocol version */
-    if ('!' == c || '#' == c || '$' == c || '%' == c ||
-        '&' == c || '\'' == c || '*' == c ||
-        '+' == c || '-' == c || '.' == c || '^' == c ||
-        '_' == c || '`' == c || '|' == c || '~' == c ||
-        '/' == c ||
-        ('0' <= c && '9' >= c) ||
-        ('A' <= c && 'Z' >= c) || ('a' <= c && 'z' >= c) )
+    if (('!' == c) || ('#' == c) || ('$' == c) || ('%' == c) ||
+        ('&' == c) || ('\'' == c) || ('*' == c) ||
+        ('+' == c) || ('-' == c) || ('.' == c) || ('^' == c) ||
+        ('_' == c) || ('`' == c) || ('|' == c) || ('~' == c) ||
+        ('/' == c) ||
+        (('0' <= c) && ('9' >= c)) ||
+        (('A' <= c) && ('Z' >= c)) || (('a' <= c) && ('z' >= c)) )
     {
       /* This is a valid token character */
       if (NULL == keyword_start)
@@ -402,26 +402,26 @@ MHD_websocket_check_upgrade_header (const char* upgrade_header)
       }
       keyword_end = upgrade_header + i + 1;
     }
-    else if (' ' == c || '\t' == c)
+    else if ((' ' == c) || ('\t' == c))
     {
       /* White-spaces around tokens will be ignored */
     }
-    else if (',' == c || 0 == c)
+    else if ((',' == c) || (0 == c))
     {
       /* Check the token (case-insensitive) */
       if (NULL != keyword_start)
       {
-        if ( 9 == (keyword_end - keyword_start) )
+        if (9 == (keyword_end - keyword_start) )
         {
-          if ( ('W' == keyword_start[0] || 'w' == keyword_start[0]) &&
-               ('E' == keyword_start[1] || 'e' == keyword_start[1]) &&
-               ('B' == keyword_start[2] || 'b' == keyword_start[2]) &&
-               ('S' == keyword_start[3] || 's' == keyword_start[3]) &&
-               ('O' == keyword_start[4] || 'o' == keyword_start[4]) &&
-               ('C' == keyword_start[5] || 'c' == keyword_start[5]) &&
-               ('K' == keyword_start[6] || 'k' == keyword_start[6]) &&
-               ('E' == keyword_start[7] || 'e' == keyword_start[7]) &&
-               ('T' == keyword_start[8] || 't' == keyword_start[8]) )
+          if ( (('W' == keyword_start[0]) || ('w' == keyword_start[0])) &&
+               (('E' == keyword_start[1]) || ('e' == keyword_start[1])) &&
+               (('B' == keyword_start[2]) || ('b' == keyword_start[2])) &&
+               (('S' == keyword_start[3]) || ('s' == keyword_start[3])) &&
+               (('O' == keyword_start[4]) || ('o' == keyword_start[4])) &&
+               (('C' == keyword_start[5]) || ('c' == keyword_start[5])) &&
+               (('K' == keyword_start[6]) || ('k' == keyword_start[6])) &&
+               (('E' == keyword_start[7]) || ('e' == keyword_start[7])) &&
+               (('T' == keyword_start[8]) || ('t' == keyword_start[8])) )
           {
             /* The keyword equals to "websocket" */
             return MHD_WEBSOCKET_STATUS_OK;
@@ -450,7 +450,7 @@ MHD_websocket_check_upgrade_header (const char* upgrade_header)
  * equals to "13"
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_check_version_header (const char* version_header)
+MHD_websocket_check_version_header (const char *version_header)
 {
   /* validate parameters */
   if (NULL == version_header)
@@ -461,9 +461,9 @@ MHD_websocket_check_version_header (const char* version_header)
     return MHD_WEBSOCKET_STATUS_NO_WEBSOCKET_HANDSHAKE_HEADER;
   }
 
-  if ('1' == version_header[0] &&
-      '3' == version_header[1] &&
-      0   == version_header[2])
+  if (('1' == version_header[0]) &&
+      ('3' == version_header[1]) &&
+      (0   == version_header[2]))
   {
     /* The version equals to "13" */
     return MHD_WEBSOCKET_STATUS_OK;
@@ -476,8 +476,8 @@ MHD_websocket_check_version_header (const char* version_header)
  * Creates the response for the Sec-WebSocket-Accept header
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_create_accept_header (const char*sec_websocket_key,
-                                    char*sec_websocket_accept)
+MHD_websocket_create_accept_header (const char *sec_websocket_key,
+                                    char *sec_websocket_accept)
 {
   /* initialize output variables for errors cases */
   if (NULL != sec_websocket_accept)
@@ -498,18 +498,18 @@ MHD_websocket_create_accept_header (const char*sec_websocket_key,
 
   /* build SHA1 hash of the given key and the UUID appended */
   char sha1[20];
-  const char*suffix = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
+  const char *suffix = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
   int length = (int) strlen (sec_websocket_key);
   struct sha1_ctx ctx;
   MHD_SHA1_init (&ctx);
-  MHD_SHA1_update (&ctx, (const uint8_t*) sec_websocket_key, length);
-  MHD_SHA1_update (&ctx, (const uint8_t*) suffix, 36);
-  MHD_SHA1_finish (&ctx, (uint8_t*) sha1);
+  MHD_SHA1_update (&ctx, (const uint8_t *) sec_websocket_key, length);
+  MHD_SHA1_update (&ctx, (const uint8_t *) suffix, 36);
+  MHD_SHA1_finish (&ctx, (uint8_t *) sha1);
 
   /* base64 encode that SHA1 hash */
   /* (simple algorithm here; SHA1 has always 20 bytes, */
   /* which will always result in a 28 bytes base64 hash) */
-  const char*base64_encoding_table =
+  const char *base64_encoding_table =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
   for (int i = 0, j = 0; i < 20;)
   {
@@ -535,7 +535,7 @@ MHD_websocket_create_accept_header (const char*sec_websocket_key,
  * Initializes a new websocket stream
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_init (struct MHD_WebSocketStream**ws,
+MHD_websocket_stream_init (struct MHD_WebSocketStream **ws,
                            int flags,
                            size_t max_payload_size)
 {
@@ -555,13 +555,13 @@ MHD_websocket_stream_init (struct MHD_WebSocketStream**ws,
  * additional parameters for allocation functions
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_init2 (struct MHD_WebSocketStream**ws,
+MHD_websocket_stream_init2 (struct MHD_WebSocketStream **ws,
                             int flags,
                             size_t max_payload_size,
                             MHD_WebSocketMallocCallback callback_malloc,
                             MHD_WebSocketReallocCallback callback_realloc,
                             MHD_WebSocketFreeCallback callback_free,
-                            void* cls_rng,
+                            void *cls_rng,
                             MHD_WebSocketRandomNumberGenerator callback_rng)
 {
   /* initialize output variables for errors cases */
@@ -576,13 +576,13 @@ MHD_websocket_stream_init2 (struct MHD_WebSocketStream**ws,
       (NULL == callback_realloc) ||
       (NULL == callback_free) ||
       ((0 != (flags & MHD_WEBSOCKET_FLAG_CLIENT)) &&
-      (NULL == callback_rng)))
+       (NULL == callback_rng)))
   {
     return MHD_WEBSOCKET_STATUS_PARAMETER_ERROR;
   }
 
   /* allocate stream */
-  struct MHD_WebSocketStream*ws_ = (struct MHD_WebSocketStream*) malloc (
+  struct MHD_WebSocketStream *ws_ = (struct MHD_WebSocketStream *) malloc (
     sizeof (struct MHD_WebSocketStream));
   if (NULL == ws_)
     return MHD_WEBSOCKET_STATUS_MEMORY_ERROR;
@@ -609,7 +609,7 @@ MHD_websocket_stream_init2 (struct MHD_WebSocketStream**ws,
  * Frees a previously allocated websocket stream
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_free (struct MHD_WebSocketStream*ws)
+MHD_websocket_stream_free (struct MHD_WebSocketStream *ws)
 {
   /* validate parameters */
   if (NULL == ws)
@@ -632,7 +632,7 @@ MHD_websocket_stream_free (struct MHD_WebSocketStream*ws)
  * Invalidates a websocket stream (no more decoding possible)
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_stream_invalidate (struct MHD_WebSocketStream*ws)
+MHD_websocket_stream_invalidate (struct MHD_WebSocketStream *ws)
 {
   /* validate parameters */
   if (NULL == ws)
@@ -649,7 +649,7 @@ MHD_websocket_stream_invalidate (struct MHD_WebSocketStream*ws)
  * Returns whether a websocket stream is valid
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_VALIDITY
-MHD_websocket_stream_is_valid (struct MHD_WebSocketStream*ws)
+MHD_websocket_stream_is_valid (struct MHD_WebSocketStream *ws)
 {
   /* validate parameters */
   if (NULL == ws)
@@ -663,12 +663,12 @@ MHD_websocket_stream_is_valid (struct MHD_WebSocketStream*ws)
  * Decodes incoming data to a websocket frame
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_decode (struct MHD_WebSocketStream*ws,
-                      const char*streambuf,
+MHD_websocket_decode (struct MHD_WebSocketStream *ws,
+                      const char *streambuf,
                       size_t streambuf_len,
-                      size_t*streambuf_read_len,
-                      char**payload,
-                      size_t*payload_len)
+                      size_t *streambuf_read_len,
+                      char **payload,
+                      size_t *payload_len)
 {
   /* initialize output variables for errors cases */
   if (NULL != streambuf_read_len)
@@ -1021,7 +1021,8 @@ MHD_websocket_decode (struct MHD_WebSocketStream*ws,
     case MHD_WebSocket_DecodeStep_Length2of2:
       {
         ws->frame_header [ws->frame_header_size++] = streambuf [current++];
-        size_t size = (size_t) MHD_htons (*((uint16_t*) &ws->frame_header [2]));
+        size_t size = (size_t) MHD_htons (
+          *((uint16_t *) &ws->frame_header [2]));
         if (125 >= size)
         {
           /* RFC 6455 5.2 Payload length: The minimal number of bytes */
@@ -1078,7 +1079,7 @@ MHD_websocket_decode (struct MHD_WebSocketStream*ws,
     case MHD_WebSocket_DecodeStep_Length8of8:
       {
         ws->frame_header [ws->frame_header_size++] = streambuf [current++];
-        uint64_t size = MHD_htonll (*((uint64_t*) &ws->frame_header [2]));
+        uint64_t size = MHD_htonll (*((uint64_t *) &ws->frame_header [2]));
         if (0x7fffffffffffffff < size)
         {
           /* RFC 6455 5.2 frame-payload-length-63: The length may */
@@ -1201,16 +1202,16 @@ MHD_websocket_decode (struct MHD_WebSocketStream*ws,
           current += bytes_to_take;
           ws->payload_index += bytes_to_take;
           if (((MHD_WebSocket_DecodeStep_PayloadOfDataFrame ==
-               ws->decode_step) &&
-              (MHD_WebSocket_Opcode_Text == ws->data_type)) ||
+                ws->decode_step) &&
+               (MHD_WebSocket_Opcode_Text == ws->data_type)) ||
               ((MHD_WebSocket_DecodeStep_PayloadOfControlFrame ==
-               ws->decode_step) &&
-              (MHD_WebSocket_Opcode_Close == (ws->frame_header [0] & 0x0f)) &&
-              (2 < ws->payload_index)) )
+                ws->decode_step) &&
+               (MHD_WebSocket_Opcode_Close == (ws->frame_header [0] & 0x0f)) &&
+               (2 < ws->payload_index)) )
           {
             /* RFC 6455 8.1: We need to check the UTF-8 validity */
             int utf8_step;
-            char*decode_payload_utf8;
+            char *decode_payload_utf8;
             size_t bytes_to_check;
             size_t utf8_error_offset = 0;
             if (MHD_WebSocket_DecodeStep_PayloadOfDataFrame == ws->decode_step)
@@ -1324,9 +1325,9 @@ MHD_websocket_decode (struct MHD_WebSocketStream*ws,
 
 
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_decode_header_complete (struct MHD_WebSocketStream*ws,
-                                      char**payload,
-                                      size_t*payload_len)
+MHD_websocket_decode_header_complete (struct MHD_WebSocketStream *ws,
+                                      char **payload,
+                                      size_t *payload_len)
 {
   /* assign either to data or control */
   char opcode = ws->frame_header [0] & 0x0f;
@@ -1356,7 +1357,7 @@ MHD_websocket_decode_header_complete (struct MHD_WebSocketStream*ws,
         return MHD_WEBSOCKET_STATUS_MAXIMUM_SIZE_EXCEEDED;
       }
       /* allocate buffer for continued data frame */
-      char*new_buf = NULL;
+      char *new_buf = NULL;
       if (0 != new_size_total)
       {
         new_buf = ws->realloc (ws->data_payload, new_size_total + 1);
@@ -1382,7 +1383,7 @@ MHD_websocket_decode_header_complete (struct MHD_WebSocketStream*ws,
     /* allocate buffer for data frame */
     {
       size_t new_size_total = ws->payload_size;
-      char*new_buf = NULL;
+      char *new_buf = NULL;
       if (0 != new_size_total)
       {
         new_buf = ws->malloc (new_size_total + 1);
@@ -1406,7 +1407,7 @@ MHD_websocket_decode_header_complete (struct MHD_WebSocketStream*ws,
     /* allocate buffer for control frame */
     {
       size_t new_size_total = ws->payload_size;
-      char*new_buf = NULL;
+      char *new_buf = NULL;
       if (0 != new_size_total)
       {
         new_buf = ws->malloc (new_size_total + 1);
@@ -1427,13 +1428,13 @@ MHD_websocket_decode_header_complete (struct MHD_WebSocketStream*ws,
 
 
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_decode_payload_complete (struct MHD_WebSocketStream*ws,
-                                       char**payload,
-                                       size_t*payload_len)
+MHD_websocket_decode_payload_complete (struct MHD_WebSocketStream *ws,
+                                       char **payload,
+                                       size_t *payload_len)
 {
   /* all payload data of the current frame has been received */
   char is_continue = MHD_WebSocket_Opcode_Continuation ==
-                      (ws->frame_header [0] & 0x0F);
+                     (ws->frame_header [0] & 0x0F);
   char is_fin      = ws->frame_header [0] & 0x80;
   if (0 != is_fin)
   {
@@ -1567,11 +1568,11 @@ MHD_websocket_decode_payload_complete (struct MHD_WebSocketStream*ws,
  * Splits the received close reason
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_split_close_reason (const char*payload,
+MHD_websocket_split_close_reason (const char *payload,
                                   size_t payload_len,
-                                  unsigned short*reason_code,
-                                  const char**reason_utf8,
-                                  size_t*reason_utf8_len)
+                                  unsigned short *reason_code,
+                                  const char **reason_utf8,
+                                  size_t *reason_utf8_len)
 {
   /* initialize output variables for errors cases */
   if (NULL != reason_code)
@@ -1598,7 +1599,7 @@ MHD_websocket_split_close_reason (const char*payload,
   else
   {
     if (NULL != reason_code)
-      *reason_code = MHD_htons (*((uint16_t*) payload));
+      *reason_code = MHD_htons (*((uint16_t *) payload));
   }
 
   /* decode reason text */
@@ -1625,13 +1626,13 @@ MHD_websocket_split_close_reason (const char*payload,
  * Encodes a text into a websocket text frame
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_text (struct MHD_WebSocketStream*ws,
-                           const char*payload_utf8,
+MHD_websocket_encode_text (struct MHD_WebSocketStream *ws,
+                           const char *payload_utf8,
                            size_t payload_utf8_len,
                            int fragmentation,
-                           char**frame,
-                           size_t*frame_len,
-                           int*utf8_step)
+                           char **frame,
+                           size_t *frame_len,
+                           int *utf8_step)
 {
   /* initialize output variables for errors cases */
   if (NULL != frame)
@@ -1654,7 +1655,7 @@ MHD_websocket_encode_text (struct MHD_WebSocketStream*ws,
       (MHD_WEBSOCKET_FRAGMENTATION_NONE > fragmentation) ||
       (MHD_WEBSOCKET_FRAGMENTATION_LAST < fragmentation) ||
       ((MHD_WEBSOCKET_FRAGMENTATION_NONE != fragmentation) &&
-      (NULL == utf8_step)) )
+       (NULL == utf8_step)) )
   {
     return MHD_WEBSOCKET_STATUS_PARAMETER_ERROR;
   }
@@ -1672,7 +1673,7 @@ MHD_websocket_encode_text (struct MHD_WebSocketStream*ws,
                                               NULL);
   if ((MHD_WebSocket_UTF8Result_Invalid == utf8_result) ||
       ((MHD_WebSocket_UTF8Result_Incomplete == utf8_result) &&
-      (MHD_WEBSOCKET_FRAGMENTATION_NONE == fragmentation)) )
+       (MHD_WEBSOCKET_FRAGMENTATION_NONE == fragmentation)) )
   {
     return MHD_WEBSOCKET_STATUS_UTF8_ENCODING_ERROR;
   }
@@ -1692,12 +1693,12 @@ MHD_websocket_encode_text (struct MHD_WebSocketStream*ws,
  * Encodes binary data into a websocket binary frame
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_binary (struct MHD_WebSocketStream*ws,
-                             const char*payload,
+MHD_websocket_encode_binary (struct MHD_WebSocketStream *ws,
+                             const char *payload,
                              size_t payload_len,
                              int fragmentation,
-                             char**frame,
-                             size_t*frame_len)
+                             char **frame,
+                             size_t *frame_len)
 {
   /* initialize output variables for errors cases */
   if (NULL != frame)
@@ -1736,12 +1737,12 @@ MHD_websocket_encode_binary (struct MHD_WebSocketStream*ws,
  * Internal function for encoding text/binary data into a websocket frame
  */
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_data (struct MHD_WebSocketStream*ws,
-                           const char*payload,
+MHD_websocket_encode_data (struct MHD_WebSocketStream *ws,
+                           const char *payload,
                            size_t payload_len,
                            int fragmentation,
-                           char**frame,
-                           size_t*frame_len,
+                           char **frame,
+                           size_t *frame_len,
                            char opcode)
 {
   /* calculate length and masking */
@@ -1751,7 +1752,7 @@ MHD_websocket_encode_data (struct MHD_WebSocketStream*ws,
   uint32_t mask       = 0 != is_masked ? MHD_websocket_generate_mask (ws) : 0;
 
   /* allocate memory */
-  char*result = ws->malloc (total_len + 1);
+  char *result = ws->malloc (total_len + 1);
   if (NULL == result)
     return MHD_WEBSOCKET_STATUS_MEMORY_ERROR;
   result [total_len] = 0;
@@ -1821,11 +1822,11 @@ MHD_websocket_encode_data (struct MHD_WebSocketStream*ws,
  * Encodes a websocket ping frame
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_ping (struct MHD_WebSocketStream*ws,
-                           const char*payload,
+MHD_websocket_encode_ping (struct MHD_WebSocketStream *ws,
+                           const char *payload,
                            size_t payload_len,
-                           char**frame,
-                           size_t*frame_len)
+                           char **frame,
+                           size_t *frame_len)
 {
   /* encode the ping frame */
   return MHD_websocket_encode_ping_pong (ws,
@@ -1841,11 +1842,11 @@ MHD_websocket_encode_ping (struct MHD_WebSocketStream*ws,
  * Encodes a websocket pong frame
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_pong (struct MHD_WebSocketStream*ws,
-                           const char*payload,
+MHD_websocket_encode_pong (struct MHD_WebSocketStream *ws,
+                           const char *payload,
                            size_t payload_len,
-                           char**frame,
-                           size_t*frame_len)
+                           char **frame,
+                           size_t *frame_len)
 {
   /* encode the pong frame */
   return MHD_websocket_encode_ping_pong (ws,
@@ -1861,11 +1862,11 @@ MHD_websocket_encode_pong (struct MHD_WebSocketStream*ws,
  * Internal function for encoding ping/pong frames
  */
 static enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_ping_pong (struct MHD_WebSocketStream*ws,
-                                const char*payload,
+MHD_websocket_encode_ping_pong (struct MHD_WebSocketStream *ws,
+                                const char *payload,
                                 size_t payload_len,
-                                char**frame,
-                                size_t*frame_len,
+                                char **frame,
+                                size_t *frame_len,
                                 char opcode)
 {
   /* initialize output variables for errors cases */
@@ -1894,7 +1895,7 @@ MHD_websocket_encode_ping_pong (struct MHD_WebSocketStream*ws,
   uint32_t mask       = is_masked != 0 ? MHD_websocket_generate_mask (ws) : 0;
 
   /* allocate memory */
-  char*result = ws->malloc (total_len + 1);
+  char *result = ws->malloc (total_len + 1);
   if (NULL == result)
     return MHD_WEBSOCKET_STATUS_MEMORY_ERROR;
   result [total_len] = 0;
@@ -1934,12 +1935,12 @@ MHD_websocket_encode_ping_pong (struct MHD_WebSocketStream*ws,
  * Encodes a websocket close frame
  */
 _MHD_EXTERN enum MHD_WEBSOCKET_STATUS
-MHD_websocket_encode_close (struct MHD_WebSocketStream*ws,
+MHD_websocket_encode_close (struct MHD_WebSocketStream *ws,
                             unsigned short reason_code,
-                            const char*reason_utf8,
+                            const char *reason_utf8,
                             size_t reason_utf8_len,
-                            char**frame,
-                            size_t*frame_len)
+                            char **frame,
+                            size_t *frame_len)
 {
   /* initialize output variables for errors cases */
   if (NULL != frame)
@@ -1953,9 +1954,9 @@ MHD_websocket_encode_close (struct MHD_WebSocketStream*ws,
       (NULL == frame) ||
       (NULL == frame_len) ||
       ((MHD_WEBSOCKET_CLOSEREASON_NO_REASON != reason_code) &&
-      (1000 > reason_code)) ||
+       (1000 > reason_code)) ||
       ((0 != reason_utf8_len) &&
-      (MHD_WEBSOCKET_CLOSEREASON_NO_REASON == reason_code)) )
+       (MHD_WEBSOCKET_CLOSEREASON_NO_REASON == reason_code)) )
   {
     return MHD_WEBSOCKET_STATUS_PARAMETER_ERROR;
   }
@@ -1986,7 +1987,7 @@ MHD_websocket_encode_close (struct MHD_WebSocketStream*ws,
   uint32_t mask       = is_masked != 0 ? MHD_websocket_generate_mask (ws) : 0;
 
   /* allocate memory */
-  char*result = ws->malloc (total_len + 1);
+  char *result = ws->malloc (total_len + 1);
   if (NULL == result)
     return MHD_WEBSOCKET_STATUS_MEMORY_ERROR;
   result [total_len] = 0;
@@ -2014,7 +2015,7 @@ MHD_websocket_encode_close (struct MHD_WebSocketStream*ws,
     /* close reason code */
     uint16_t reason_code_nb = MHD_htons (reason_code);
     MHD_websocket_copy_payload (result,
-                                (const char*) &reason_code_nb,
+                                (const char *) &reason_code_nb,
                                 2,
                                 mask,
                                 0);
@@ -2039,7 +2040,7 @@ MHD_websocket_encode_close (struct MHD_WebSocketStream*ws,
  * Returns the 0x80 prefix for masked data, 0x00 otherwise
  */
 static char
-MHD_websocket_encode_is_masked (struct MHD_WebSocketStream*ws)
+MHD_websocket_encode_is_masked (struct MHD_WebSocketStream *ws)
 {
   return (ws->flags & MHD_WEBSOCKET_FLAG_MASK_SERVERCLIENT) ==
          MHD_WEBSOCKET_FLAG_CLIENT ? 0x80 : 0x00;
@@ -2050,7 +2051,7 @@ MHD_websocket_encode_is_masked (struct MHD_WebSocketStream*ws)
  * Calculates the size of the overhead in bytes
  */
 static char
-MHD_websocket_encode_overhead_size (struct MHD_WebSocketStream*ws,
+MHD_websocket_encode_overhead_size (struct MHD_WebSocketStream *ws,
                                     size_t payload_len)
 {
   return 2 + (MHD_websocket_encode_is_masked (ws) != 0 ? 4 : 0) + (125 <
@@ -2065,8 +2066,8 @@ MHD_websocket_encode_overhead_size (struct MHD_WebSocketStream*ws,
  * Copies the payload to the destination (using mask)
  */
 static void
-MHD_websocket_copy_payload (char*dst,
-                            const char*src,
+MHD_websocket_copy_payload (char *dst,
+                            const char *src,
                             size_t len,
                             uint32_t mask,
                             unsigned long mask_offset)
@@ -2096,10 +2097,10 @@ MHD_websocket_copy_payload (char*dst,
  * Checks a UTF-8 sequence
  */
 static int
-MHD_websocket_check_utf8 (const char*buf,
+MHD_websocket_check_utf8 (const char *buf,
                           size_t buf_len,
-                          int*utf8_step,
-                          size_t*buf_offset)
+                          int *utf8_step,
+                          size_t *buf_offset)
 {
   int utf8_step_ = (NULL != utf8_step) ? *utf8_step :
                    MHD_WEBSOCKET_UTF8STEP_NORMAL;
@@ -2310,7 +2311,7 @@ MHD_websocket_check_utf8 (const char*buf,
  * a random number generator.
  */
 static uint32_t
-MHD_websocket_generate_mask (struct MHD_WebSocketStream*ws)
+MHD_websocket_generate_mask (struct MHD_WebSocketStream *ws)
 {
   unsigned char mask_[4];
   if (NULL != ws->rng)
@@ -2340,8 +2341,8 @@ MHD_websocket_generate_mask (struct MHD_WebSocketStream*ws)
 /**
  * Calls the malloc function associated with the websocket steam
  */
-_MHD_EXTERN void*
-MHD_websocket_malloc (struct MHD_WebSocketStream* ws,
+_MHD_EXTERN void *
+MHD_websocket_malloc (struct MHD_WebSocketStream *ws,
                       size_t buf_len)
 {
   if (NULL == ws)
@@ -2356,9 +2357,9 @@ MHD_websocket_malloc (struct MHD_WebSocketStream* ws,
 /**
  * Calls the realloc function associated with the websocket steam
  */
-_MHD_EXTERN void*
-MHD_websocket_realloc (struct MHD_WebSocketStream* ws,
-                       void* buf,
+_MHD_EXTERN void *
+MHD_websocket_realloc (struct MHD_WebSocketStream *ws,
+                       void *buf,
                        size_t new_buf_len)
 {
   if (NULL == ws)
@@ -2374,8 +2375,8 @@ MHD_websocket_realloc (struct MHD_WebSocketStream* ws,
  * Calls the free function associated with the websocket steam
  */
 _MHD_EXTERN int
-MHD_websocket_free (struct MHD_WebSocketStream* ws,
-                    void* buf)
+MHD_websocket_free (struct MHD_WebSocketStream *ws,
+                    void *buf)
 {
   if (NULL == ws)
   {
@@ -2387,6 +2388,7 @@ MHD_websocket_free (struct MHD_WebSocketStream* ws,
   return MHD_WEBSOCKET_STATUS_OK;
 }
 
+
 /**
  * Converts a 16 bit value into network byte order (MSB first)
  * in dependence of the host system
@@ -2410,6 +2412,7 @@ MHD_htons (uint16_t value)
   }
 }
 
+
 /**
  * Converts a 64 bit value into network byte order (MSB first)
  * in dependence of the host system

+ 1 - 1
src/microhttpd_ws/sha1.c

@@ -116,7 +116,7 @@ sha1_transform (uint32_t H[_SHA1_DIGEST_LENGTH],
     /* The W[] buffer itself will be used as the source of the data,
      * but data will be reloaded in correct bytes order during
      * the next steps */
-    data = (uint8_t*) W;
+    data = (uint8_t *) W;
   }
 #endif /* _MHD_GET_32BIT_BE_UNALIGNED */
 

Dosya farkı çok büyük olduğundan ihmal edildi
+ 127 - 126
src/microhttpd_ws/test_websocket.c


+ 39 - 32
src/microhttpd_ws/test_websocket_browser.c

@@ -187,6 +187,7 @@ static void
 send_all (MHD_socket fd,
           const char *buf,
           size_t len);
+
 static void
 make_blocking (MHD_socket fd);
 
@@ -203,7 +204,7 @@ upgrade_handler (void *cls,
   make_blocking (fd);
 
   /* create a websocket stream for this connection */
-  struct MHD_WebSocketStream* ws;
+  struct MHD_WebSocketStream *ws;
   int result = MHD_websocket_stream_init (&ws,
                                           0,
                                           0);
@@ -253,7 +254,8 @@ upgrade_handler (void *cls,
       if (0 > status)
       {
         /* an error occurred and the connection must be closed */
-        printf ("Decoding failed: status=%d, passed=%u\n", status, ((size_t) got) - buf_offset);
+        printf ("Decoding failed: status=%d, passed=%u\n", status,
+                ((size_t) got) - buf_offset);
         if (NULL != payload_data)
         {
           MHD_websocket_free (ws, payload_data);
@@ -266,13 +268,15 @@ upgrade_handler (void *cls,
         if (0 < status)
         {
           /* the frame is complete */
-          printf ("Decoding succeeded: type=%d, passed=%u, parsed=%u, payload_len=%d\n", status, ((size_t) got) - buf_offset, new_offset, payload_len);
+          printf (
+            "Decoding succeeded: type=%d, passed=%u, parsed=%u, payload_len=%d\n",
+            status, ((size_t) got) - buf_offset, new_offset, payload_len);
           switch (status)
           {
           case MHD_WEBSOCKET_STATUS_TEXT_FRAME:
           case MHD_WEBSOCKET_STATUS_BINARY_FRAME:
             /* The client has sent some data. */
-            if (NULL != payload_data || 0 == payload_len)
+            if ((NULL != payload_data) || (0 == payload_len))
             {
               /* Send the received data back to the client */
               if (MHD_WEBSOCKET_STATUS_TEXT_FRAME == status)
@@ -288,11 +292,11 @@ upgrade_handler (void *cls,
               else
               {
                 result = MHD_websocket_encode_binary (ws,
-                                                    payload_data,
-                                                    payload_len,
-                                                    0,
-                                                    &frame_data,
-                                                    &frame_len);
+                                                      payload_data,
+                                                      payload_len,
+                                                      0,
+                                                      &frame_data,
+                                                      &frame_len);
               }
               if (0 == result)
               {
@@ -336,6 +340,7 @@ upgrade_handler (void *cls,
                       MHD_UPGRADE_ACTION_CLOSE);
 }
 
+
 /* This helper function is used for the case that
  * we need to resend some data
  */
@@ -367,6 +372,7 @@ send_all (MHD_socket fd,
   }
 }
 
+
 /* This helper function contains operating-system-dependent code and
  * is used to make a socket blocking.
  */
@@ -389,6 +395,7 @@ make_blocking (MHD_socket fd)
 #endif
 }
 
+
 static enum MHD_Result
 access_handler (void *cls,
                 struct MHD_Connection *connection,
@@ -421,9 +428,9 @@ access_handler (void *cls,
   {
     /* Default page for visiting the server */
     struct MHD_Response *response = MHD_create_response_from_buffer (
-                                      strlen (PAGE),
-                                      PAGE,
-                                      MHD_RESPMEM_PERSISTENT);
+      strlen (PAGE),
+      PAGE,
+      MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_OK,
                               response);
@@ -435,9 +442,9 @@ access_handler (void *cls,
     fprintf (stderr, "Error in test (%s)\n", url + 7);
 
     struct MHD_Response *response = MHD_create_response_from_buffer (
-                                      0,
-                                      "",
-                                      MHD_RESPMEM_PERSISTENT);
+      0,
+      "",
+      MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_OK,
                               response);
@@ -446,7 +453,7 @@ access_handler (void *cls,
   else if (0 == strcmp (url, "/websocket"))
   {
     char is_valid = 1;
-    const char* value = NULL;
+    const char *value = NULL;
     char sec_websocket_accept[29];
 
     if (0 != MHD_websocket_check_http_version (version))
@@ -504,10 +511,10 @@ access_handler (void *cls,
     else
     {
       /* return error page */
-      struct MHD_Response*response = MHD_create_response_from_buffer (
-                                       strlen (PAGE_INVALID_WEBSOCKET_REQUEST),
-                                       PAGE_INVALID_WEBSOCKET_REQUEST,
-                                       MHD_RESPMEM_PERSISTENT);
+      struct MHD_Response *response = MHD_create_response_from_buffer (
+        strlen (PAGE_INVALID_WEBSOCKET_REQUEST),
+        PAGE_INVALID_WEBSOCKET_REQUEST,
+        MHD_RESPMEM_PERSISTENT);
       ret = MHD_queue_response (connection,
                                 MHD_HTTP_BAD_REQUEST,
                                 response);
@@ -516,10 +523,10 @@ access_handler (void *cls,
   }
   else
   {
-    struct MHD_Response*response = MHD_create_response_from_buffer (
-                                     strlen (PAGE_NOT_FOUND),
-                                     PAGE_NOT_FOUND,
-                                     MHD_RESPMEM_PERSISTENT);
+    struct MHD_Response *response = MHD_create_response_from_buffer (
+      strlen (PAGE_NOT_FOUND),
+      PAGE_NOT_FOUND,
+      MHD_RESPMEM_PERSISTENT);
     ret = MHD_queue_response (connection,
                               MHD_HTTP_NOT_FOUND,
                               response);
@@ -529,6 +536,7 @@ access_handler (void *cls,
   return ret;
 }
 
+
 int
 main (int argc,
       char *const *argv)
@@ -537,10 +545,10 @@ main (int argc,
   (void) argv;               /* Unused. Silent compiler warning. */
   struct MHD_Daemon *daemon;
 
-  daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD |
-                             MHD_USE_THREAD_PER_CONNECTION |
-                             MHD_ALLOW_UPGRADE |
-                             MHD_USE_ERROR_LOG,
+  daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD
+                             | MHD_USE_THREAD_PER_CONNECTION
+                             | MHD_ALLOW_UPGRADE
+                             | MHD_USE_ERROR_LOG,
                              PORT, NULL, NULL,
                              &access_handler, NULL,
                              MHD_OPTION_END);
@@ -550,9 +558,9 @@ main (int argc,
     fprintf (stderr, "Error (Couldn't start daemon for testing)\n");
     return 1;
   }
-  printf("The server is listening now.\n");
-  printf("Access the server now with a websocket-capable webbrowser.\n\n");
-  printf("Press return to close.\n");
+  printf ("The server is listening now.\n");
+  printf ("Access the server now with a websocket-capable webbrowser.\n\n");
+  printf ("Press return to close.\n");
 
   (void) getc (stdin);
 
@@ -560,4 +568,3 @@ main (int argc,
 
   return 0;
 }
-

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor