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.

content_disposition_parser.rl 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. %%{
  2. machine content_type_parser;
  3. alphtype unsigned char;
  4. action Disposition_Start {
  5. }
  6. action Disposition_End {
  7. }
  8. action Disposition_Inline {
  9. cd->type = RSPAMD_CT_INLINE;
  10. }
  11. action Disposition_Attachment {
  12. cd->type = RSPAMD_CT_ATTACHMENT;
  13. }
  14. action Param_Name_Start {
  15. qstart = NULL;
  16. qend = NULL;
  17. pname_start = p;
  18. pname_end = NULL;
  19. }
  20. action Param_Name_End {
  21. if (qstart) {
  22. pname_start = qstart;
  23. }
  24. if (qend && qend >= qstart) {
  25. pname_end = qend;
  26. }
  27. else if (p >= pname_start) {
  28. pname_end = p;
  29. }
  30. qstart = NULL;
  31. qend = NULL;
  32. }
  33. action Param_Value_Start {
  34. qstart = NULL;
  35. qend = NULL;
  36. if (pname_end) {
  37. pvalue_start = p;
  38. pvalue_end = NULL;
  39. }
  40. }
  41. action Param_Value_End {
  42. if (pname_end) {
  43. if (qstart) {
  44. pvalue_start = qstart;
  45. }
  46. if (qend && qend >= qstart) {
  47. pvalue_end = qend;
  48. }
  49. else if (p >= pvalue_start) {
  50. pvalue_end = p;
  51. }
  52. qstart = NULL;
  53. qend = NULL;
  54. if (pvalue_end && pvalue_end > pvalue_start && pname_end > pname_start) {
  55. rspamd_content_disposition_add_param (pool, cd, pname_start, pname_end, pvalue_start, pvalue_end);
  56. }
  57. }
  58. pname_start = NULL;
  59. pname_end = NULL;
  60. pvalue_start = NULL;
  61. pvalue_end = NULL;
  62. qend = NULL;
  63. qstart = NULL;
  64. }
  65. action Quoted_Str_Start {
  66. qstart = p;
  67. qend = NULL;
  68. }
  69. action Quoted_Str_End {
  70. if (qstart) {
  71. qend = p;
  72. }
  73. }
  74. include smtp_base "smtp_base.rl";
  75. include content_disposition "content_disposition.rl";
  76. main := content_disposition;
  77. }%%
  78. #include "smtp_parsers.h"
  79. #include "content_type.h"
  80. %% write data;
  81. gboolean
  82. rspamd_content_disposition_parser (const char *data, size_t len, struct rspamd_content_disposition *cd, rspamd_mempool_t *pool)
  83. {
  84. const unsigned char *p = data, *pe = data + len, *eof, *qstart = NULL, *qend = NULL,
  85. *pname_start = NULL, *pname_end = NULL, *pvalue_start = NULL, *pvalue_end = NULL;
  86. int cs, *stack = NULL;
  87. gsize top = 0;
  88. struct _ragel_st_storage {
  89. int *data;
  90. gsize size;
  91. } st_storage;
  92. memset (&st_storage, 0, sizeof (st_storage));
  93. memset (cd, 0, sizeof (*cd));
  94. eof = pe;
  95. %% write init;
  96. %% write exec;
  97. if (st_storage.data) {
  98. free (st_storage.data);
  99. }
  100. return cd->attrs != NULL || cd->type != RSPAMD_CT_UNKNOWN;
  101. }