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.

rspamd_expression_test.c 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <sys/types.h>
  2. #include <sys/time.h>
  3. #include <sys/wait.h>
  4. #include <sys/param.h>
  5. #include <netinet/in.h>
  6. #include <arpa/inet.h>
  7. #include <netdb.h>
  8. #include <syslog.h>
  9. #include <fcntl.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include "../src/config.h"
  14. #include "../src/main.h"
  15. #include "../src/cfg_file.h"
  16. #include "tests.h"
  17. /* Vector of test expressions */
  18. char *test_expressions[] = {
  19. "(A&B|!C)&!(D|E)",
  20. "/test&!/&!/\\/|/",
  21. NULL
  22. };
  23. void
  24. rspamd_expression_test_func ()
  25. {
  26. memory_pool_t *pool;
  27. struct expression *cur;
  28. char **line, *outstr;
  29. int r, s;
  30. pool = memory_pool_new (1024);
  31. line = test_expressions;
  32. while (*line) {
  33. r = 0;
  34. cur = parse_expression (pool, *line);
  35. s = strlen (*line) + 1;
  36. outstr = memory_pool_alloc (pool, s);
  37. while (cur) {
  38. if (cur->type == EXPR_OPERAND) {
  39. r += snprintf (outstr + r, s - r, "%s", (char *)cur->content.operand);
  40. }
  41. else {
  42. r += snprintf (outstr + r, s - r, "%c", cur->content.operation);
  43. }
  44. cur = cur->next;
  45. }
  46. msg_debug ("Parsed expression: '%s' -> '%s'", *line, outstr);
  47. line ++;
  48. }
  49. memory_pool_delete (pool);
  50. }