Pārlūkot izejas kodu

Fix CivetHandler.cpp handleOptions

New code had a wrong return type and value (warning C4305: 'return': truncation from 'int' to 'bool'):
https://github.com/civetweb/civetweb/commit/cf080fd5f1de9d782de67757842faffca4ce3f14#commitcomment-43059941
bel2125 4 gadi atpakaļ
vecāks
revīzija
958dcef8d1
2 mainītis faili ar 66 papildinājumiem un 38 dzēšanām
  1. 21 7
      include/CivetServer.h
  2. 45 31
      src/CivetServer.cpp

+ 21 - 7
include/CivetServer.h

@@ -75,7 +75,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handleGet(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handleGet(CivetServer *server,
+	                       struct mg_connection *conn,
+	                       int *status_code);
 
 	/**
 	 * Callback method for POST request.
@@ -94,7 +96,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handlePost(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handlePost(CivetServer *server,
+	                        struct mg_connection *conn,
+	                        int *status_code);
 
 	/**
 	 * Callback method for HEAD request.
@@ -113,7 +117,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handleHead(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handleHead(CivetServer *server,
+	                        struct mg_connection *conn,
+	                        int *status_code);
 
 	/**
 	 * Callback method for PUT request.
@@ -132,7 +138,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handlePut(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handlePut(CivetServer *server,
+	                       struct mg_connection *conn,
+	                       int *status_code);
 
 	/**
 	 * Callback method for DELETE request.
@@ -151,7 +159,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handleDelete(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handleDelete(CivetServer *server,
+	                          struct mg_connection *conn,
+	                          int *status_code);
 
 	/**
 	 * Callback method for OPTIONS request.
@@ -170,7 +180,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handleOptions(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handleOptions(CivetServer *server,
+	                           struct mg_connection *conn,
+	                           int *status_code);
 
 	/**
 	 * Callback method for PATCH request.
@@ -189,7 +201,9 @@ class CIVETWEB_CXX_API CivetHandler
 	 * @param http - pointer to return status code
 	 * @returns true if implemented, false otherwise
 	 */
-	virtual bool handlePatch(CivetServer *server, struct mg_connection *conn, int *status_code);
+	virtual bool handlePatch(CivetServer *server,
+	                         struct mg_connection *conn,
+	                         int *status_code);
 };
 
 /**

+ 45 - 31
src/CivetServer.cpp

@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2017 the Civetweb developers
+/* Copyright (c) 2013-2020 the Civetweb developers
  * Copyright (c) 2013 No Face Press, LLC
  *
  * License http://opensource.org/licenses/mit-license.php MIT License
@@ -28,11 +28,13 @@ CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handleGet(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handleGet(CivetServer *server,
+                        struct mg_connection *conn,
+                        int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-	if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
 	return false;
@@ -47,11 +49,13 @@ CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handlePost(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handlePost(CivetServer *server,
+                         struct mg_connection *conn,
+                         int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-	if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
 	return false;
@@ -66,11 +70,13 @@ CivetHandler::handleHead(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handleHead(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handleHead(CivetServer *server,
+                         struct mg_connection *conn,
+                         int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-		if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
 	return false;
@@ -85,11 +91,13 @@ CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handlePut(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handlePut(CivetServer *server,
+                        struct mg_connection *conn,
+                        int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-	if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
 	return false;
@@ -104,11 +112,13 @@ CivetHandler::handlePatch(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handlePatch(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handlePatch(CivetServer *server,
+                          struct mg_connection *conn,
+                          int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-	if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
 	return false;
@@ -123,11 +133,13 @@ CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handleDelete(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handleDelete(CivetServer *server,
+                           struct mg_connection *conn,
+                           int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-	if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
 	return false;
@@ -142,14 +154,16 @@ CivetHandler::handleOptions(CivetServer *server, struct mg_connection *conn)
 }
 
 bool
-CivetHandler::handleOptions(CivetServer *server, struct mg_connection *conn, int *status_code)
+CivetHandler::handleOptions(CivetServer *server,
+                            struct mg_connection *conn,
+                            int *status_code)
 {
 	UNUSED_PARAMETER(server);
 	UNUSED_PARAMETER(conn);
-	if(status_code){
+	if (status_code) {
 		*status_code = -1;
 	}
-	return -1;
+	return false;
 }
 
 bool
@@ -216,44 +230,44 @@ CivetServer::requestHandler(struct mg_connection *conn, void *cbdata)
 
 	if (handler) {
 		if (strcmp(request_info->request_method, "GET") == 0) {
-			status_ok = handler->handleGet(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handleGet(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handleGet(me, conn);
 			}
 		} else if (strcmp(request_info->request_method, "POST") == 0) {
-			status_ok = handler->handlePost(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handlePost(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handlePost(me, conn);
 			}
 		} else if (strcmp(request_info->request_method, "HEAD") == 0) {
-			status_ok = handler->handleHead(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handleHead(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handleHead(me, conn);
 			}
 		} else if (strcmp(request_info->request_method, "PUT") == 0) {
-			status_ok = handler->handlePut(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handlePut(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handlePut(me, conn);
 			}
 		} else if (strcmp(request_info->request_method, "DELETE") == 0) {
-			status_ok = handler->handleDelete(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handleDelete(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handleDelete(me, conn);
 			}
 		} else if (strcmp(request_info->request_method, "OPTIONS") == 0) {
-			status_ok = handler->handleOptions(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handleOptions(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handleOptions(me, conn);
 			}
 		} else if (strcmp(request_info->request_method, "PATCH") == 0) {
-			status_ok = handler->handlePatch(me, conn,&http_status_code);
-			if(http_status_code < 0){
+			status_ok = handler->handlePatch(me, conn, &http_status_code);
+			if (http_status_code < 0) {
 				status_ok = handler->handlePatch(me, conn);
 			}
 		}
 	}
 
-	if(http_status_code < 0){
+	if (http_status_code < 0) {
 		http_status_code = status_ok ? 1 : 0;
 	}