You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http_private.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright 2024 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBUTIL_HTTP_PRIVATE_H_
  17. #define SRC_LIBUTIL_HTTP_PRIVATE_H_
  18. #include "http_connection.h"
  19. #include "http_parser.h"
  20. #include "str_util.h"
  21. #include "keypair.h"
  22. #include "keypairs_cache.h"
  23. #include "ref.h"
  24. #include "upstream.h"
  25. #include "khash.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. * HTTP header structure
  31. */
  32. struct rspamd_http_header {
  33. rspamd_fstring_t *combined;
  34. rspamd_ftok_t name;
  35. rspamd_ftok_t value;
  36. struct rspamd_http_header *prev, *next;
  37. };
  38. KHASH_INIT(rspamd_http_headers_hash, rspamd_ftok_t *,
  39. struct rspamd_http_header *, 1,
  40. rspamd_ftok_icase_hash, rspamd_ftok_icase_equal);
  41. /**
  42. * HTTP message structure, used for requests and replies
  43. */
  44. struct rspamd_http_message {
  45. rspamd_fstring_t *url;
  46. GString *host;
  47. rspamd_fstring_t *status;
  48. khash_t(rspamd_http_headers_hash) * headers;
  49. struct _rspamd_body_buf_s {
  50. /* Data start */
  51. const gchar *begin;
  52. /* Data len */
  53. gsize len;
  54. /* Allocated len */
  55. gsize allocated_len;
  56. /* Data buffer (used to write data inside) */
  57. gchar *str;
  58. /* Internal storage */
  59. union _rspamd_storage_u {
  60. rspamd_fstring_t *normal;
  61. struct _rspamd_storage_shared_s {
  62. struct rspamd_storage_shmem *name;
  63. gint shm_fd;
  64. } shared;
  65. } c;
  66. } body_buf;
  67. struct rspamd_cryptobox_pubkey *peer_key;
  68. time_t date;
  69. time_t last_modified;
  70. unsigned port;
  71. int type;
  72. gint code;
  73. enum http_method method;
  74. gint flags;
  75. ref_entry_t ref;
  76. };
  77. struct rspamd_keepalive_hash_key {
  78. rspamd_inet_addr_t *addr;
  79. gchar *host;
  80. gboolean is_ssl;
  81. unsigned port;
  82. GQueue conns;
  83. };
  84. int32_t rspamd_keep_alive_key_hash(struct rspamd_keepalive_hash_key *k);
  85. bool rspamd_keep_alive_key_equal(struct rspamd_keepalive_hash_key *k1,
  86. struct rspamd_keepalive_hash_key *k2);
  87. KHASH_INIT(rspamd_keep_alive_hash, struct rspamd_keepalive_hash_key *,
  88. char, 0, rspamd_keep_alive_key_hash, rspamd_keep_alive_key_equal);
  89. struct rspamd_http_context {
  90. struct rspamd_http_context_cfg config;
  91. struct rspamd_keypair_cache *client_kp_cache;
  92. struct rspamd_cryptobox_keypair *client_kp;
  93. struct rspamd_keypair_cache *server_kp_cache;
  94. struct upstream_ctx *ups_ctx;
  95. struct upstream_list *http_proxies;
  96. gpointer ssl_ctx;
  97. gpointer ssl_ctx_noverify;
  98. struct ev_loop *event_loop;
  99. ev_timer client_rotate_ev;
  100. khash_t(rspamd_keep_alive_hash) * keep_alive_hash;
  101. };
  102. #define HTTP_ERROR http_error_quark()
  103. GQuark http_error_quark(void);
  104. void rspamd_http_message_storage_cleanup(struct rspamd_http_message *msg);
  105. gboolean rspamd_http_message_grow_body(struct rspamd_http_message *msg,
  106. gsize len);
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* SRC_LIBUTIL_HTTP_PRIVATE_H_ */