doh.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef HEADER_CURL_DOH_H
  2. #define HEADER_CURL_DOH_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2018 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "urldata.h"
  25. #include "curl_addrinfo.h"
  26. #ifndef CURL_DISABLE_DOH
  27. /*
  28. * Curl_doh() resolve a name using DoH (DNS-over-HTTPS). It resolves a name
  29. * and returns a 'Curl_addrinfo *' with the address information.
  30. */
  31. struct Curl_addrinfo *Curl_doh(struct Curl_easy *data,
  32. const char *hostname,
  33. int port,
  34. int *waitp);
  35. CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
  36. struct Curl_dns_entry **dns);
  37. int Curl_doh_getsock(struct connectdata *conn, curl_socket_t *socks);
  38. typedef enum {
  39. DOH_OK,
  40. DOH_DNS_BAD_LABEL, /* 1 */
  41. DOH_DNS_OUT_OF_RANGE, /* 2 */
  42. DOH_DNS_LABEL_LOOP, /* 3 */
  43. DOH_TOO_SMALL_BUFFER, /* 4 */
  44. DOH_OUT_OF_MEM, /* 5 */
  45. DOH_DNS_RDATA_LEN, /* 6 */
  46. DOH_DNS_MALFORMAT, /* 7 */
  47. DOH_DNS_BAD_RCODE, /* 8 - no such name */
  48. DOH_DNS_UNEXPECTED_TYPE, /* 9 */
  49. DOH_DNS_UNEXPECTED_CLASS, /* 10 */
  50. DOH_NO_CONTENT, /* 11 */
  51. DOH_DNS_BAD_ID, /* 12 */
  52. DOH_DNS_NAME_TOO_LONG /* 13 */
  53. } DOHcode;
  54. typedef enum {
  55. DNS_TYPE_A = 1,
  56. DNS_TYPE_NS = 2,
  57. DNS_TYPE_CNAME = 5,
  58. DNS_TYPE_AAAA = 28,
  59. DNS_TYPE_DNAME = 39 /* RFC6672 */
  60. } DNStype;
  61. #define DOH_MAX_ADDR 24
  62. #define DOH_MAX_CNAME 4
  63. struct dohaddr {
  64. int type;
  65. union {
  66. unsigned char v4[4]; /* network byte order */
  67. unsigned char v6[16];
  68. } ip;
  69. };
  70. struct dohentry {
  71. struct dynbuf cname[DOH_MAX_CNAME];
  72. struct dohaddr addr[DOH_MAX_ADDR];
  73. int numaddr;
  74. unsigned int ttl;
  75. int numcname;
  76. };
  77. #ifdef DEBUGBUILD
  78. DOHcode doh_encode(const char *host,
  79. DNStype dnstype,
  80. unsigned char *dnsp, /* buffer */
  81. size_t len, /* buffer size */
  82. size_t *olen); /* output length */
  83. DOHcode doh_decode(const unsigned char *doh,
  84. size_t dohlen,
  85. DNStype dnstype,
  86. struct dohentry *d);
  87. void de_init(struct dohentry *d);
  88. void de_cleanup(struct dohentry *d);
  89. #endif
  90. #else /* if DoH is disabled */
  91. #define Curl_doh(a,b,c,d) NULL
  92. #define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
  93. #endif
  94. #endif /* HEADER_CURL_DOH_H */