Browse Source

Merge branch 'master' of https://github.com/civetweb/civetweb

bel2125 6 years ago
parent
commit
e440e061ce

+ 1 - 1
docs/APIReference.md

@@ -39,7 +39,7 @@ The content of both structures is not defined in the interface - they are only u
 * [`struct mg_option;`](api/mg_option.md)
 * [`struct mg_option;`](api/mg_option.md)
 * [`struct mg_request_info;`](api/mg_request_info.md)
 * [`struct mg_request_info;`](api/mg_request_info.md)
 * [`struct mg_response_info;`](api/mg_response_info.md)
 * [`struct mg_response_info;`](api/mg_response_info.md)
-* [`struct mg_server_ports;`](api/mg_server_ports.md)
+* [`struct mg_server_port;`](api/mg_server_port.md)
 
 
 
 
 ## Library API Functions
 ## Library API Functions

+ 1 - 1
docs/api/mg_get_ports.md

@@ -27,5 +27,5 @@ The function returns the number of ports actually stored in the buffer.
 
 
 ### See Also
 ### See Also
 
 
-* [`struct mg_server_ports;`](mg_server_ports.md)
+* [`struct mg_server_port;`](mg_server_port.md)
 * [`mg_get_server_ports();`](mg_get_server_ports.md)
 * [`mg_get_server_ports();`](mg_get_server_ports.md)

+ 2 - 2
docs/api/mg_get_server_ports.md

@@ -8,7 +8,7 @@
 | :--- | :--- | :--- |
 | :--- | :--- | :--- |
 |**`ctx`**|`const struct mg_context *`|The context for which the server ports are requested|
 |**`ctx`**|`const struct mg_context *`|The context for which the server ports are requested|
 |**`size`**|`int`|The size of the buffer to store the port information|
 |**`size`**|`int`|The size of the buffer to store the port information|
-|**`ports`**|`struct mg_server_ports *`|Buffer to store the port information|
+|**`ports`**|`struct mg_server_port *`|Buffer to store the port information|
 
 
 ### Return Value
 ### Return Value
 
 
@@ -25,4 +25,4 @@ The function returns the number of items in the list, or a negative value if an
 ### See Also
 ### See Also
 
 
 * [~~`mg_get_ports();`~~](mg_get_ports.md)
 * [~~`mg_get_ports();`~~](mg_get_ports.md)
-* [`struct mg_server_ports;`](mg_server_ports.md)
+* [`struct mg_server_port;`](mg_server_port.md)

+ 2 - 2
docs/api/mg_server_ports.md → docs/api/mg_server_port.md

@@ -1,6 +1,6 @@
 # Civetweb API Reference
 # Civetweb API Reference
 
 
-### `struct mg_server_ports;`
+### `struct mg_server_port;`
 
 
 ### Fields
 ### Fields
 
 
@@ -17,7 +17,7 @@
 
 
 ### Description
 ### Description
 
 
-A call to the function [`mg_get_server_ports()`](mg_get_server_ports.md) returns a list of structures with information about each running Civetweb service. These structures are of type `struct mg_server_ports` and contain the base information of each service.
+A call to the function [`mg_get_server_ports()`](mg_get_server_ports.md) returns a list of structures with information about each running Civetweb service. These structures are of type `struct mg_server_port` and contain the base information of each service.
 
 
 ### See Also
 ### See Also
 
 

+ 1 - 1
examples/embedded_c/embedded_c.c

@@ -975,7 +975,7 @@ main(int argc, char *argv[])
 	    0};
 	    0};
 	struct mg_callbacks callbacks;
 	struct mg_callbacks callbacks;
 	struct mg_context *ctx;
 	struct mg_context *ctx;
-	struct mg_server_ports ports[32];
+	struct mg_server_port ports[32];
 	int port_cnt, n;
 	int port_cnt, n;
 	int err = 0;
 	int err = 0;
 
 

+ 1 - 1
include/CivetServer.h

@@ -376,7 +376,7 @@ class CIVETWEB_CXX_API CivetServer
 	 *
 	 *
 	 * @return A vector of ports
 	 * @return A vector of ports
 	 */
 	 */
-	std::vector<struct mg_server_ports> getListeningPortsFull();
+	std::vector<struct mg_server_port> getListeningPortsFull();
 
 
 	/**
 	/**
 	 * getCookie(struct mg_connection *conn, const std::string &cookieName,
 	 * getCookie(struct mg_connection *conn, const std::string &cookieName,

+ 6 - 3
include/civetweb.h

@@ -681,7 +681,7 @@ enum {
 CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
 CIVETWEB_API const struct mg_option *mg_get_valid_options(void);
 
 
 
 
-struct mg_server_ports {
+struct mg_server_port {
 	int protocol;    /* 1 = IPv4, 2 = IPv6, 3 = both */
 	int protocol;    /* 1 = IPv4, 2 = IPv6, 3 = both */
 	int port;        /* port number */
 	int port;        /* port number */
 	int is_ssl;      /* https port: 0 = no, 1 = yes */
 	int is_ssl;      /* https port: 0 = no, 1 = yes */
@@ -692,15 +692,18 @@ struct mg_server_ports {
 	int _reserved4;
 	int _reserved4;
 };
 };
 
 
+/* Legacy name */
+#define mg_server_ports mg_server_port
+
 
 
 /* Get the list of ports that civetweb is listening on.
 /* Get the list of ports that civetweb is listening on.
    The parameter size is the size of the ports array in elements.
    The parameter size is the size of the ports array in elements.
    The caller is responsibility to allocate the required memory.
    The caller is responsibility to allocate the required memory.
-   This function returns the number of struct mg_server_ports elements
+   This function returns the number of struct mg_server_port elements
    filled in, or <0 in case of an error. */
    filled in, or <0 in case of an error. */
 CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx,
 CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx,
                                      int size,
                                      int size,
-                                     struct mg_server_ports *ports);
+                                     struct mg_server_port *ports);
 
 
 
 
 #if defined(MG_LEGACY_INTERFACE) /* 2017-04-02 */
 #if defined(MG_LEGACY_INTERFACE) /* 2017-04-02 */

+ 3 - 3
src/CivetServer.cpp

@@ -623,7 +623,7 @@ CivetServer::urlEncode(const char *src,
 std::vector<int>
 std::vector<int>
 CivetServer::getListeningPorts()
 CivetServer::getListeningPorts()
 {
 {
-	std::vector<struct mg_server_ports> server_ports = getListeningPortsFull();
+	std::vector<struct mg_server_port> server_ports = getListeningPortsFull();
 
 
 	std::vector<int> ports(server_ports.size());
 	std::vector<int> ports(server_ports.size());
 	for (size_t i = 0; i < server_ports.size(); i++) {
 	for (size_t i = 0; i < server_ports.size(); i++) {
@@ -633,10 +633,10 @@ CivetServer::getListeningPorts()
 	return ports;
 	return ports;
 }
 }
 
 
-std::vector<struct mg_server_ports>
+std::vector<struct mg_server_port>
 CivetServer::getListeningPortsFull()
 CivetServer::getListeningPortsFull()
 {
 {
-	std::vector<struct mg_server_ports> server_ports(50);
+	std::vector<struct mg_server_port> server_ports(50);
 	int size = mg_get_server_ports(context,
 	int size = mg_get_server_ports(context,
 	                               (int)server_ports.size(),
 	                               (int)server_ports.size(),
 	                               &server_ports[0]);
 	                               &server_ports[0]);

+ 25 - 24
src/civetweb.c

@@ -2753,7 +2753,7 @@ struct mg_connection {
 	                       * throttle */
 	                       * throttle */
 
 
 	time_t last_throttle_time;   /* Last time throttled data was sent */
 	time_t last_throttle_time;   /* Last time throttled data was sent */
-	int64_t last_throttle_bytes; /* Bytes sent this second */
+	int last_throttle_bytes;     /* Bytes sent this second */
 	pthread_mutex_t mutex;       /* Used by mg_(un)lock_connection to ensure
 	pthread_mutex_t mutex;       /* Used by mg_(un)lock_connection to ensure
 	                              * atomic transmissions for websockets */
 	                              * atomic transmissions for websockets */
 #if defined(USE_LUA) && defined(USE_WEBSOCKET)
 #if defined(USE_LUA) && defined(USE_WEBSOCKET)
@@ -3504,7 +3504,7 @@ mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl)
 int
 int
 mg_get_server_ports(const struct mg_context *ctx,
 mg_get_server_ports(const struct mg_context *ctx,
                     int size,
                     int size,
-                    struct mg_server_ports *ports)
+                    struct mg_server_port *ports)
 {
 {
 	int i, cnt = 0;
 	int i, cnt = 0;
 
 
@@ -6255,16 +6255,16 @@ push_inner(struct mg_context *ctx,
 }
 }
 
 
 
 
-static int64_t
+static int
 push_all(struct mg_context *ctx,
 push_all(struct mg_context *ctx,
          FILE *fp,
          FILE *fp,
          SOCKET sock,
          SOCKET sock,
          SSL *ssl,
          SSL *ssl,
          const char *buf,
          const char *buf,
-         int64_t len)
+         int len)
 {
 {
 	double timeout = -1.0;
 	double timeout = -1.0;
-	int64_t n, nwritten = 0;
+	int n, nwritten = 0;
 
 
 	if (ctx == NULL) {
 	if (ctx == NULL) {
 		return -1;
 		return -1;
@@ -6275,10 +6275,10 @@ push_all(struct mg_context *ctx,
 	}
 	}
 
 
 	while ((len > 0) && (ctx->stop_flag == 0)) {
 	while ((len > 0) && (ctx->stop_flag == 0)) {
-		n = push_inner(ctx, fp, sock, ssl, buf + nwritten, (int)len, timeout);
+		n = push_inner(ctx, fp, sock, ssl, buf + nwritten, len, timeout);
 		if (n < 0) {
 		if (n < 0) {
 			if (nwritten == 0) {
 			if (nwritten == 0) {
-				nwritten = n; /* Propagate the error */
+				nwritten = -1; /* Propagate the error */
 			}
 			}
 			break;
 			break;
 		} else if (n == 0) {
 		} else if (n == 0) {
@@ -6760,11 +6760,14 @@ int
 mg_write(struct mg_connection *conn, const void *buf, size_t len)
 mg_write(struct mg_connection *conn, const void *buf, size_t len)
 {
 {
 	time_t now;
 	time_t now;
-	int64_t n, total, allowed;
+	int n, total, allowed;
 
 
 	if (conn == NULL) {
 	if (conn == NULL) {
 		return 0;
 		return 0;
 	}
 	}
+	if (len > INT_MAX) {
+		return -1;
+	}
 
 
 	if (conn->throttle > 0) {
 	if (conn->throttle > 0) {
 		if ((now = time(NULL)) != conn->last_throttle_time) {
 		if ((now = time(NULL)) != conn->last_throttle_time) {
@@ -6772,28 +6775,28 @@ mg_write(struct mg_connection *conn, const void *buf, size_t len)
 			conn->last_throttle_bytes = 0;
 			conn->last_throttle_bytes = 0;
 		}
 		}
 		allowed = conn->throttle - conn->last_throttle_bytes;
 		allowed = conn->throttle - conn->last_throttle_bytes;
-		if (allowed > (int64_t)len) {
-			allowed = (int64_t)len;
+		if (allowed > (int)len) {
+			allowed = (int)len;
 		}
 		}
 		if ((total = push_all(conn->phys_ctx,
 		if ((total = push_all(conn->phys_ctx,
 		                      NULL,
 		                      NULL,
 		                      conn->client.sock,
 		                      conn->client.sock,
 		                      conn->ssl,
 		                      conn->ssl,
 		                      (const char *)buf,
 		                      (const char *)buf,
-		                      (int64_t)allowed))
+		                      allowed))
 		    == allowed) {
 		    == allowed) {
 			buf = (const char *)buf + total;
 			buf = (const char *)buf + total;
 			conn->last_throttle_bytes += total;
 			conn->last_throttle_bytes += total;
-			while ((total < (int64_t)len) && (conn->phys_ctx->stop_flag == 0)) {
-				allowed = (conn->throttle > ((int64_t)len - total))
-				              ? (int64_t)len - total
+			while ((total < (int)len) && (conn->phys_ctx->stop_flag == 0)) {
+				allowed = (conn->throttle > ((int)len - total))
+				              ? (int)len - total
 				              : conn->throttle;
 				              : conn->throttle;
 				if ((n = push_all(conn->phys_ctx,
 				if ((n = push_all(conn->phys_ctx,
 				                  NULL,
 				                  NULL,
 				                  conn->client.sock,
 				                  conn->client.sock,
 				                  conn->ssl,
 				                  conn->ssl,
 				                  (const char *)buf,
 				                  (const char *)buf,
-				                  (int64_t)allowed))
+				                  allowed))
 				    != allowed) {
 				    != allowed) {
 					break;
 					break;
 				}
 				}
@@ -6810,12 +6813,12 @@ mg_write(struct mg_connection *conn, const void *buf, size_t len)
 		                 conn->client.sock,
 		                 conn->client.sock,
 		                 conn->ssl,
 		                 conn->ssl,
 		                 (const char *)buf,
 		                 (const char *)buf,
-		                 (int64_t)len);
+		                 (int)len);
 	}
 	}
 	if (total > 0) {
 	if (total > 0) {
 		conn->num_bytes_sent += total;
 		conn->num_bytes_sent += total;
 	}
 	}
-	return (int)total;
+	return total;
 }
 }
 
 
 
 
@@ -10529,7 +10532,7 @@ forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl)
 	const char *expect, *body;
 	const char *expect, *body;
 	char buf[MG_BUF_LEN];
 	char buf[MG_BUF_LEN];
 	int to_read, nread, success = 0;
 	int to_read, nread, success = 0;
-	int64_t buffered_len;
+	int buffered_len;
 	double timeout = -1.0;
 	double timeout = -1.0;
 
 
 	if (!conn) {
 	if (!conn) {
@@ -10568,8 +10571,7 @@ forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl)
 			conn->status_code = 200;
 			conn->status_code = 200;
 		}
 		}
 
 
-		buffered_len = (int64_t)(conn->data_len) - (int64_t)conn->request_len
-		               - conn->consumed_content;
+		buffered_len = conn->data_len - conn->request_len;
 
 
 		DEBUG_ASSERT(buffered_len >= 0);
 		DEBUG_ASSERT(buffered_len >= 0);
 		DEBUG_ASSERT(conn->consumed_content == 0);
 		DEBUG_ASSERT(conn->consumed_content == 0);
@@ -10583,9 +10585,8 @@ forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl)
 			if ((int64_t)buffered_len > conn->content_len) {
 			if ((int64_t)buffered_len > conn->content_len) {
 				buffered_len = (int)conn->content_len;
 				buffered_len = (int)conn->content_len;
 			}
 			}
-			body = conn->buf + conn->request_len + conn->consumed_content;
-			push_all(
-			    conn->phys_ctx, fp, sock, ssl, body, (int64_t)buffered_len);
+			body = conn->buf + conn->request_len;
+			push_all(conn->phys_ctx, fp, sock, ssl, body, buffered_len);
 			conn->consumed_content += buffered_len;
 			conn->consumed_content += buffered_len;
 		}
 		}
 
 
@@ -10605,8 +10606,8 @@ forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl)
 				    != nread) {
 				    != nread) {
 					break;
 					break;
 				}
 				}
+				conn->consumed_content += nread;
 			}
 			}
-			conn->consumed_content += nread;
 		}
 		}
 
 
 		if (conn->consumed_content == conn->content_len) {
 		if (conn->consumed_content == conn->content_len) {

+ 3 - 3
unittest/public_server.c

@@ -344,7 +344,7 @@ test_mg_start_stop_http_server_impl(int ipv6, int bound)
 	char client_err[256];
 	char client_err[256];
 	const struct mg_response_info *client_ri;
 	const struct mg_response_info *client_ri;
 	int client_res, ret;
 	int client_res, ret;
-	struct mg_server_ports portinfo[8];
+	struct mg_server_port portinfo[8];
 
 
 	mark_point();
 	mark_point();
 
 
@@ -585,7 +585,7 @@ START_TEST(test_mg_start_stop_https_server)
 	char client_err[256];
 	char client_err[256];
 	const struct mg_response_info *client_ri;
 	const struct mg_response_info *client_ri;
 	int client_res, ret;
 	int client_res, ret;
-	struct mg_server_ports portinfo[8];
+	struct mg_server_port portinfo[8];
 
 
 	ck_assert(ssl_cert != NULL);
 	ck_assert(ssl_cert != NULL);
 
 
@@ -699,7 +699,7 @@ START_TEST(test_mg_server_and_client_tls)
 	struct mg_context *ctx;
 	struct mg_context *ctx;
 
 
 	int ports_cnt;
 	int ports_cnt;
-	struct mg_server_ports ports[16];
+	struct mg_server_port ports[16];
 	struct mg_callbacks callbacks;
 	struct mg_callbacks callbacks;
 	char errmsg[256];
 	char errmsg[256];