فهرست منبع

mg_upload has been replaced by mg_handle_form_request (#180)

bel 9 سال پیش
والد
کامیت
bd3528863f
3فایلهای تغییر یافته به همراه19 افزوده شده و 5 حذف شده
  1. 1 0
      RELEASE_NOTES.md
  2. 5 0
      include/civetweb.h
  3. 13 5
      src/civetweb.c

+ 1 - 0
RELEASE_NOTES.md

@@ -5,6 +5,7 @@ Release Notes v1.8 (work in progress)
 Changes
 -------
 
+- Replace mg_upload by mg_handle_form_request
 - CGI-scripts must receive EOF if all POST data is read
 - Add API function to handle all kinds of HTML form data
 - Do not allow short file names in Windows

+ 5 - 0
include/civetweb.h

@@ -185,11 +185,14 @@ struct mg_callbacks {
 	     lua_context: "lua_State *" pointer. */
 	void (*init_lua)(const struct mg_connection *, void *lua_context);
 
+#if defined(MG_LEGACY_INTERFACE)
 	/* Called when civetweb has uploaded a file to a temporary directory as a
 	   result of mg_upload() call.
+	   Note that mg_upload is deprecated. Use mg_handle_form_request instead.
 	   Parameters:
 	     file_name: full path name to the uploaded file. */
 	void (*upload)(struct mg_connection *, const char *file_name);
+#endif
 
 	/* Called when civetweb is about to send HTTP error to the client.
 	   Implementing this callback allows to create custom error pages.
@@ -741,12 +744,14 @@ mg_download(const char *host,
 CIVETWEB_API void mg_close_connection(struct mg_connection *conn);
 
 
+#if defined(MG_LEGACY_INTERFACE)
 /* File upload functionality. Each uploaded file gets saved into a temporary
    file and MG_UPLOAD event is sent.
    Return number of uploaded files.
    Deprecated: Use mg_handle_form_request instead. */
 CIVETWEB_API int mg_upload(struct mg_connection *conn,
                            const char *destination_dir);
+#endif
 
 
 /* This structure contains callback functions for handling form fields.

+ 13 - 5
src/civetweb.c

@@ -2258,12 +2258,14 @@ send_static_cache_header(struct mg_connection *conn)
 	/* Use "Cache-Control: max-age" instead of "Expires" header.
 	 * Reason: see https://www.mnot.net/blog/2007/05/15/expires_max-age */
 	/* See also https://www.mnot.net/cache_docs/ */
-    /* According to RFC 2616, Section 14.21, caching times should not exceed
+	/* According to RFC 2616, Section 14.21, caching times should not exceed
      * one year. A year with 365 days corresponds to 31536000 seconds, a leap
      * year to 31622400 seconds. For the moment, we just send whatever has
      * been configured, still the behavior for >1 year should be considered
-     * as undefined. */.
-	return mg_printf(conn, "Cache-Control: max-age=%u\r\n", (unsigned)max_age);
+     * as undefined. */
+	    .return mg_printf(conn,
+	                      "Cache-Control: max-age=%u\r\n",
+	                      (unsigned)max_age);
 #else  /* NO_CACHING */
 	return send_no_cache_header(conn);
 #endif /* !NO_CACHING */
@@ -9229,11 +9231,16 @@ get_remote_ip(const struct mg_connection *conn)
 }
 
 
-/* Experimental replacement for mg_upload. */
+/* The mg_upload function is superseeded by mg_handle_form_request. */
 #include "handle_form.inl"
 
 
-/* Replacement for mg_upload (Note: mg_upload is deprecated) */
+#if defined(MG_LEGACY_INTERFACE)
+/* Implement the deprecated mg_upload function by calling the new
+ * mg_handle_form_request function. While mg_upload could only handle
+ * HTML forms sent as POST request in multipart/form-data format
+ * containing only file input elements, mg_handle_form_request can
+ * handle all form input elements and all standard request methods. */
 struct mg_upload_user_data {
 	struct mg_connection *conn;
 	const char *destination_dir;
@@ -9323,6 +9330,7 @@ mg_upload(struct mg_connection *conn, const char *destination_dir)
 
 	return fud.num_uploaded_files;
 }
+#endif
 
 
 static int