瀏覽代碼

Alternative to mg_upload (Step 27/?)

bel 9 年之前
父節點
當前提交
18aaa35145
共有 3 個文件被更改,包括 36 次插入5 次删除
  1. 1 1
      examples/embedded_c/embedded_c.c
  2. 1 1
      src/civetweb.c
  3. 34 3
      src/handle_form.inl

+ 1 - 1
examples/embedded_c/embedded_c.c

@@ -162,7 +162,7 @@ enum {
 	FORM_DISPOSITION_SKIP = 0x0,
 	FORM_DISPOSITION_GET = 0x1,
 	FORM_DISPOSITION_STORE = 0x2,
-	FORM_DISPOSITION_READ = 0x3,
+	/*	FORM_DISPOSITION_READ = 0x3, not in the first step */
 	FORM_DISPOSITION_ABORT = 0x10
 };
 

+ 1 - 1
src/civetweb.c

@@ -6462,7 +6462,7 @@ parse_http_headers(char **buf, struct mg_request_info *ri)
 		char *dp = *buf;
 		while ((*dp != ':') && (*dp != '\r') && (*dp != 0)) {
 			dp++;
-        }
+		}
 		if (!*dp) {
 			/* neither : nor \r\n. This is not a valid field. */
 			break;

+ 34 - 3
src/handle_form.inl

@@ -224,7 +224,6 @@ mg_handle_form_data(struct mg_connection *conn,
 			}
 			if (disposition == FORM_DISPOSITION_STORE) {
 				/* Store the content to a file */
-				/* TODO: Get "path" from callback" */
 				FILE *f = fopen(path, "wb");
 				if (f != NULL) {
 					size_t n = (size_t)fwrite(val, 1, (size_t)vallen, f);
@@ -250,7 +249,7 @@ mg_handle_form_data(struct mg_connection *conn,
 				 * sense, since the data is already stored in memory, as it is
 				 * part of the query string.
 				 */
-				/* TODO */
+				/* TODO, or not TODO, that is the question */
 			}
 			if ((disposition & FORM_DISPOSITION_ABORT)
 			    == FORM_DISPOSITION_ABORT) {
@@ -320,6 +319,18 @@ mg_handle_form_data(struct mg_connection *conn,
 			disposition = url_encoded_field_found(
 			    buf, (size_t)keylen, NULL, 0, path, sizeof(path) - 1, fdh);
 
+			if (disposition == FORM_DISPOSITION_GET) {
+				/* TODO */
+			}
+			if (disposition == FORM_DISPOSITION_STORE) {
+				/* TODO */
+			}
+			if ((disposition & FORM_DISPOSITION_ABORT)
+			    == FORM_DISPOSITION_ABORT) {
+				/* Stop parsing the request */
+				break;
+			}
+
 			/* Proceed to next entry */
 			used = next - buf;
 			memmove(buf, buf + (size_t)used, sizeof(buf) - (size_t)used);
@@ -424,6 +435,10 @@ mg_handle_form_data(struct mg_connection *conn,
 				 * exists, it needs to be terminated correctly). */
 				return 0;
 			}
+
+			/* TODO: check Content-Type */
+			/* Content-Type: application/octet-stream */
+
 		} else {
 			fend = fbeg;
 		}
@@ -437,8 +452,24 @@ mg_handle_form_data(struct mg_connection *conn,
 		                                      sizeof(path) - 1,
 		                                      fdh);
 
+		if (disposition == FORM_DISPOSITION_GET) {
+			/* TODO */
+		}
+		if (disposition == FORM_DISPOSITION_STORE) {
+			/* Store the content to a file */
+			FILE *f = fopen(path, "wb");
+			if (f != NULL) {
 
-		/* Content-Type: application/octet-stream */
+				/* TODO: store from part_header to next boundary */
+				fclose(f);
+			} else {
+				mg_cry(conn, "%s: Cannot create file %s", __func__, path);
+			}
+		}
+		if ((disposition & FORM_DISPOSITION_ABORT) == FORM_DISPOSITION_ABORT) {
+			/* Stop parsing the request */
+			/* TODO: break; */
+		}
 
 		/* TODO: handle multipart request */
 		return 0;