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_type.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. enum rspamd_content_type_flags {
  25. RSPAMD_CONTENT_TYPE_VALID = 0,
  26. RSPAMD_CONTENT_TYPE_BROKEN = 1 << 0,
  27. RSPAMD_CONTENT_TYPE_MULTIPART = 1 << 1,
  28. RSPAMD_CONTENT_TYPE_TEXT = 1 << 2,
  29. RSPAMD_CONTENT_TYPE_MESSAGE = 1 << 3,
  30. RSPAMD_CONTENT_TYPE_DSN = 1 << 4,
  31. RSPAMD_CONTENT_TYPE_MISSING = 1 << 5,
  32. RSPAMD_CONTENT_TYPE_ENCRYPTED = 1 << 6,
  33. RSPAMD_CONTENT_TYPE_SMIME = 1 << 7,
  34. };
  35. enum rspamd_content_param_flags {
  36. RSPAMD_CONTENT_PARAM_NORMAL = 0,
  37. RSPAMD_CONTENT_PARAM_RFC2231 = (1 << 0),
  38. RSPAMD_CONTENT_PARAM_PIECEWISE = (1 << 1),
  39. RSPAMD_CONTENT_PARAM_BROKEN = (1 << 2),
  40. };
  41. struct rspamd_content_type_param {
  42. rspamd_ftok_t name;
  43. rspamd_ftok_t value;
  44. unsigned int rfc2231_id;
  45. enum rspamd_content_param_flags flags;
  46. struct rspamd_content_type_param *prev, *next;
  47. };
  48. struct rspamd_content_type {
  49. char *cpy;
  50. rspamd_ftok_t type;
  51. rspamd_ftok_t subtype;
  52. rspamd_ftok_t charset;
  53. rspamd_ftok_t boundary;
  54. rspamd_ftok_t orig_boundary;
  55. enum rspamd_content_type_flags flags;
  56. GHashTable *attrs; /* Can be empty */
  57. };
  58. enum rspamd_content_disposition_type {
  59. RSPAMD_CT_UNKNOWN = 0,
  60. RSPAMD_CT_INLINE = 1,
  61. RSPAMD_CT_ATTACHMENT = 2,
  62. };
  63. struct rspamd_content_disposition {
  64. char *lc_data;
  65. enum rspamd_content_disposition_type type;
  66. rspamd_ftok_t filename;
  67. GHashTable *attrs; /* Can be empty */
  68. };
  69. /**
  70. * Adds new parameter to content type structure
  71. * @param ct
  72. * @param name_start (can be modified)
  73. * @param name_end
  74. * @param value_start (can be modified)
  75. * @param value_end
  76. */
  77. void rspamd_content_type_add_param(rspamd_mempool_t *pool,
  78. struct rspamd_content_type *ct,
  79. char *name_start, char *name_end,
  80. char *value_start, char *value_end);
  81. /**
  82. * Parse content type from the header (performs copy + lowercase)
  83. * @param in
  84. * @param len
  85. * @param pool
  86. * @return
  87. */
  88. struct rspamd_content_type *rspamd_content_type_parse(const char *in,
  89. gsize len, rspamd_mempool_t *pool);
  90. /**
  91. * Adds new param for content disposition header
  92. * @param pool
  93. * @param cd
  94. * @param name_start
  95. * @param name_end
  96. * @param value_start
  97. * @param value_end
  98. */
  99. void rspamd_content_disposition_add_param(rspamd_mempool_t *pool,
  100. struct rspamd_content_disposition *cd,
  101. const char *name_start, const char *name_end,
  102. const char *value_start, const char *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 char *in,
  111. gsize len,
  112. rspamd_mempool_t *pool);
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif /* SRC_LIBMIME_CONTENT_TYPE_H_ */