Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

content_type.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBMIME_CONTENT_TYPE_H_
  17. #define SRC_LIBMIME_CONTENT_TYPE_H_
  18. #include "config.h"
  19. #include "libutil/fstring.h"
  20. #include "libutil/mem_pool.h"
  21. enum rspamd_content_type_flags {
  22. RSPAMD_CONTENT_TYPE_VALID = 0,
  23. RSPAMD_CONTENT_TYPE_BROKEN = 1 << 0,
  24. RSPAMD_CONTENT_TYPE_MULTIPART = 1 << 1,
  25. RSPAMD_CONTENT_TYPE_TEXT = 1 << 2,
  26. RSPAMD_CONTENT_TYPE_MESSAGE = 1 << 3,
  27. RSPAMD_CONTENT_TYPE_DSN = 1 << 4,
  28. RSPAMD_CONTENT_TYPE_MISSING = 1 << 5,
  29. };
  30. #define IS_CT_MULTIPART(ct) ((ct) && ((ct)->flags & RSPAMD_CONTENT_TYPE_MULTIPART))
  31. #define IS_CT_TEXT(ct) ((ct) && ((ct)->flags & RSPAMD_CONTENT_TYPE_TEXT))
  32. #define IS_CT_MESSAGE(ct) ((ct) &&((ct)->flags & RSPAMD_CONTENT_TYPE_MESSAGE))
  33. enum rspamd_content_param_flags {
  34. RSPAMD_CONTENT_PARAM_NORMAL = 0,
  35. RSPAMD_CONTENT_PARAM_RFC2231 = (1 << 0),
  36. RSPAMD_CONTENT_PARAM_PIECEWISE = (1 << 1),
  37. RSPAMD_CONTENT_PARAM_BROKEN = (1 << 2),
  38. };
  39. struct rspamd_content_type_param {
  40. rspamd_ftok_t name;
  41. rspamd_ftok_t value;
  42. guint rfc2231_id;
  43. enum rspamd_content_param_flags flags;
  44. struct rspamd_content_type_param *prev, *next;
  45. };
  46. struct rspamd_content_type {
  47. gchar *cpy;
  48. rspamd_ftok_t type;
  49. rspamd_ftok_t subtype;
  50. rspamd_ftok_t charset;
  51. rspamd_ftok_t boundary;
  52. rspamd_ftok_t orig_boundary;
  53. enum rspamd_content_type_flags flags;
  54. GHashTable *attrs; /* Can be empty */
  55. };
  56. enum rspamd_content_disposition_type {
  57. RSPAMD_CT_UNKNOWN = 0,
  58. RSPAMD_CT_INLINE = 1,
  59. RSPAMD_CT_ATTACHMENT = 2,
  60. };
  61. struct rspamd_content_disposition {
  62. gchar *lc_data;
  63. enum rspamd_content_disposition_type type;
  64. rspamd_ftok_t filename;
  65. GHashTable *attrs; /* Can be empty */
  66. };
  67. /**
  68. * Adds new parameter to content type structure
  69. * @param ct
  70. * @param name_start (can be modified)
  71. * @param name_end
  72. * @param value_start (can be modified)
  73. * @param value_end
  74. */
  75. void
  76. rspamd_content_type_add_param (rspamd_mempool_t *pool,
  77. struct rspamd_content_type *ct,
  78. gchar *name_start, gchar *name_end,
  79. gchar *value_start, gchar *value_end);
  80. /**
  81. * Parse content type from the header (performs copy + lowercase)
  82. * @param in
  83. * @param len
  84. * @param pool
  85. * @return
  86. */
  87. struct rspamd_content_type * rspamd_content_type_parse (const gchar *in,
  88. gsize len, rspamd_mempool_t *pool);
  89. /**
  90. * Adds new param for content disposition header
  91. * @param pool
  92. * @param cd
  93. * @param name_start
  94. * @param name_end
  95. * @param value_start
  96. * @param value_end
  97. */
  98. void
  99. rspamd_content_disposition_add_param (rspamd_mempool_t *pool,
  100. struct rspamd_content_disposition *cd,
  101. const gchar *name_start, const gchar *name_end,
  102. const gchar *value_start, const gchar *value_end);
  103. /**
  104. * Parse content-disposition header
  105. * @param in
  106. * @param len
  107. * @param pool
  108. * @return
  109. */
  110. struct rspamd_content_disposition * rspamd_content_disposition_parse (const gchar *in,
  111. gsize len, rspamd_mempool_t *pool);
  112. #endif /* SRC_LIBMIME_CONTENT_TYPE_H_ */