瀏覽代碼

Reformat some code and some comments

bel 9 年之前
父節點
當前提交
1ffdf7ee3f
共有 2 個文件被更改,包括 34 次插入20 次删除
  1. 14 9
      src/civetweb.c
  2. 20 11
      src/handle_form.inl

+ 14 - 9
src/civetweb.c

@@ -2851,15 +2851,15 @@ path_to_unicode(const struct mg_connection *conn,
 		wbuf[0] = L'\0';
 	}
 
-	/* TODO: Add a configuration to switch between case sensitive and 
-     * case insensitive URIs for Windows server. */
-    /*
+	/* TODO: Add a configuration to switch between case sensitive and
+	 * case insensitive URIs for Windows server. */
+	/*
 	if (conn) {
-		if (conn->ctx->config[WINDOWS_CASE_SENSITIVE]) {
-			fcompare = wcscmp;
-		}
+	    if (conn->ctx->config[WINDOWS_CASE_SENSITIVE]) {
+	        fcompare = wcscmp;
+	    }
 	}
-    */
+	*/
 
 	/* Only accept a full file path, not a Windows short (8.3) path. */
 	memset(wbuf2, 0, ARRAY_SIZE(wbuf2) * sizeof(wchar_t));
@@ -6628,6 +6628,7 @@ mg_send_file(struct mg_connection *conn, const char *path)
 	mg_send_mime_file(conn, path, NULL);
 }
 
+
 void
 mg_send_mime_file(struct mg_connection *conn,
                   const char *path,
@@ -9550,6 +9551,7 @@ mg_set_websocket_handler(struct mg_context *ctx,
 	                    cbdata);
 }
 
+
 void
 mg_set_auth_handler(struct mg_context *ctx,
                     const char *uri,
@@ -9569,6 +9571,7 @@ mg_set_auth_handler(struct mg_context *ctx,
 	                    cbdata);
 }
 
+
 static int
 get_request_handler(struct mg_connection *conn,
                     int handler_type,
@@ -9755,8 +9758,7 @@ handle_request(struct mg_connection *conn)
 		}
 
 		/* 1.3. clean URIs, so a path like allowed_dir/../forbidden_file is
-		 * not
-		 * possible */
+		 * not possible */
 		remove_double_dots_and_double_slashes((char *)ri->local_uri);
 
 		/* step 1. completed, the url is known now */
@@ -11946,6 +11948,7 @@ mg_download(const char *host,
 	return conn;
 }
 
+
 struct websocket_client_thread_data {
 	struct mg_connection *conn;
 	mg_websocket_data_handler data_handler;
@@ -11982,6 +11985,7 @@ websocket_client_thread(void *data)
 }
 #endif
 
+
 struct mg_connection *
 mg_connect_websocket_client(const char *host,
                             int port,
@@ -12788,6 +12792,7 @@ get_system_name(char **sysName)
 #endif
 }
 
+
 struct mg_context *
 mg_start(const struct mg_callbacks *callbacks,
          void *user_data,

+ 20 - 11
src/handle_form.inl

@@ -341,7 +341,7 @@ mg_handle_form_request(struct mg_connection *conn,
 				}
 				if (r != (int)to_read) {
 					/* TODO: Create a function to get "all_data_read" from
-					 * the conn object. Add data is read if the Content-Length
+					 * the conn object. All data is read if the Content-Length
 					 * has been reached, or if chunked encoding is used and
 					 * the end marker has been read, or if the connection has
 					 * been closed. */
@@ -493,6 +493,7 @@ mg_handle_form_request(struct mg_connection *conn,
 		}
 
 		for (;;) {
+			size_t towrite, n;
 
 			r = mg_read(conn,
 			            buf + (size_t)buf_fill,
@@ -604,6 +605,18 @@ mg_handle_form_request(struct mg_connection *conn,
 			                       boundary,
 			                       bl);
 
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
+				/* Store the content to a file */
+				if (mg_fopen(conn, path, "wb", &fstore) == 0) {
+					fstore.fp = NULL;
+				}
+				file_size = 0;
+
+				if (!fstore.fp) {
+					mg_cry(conn, "%s: Cannot create file %s", __func__, path);
+				}
+			}
+
 			if (field_storage == FORM_FIELD_STORAGE_GET) {
 				if (!next) {
 					/* TODO: check for an easy way to get longer data */
@@ -621,16 +634,6 @@ mg_handle_form_request(struct mg_connection *conn,
 			}
 
 			if (field_storage == FORM_FIELD_STORAGE_STORE) {
-				/* Store the content to a file */
-				size_t towrite, n;
-				if (mg_fopen(conn, path, "wb", &fstore) == 0) {
-					fstore.fp = NULL;
-				}
-				file_size = 0;
-
-				if (!fstore.fp) {
-					mg_cry(conn, "%s: Cannot create file %s", __func__, path);
-				}
 
 				while (!next) {
 					/* Set "towrite" to the number of bytes available
@@ -679,6 +682,9 @@ mg_handle_form_request(struct mg_connection *conn,
 					/* Find boundary */
 					next = search_boundary(buf, (size_t)buf_fill, boundary, bl);
 				}
+			}
+
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
 
 				if (fstore.fp) {
 					towrite = (size_t)(next - hend);
@@ -694,6 +700,9 @@ mg_handle_form_request(struct mg_connection *conn,
 					}
 					file_size += (size_t)n;
 				}
+			}
+
+			if (field_storage == FORM_FIELD_STORAGE_STORE) {
 
 				if (fstore.fp) {
 					r = fclose(fstore.fp);