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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #define RSPAMD_FILTER_ERROR 1
  10. #define RSPAMD_NETWORK_ERROR 2
  11. #define RSPAMD_PROTOCOL_ERROR 3
  12. #define RSPAMD_LENGTH_ERROR 4
  13. #define RSPAMD_STATFILE_ERROR 5
  14. #define RSPAMC_PROTO_1_0 "1.0"
  15. #define RSPAMC_PROTO_1_1 "1.1"
  16. #define RSPAMC_PROTO_1_2 "1.2"
  17. #define RSPAMC_PROTO_1_3 "1.3"
  18. /*
  19. * Reply messages
  20. */
  21. #define RSPAMD_REPLY_BANNER "RSPAMD"
  22. #define SPAMD_REPLY_BANNER "SPAMD"
  23. #define SPAMD_OK "EX_OK"
  24. /* XXX: try to convert rspamd errors to spamd errors */
  25. #define SPAMD_ERROR "EX_ERROR"
  26. struct worker_task;
  27. struct metric;
  28. enum rspamd_protocol {
  29. SPAMC_PROTO,
  30. RSPAMC_PROTO,
  31. };
  32. enum rspamd_command {
  33. CMD_CHECK,
  34. CMD_SYMBOLS,
  35. CMD_REPORT,
  36. CMD_REPORT_IFSPAM,
  37. CMD_SKIP,
  38. CMD_PING,
  39. CMD_PROCESS,
  40. CMD_LEARN,
  41. CMD_OTHER,
  42. };
  43. typedef gint (*protocol_reply_func)(struct worker_task *task);
  44. struct custom_command {
  45. const gchar *name;
  46. protocol_reply_func func;
  47. };
  48. /**
  49. * Find a character in command in and return pointer to the first part of the string, in is modified to point to the second part of string
  50. * @param in f_str_t input
  51. * @param c separator character
  52. * @return pointer to the first part of string or NULL if there is no separator found
  53. */
  54. gchar* separate_command (f_str_t * in, gchar c);
  55. /**
  56. * Read one line of user's input for specified task
  57. * @param task task object
  58. * @param line line of user's input
  59. * @return 0 if line was successfully parsed and -1 if we have protocol error
  60. */
  61. gboolean read_rspamd_input_line (struct worker_task *task, f_str_t *line);
  62. /**
  63. * Write reply for specified task command
  64. * @param task task object
  65. * @return 0 if we wrote reply and -1 if there was some error
  66. */
  67. gboolean write_reply (struct worker_task *task) G_GNUC_WARN_UNUSED_RESULT;
  68. /**
  69. * Register custom fucntion to extend protocol
  70. * @param name symbolic name of custom function
  71. * @param func callback function for writing reply
  72. */
  73. void register_protocol_command (const gchar *name, protocol_reply_func func);
  74. #endif