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.

smtp_date_parser.rl 1013B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. %%{
  2. machine smtp_date_parser;
  3. alphtype unsigned char;
  4. include smtp_base "smtp_base.rl";
  5. include smtp_date "smtp_date.rl";
  6. main := date_time;
  7. }%%
  8. #include "smtp_parsers.h"
  9. #include "util.h"
  10. %% write data;
  11. uint64_t
  12. rspamd_parse_smtp_date (const unsigned char *data, size_t len, GError **err)
  13. {
  14. const unsigned char *p = data, *pe = data + len, *eof = data + len, *tmp = data;
  15. struct tm tm;
  16. glong tz = 0;
  17. int cs = 0, *stack = NULL;;
  18. gsize top = 0;
  19. memset (&tm, 0, sizeof (tm));
  20. struct _ragel_st_storage {
  21. int *data;
  22. gsize size;
  23. } st_storage;
  24. memset (&st_storage, 0, sizeof (st_storage));
  25. %% write init;
  26. %% write exec;
  27. if (st_storage.data) {
  28. free (st_storage.data);
  29. }
  30. if ( cs < %%{ write first_final; }%% ) {
  31. g_set_error (err, g_quark_from_static_string ("smtp_date"), cs, "invalid date at offset %d (%c), state %d",
  32. (int)(p - data), (*p > 0 && *p < 128) ? *p : '?', cs);
  33. return (uint64_t)(-1);
  34. }
  35. return rspamd_tm_to_time (&tm, tz);
  36. }