Kaynağa Gözat

Fixed important lost code, broken by options-generator commit 59b558d92885c2a3a9bb3d0ceb367db209cb08dc

A fix that would take just a couple of minutes without options-generator.
Evgeny Grin (Karlson2k) 1 yıl önce
ebeveyn
işleme
7ed36eb9cb

+ 1 - 1
src/include/microhttpd2.h

@@ -4256,7 +4256,7 @@ MHD_D_OPTION_DAUTH_DEF_MAX_NC (
 #if 0
 
 /**
- * Make the response object re-usable. (FIXME: not used in struct ResponseOptions; remove!?)
+ * Make the response object re-usable.
  * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
  * Useful if the same response is often used to reply.
  * @param value the value of the parameter * @return structure with the requested setting

+ 3 - 3
src/include/microhttpd2_generated_response_options.h

@@ -11,7 +11,7 @@ enum MHD_FIXED_ENUM_APP_SET_ MHD_ResponseOption
   ,
 
   /**
-   * Make the response object re-usable. (FIXME: not used in struct ResponseOptions; remove!?)
+   * Make the response object re-usable.
    * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
    * Useful if the same response is often used to reply.
    */
@@ -178,7 +178,7 @@ struct MHD_ResponseOptionAndValue
 
 #if defined(MHD_USE_COMPOUND_LITERALS) && defined(MHD_USE_DESIG_NEST_INIT)
 /**
- * Make the response object re-usable. (FIXME: not used in struct ResponseOptions; remove!?)
+ * Make the response object re-usable.
  * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
  * Useful if the same response is often used to reply.
  * @param value the value of the parameter * @return structure with the requested setting
@@ -321,7 +321,7 @@ With this option HTTP/1.0 server is emulated (with support for 'keep-alive' conn
 #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */
 MHD_NOWARN_UNUSED_FUNC_
 /**
- * Make the response object re-usable. (FIXME: not used in struct ResponseOptions; remove!?)
+ * Make the response object re-usable.
  * The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
  * Useful if the same response is often used to reply.
  * @param value the value of the parameter * @return structure with the requested setting

+ 28 - 16
src/include/options-generator.c

@@ -1021,26 +1021,38 @@ TOP:
              "/* *INDENT-OFF* */\n"
              "/**\n"
              " * @file %s_set_options.c\n"
-             " * @author %s-options-generator.c\n"
+             " * @author options-generator.c\n"
              " */\n"
-             "\n"
-             "#include \"mhd_sys_options.h\"\n"
-             "#include \"sys_bool_type.h\"\n"
-             "#include \"sys_base_types.h\"\n"
-             "#include \"sys_malloc.h\"\n"
-             "#include <string.h>\n"
-             "#include \"mhd_%s.h\"\n"
-             "#include \"%s_options.h\"\n"
-             "#include \"mhd_public_api.h\"\n",
-             category,
-             category,
-             category,
+             "\n",
              category);
-    if (0 == strcmp (category, "response"))
+    if (0 == strcmp (category, "daemon"))
+    {
       fprintf (f,
+               "#include \"mhd_sys_options.h\"\n"
+               "#include \"sys_base_types.h\"\n"
+               "#include \"sys_malloc.h\"\n"
+               "#include <string.h>\n"
+               "#include \"mhd_daemon.h\"\n"
+               "#include \"daemon_options.h\"\n"
+               "#include \"mhd_public_api.h\"\n"
+               "\n");
+    }
+    else if (0 == strcmp (category, "response"))
+    {
+      fprintf (f,
+               "#include \"mhd_sys_options.h\"\n"
+               "#include \"response_set_options.h\"\n"
+               "#include \"sys_base_types.h\"\n"
+               "#include \"sys_bool_type.h\"\n"
+               "#include \"response_options.h\"\n"
+               "#include \"mhd_response.h\"\n"
+               "#include \"mhd_public_api.h\"\n"
                "#include \"mhd_locks.h\"\n"
                "#include \"mhd_assert.h\"\n"
-               "#include \"response_funcs.h\"\n");
+               "#include \"response_funcs.h\"\n"
+               "\n");
+    }
+
     fprintf (f,
              "\n"
              "MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_\n"
@@ -1081,7 +1093,7 @@ TOP:
                "    if (! mhd_mutex_lock(&response->reuse.settings_lock))\n"
                "      return MHD_SC_RESPONSE_MUTEX_LOCK_FAILED;\n"
                "    mhd_assert (1 == mhd_atomic_counter_get(&response->reuse.counter));\n"
-               "    if (! response->frozen) /* Firm re-check under the lock */\n"
+               "    if (response->frozen) /* Firm re-check under the lock */\n"
                "    {\n"
                "      mhd_mutex_unlock_chk(&response->reuse.settings_lock);\n"
                "      return MHD_SC_TOO_LATE;\n"

+ 18 - 1
src/include/r_options.rec

@@ -20,9 +20,26 @@
 Name: REUSABLE
 Value: 20
 Type: enum MHD_Bool
-Comment: Make the response object re-usable. (FIXME: not used in struct ResponseOptions; remove!?)
+Comment: Make the response object re-usable.
 + The response will not be consumed by MHD_action_from_response() and must be destroyed by MHD_response_destroy().
 + Useful if the same response is often used to reply.
+CustomSetter: /* custom setter */
++ if (response->reuse.reusable)
++ {
++   if (MHD_NO == option->val.reusable)
++   {
++     res = MHD_SC_RESPONSE_CANNOT_CLEAR_REUSE;
++     i = options_max_num - 1;
++     break;
++   }
++ }
++ else if ((MHD_NO != option->val.reusable) &&
++          (! response_make_reusable(response)))
++ {
++   res = MHD_SC_RESPONSE_MUTEX_INIT_FAILED;
++   i = options_max_num - 1;
++   break;
++ }
 
 # Content control
 

+ 2 - 2
src/mhd2/daemon_set_options.c

@@ -3,11 +3,10 @@
 /* *INDENT-OFF* */
 /**
  * @file daemon_set_options.c
- * @author daemon-options-generator.c
+ * @author options-generator.c
  */
 
 #include "mhd_sys_options.h"
-#include "sys_bool_type.h"
 #include "sys_base_types.h"
 #include "sys_malloc.h"
 #include <string.h>
@@ -15,6 +14,7 @@
 #include "daemon_options.h"
 #include "mhd_public_api.h"
 
+
 MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_
 enum MHD_StatusCode
 MHD_daemon_set_options (

+ 23 - 7
src/mhd2/response_set_options.c

@@ -3,21 +3,21 @@
 /* *INDENT-OFF* */
 /**
  * @file response_set_options.c
- * @author response-options-generator.c
+ * @author options-generator.c
  */
 
 #include "mhd_sys_options.h"
-#include "sys_bool_type.h"
+#include "response_set_options.h"
 #include "sys_base_types.h"
-#include "sys_malloc.h"
-#include <string.h>
-#include "mhd_response.h"
+#include "sys_bool_type.h"
 #include "response_options.h"
+#include "mhd_response.h"
 #include "mhd_public_api.h"
 #include "mhd_locks.h"
 #include "mhd_assert.h"
 #include "response_funcs.h"
 
+
 MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_
 enum MHD_StatusCode
 MHD_response_set_options (
@@ -38,7 +38,7 @@ MHD_response_set_options (
     if (! mhd_mutex_lock(&response->reuse.settings_lock))
       return MHD_SC_RESPONSE_MUTEX_LOCK_FAILED;
     mhd_assert (1 == mhd_atomic_counter_get(&response->reuse.counter));
-    if (! response->frozen) /* Firm re-check under the lock */
+    if (response->frozen) /* Firm re-check under the lock */
     {
       mhd_mutex_unlock_chk(&response->reuse.settings_lock);
       return MHD_SC_TOO_LATE;
@@ -55,7 +55,23 @@ MHD_response_set_options (
       i = options_max_num - 1;
       break;
     case MHD_R_O_REUSABLE:
-      settings->reusable = option->val.reusable;
+      /* custom setter */
+      if (response->reuse.reusable)
+      {
+        if (MHD_NO == option->val.reusable)
+        {
+          res = MHD_SC_RESPONSE_CANNOT_CLEAR_REUSE;
+          i = options_max_num - 1;
+          break;
+        }
+      }
+      else if ((MHD_NO != option->val.reusable) &&
+               (! response_make_reusable(response)))
+      {
+        res = MHD_SC_RESPONSE_MUTEX_INIT_FAILED;
+        i = options_max_num - 1;
+        break;
+      }
       continue;
     case MHD_R_O_HEAD_ONLY_RESPONSE:
       settings->head_only_response = option->val.head_only_response;