11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * nghttp2 - HTTP/2 C Library
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Copyright (c) 2014 Tatsuhiro Tsujikawa
51cb0ef41Sopenharmony_ci *
61cb0ef41Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining
71cb0ef41Sopenharmony_ci * a copy of this software and associated documentation files (the
81cb0ef41Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
91cb0ef41Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
101cb0ef41Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to
111cb0ef41Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
121cb0ef41Sopenharmony_ci * the following conditions:
131cb0ef41Sopenharmony_ci *
141cb0ef41Sopenharmony_ci * The above copyright notice and this permission notice shall be
151cb0ef41Sopenharmony_ci * included in all copies or substantial portions of the Software.
161cb0ef41Sopenharmony_ci *
171cb0ef41Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
181cb0ef41Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
191cb0ef41Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
201cb0ef41Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
211cb0ef41Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
221cb0ef41Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
231cb0ef41Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
241cb0ef41Sopenharmony_ci */
251cb0ef41Sopenharmony_ci#include "nghttp2_option.h"
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci#include "nghttp2_session.h"
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciint nghttp2_option_new(nghttp2_option **option_ptr) {
301cb0ef41Sopenharmony_ci  *option_ptr = calloc(1, sizeof(nghttp2_option));
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  if (*option_ptr == NULL) {
331cb0ef41Sopenharmony_ci    return NGHTTP2_ERR_NOMEM;
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  return 0;
371cb0ef41Sopenharmony_ci}
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_civoid nghttp2_option_del(nghttp2_option *option) { free(option); }
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_civoid nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val) {
421cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE;
431cb0ef41Sopenharmony_ci  option->no_auto_window_update = val;
441cb0ef41Sopenharmony_ci}
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_civoid nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
471cb0ef41Sopenharmony_ci                                                    uint32_t val) {
481cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS;
491cb0ef41Sopenharmony_ci  option->peer_max_concurrent_streams = val;
501cb0ef41Sopenharmony_ci}
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_civoid nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val) {
531cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_NO_RECV_CLIENT_MAGIC;
541cb0ef41Sopenharmony_ci  option->no_recv_client_magic = val;
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_civoid nghttp2_option_set_no_http_messaging(nghttp2_option *option, int val) {
581cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_NO_HTTP_MESSAGING;
591cb0ef41Sopenharmony_ci  option->no_http_messaging = val;
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_civoid nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option,
631cb0ef41Sopenharmony_ci                                                    uint32_t val) {
641cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_MAX_RESERVED_REMOTE_STREAMS;
651cb0ef41Sopenharmony_ci  option->max_reserved_remote_streams = val;
661cb0ef41Sopenharmony_ci}
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_cistatic void set_ext_type(uint8_t *ext_types, uint8_t type) {
691cb0ef41Sopenharmony_ci  ext_types[type / 8] = (uint8_t)(ext_types[type / 8] | (1 << (type & 0x7)));
701cb0ef41Sopenharmony_ci}
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_civoid nghttp2_option_set_user_recv_extension_type(nghttp2_option *option,
731cb0ef41Sopenharmony_ci                                                 uint8_t type) {
741cb0ef41Sopenharmony_ci  if (type < 10) {
751cb0ef41Sopenharmony_ci    return;
761cb0ef41Sopenharmony_ci  }
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_USER_RECV_EXT_TYPES;
791cb0ef41Sopenharmony_ci  set_ext_type(option->user_recv_ext_types, type);
801cb0ef41Sopenharmony_ci}
811cb0ef41Sopenharmony_ci
821cb0ef41Sopenharmony_civoid nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option,
831cb0ef41Sopenharmony_ci                                                    uint8_t type) {
841cb0ef41Sopenharmony_ci  switch (type) {
851cb0ef41Sopenharmony_ci  case NGHTTP2_ALTSVC:
861cb0ef41Sopenharmony_ci    option->opt_set_mask |= NGHTTP2_OPT_BUILTIN_RECV_EXT_TYPES;
871cb0ef41Sopenharmony_ci    option->builtin_recv_ext_types |= NGHTTP2_TYPEMASK_ALTSVC;
881cb0ef41Sopenharmony_ci    return;
891cb0ef41Sopenharmony_ci  case NGHTTP2_ORIGIN:
901cb0ef41Sopenharmony_ci    option->opt_set_mask |= NGHTTP2_OPT_BUILTIN_RECV_EXT_TYPES;
911cb0ef41Sopenharmony_ci    option->builtin_recv_ext_types |= NGHTTP2_TYPEMASK_ORIGIN;
921cb0ef41Sopenharmony_ci    return;
931cb0ef41Sopenharmony_ci  case NGHTTP2_PRIORITY_UPDATE:
941cb0ef41Sopenharmony_ci    option->opt_set_mask |= NGHTTP2_OPT_BUILTIN_RECV_EXT_TYPES;
951cb0ef41Sopenharmony_ci    option->builtin_recv_ext_types |= NGHTTP2_TYPEMASK_PRIORITY_UPDATE;
961cb0ef41Sopenharmony_ci    return;
971cb0ef41Sopenharmony_ci  default:
981cb0ef41Sopenharmony_ci    return;
991cb0ef41Sopenharmony_ci  }
1001cb0ef41Sopenharmony_ci}
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_civoid nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option, int val) {
1031cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_NO_AUTO_PING_ACK;
1041cb0ef41Sopenharmony_ci  option->no_auto_ping_ack = val;
1051cb0ef41Sopenharmony_ci}
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_civoid nghttp2_option_set_max_send_header_block_length(nghttp2_option *option,
1081cb0ef41Sopenharmony_ci                                                     size_t val) {
1091cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_MAX_SEND_HEADER_BLOCK_LENGTH;
1101cb0ef41Sopenharmony_ci  option->max_send_header_block_length = val;
1111cb0ef41Sopenharmony_ci}
1121cb0ef41Sopenharmony_ci
1131cb0ef41Sopenharmony_civoid nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option,
1141cb0ef41Sopenharmony_ci                                                       size_t val) {
1151cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_MAX_DEFLATE_DYNAMIC_TABLE_SIZE;
1161cb0ef41Sopenharmony_ci  option->max_deflate_dynamic_table_size = val;
1171cb0ef41Sopenharmony_ci}
1181cb0ef41Sopenharmony_ci
1191cb0ef41Sopenharmony_civoid nghttp2_option_set_no_closed_streams(nghttp2_option *option, int val) {
1201cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_NO_CLOSED_STREAMS;
1211cb0ef41Sopenharmony_ci  option->no_closed_streams = val;
1221cb0ef41Sopenharmony_ci}
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_civoid nghttp2_option_set_max_outbound_ack(nghttp2_option *option, size_t val) {
1251cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_MAX_OUTBOUND_ACK;
1261cb0ef41Sopenharmony_ci  option->max_outbound_ack = val;
1271cb0ef41Sopenharmony_ci}
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_civoid nghttp2_option_set_max_settings(nghttp2_option *option, size_t val) {
1301cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_MAX_SETTINGS;
1311cb0ef41Sopenharmony_ci  option->max_settings = val;
1321cb0ef41Sopenharmony_ci}
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_civoid nghttp2_option_set_server_fallback_rfc7540_priorities(
1351cb0ef41Sopenharmony_ci    nghttp2_option *option, int val) {
1361cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_SERVER_FALLBACK_RFC7540_PRIORITIES;
1371cb0ef41Sopenharmony_ci  option->server_fallback_rfc7540_priorities = val;
1381cb0ef41Sopenharmony_ci}
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_civoid nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
1411cb0ef41Sopenharmony_ci    nghttp2_option *option, int val) {
1421cb0ef41Sopenharmony_ci  option->opt_set_mask |=
1431cb0ef41Sopenharmony_ci      NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION;
1441cb0ef41Sopenharmony_ci  option->no_rfc9113_leading_and_trailing_ws_validation = val;
1451cb0ef41Sopenharmony_ci}
1461cb0ef41Sopenharmony_ci
1471cb0ef41Sopenharmony_civoid nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
1481cb0ef41Sopenharmony_ci                                                uint64_t burst, uint64_t rate) {
1491cb0ef41Sopenharmony_ci  option->opt_set_mask |= NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT;
1501cb0ef41Sopenharmony_ci  option->stream_reset_burst = burst;
1511cb0ef41Sopenharmony_ci  option->stream_reset_rate = rate;
1521cb0ef41Sopenharmony_ci}
153