Home | History | Annotate | Download | only in lib

Lines Matching defs:doh

27 #include "doh.h"
157 /* called from multi.c when this DOH transfer is complete */
158 static int Curl_doh_done(struct Curl_easy *doh, CURLcode result)
160 struct Curl_easy *data = doh->set.dohfor;
161 /* so one of the DOH request done for the 'data' transfer is now complete! */
162 data->req.doh.pending--;
163 infof(data, "a DOH request is completed, %u to go\n", data->req.doh.pending);
165 infof(data, "DOH request %s\n", curl_easy_strerror(result));
167 if(!data->req.doh.pending) {
168 /* DOH completed */
169 curl_slist_free_all(data->req.doh.headers);
170 data->req.doh.headers = NULL;
178 result = curl_easy_setopt(doh, x, y); \
189 struct Curl_easy *doh = NULL;
196 failf(data, "Failed to encode DOH packet [%d]\n", d);
206 /* Note: this is code for sending the DoH request with GET but there's still
228 result = Curl_open(&doh);
311 doh->set.fmultidone = Curl_doh_done;
312 doh->set.dohfor = data; /* identify for which transfer this is done */
313 p->easy = doh;
316 if(curl_multi_add_handle(multi, doh))
326 Curl_close(doh);
331 * Curl_doh() resolves a name using DOH. It resolves a name and returns a
348 memset(&data->req.doh, 0, sizeof(struct dohdata));
350 data->req.doh.host = hostname;
351 data->req.doh.port = port;
352 data->req.doh.headers =
355 if(!data->req.doh.headers)
359 /* create IPv4 DOH request */
360 result = dohprobe(data, &data->req.doh.probe[0], DNS_TYPE_A,
362 data->multi, data->req.doh.headers);
365 data->req.doh.pending++;
369 /* create IPv6 DOH request */
370 result = dohprobe(data, &data->req.doh.probe[1], DNS_TYPE_AAAA,
372 data->multi, data->req.doh.headers);
375 data->req.doh.pending++;
380 curl_slist_free_all(data->req.doh.headers);
381 data->req.doh.headers = NULL;
382 curl_easy_cleanup(data->req.doh.probe[0].easy);
383 data->req.doh.probe[0].easy = NULL;
384 curl_easy_cleanup(data->req.doh.probe[1].easy);
385 data->req.doh.probe[1].easy = NULL;
389 static DOHcode skipqname(unsigned char *doh, size_t dohlen,
396 length = doh[*indexp];
413 static unsigned short get16bit(unsigned char *doh, int index)
415 return (unsigned short)((doh[index] << 8) | doh[index + 1]);
418 static unsigned int get32bit(unsigned char *doh, int index)
420 return (doh[index] << 24) | (doh[index + 1] << 16) |
421 (doh[index + 2] << 8) | doh[index + 3];
424 static DOHcode store_a(unsigned char *doh, int index, struct dohentry *d)
430 memcpy(&a->ip.v4, &doh[index], 4);
436 static DOHcode store_aaaa(unsigned char *doh, int index, struct dohentry *d)
442 memcpy(&a->ip.v6, &doh[index], 16);
474 static DOHcode store_cname(unsigned char *doh,
490 length = doh[index];
498 newpos = (length & 0x3f) << 8 | doh[index + 1];
517 rc = cnameappend(c, &doh[index], length);
529 static DOHcode rdata(unsigned char *doh,
546 rc = store_a(doh, index, d);
553 rc = store_aaaa(doh, index, d);
558 rc = store_cname(doh, dohlen, index, d);
576 UNITTEST DOHcode doh_decode(unsigned char *doh,
594 if(!doh || doh[0] || doh[1])
596 rcode = doh[3] & 0x0f;
600 qdcount = get16bit(doh, 4);
602 rc = skipqname(doh, dohlen, &index);
611 ancount = get16bit(doh, 6);
615 rc = skipqname(doh, dohlen, &index);
622 type = get16bit(doh, index);
630 class = get16bit(doh, index);
638 ttl = get32bit(doh, index);
646 rdlength = get16bit(doh, index);
651 rc = rdata(doh, dohlen, rdlength, type, index, d);
658 nscount = get16bit(doh, 8);
660 rc = skipqname(doh, dohlen, &index);
672 rdlength = get16bit(doh, index);
680 arcount = get16bit(doh, 10);
682 rc = skipqname(doh, dohlen, &index);
694 rdlength = get16bit(doh, index);
721 infof(data, "DOH A: %u.%u.%u.%u\n",
730 msnprintf(buffer, 128, "DOH AAAA: ");
756 * Curl_addrinfo struct linked list filled with the data from a set of DOH
888 if(!data->req.doh.probe[0].easy && !data->req.doh.probe[1].easy) {
889 failf(data, "Could not DOH-resolve: %s", conn->async.hostname);
893 else if(!data->req.doh.pending) {
899 /* remove DOH handles from multi handle and close them */
900 curl_multi_remove_handle(data->multi, data->req.doh.probe[0].easy);
901 Curl_close(data->req.doh.probe[0].easy);
902 curl_multi_remove_handle(data->multi, data->req.doh.probe[1].easy);
903 Curl_close(data->req.doh.probe[1].easy);
907 rc = doh_decode(data->req.doh.probe[0].serverdoh.memory,
908 data->req.doh.probe[0].serverdoh.size,
909 data->req.doh.probe[0].dnstype,
911 free(data->req.doh.probe[0].serverdoh.memory);
913 infof(data, "DOH: %s type %s for %s\n", doh_strerror(rc),
914 type2name(data->req.doh.probe[0].dnstype),
915 data->req.doh.host);
917 rc2 = doh_decode(data->req.doh.probe[1].serverdoh.memory,
918 data->req.doh.probe[1].serverdoh.size,
919 data->req.doh.probe[1].dnstype,
921 free(data->req.doh.probe[1].serverdoh.memory);
923 infof(data, "DOH: %s type %s for %s\n", doh_strerror(rc2),
924 type2name(data->req.doh.probe[1].dnstype),
925 data->req.doh.host);
928 infof(data, "DOH Host name: %s\n", data->req.doh.host);
931 ai = doh2ai(&de, data->req.doh.host, data->req.doh.port);
941 dns = Curl_cache_addr(data, ai, data->req.doh.host, data->req.doh.port);