Coverage Report

Created: 2025-11-09 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mhd2/src/mhd2/response_set_options.c
Line
Count
Source
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
5.02k
{
28
5.02k
  struct ResponseOptions *restrict settings = response->settings;
29
5.02k
  enum MHD_StatusCode res = MHD_SC_OK;
30
5.02k
  size_t i;
31
5.02k
  bool need_unlock = false;
32
33
5.02k
  if (response->frozen)
34
0
    return MHD_SC_TOO_LATE;
35
5.02k
  if (response->reuse.reusable)
36
1.17k
  {
37
1.17k
    need_unlock = true;
38
1.17k
    if (! mhd_mutex_lock(&response->reuse.settings_lock))
39
0
      return MHD_SC_RESPONSE_MUTEX_LOCK_FAILED;
40
1.17k
    mhd_assert (1 == mhd_atomic_counter_get(&response->reuse.counter));
41
1.17k
    if (response->frozen) /* Firm re-check under the lock */
42
0
    {
43
0
      mhd_mutex_unlock_chk(&response->reuse.settings_lock);
44
0
      return MHD_SC_TOO_LATE;
45
0
    }
46
1.17k
  }
47
48
10.0k
  for (i = 0; i < options_max_num; i++)
49
5.02k
  {
50
5.02k
    const struct MHD_ResponseOptionAndValue *const option
51
5.02k
      = options + i;
52
5.02k
    switch (option->opt)
53
5.02k
    {
54
0
    case MHD_R_O_END:
55
0
      i = options_max_num - 1;
56
0
      break;
57
1.06k
    case MHD_R_O_REUSABLE:
58
      /* custom setter */
59
1.06k
      if (response->reuse.reusable)
60
0
      {
61
0
        if (MHD_NO == option->val.reusable)
62
0
        {
63
0
          res = MHD_SC_RESPONSE_CANNOT_CLEAR_REUSE;
64
0
          i = options_max_num - 1;
65
0
          break;
66
0
        }
67
0
      }
68
1.06k
      else if ((MHD_NO != option->val.reusable) &&
69
366
               (! response_make_reusable(response)))
70
0
      {
71
0
        res = MHD_SC_RESPONSE_MUTEX_INIT_FAILED;
72
0
        i = options_max_num - 1;
73
0
        break;
74
0
      }
75
1.06k
      continue;
76
1.06k
    case MHD_R_O_HEAD_ONLY_RESPONSE:
77
1.05k
      settings->head_only_response = option->val.head_only_response;
78
1.05k
      continue;
79
1.04k
    case MHD_R_O_CHUNKED_ENC:
80
1.04k
      settings->chunked_enc = option->val.chunked_enc;
81
1.04k
      continue;
82
1.04k
    case MHD_R_O_CONN_CLOSE:
83
1.04k
      settings->conn_close = option->val.conn_close;
84
1.04k
      continue;
85
100
    case MHD_R_O_HTTP_1_0_COMPATIBLE_STRICT:
86
100
      settings->http_1_0_compatible_strict = option->val.http_1_0_compatible_strict;
87
100
      continue;
88
115
    case MHD_R_O_HTTP_1_0_SERVER:
89
115
      settings->http_1_0_server = option->val.http_1_0_server;
90
115
      continue;
91
120
    case MHD_R_O_INSANITY_HEADER_CONTENT_LENGTH:
92
120
      settings->insanity_header_content_length = option->val.insanity_header_content_length;
93
120
      continue;
94
475
    case MHD_R_O_TERMINATION_CALLBACK:
95
475
      settings->termination_callback.v_ended_cb = option->val.termination_callback.v_ended_cb;
96
475
      settings->termination_callback.v_ended_cb_cls = option->val.termination_callback.v_ended_cb_cls;
97
475
      continue;
98
0
    case MHD_R_O_SENTINEL:
99
0
    default: /* for -Wswitch-default -Wswitch-enum */
100
0
      res = MHD_SC_OPTION_UNKNOWN;
101
0
      i = options_max_num - 1;
102
0
      break;
103
5.02k
    }
104
5.02k
  }
105
106
5.02k
  if (need_unlock)
107
1.17k
    mhd_mutex_unlock_chk(&response->reuse.settings_lock);
108
109
5.02k
  return res;
110
5.02k
}