選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

protocol.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @file protocol.h
  3. * Rspamd protocol definition
  4. */
  5. #ifndef RSPAMD_PROTOCOL_H
  6. #define RSPAMD_PROTOCOL_H
  7. #include "config.h"
  8. #include "scan_result.h"
  9. #include "libserver/http/http_connection.h"
  10. #include "task.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #define RSPAMD_BASE_ERROR 500
  15. #define RSPAMD_FILTER_ERROR RSPAMD_BASE_ERROR + 1
  16. #define RSPAMD_NETWORK_ERROR RSPAMD_BASE_ERROR + 2
  17. #define RSPAMD_PROTOCOL_ERROR RSPAMD_BASE_ERROR + 3
  18. #define RSPAMD_LENGTH_ERROR RSPAMD_BASE_ERROR + 4
  19. #define RSPAMD_STATFILE_ERROR RSPAMD_BASE_ERROR + 5
  20. struct rspamd_protocol_log_symbol_result {
  21. guint32 id;
  22. float score;
  23. };
  24. struct rspamd_protocol_log_message_sum {
  25. guint32 nresults;
  26. guint32 nextra;
  27. guint32 settings_id;
  28. gdouble score;
  29. gdouble required_score;
  30. struct rspamd_protocol_log_symbol_result results[];
  31. };
  32. struct rspamd_metric;
  33. /**
  34. * Process headers into HTTP message and set appropriate task fields
  35. * @param task
  36. * @param msg
  37. * @return
  38. */
  39. gboolean rspamd_protocol_handle_headers (struct rspamd_task *task,
  40. struct rspamd_http_message *msg);
  41. /**
  42. * Process control chunk and update task structure accordingly
  43. * @param task
  44. * @param control
  45. * @return
  46. */
  47. gboolean rspamd_protocol_handle_control (struct rspamd_task *task,
  48. const ucl_object_t *control);
  49. /**
  50. * Process HTTP request to the task structure
  51. * @param task
  52. * @param msg
  53. * @return
  54. */
  55. gboolean rspamd_protocol_handle_request (struct rspamd_task *task,
  56. struct rspamd_http_message *msg);
  57. /**
  58. * Write task results to http message
  59. * @param msg
  60. * @param task
  61. */
  62. void rspamd_protocol_http_reply (struct rspamd_http_message *msg,
  63. struct rspamd_task *task, ucl_object_t **pobj);
  64. /**
  65. * Write data to log pipes
  66. * @param task
  67. */
  68. void rspamd_protocol_write_log_pipe (struct rspamd_task *task);
  69. enum rspamd_protocol_flags {
  70. RSPAMD_PROTOCOL_BASIC = 1 << 0,
  71. RSPAMD_PROTOCOL_METRICS = 1 << 1,
  72. RSPAMD_PROTOCOL_MESSAGES = 1 << 2,
  73. RSPAMD_PROTOCOL_RMILTER = 1 << 3,
  74. RSPAMD_PROTOCOL_DKIM = 1 << 4,
  75. RSPAMD_PROTOCOL_URLS = 1 << 5,
  76. RSPAMD_PROTOCOL_EXTRA = 1 << 6,
  77. };
  78. #define RSPAMD_PROTOCOL_DEFAULT (RSPAMD_PROTOCOL_BASIC| \
  79. RSPAMD_PROTOCOL_METRICS| \
  80. RSPAMD_PROTOCOL_MESSAGES| \
  81. RSPAMD_PROTOCOL_RMILTER| \
  82. RSPAMD_PROTOCOL_DKIM| \
  83. RSPAMD_PROTOCOL_EXTRA)
  84. /**
  85. * Write reply to ucl object filling log buffer
  86. * @param task
  87. * @param logbuf
  88. * @return
  89. */
  90. ucl_object_t *rspamd_protocol_write_ucl (struct rspamd_task *task,
  91. enum rspamd_protocol_flags flags);
  92. /**
  93. * Write reply for specified task command
  94. * @param task task object
  95. * @return 0 if we wrote reply and -1 if there was some error
  96. */
  97. void rspamd_protocol_write_reply (struct rspamd_task *task, ev_tstamp timeout);
  98. /**
  99. * Convert rspamd output to legacy protocol reply
  100. * @param task
  101. * @param top
  102. * @param out
  103. */
  104. void rspamd_ucl_torspamc_output (const ucl_object_t *top,
  105. rspamd_fstring_t **out);
  106. void rspamd_ucl_tospamc_output (const ucl_object_t *top,
  107. rspamd_fstring_t **out);
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. #endif