001/** 002 * 003 * Copyright 2019 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.dox.resolver.minidns; 018 019import java.io.IOException; 020 021import org.jivesoftware.smackx.dox.DnsOverXmppResolver; 022 023import org.minidns.DnsClient; 024import org.minidns.dnsmessage.DnsMessage; 025import org.minidns.dnsmessage.Question; 026import org.minidns.dnsqueryresult.DnsQueryResult; 027import org.minidns.dnssec.DnssecClient; 028import org.minidns.dnssec.DnssecQueryResult; 029 030public final class DnsOverXmppMiniDnsResolver implements DnsOverXmppResolver { 031 032 public static final DnsOverXmppMiniDnsResolver INSTANCE = new DnsOverXmppMiniDnsResolver(new DnsClient(), new DnssecClient()); 033 034 private final DnsClient dnsClient; 035 private final DnssecClient dnssecClient; 036 037 DnsOverXmppMiniDnsResolver(DnsClient dnsClient, DnssecClient dnssecClient) { 038 this.dnsClient = dnsClient; 039 this.dnssecClient = dnssecClient; 040 } 041 042 @Override 043 public DnsMessage resolve(DnsMessage query) throws IOException { 044 Question question = query.getQuestion(); 045 046 final DnsQueryResult dnsQueryResult; 047 if (query.isDnssecOk()) { 048 DnssecQueryResult dnssecQueryResult = dnssecClient.queryDnssec(question); 049 dnsQueryResult = dnssecQueryResult.dnsQueryResult; 050 } else { 051 dnsQueryResult = dnsClient.query(question); 052 } 053 054 return dnsQueryResult.response; 055 } 056 057}