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.

protocol.h 2.8KB

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