Kaynağa Gözat

Autoformat after merge of #367

bel 8 yıl önce
ebeveyn
işleme
846ef34a7c
2 değiştirilmiş dosya ile 56 ekleme ve 48 silme
  1. 12 11
      include/civetweb.h
  2. 44 37
      src/civetweb.c

+ 12 - 11
include/civetweb.h

@@ -89,7 +89,8 @@ struct mg_request_info {
 
 	struct client_cert *client_cert; /* Client certificate information */
 
-	const char *acceptedSubprotocol; /* websocket, subprotocol accepted during handshake */
+	const char *acceptedSubprotocol; /* websocket, subprotocol accepted during
+	                                    handshake */
 };
 
 
@@ -361,7 +362,7 @@ typedef void (*mg_websocket_close_handler)(const struct mg_connection *,
  */
 struct mg_websocket_subprotocols {
 	int nb_subprotocols;
-	char ** subprotocols;
+	char **subprotocols;
 };
 
 /* mg_set_websocket_handler
@@ -381,15 +382,15 @@ mg_set_websocket_handler(struct mg_context *ctx,
 
    Set or remove handler functions for websocket connections.
    This function works similar to mg_set_request_handler - see there. */
-CIVETWEB_API void
-mg_set_websocket_handler_with_subprotocols(struct mg_context *ctx,
-                         const char *uri,
-						 struct mg_websocket_subprotocols *subprotocols,
-                         mg_websocket_connect_handler connect_handler,
-                         mg_websocket_ready_handler ready_handler,
-                         mg_websocket_data_handler data_handler,
-                         mg_websocket_close_handler close_handler,
-                         void *cbdata);
+CIVETWEB_API void mg_set_websocket_handler_with_subprotocols(
+    struct mg_context *ctx,
+    const char *uri,
+    struct mg_websocket_subprotocols *subprotocols,
+    mg_websocket_connect_handler connect_handler,
+    mg_websocket_ready_handler ready_handler,
+    mg_websocket_data_handler data_handler,
+    mg_websocket_close_handler close_handler,
+    void *cbdata);
 
 
 /* mg_authorization_handler

+ 44 - 37
src/civetweb.c

@@ -9392,7 +9392,9 @@ send_websocket_handshake(struct mg_connection *conn, const char *websock_key)
 	          "Sec-WebSocket-Accept: %s\r\n",
 	          b64_sha);
 	if (conn->request_info.acceptedSubprotocol) {
-		mg_printf(conn, "Sec-WebSocket-Protocol: %s\r\n\r\n", conn->request_info.acceptedSubprotocol);
+		mg_printf(conn,
+		          "Sec-WebSocket-Protocol: %s\r\n\r\n",
+		          conn->request_info.acceptedSubprotocol);
 	} else {
 		mg_printf(conn, "%s", "\r\n");
 	}
@@ -9709,7 +9711,7 @@ static void
 handle_websocket_request(struct mg_connection *conn,
                          const char *path,
                          int is_callback_resource,
-						 struct mg_websocket_subprotocols * subprotocols,
+                         struct mg_websocket_subprotocols *subprotocols,
                          mg_websocket_connect_handler ws_connect_handler,
                          mg_websocket_ready_handler ws_ready_handler,
                          mg_websocket_data_handler ws_data_handler,
@@ -9769,7 +9771,7 @@ handle_websocket_request(struct mg_connection *conn,
 	if (is_callback_resource) {
 		/* Step 2.1 check and select subprotocol */
 		const char *protocol = mg_get_header(conn, "Sec-WebSocket-Protocol");
-		if(protocol && subprotocols) {
+		if (protocol && subprotocols) {
 			int len, idx;
 			const char *sep, *curSubProtocol, *acceptedSubProtocol = NULL;
 
@@ -9778,18 +9780,20 @@ handle_websocket_request(struct mg_connection *conn,
 			do {
 				sep = strchr(protocol, ',');
 				curSubProtocol = protocol;
-				len = sep ? (int) (sep - protocol) : strlen(protocol);
+				len = sep ? (int)(sep - protocol) : strlen(protocol);
 				protocol = sep ? sep + 1 : NULL;
 
 
-				for(idx = 0; idx < subprotocols->nb_subprotocols; idx++) {
-					if(strlen(subprotocols->subprotocols[idx])==len
-							&& strncmp(curSubProtocol, subprotocols->subprotocols[idx], len)==0) {
+				for (idx = 0; idx < subprotocols->nb_subprotocols; idx++) {
+					if (strlen(subprotocols->subprotocols[idx]) == len
+					    && strncmp(curSubProtocol,
+					               subprotocols->subprotocols[idx],
+					               len) == 0) {
 						acceptedSubProtocol = subprotocols->subprotocols[idx];
 						break;
 					}
 				}
-			} while(sep && !acceptedSubProtocol);
+			} while (sep && !acceptedSubProtocol);
 
 			conn->request_info.acceptedSubprotocol = acceptedSubProtocol;
 		} else if (protocol) {
@@ -9805,10 +9809,12 @@ handle_websocket_request(struct mg_connection *conn,
 			} else {
 				/* Multiple protocols -> accept the last one. */
 				/* This is just a quick fix if the client offers multiple
-				 * protocols. The handler should have a list of accepted protocols on his own
-				 * and use it to select one protocol among those the client has offered.
+				 * protocols. The handler should have a list of accepted
+				 * protocols on his own
+				 * and use it to select one protocol among those the client has
+				 * offered.
 				 */
-				conn->request_info.acceptedSubprotocol = (sep+1);
+				conn->request_info.acceptedSubprotocol = (sep + 1);
 			}
 		}
 
@@ -10173,7 +10179,7 @@ mg_set_handler_type(struct mg_context *ctx,
                     int handler_type,
                     int is_delete_request,
                     mg_request_handler handler,
-					struct mg_websocket_subprotocols *subprotocols,
+                    struct mg_websocket_subprotocols *subprotocols,
                     mg_websocket_connect_handler connect_handler,
                     mg_websocket_ready_handler ready_handler,
                     mg_websocket_data_handler data_handler,
@@ -10329,7 +10335,7 @@ mg_set_request_handler(struct mg_context *ctx,
 	                    REQUEST_HANDLER,
 	                    handler == NULL,
 	                    handler,
-						NULL,
+	                    NULL,
 	                    NULL,
 	                    NULL,
 	                    NULL,
@@ -10342,32 +10348,33 @@ mg_set_request_handler(struct mg_context *ctx,
 void
 mg_set_websocket_handler(struct mg_context *ctx,
                          const char *uri,
-						 mg_websocket_connect_handler connect_handler,
+                         mg_websocket_connect_handler connect_handler,
                          mg_websocket_ready_handler ready_handler,
                          mg_websocket_data_handler data_handler,
                          mg_websocket_close_handler close_handler,
                          void *cbdata)
 {
 	mg_set_websocket_handler_with_subprotocols(ctx,
-			uri,
-			NULL,
-			connect_handler,
-			ready_handler,
-			data_handler,
-			close_handler,
-			cbdata);
+	                                           uri,
+	                                           NULL,
+	                                           connect_handler,
+	                                           ready_handler,
+	                                           data_handler,
+	                                           close_handler,
+	                                           cbdata);
 }
 
 
 void
-mg_set_websocket_handler_with_subprotocols(struct mg_context *ctx,
-                         const char *uri,
-						 struct mg_websocket_subprotocols* subprotocols,
-                         mg_websocket_connect_handler connect_handler,
-                         mg_websocket_ready_handler ready_handler,
-                         mg_websocket_data_handler data_handler,
-                         mg_websocket_close_handler close_handler,
-                         void *cbdata)
+mg_set_websocket_handler_with_subprotocols(
+    struct mg_context *ctx,
+    const char *uri,
+    struct mg_websocket_subprotocols *subprotocols,
+    mg_websocket_connect_handler connect_handler,
+    mg_websocket_ready_handler ready_handler,
+    mg_websocket_data_handler data_handler,
+    mg_websocket_close_handler close_handler,
+    void *cbdata)
 {
 	int is_delete_request = (connect_handler == NULL) && (ready_handler == NULL)
 	                        && (data_handler == NULL)
@@ -10377,7 +10384,7 @@ mg_set_websocket_handler_with_subprotocols(struct mg_context *ctx,
 	                    WEBSOCKET_HANDLER,
 	                    is_delete_request,
 	                    NULL,
-						subprotocols,
+	                    subprotocols,
 	                    connect_handler,
 	                    ready_handler,
 	                    data_handler,
@@ -10398,7 +10405,7 @@ mg_set_auth_handler(struct mg_context *ctx,
 	                    AUTH_HANDLER,
 	                    handler == NULL,
 	                    NULL,
-						NULL,
+	                    NULL,
 	                    NULL,
 	                    NULL,
 	                    NULL,
@@ -10412,7 +10419,7 @@ static int
 get_request_handler(struct mg_connection *conn,
                     int handler_type,
                     mg_request_handler *handler,
-					struct mg_websocket_subprotocols **subprotocols,
+                    struct mg_websocket_subprotocols **subprotocols,
                     mg_websocket_connect_handler *connect_handler,
                     mg_websocket_ready_handler *ready_handler,
                     mg_websocket_data_handler *data_handler,
@@ -10663,7 +10670,7 @@ handle_request(struct mg_connection *conn)
 		                        is_websocket_request ? WEBSOCKET_HANDLER
 		                                             : REQUEST_HANDLER,
 		                        &callback_handler,
-								&subprotocols,
+		                        &subprotocols,
 		                        &ws_connect_handler,
 		                        &ws_ready_handler,
 		                        &ws_data_handler,
@@ -10699,7 +10706,7 @@ handle_request(struct mg_connection *conn)
 		                        AUTH_HANDLER,
 		                        NULL,
 		                        NULL,
-								NULL,
+		                        NULL,
 		                        NULL,
 		                        NULL,
 		                        NULL,
@@ -10789,7 +10796,7 @@ handle_request(struct mg_connection *conn)
 				handle_websocket_request(conn,
 				                         path,
 				                         is_callback_resource,
-										 subprotocols,
+				                         subprotocols,
 				                         ws_connect_handler,
 				                         ws_ready_handler,
 				                         ws_data_handler,
@@ -10808,7 +10815,7 @@ handle_request(struct mg_connection *conn)
 				handle_websocket_request(conn,
 				                         path,
 				                         0 /* Lua Script */,
-										 NULL,
+				                         NULL,
 				                         NULL,
 				                         NULL,
 				                         NULL,
@@ -10820,7 +10827,7 @@ handle_request(struct mg_connection *conn)
 				    conn,
 				    path,
 				    !is_script_resource /* could be deprecated global callback */,
-					NULL,
+				    NULL,
 				    deprecated_websocket_connect_wrapper,
 				    deprecated_websocket_ready_wrapper,
 				    deprecated_websocket_data_wrapper,