libmicrohttpd2

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

response_set_options.c (3269B)


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