doh.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef HEADER_CURL_DOH_H
  2. #define HEADER_CURL_DOH_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2018 - 2019, 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.haxx.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. Curl_addrinfo *Curl_doh(struct connectdata *conn,
  32. const char *hostname,
  33. int port,
  34. int *waitp);
  35. CURLcode Curl_doh_is_resolved(struct connectdata *conn,
  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. } DOHcode;
  53. typedef enum {
  54. DNS_TYPE_A = 1,
  55. DNS_TYPE_NS = 2,
  56. DNS_TYPE_CNAME = 5,
  57. DNS_TYPE_AAAA = 28
  58. } DNStype;
  59. #define DOH_MAX_ADDR 24
  60. #define DOH_MAX_CNAME 4
  61. struct cnamestore {
  62. size_t len; /* length of cname */
  63. char *alloc; /* allocated pointer */
  64. size_t allocsize; /* allocated size */
  65. };
  66. struct dohaddr {
  67. int type;
  68. union {
  69. unsigned char v4[4]; /* network byte order */
  70. unsigned char v6[16];
  71. } ip;
  72. };
  73. struct dohentry {
  74. unsigned int ttl;
  75. int numaddr;
  76. struct dohaddr addr[DOH_MAX_ADDR];
  77. int numcname;
  78. struct cnamestore cname[DOH_MAX_CNAME];
  79. };
  80. #ifdef DEBUGBUILD
  81. DOHcode doh_encode(const char *host,
  82. DNStype dnstype,
  83. unsigned char *dnsp, /* buffer */
  84. size_t len, /* buffer size */
  85. size_t *olen); /* output length */
  86. DOHcode doh_decode(unsigned char *doh,
  87. size_t dohlen,
  88. DNStype dnstype,
  89. struct dohentry *d);
  90. void de_cleanup(struct dohentry *d);
  91. #endif
  92. #else /* if DOH is disabled */
  93. #define Curl_doh(a,b,c,d) NULL
  94. #define Curl_doh_is_resolved(x,y) CURLE_COULDNT_RESOLVE_HOST
  95. #endif
  96. #endif /* HEADER_CURL_DOH_H */