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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*-
  2. * Copyright 2021 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 RSPAMD_HTML_H
  17. #define RSPAMD_HTML_H
  18. #include "config.h"
  19. #include "libutil/mem_pool.h"
  20. #include "libserver/url.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /*
  25. * HTML content flags
  26. */
  27. #define RSPAMD_HTML_FLAG_BAD_START (1 << 0)
  28. #define RSPAMD_HTML_FLAG_BAD_ELEMENTS (1 << 1)
  29. #define RSPAMD_HTML_FLAG_XML (1 << 2)
  30. #define RSPAMD_HTML_FLAG_UNBALANCED (1 << 3)
  31. #define RSPAMD_HTML_FLAG_UNKNOWN_ELEMENTS (1 << 4)
  32. #define RSPAMD_HTML_FLAG_DUPLICATE_ELEMENTS (1 << 5)
  33. #define RSPAMD_HTML_FLAG_TOO_MANY_TAGS (1 << 6)
  34. #define RSPAMD_HTML_FLAG_HAS_DATA_URLS (1 << 7)
  35. #define RSPAMD_HTML_FLAG_HAS_ZEROS (1 << 8)
  36. /*
  37. * Image flags
  38. */
  39. #define RSPAMD_HTML_FLAG_IMAGE_EMBEDDED (1 << 0)
  40. #define RSPAMD_HTML_FLAG_IMAGE_EXTERNAL (1 << 1)
  41. #define RSPAMD_HTML_FLAG_IMAGE_DATA (1 << 2)
  42. struct rspamd_image;
  43. struct html_image {
  44. unsigned int height;
  45. unsigned int width;
  46. unsigned int flags;
  47. char *src;
  48. struct rspamd_url *url;
  49. struct rspamd_image *embedded_image;
  50. void *tag;
  51. };
  52. /* Forwarded declaration */
  53. struct rspamd_task;
  54. /*
  55. * Decode HTML entitles in text. Text is modified in place.
  56. */
  57. unsigned int rspamd_html_decode_entitles_inplace(char *s, gsize len);
  58. void *rspamd_html_process_part(rspamd_mempool_t *pool,
  59. GByteArray *in);
  60. void *rspamd_html_process_part_full(struct rspamd_task *task,
  61. GByteArray *in, GList **exceptions,
  62. khash_t(rspamd_url_hash) * url_set,
  63. GPtrArray *part_urls,
  64. bool allow_css,
  65. uint16_t *cur_url_order);
  66. /*
  67. * Returns true if a specified tag has been seen in a part
  68. */
  69. gboolean rspamd_html_tag_seen(void *ptr, const char *tagname);
  70. /**
  71. * Returns name for the specified tag id
  72. * @param id
  73. * @return
  74. */
  75. const char *rspamd_html_tag_by_id(int id);
  76. /**
  77. * Returns HTML tag id by name
  78. * @param name
  79. * @return
  80. */
  81. int rspamd_html_tag_by_name(const char *name);
  82. /**
  83. * Gets a name for a tag
  84. * @param tag
  85. * @param len
  86. * @return
  87. */
  88. const char *rspamd_html_tag_name(void *tag, gsize *len);
  89. /**
  90. * Find HTML image by content id
  91. * @param html_content
  92. * @param cid
  93. * @param cid_len
  94. * @return
  95. */
  96. struct html_image *rspamd_html_find_embedded_image(void *html_content,
  97. const char *cid, gsize cid_len);
  98. /**
  99. * Stores parsed content in ftok_t structure
  100. * @param html_content
  101. * @param dest
  102. * @return
  103. */
  104. bool rspamd_html_get_parsed_content(void *html_content, rspamd_ftok_t *dest);
  105. /**
  106. * Returns number of tags in the html content
  107. * @param html_content
  108. * @return
  109. */
  110. gsize rspamd_html_get_tags_count(void *html_content);
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif