Parcourir la source

Alternative to mg_upload (Step 54/?)

bel2125 il y a 9 ans
Parent
commit
2ef1efcd5d
2 fichiers modifiés avec 18 ajouts et 4 suppressions
  1. 0 2
      include/civetweb.h
  2. 18 2
      src/handle_form.inl

+ 0 - 2
include/civetweb.h

@@ -796,8 +796,6 @@ enum {
 	FORM_FIELD_STORAGE_GET = 0x1,
 	/* Store the field value into a file. */
 	FORM_FIELD_STORAGE_STORE = 0x2,
-	/* Read the filed in chunks using a read function. */
-	/*	FORM_FIELD_STORAGE_READ = 0x3, not in the first step */
 	/* Stop parsing this request. Skip the remaining fields. */
 	FORM_FIELD_STORAGE_ABORT = 0x10
 };

+ 18 - 2
src/handle_form.inl

@@ -34,6 +34,7 @@ url_encoded_field_found(const struct mg_connection *conn,
 	char filename_dec[1024];
 	int key_dec_len;
 	int filename_dec_len;
+	int ret;
 
 	key_dec_len =
 	    mg_url_decode(key, (int)key_len, key_dec, (int)sizeof(key_dec), 1);
@@ -59,8 +60,23 @@ url_encoded_field_found(const struct mg_connection *conn,
 		filename_dec[0] = 0;
 	}
 
-	return fdh->field_found(
-	    key_dec, filename_dec, path, path_len, fdh->user_data);
+	ret =
+	    fdh->field_found(key_dec, filename_dec, path, path_len, fdh->user_data);
+
+	if ((ret & 0xF) == FORM_FIELD_STORAGE_GET) {
+		if (fdh->field_get == NULL) {
+			mg_cry(conn, "%s: Function \"Get\" not available", __func__);
+			return FORM_FIELD_STORAGE_SKIP;
+		}
+	}
+	if ((ret & 0xF) == FORM_FIELD_STORAGE_STORE) {
+		if (fdh->field_store == NULL) {
+			mg_cry(conn, "%s: Function \"Store\" not available", __func__);
+			return FORM_FIELD_STORAGE_SKIP;
+		}
+	}
+
+	return ret;
 }