libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

response_set_options.c (3262B)


      1 /* This is generated code, it is still under LGPLv2.1+.
      2    Do not edit directly! */
      3 /* *INDENT-OFF* */
      4 /**
      5  * @file response_set_options.c
      6  * @author options-generator.c
      7  */
      8 
      9 #include "mhd_sys_options.h"
     10 #include "response_set_options.h"
     11 #include "sys_base_types.h"
     12 #include "sys_bool_type.h"
     13 #include "response_options.h"
     14 #include "mhd_response.h"
     15 #include "mhd_public_api.h"
     16 #include "mhd_locks.h"
     17 #include "mhd_assert.h"
     18 #include "response_funcs.h"
     19 
     20 
     21 MHD_FN_PAR_NONNULL_ALL_ MHD_EXTERN_
     22 enum MHD_StatusCode
     23 MHD_response_set_options (
     24   struct MHD_Response *MHD_RESTRICT response,
     25   const struct MHD_ResponseOptionAndValue *MHD_RESTRICT options,
     26   size_t options_max_num)
     27 {
     28   struct ResponseOptions *restrict settings = response->settings;
     29   enum MHD_StatusCode res = MHD_SC_OK;
     30   size_t i;
     31   bool need_unlock = false;
     32 
     33   if (response->frozen)
     34     return MHD_SC_TOO_LATE;
     35   if (response->reuse.reusable)
     36   {
     37     need_unlock = true;
     38     if (! mhd_mutex_lock(&response->reuse.settings_lock))
     39       return MHD_SC_RESPONSE_MUTEX_LOCK_FAILED;
     40     mhd_assert (1 == mhd_atomic_counter_get(&response->reuse.counter));
     41     if (response->frozen) /* Firm re-check under the lock */
     42     {
     43       mhd_mutex_unlock_chk(&response->reuse.settings_lock);
     44       return MHD_SC_TOO_LATE;
     45     }
     46   }
     47 
     48   for (i = 0; i < options_max_num; i++)
     49   {
     50     const struct MHD_ResponseOptionAndValue *const option
     51       = options + i;
     52     switch (option->opt)
     53     {
     54     case MHD_R_O_END:
     55       i = options_max_num - 1;
     56       break;
     57     case MHD_R_O_REUSABLE:
     58       /* custom setter */
     59       if (response->reuse.reusable)
     60       {
     61         if (MHD_NO == option->val.reusable)
     62         {
     63           res = MHD_SC_RESPONSE_CANNOT_CLEAR_REUSE;
     64           i = options_max_num - 1;
     65           break;
     66         }
     67       }
     68       else if ((MHD_NO != option->val.reusable) &&
     69                (! response_make_reusable(response)))
     70       {
     71         res = MHD_SC_RESPONSE_MUTEX_INIT_FAILED;
     72         i = options_max_num - 1;
     73         break;
     74       }
     75       continue;
     76     case MHD_R_O_HEAD_ONLY_RESPONSE:
     77       settings->head_only_response = option->val.head_only_response;
     78       continue;
     79     case MHD_R_O_CHUNKED_ENC:
     80       settings->chunked_enc = option->val.chunked_enc;
     81       continue;
     82     case MHD_R_O_CONN_CLOSE:
     83       settings->conn_close = option->val.conn_close;
     84       continue;
     85     case MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT:
     86       settings->http_1_0_compatible_strict = option->val.http_1_0_compatible_strict;
     87       continue;
     88     case MHD_R_O_HTTP_1_0_SERVER:
     89       settings->http_1_0_server = option->val.http_1_0_server;
     90       continue;
     91     case MHD_R_O_INSANITY_HEADER_CONTENT_LENGTH:
     92       settings->insanity_header_content_length = option->val.insanity_header_content_length;
     93       continue;
     94     case MHD_R_O_TERMINATION_CALLBACK:
     95       settings->termination_callback.v_ended_cb = option->val.termination_callback.v_ended_cb;
     96       settings->termination_callback.v_ended_cb_cls = option->val.termination_callback.v_ended_cb_cls;
     97       continue;
     98     case MHD_R_O_SENTINEL:
     99     default: /* for -Wswitch-default -Wswitch-enum */
    100       res = MHD_SC_OPTION_UNKNOWN;
    101       i = options_max_num - 1;
    102       break;
    103     }
    104   }
    105 
    106   if (need_unlock)
    107     mhd_mutex_unlock_chk(&response->reuse.settings_lock);
    108 
    109   return res;
    110 }