+SPF_dns_rr_t * spf_nxdomain = NULL;
+
+
+
+static SPF_dns_rr_t *
+SPF_dns_exim_lookup(SPF_dns_server_t *spf_dns_server,
+const char *domain, ns_type rr_type, int should_cache)
+{
+dns_answer dnsa;
+dns_scan dnss;
+SPF_dns_rr_t * spfrr;
+
+DEBUG(D_receive) debug_printf("SPF_dns_exim_lookup\n");
+
+if (dns_lookup(&dnsa, US domain, rr_type, NULL) == DNS_SUCCEED)
+ for (dns_record * rr = dns_next_rr(&dnsa, &dnss, RESET_ANSWERS); rr;
+ rr = dns_next_rr(&dnsa, &dnss, RESET_NEXT))
+ if ( rr->type == rr_type
+ && Ustrncmp(rr->data+1, "v=spf1", 6) == 0)
+ {
+ gstring * g = NULL;
+ uschar chunk_len;
+ uschar * s;
+ SPF_dns_rr_t srr = {
+ .domain = CS rr->name, /* query information */
+ .domain_buf_len = DNS_MAXNAME,
+ .rr_type = rr->type,
+
+ .num_rr = 1, /* answer information */
+ .rr = NULL,
+ .rr_buf_len = 0,
+ .rr_buf_num = 0,
+ .ttl = rr->ttl,
+ .utc_ttl = 0,
+ .herrno = NETDB_SUCCESS,
+
+ .hook = NULL, /* misc information */
+ .source = spf_dns_server
+ };
+
+ for (int off = 0; off < rr->size; off += chunk_len)
+ {
+ chunk_len = (rr->data)[off++];
+ g = string_catn(g, US ((rr->data)+off), chunk_len);
+ }
+ if (!g)
+ {
+ HDEBUG(D_host_lookup) debug_printf("IP address lookup yielded an "
+ "empty name: treated as non-existent host name\n");
+ continue;
+ }
+ gstring_release_unused(g);
+ s = string_copy_malloc(string_from_gstring(g));
+ srr.rr = (void *) &s;
+
+ /* spfrr->rr must have been malloc()d for this */
+ SPF_dns_rr_dup(&spfrr, &srr);
+
+ return spfrr;
+ }
+
+SPF_dns_rr_dup(&spfrr, spf_nxdomain);
+return spfrr;
+}
+
+
+
+SPF_dns_server_t *
+SPF_dns_exim_new(int debug)
+{
+SPF_dns_server_t *spf_dns_server;
+
+DEBUG(D_receive) debug_printf("SPF_dns_exim_new\n");
+
+if (!(spf_dns_server = malloc(sizeof(SPF_dns_server_t))))
+ return NULL;
+memset(spf_dns_server, 0, sizeof(SPF_dns_server_t));
+
+spf_dns_server->destroy = NULL;
+spf_dns_server->lookup = SPF_dns_exim_lookup;
+spf_dns_server->get_spf = NULL;
+spf_dns_server->get_exp = NULL;
+spf_dns_server->add_cache = NULL;
+spf_dns_server->layer_below = NULL;
+spf_dns_server->name = "exim";
+spf_dns_server->debug = debug;
+
+/* XXX This might have to return NO_DATA sometimes. */
+
+spf_nxdomain = SPF_dns_rr_new_init(spf_dns_server,
+ "", ns_t_any, 24 * 60 * 60, HOST_NOT_FOUND);
+if (!spf_nxdomain)
+ {
+ free(spf_dns_server);
+ return NULL;
+ }
+
+return spf_dns_server;
+}
+
+