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.

rspamdclient.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 RSPAMDCLIENT_H_
  17. #define RSPAMDCLIENT_H_
  18. #include "config.h"
  19. #include "ucl.h"
  20. #include "contrib/libev/ev.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. struct rspamd_client_connection;
  25. struct rspamd_http_message;
  26. struct rspamd_http_client_header {
  27. char *name;
  28. char *value;
  29. };
  30. /**
  31. * Callback is called on client connection completed
  32. * @param name name of server
  33. * @param port port for server
  34. * @param result result object
  35. * @param ud opaque user data
  36. * @param err error pointer
  37. */
  38. typedef void (*rspamd_client_callback)(
  39. struct rspamd_client_connection *conn,
  40. struct rspamd_http_message *msg,
  41. const char *name,
  42. ucl_object_t *result,
  43. GString *input,
  44. gpointer ud,
  45. double start_time,
  46. double send_time,
  47. const char *body,
  48. gsize body_len,
  49. GError *err);
  50. struct rspamd_http_context;
  51. /**
  52. * Start rspamd worker or controller command
  53. * @param ev_base event base
  54. * @param name server name (hostname or unix socket)
  55. * @param port port number (in host order)
  56. * @param timeout timeout in seconds
  57. * @return
  58. */
  59. struct rspamd_client_connection *rspamd_client_init(
  60. struct rspamd_http_context *http_ctx,
  61. struct ev_loop *ev_base,
  62. const char *name,
  63. uint16_t port,
  64. double timeout,
  65. const char *key);
  66. /**
  67. *
  68. * @param conn connection object
  69. * @param command command name
  70. * @param attrs additional attributes
  71. * @param in input file or NULL if no input required
  72. * @param cb callback to be called on command completion
  73. * @param ud opaque user data
  74. * @return
  75. */
  76. gboolean rspamd_client_command(
  77. struct rspamd_client_connection *conn,
  78. const char *command,
  79. GQueue *attrs,
  80. FILE *in,
  81. rspamd_client_callback cb,
  82. gpointer ud,
  83. gboolean compressed,
  84. const char *comp_dictionary,
  85. const char *filename,
  86. GError **err);
  87. /**
  88. * Destroy a connection to rspamd
  89. * @param conn
  90. */
  91. void rspamd_client_destroy(struct rspamd_client_connection *conn);
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* RSPAMDCLIENT_H_ */