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

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