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.

proxy.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*-
  2. * Copyright 2016 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 PROXY_H_
  17. #define PROXY_H_
  18. #include "config.h"
  19. #include "buffer.h"
  20. #include <event.h>
  21. /**
  22. * @file proxy.h
  23. * Direct asynchronous proxy implementation
  24. */
  25. typedef struct rspamd_proxy_s {
  26. struct event client_ev; /**< event for client's communication */
  27. struct event backend_ev; /**< event for backend communication */
  28. struct event_base *base; /**< base for event operations */
  29. rspamd_mempool_t *pool; /**< memory pool */
  30. dispatcher_err_callback_t err_cb; /**< error callback */
  31. struct event_base *ev_base; /**< event base */
  32. gint cfd; /**< client's socket */
  33. gint bfd; /**< backend's socket */
  34. guint8 *buf; /**< exchange buffer */
  35. gsize bufsize; /**< buffer size */
  36. gint read_len; /**< read length */
  37. gint buf_offset; /**< offset to write */
  38. gpointer user_data; /**< user's data for callbacks */
  39. struct timeval *tv; /**< timeout for communications */
  40. gboolean closed; /**< whether descriptors are closed */
  41. } rspamd_proxy_t;
  42. /**
  43. * Create new proxy between cfd and bfd
  44. * @param cfd client's socket
  45. * @param bfd backend's socket
  46. * @param bufsize size of exchange buffer
  47. * @param err_cb callback for erorrs or completing
  48. * @param ud user data for callback
  49. * @return new proxy object
  50. */
  51. rspamd_proxy_t * rspamd_create_proxy (gint cfd,
  52. gint bfd,
  53. rspamd_mempool_t *pool,
  54. struct event_base *base,
  55. gsize bufsize,
  56. struct timeval *tv,
  57. dispatcher_err_callback_t err_cb,
  58. gpointer ud);
  59. void rspamd_proxy_close (rspamd_proxy_t *proxy);
  60. #endif /* PROXY_H_ */