Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (c) 2010, Vsevolod Stakhov
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
  13. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
  16. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  18. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef KVSTORAGE_SERVER_H_
  24. #define KVSTORAGE_SERVER_H_
  25. #include "config.h"
  26. #include "mem_pool.h"
  27. #include "buffer.h"
  28. /* Configuration context for kvstorage worker */
  29. struct kvstorage_worker_ctx {
  30. struct timeval io_timeout;
  31. guint32 timeout_raw;
  32. GList *threads;
  33. gint s_pair[2];
  34. gboolean is_redis;
  35. memory_pool_t *pool;
  36. struct event_base *ev_base;
  37. GStaticMutex log_mtx;
  38. GStaticMutex accept_mtx;
  39. };
  40. struct kvstorage_worker_thread {
  41. struct event bind_ev;
  42. struct timeval *tv;
  43. struct kvstorage_worker_ctx *ctx;
  44. struct rspamd_worker *worker;
  45. GThread *thr;
  46. struct event_base *ev_base;
  47. GStaticMutex *log_mtx;
  48. GStaticMutex *accept_mtx;
  49. guint id;
  50. sigset_t *signals;
  51. };
  52. struct kvstorage_session {
  53. rspamd_io_dispatcher_t *dispather;
  54. enum {
  55. KVSTORAGE_STATE_READ_CMD,
  56. KVSTORAGE_STATE_READ_ARGLEN,
  57. KVSTORAGE_STATE_READ_ARG,
  58. KVSTORAGE_STATE_READ_DATA
  59. } state;
  60. enum {
  61. KVSTORAGE_CMD_SET,
  62. KVSTORAGE_CMD_GET,
  63. KVSTORAGE_CMD_DELETE,
  64. KVSTORAGE_CMD_SYNC,
  65. KVSTORAGE_CMD_SELECT,
  66. KVSTORAGE_CMD_INCR,
  67. KVSTORAGE_CMD_DECR,
  68. KVSTORAGE_CMD_QUIT
  69. } command;
  70. guint id;
  71. guint argc;
  72. guint argnum;
  73. memory_pool_t *pool;
  74. gchar *key;
  75. guint keylen;
  76. struct kvstorage_config *cf;
  77. struct kvstorage_worker_thread *thr;
  78. struct rspamd_kv_element *elt;
  79. struct in_addr client_addr;
  80. gint sock;
  81. guint flags;
  82. guint expire;
  83. union {
  84. glong value;
  85. guint length;
  86. } arg_data;
  87. time_t now;
  88. };
  89. #endif /* KVSTORAGE_SERVER_H_ */