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.

dns.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 RSPAMD_DNS_H
  17. #define RSPAMD_DNS_H
  18. #include "config.h"
  19. #include "mem_pool.h"
  20. #include "async_session.h"
  21. #include "logger.h"
  22. #include "rdns.h"
  23. #include "upstream.h"
  24. #include "libutil/hash.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. struct rspamd_config;
  29. struct rspamd_task;
  30. struct rspamd_dns_resolver {
  31. struct rdns_resolver *r;
  32. struct ev_loop *event_loop;
  33. rspamd_lru_hash_t *fails_cache;
  34. void *uidna;
  35. ev_tstamp fails_cache_time;
  36. struct upstream_list *ups;
  37. struct rspamd_config *cfg;
  38. gdouble request_timeout;
  39. guint max_retransmits;
  40. };
  41. /* Rspamd DNS API */
  42. /**
  43. * Init DNS resolver, params are obtained from a config file or system file /etc/resolv.conf
  44. */
  45. struct rspamd_dns_resolver *rspamd_dns_resolver_init (rspamd_logger_t *logger,
  46. struct ev_loop *ev_base,
  47. struct rspamd_config *cfg);
  48. void rspamd_dns_resolver_deinit (struct rspamd_dns_resolver *resolver);
  49. struct rspamd_dns_request_ud;
  50. /**
  51. * Make a DNS request
  52. * @param resolver resolver object
  53. * @param session async session to register event
  54. * @param pool memory pool for storage
  55. * @param cb callback to call on resolve completing
  56. * @param ud user data for callback
  57. * @param type request type
  58. * @param ... string or ip address based on a request type
  59. * @return TRUE if request was sent.
  60. */
  61. struct rspamd_dns_request_ud *rspamd_dns_resolver_request (struct rspamd_dns_resolver *resolver,
  62. struct rspamd_async_session *session,
  63. rspamd_mempool_t *pool,
  64. dns_callback_type cb,
  65. gpointer ud,
  66. enum rdns_request_type type,
  67. const char *name);
  68. gboolean rspamd_dns_resolver_request_task (struct rspamd_task *task,
  69. dns_callback_type cb,
  70. gpointer ud,
  71. enum rdns_request_type type,
  72. const char *name);
  73. gboolean rspamd_dns_resolver_request_task_forced (struct rspamd_task *task,
  74. dns_callback_type cb,
  75. gpointer ud,
  76. enum rdns_request_type type,
  77. const char *name);
  78. /**
  79. * Converts a name into idna from UTF8
  80. * @param resolver resolver (must be initialised)
  81. * @param pool optional memory pool (can be NULL, then you need to g_free) the result
  82. * @param name input name
  83. * @param namelen length of input (-1 for zero terminated)
  84. * @return encoded string
  85. */
  86. gchar* rspamd_dns_resolver_idna_convert_utf8 (struct rspamd_dns_resolver *resolver,
  87. rspamd_mempool_t *pool,
  88. const char *name,
  89. gint namelen,
  90. guint *outlen);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif