nghttp2_option.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2015-2018 Alibaba Group Holding Limited
  3. */
  4. #include <string.h>
  5. #include "nghttp2_option.h"
  6. #include "nghttp2_session.h"
  7. #ifdef INFRA_MEM_STATS
  8. #include "infra_mem_stats.h"
  9. #endif
  10. extern void *HAL_Malloc(uint32_t size);
  11. extern void *HAL_Realloc(void *ptr, uint32_t size);
  12. extern void HAL_Free(void *ptr);
  13. #if INFRA_MEM_STATS
  14. #define NGHTTP2_OPTION_MALLOC(size) LITE_malloc(size, MEM_MAGIC, "nghttp2.option")
  15. #define NGHTTP2_OPTION_FREE(ptr) LITE_free(ptr)
  16. #else
  17. #define NGHTTP2_OPTION_MALLOC(size) HAL_Malloc(size)
  18. #define NGHTTP2_OPTION_FREE(ptr) {HAL_Free((void *)ptr);ptr = NULL;}
  19. #endif
  20. int nghttp2_option_new(nghttp2_option **option_ptr) {
  21. *option_ptr = NGHTTP2_OPTION_MALLOC(sizeof(nghttp2_option));
  22. if (*option_ptr == NULL) {
  23. return NGHTTP2_ERR_NOMEM;
  24. }
  25. memset(*option_ptr, 0, sizeof(nghttp2_option));
  26. return 0;
  27. }
  28. void nghttp2_option_del(nghttp2_option *option) { NGHTTP2_OPTION_FREE(option); }
  29. void nghttp2_option_set_no_auto_window_update(nghttp2_option *option, int val) {
  30. option->opt_set_mask |= NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE;
  31. option->no_auto_window_update = val;
  32. }
  33. void nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option,
  34. uint32_t val) {
  35. option->opt_set_mask |= NGHTTP2_OPT_PEER_MAX_CONCURRENT_STREAMS;
  36. option->peer_max_concurrent_streams = val;
  37. }
  38. void nghttp2_option_set_no_recv_client_magic(nghttp2_option *option, int val) {
  39. option->opt_set_mask |= NGHTTP2_OPT_NO_RECV_CLIENT_MAGIC;
  40. option->no_recv_client_magic = val;
  41. }
  42. void nghttp2_option_set_no_http_messaging(nghttp2_option *option, int val) {
  43. option->opt_set_mask |= NGHTTP2_OPT_NO_HTTP_MESSAGING;
  44. option->no_http_messaging = val;
  45. }
  46. void nghttp2_option_set_max_reserved_remote_streams(nghttp2_option *option,
  47. uint32_t val) {
  48. option->opt_set_mask |= NGHTTP2_OPT_MAX_RESERVED_REMOTE_STREAMS;
  49. option->max_reserved_remote_streams = val;
  50. }
  51. static void set_ext_type(uint8_t *ext_types, uint8_t type) {
  52. ext_types[type / 8] = (uint8_t)(ext_types[type / 8] | (1 << (type & 0x7)));
  53. }
  54. void nghttp2_option_set_user_recv_extension_type(nghttp2_option *option,
  55. uint8_t type) {
  56. if (type < 10) {
  57. return;
  58. }
  59. option->opt_set_mask |= NGHTTP2_OPT_USER_RECV_EXT_TYPES;
  60. set_ext_type(option->user_recv_ext_types, type);
  61. }
  62. void nghttp2_option_set_builtin_recv_extension_type(nghttp2_option *option,
  63. uint8_t type) {
  64. switch (type) {
  65. case NGHTTP2_ALTSVC:
  66. option->opt_set_mask |= NGHTTP2_OPT_BUILTIN_RECV_EXT_TYPES;
  67. option->builtin_recv_ext_types |= NGHTTP2_TYPEMASK_ALTSVC;
  68. return;
  69. default:
  70. return;
  71. }
  72. }
  73. void nghttp2_option_set_no_auto_ping_ack(nghttp2_option *option, int val) {
  74. option->opt_set_mask |= NGHTTP2_OPT_NO_AUTO_PING_ACK;
  75. option->no_auto_ping_ack = val;
  76. }
  77. void nghttp2_option_set_max_send_header_block_length(nghttp2_option *option,
  78. size_t val) {
  79. option->opt_set_mask |= NGHTTP2_OPT_MAX_SEND_HEADER_BLOCK_LENGTH;
  80. option->max_send_header_block_length = val;
  81. }
  82. void nghttp2_option_set_max_deflate_dynamic_table_size(nghttp2_option *option,
  83. size_t val) {
  84. option->opt_set_mask |= NGHTTP2_OPT_MAX_DEFLATE_DYNAMIC_TABLE_SIZE;
  85. option->max_deflate_dynamic_table_size = val;
  86. }
  87. void nghttp2_option_set_no_closed_streams(nghttp2_option *option, int val) {
  88. option->opt_set_mask |= NGHTTP2_OPT_NO_CLOSED_STREAMS;
  89. option->no_closed_streams = val;
  90. }