Merge branch 'dnssec'

sip-call-params
Ingo Bauersachs 10 years ago
commit eb946e3f49

@ -14,7 +14,7 @@
<classpathentry kind="lib" path="lib/bundle/commons-logging.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dhcp4java-1.00.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dict4j.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dnsjava.jar">
<classpathentry kind="lib" path="lib/installer-exclude/dnsjava-2.1.7.jar" sourcepath="/dnsjava">
<attributes>
<attribute name="javadoc_location" value="http://www.dnsjava.org/dnsjava-current/doc/"/>
</attributes>
@ -88,5 +88,6 @@
<classpathentry kind="lib" path="lib/installer-exclude/google-http-client-jackson2-1.20.0.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/google-oauth-client-1.20.0.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/jackson-core-2.5.3.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dnssecjava-1.1.jar" sourcepath="/dnssecjava"/>
<classpathentry kind="output" path="classes"/>
</classpath>

@ -1127,6 +1127,8 @@
<copy file="${lib.noinst}/sip-api-1.2-1.2.jar" tofile="${bundles.dest}/sip-api.jar"/>
<copy file="${lib.noinst}/java-sdp-nist-bridge-1.2.jar" tofile="${bundles.dest}/java-sdp-nist-bridge.jar"/>
<copy file="${lib.noinst}/jain-sip-ri-ossonly-1.2.279-jitsi-oss1.jar" tofile="${bundles.dest}/jain-sip-ri.jar"/>
<copy file="${lib.noinst}/dnsjava-2.1.7.jar" tofile="${bundles.dest}/dnsjava.jar"/>
<copy file="${lib.noinst}/dnssecjava-1.1.jar" tofile="${bundles.dest}/dnssecjava.jar"/>
</target>
<!--BUNDLE-SC-LAUNCHER-->
@ -1250,7 +1252,9 @@
<zipfileset dir="${dest}/net/java/sip/communicator/util"
prefix="net/java/sip/communicator/util">
</zipfileset>
<zipfileset src="${lib.noinst}/dnsjava.jar" prefix=""/>
<service
type="sun.net.spi.nameservice.NameServiceDescriptor"
provider="net.java.sip.communicator.util.JitsiDnsNameServiceDescriptor"/>
</jar>
</target>

@ -2,32 +2,35 @@
# Framework config properties.
#
org.osgi.framework.system.packages.extra= \
apple.awt; \
com.apple.cocoa.application; \
com.apple.cocoa.foundation; \
com.apple.eawt; \
com.apple.eio; \
com.sun.awt; \
net.java.sip.communicator.util.launchutils; \
org.apache.xml.serialize; \
org.growl4j; \
org.xbill.DNS; \
quicktime; \
quicktime.qd; \
quicktime.std.image; \
quicktime.std.sg; \
quicktime.util; \
sun.awt.shell; \
sun.lwawt; \
sun.lwawt.macosx; \
sun.misc; \
sun.net.util; \
sun.net.dns; \
sun.security.action; \
sun.security.pkcs11;\
sun.audio;\
sun.nio.ch;\
com.sun.nio.sctp
apple.awt, \
com.apple.cocoa.application, \
com.apple.cocoa.foundation, \
com.apple.eawt, \
com.apple.eio, \
com.sun.awt, \
net.java.sip.communicator.util.launchutils, \
org.apache.xml.serialize, \
org.growl4j, \
org.xbill.DNS;version="2.1.7", \
org.xbill.DNS.utils;version="2.1.7", \
quicktime, \
quicktime.qd, \
quicktime.std.image, \
quicktime.std.sg, \
quicktime.util, \
sun.awt.shell, \
sun.lwawt, \
sun.lwawt.macosx, \
sun.misc, \
sun.net.util, \
sun.net.dns, \
sun.security.action, \
sun.security.pkcs11,\
sun.audio,\
sun.nio.ch,\
com.sun.nio.sctp, \
android.os, \
sun.net.spi.nameservice
felix.auto.start.5=reference:file:sc-bundles/splash-screen.jar
@ -45,7 +48,8 @@ felix.auto.start.10= \
reference:file:sc-bundles/commons-lang.jar \
reference:file:sc-bundles/guava.jar \
reference:file:sc-bundles/slf4j-api.jar \
reference:file:sc-bundles/weupnp.jar
reference:file:sc-bundles/weupnp.jar \
reference:file:sc-bundles/dnssecjava.jar
felix.auto.start.11= \
reference:file:sc-bundles/sip-api.jar \

@ -4,36 +4,37 @@
# and Service Implementation Compatibility Kits
#
org.osgi.framework.system.packages.extra= \
apple.awt; \
com.apple.cocoa.application; \
com.apple.cocoa.foundation; \
com.apple.eawt; \
com.apple.eio; \
gnu.java.zrtp; \
gnu.java.zrtp.packets; \
gnu.java.zrtp.utils; \
gnu.java.zrtp.zidfile; \
net.java.stun4j;\
net.java.stun4j.client;\
org.apache.xml.serialize;\
quicktime; \
quicktime.qd; \
quicktime.std.image; \
quicktime.std.sg; \
quicktime.util; \
com.sun.awt; \
sun.lwawt; \
sun.lwawt.macosx; \
sun.awt.shell; \
sun.misc; \
sun.net.util; \
sun.net.dns; \
sun.security.action; \
sun.security.pkcs11; \
sun.reflect; \
org.xbill.DNS;\
sun.audio;\
sun.nio.ch;\
apple.awt, \
com.apple.cocoa.application, \
com.apple.cocoa.foundation, \
com.apple.eawt, \
com.apple.eio, \
gnu.java.zrtp, \
gnu.java.zrtp.packets, \
gnu.java.zrtp.utils, \
gnu.java.zrtp.zidfile, \
net.java.stun4j,\
net.java.stun4j.client,\
org.apache.xml.serialize,\
quicktime, \
quicktime.qd, \
quicktime.std.image, \
quicktime.std.sg, \
quicktime.util, \
com.sun.awt, \
sun.lwawt, \
sun.lwawt.macosx, \
sun.awt.shell, \
sun.misc, \
sun.net.util, \
sun.net.dns, \
sun.security.action, \
sun.security.pkcs11, \
sun.reflect, \
org.xbill.DNS;version="2.1.7",\
org.xbill.DNS.util;version="2.1.7",\
sun.audio,\
sun.nio.ch,\
com.sun.nio.sctp
@ -61,7 +62,8 @@ felix.auto.start.10= \
reference:file:sc-bundles/hsqldb.jar \
reference:file:sc-bundles/commons-lang.jar \
reference:file:sc-bundles/guava.jar \
reference:file:sc-bundles/weupnp.jar
reference:file:sc-bundles/weupnp.jar \
reference:file:sc-bundles/dnssecjava.jar
felix.auto.start.11= \
reference:file:sc-bundles/sip-api.jar \

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -22,6 +22,11 @@
<artifactId>dnsjava</artifactId>
</dependency>
<!-- org.jitsi -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dnssecjava</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-protocol</artifactId>

@ -60,9 +60,27 @@
</archive>
<includes>
<include>net/java/sip/communicator/util/**</include>
<include>META-INF/services/**</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>eu.somatik.serviceloader-maven-plugin</groupId>
<artifactId>serviceloader-maven-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<services>
<param>sun.net.spi.nameservice.NameServiceDescriptor</param>
</services>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -2407,7 +2407,7 @@
and libjdic.so to deb and i386 package fail to build -->
<replace file="${debianize.dir}/rules"
token="get-orig-source:"
value="override_dh_shlibdeps:&#010;&#009;dh_shlibdeps -Xlibjunbound.so -Xlibsysactivitynotifications.so&#010;&#010;get-orig-source:"/>
value="override_dh_shlibdeps:&#010;&#009;dh_shlibdeps -Xlibsysactivitynotifications.so&#010;&#010;get-orig-source:"/>
<!-- removes the rule override_dh_auto_clean -->
<replace file="${debianize.dir}/rules"
@ -3300,7 +3300,6 @@
<antcall target="globalshortcut"/>
<antcall target="hid"/>
<antcall target="sysactivity"/>
<antcall target="unbound"/>
<antcall target="hwaddressretriever"/>
</target>

@ -42,7 +42,6 @@ Build-Depends: debhelper (>= 9), javahelper,
libxtst-dev,
libxv-dev,
libdbus-1-dev,
libunbound-dev,
libxss-dev,
libgtk2.0-dev,
libglib2.0-dev,

@ -48,7 +48,6 @@ Build-Depends: debhelper (>= 9), javahelper,
libasound2-dev,
libspeexdsp-dev,
libspeex-dev,
libunbound-dev,
libxss-dev,
libgtk2.0-dev,
libglib2.0-dev,

@ -30,7 +30,7 @@ javabin=`which java`
SCDIR=/usr/share/_PACKAGE_NAME_
JITSI_COMMON_DIR=/usr/share/_PACKAGE_NAME_-common
LIBPATH=$SCDIR/lib
CLASSPATH=/usr/share/java/org.apache.felix.framework.jar:/usr/share/java/org.apache.felix.main.jar:$SCDIR/sc-bundles/sc-launcher.jar:$JITSI_COMMON_DIR/util.jar/launchutils.jar:$LIBPATH
CLASSPATH=/usr/share/java/org.apache.felix.framework.jar:/usr/share/java/org.apache.felix.main.jar:/usr/share/java/dnsjava.jar:$SCDIR/sc-bundles/sc-launcher.jar:$JITSI_COMMON_DIR/util.jar/launchutils.jar:$LIBPATH
FELIX_CONFIG=$LIBPATH/felix.client.run.properties
LOG_CONFIG=$LIBPATH/logging.properties
COMMAND="$javabin $CLIENTARGS -classpath $CLASSPATH -Djna.library.path=/usr/lib/jni -Dfelix.config.properties=file:$FELIX_CONFIG -Djava.util.logging.config.file=$LOG_CONFIG $SPLASH_ARG net.java.sip.communicator.launcher.SIPCommunicator"

@ -2,4 +2,4 @@ mkdir -p $HOME/.sip-communicator/log
export PATH=$PATH:native
export JAVA_HOME=jre
${JAVA_HOME}/bin/java -classpath "lib/felix.jar:sc-bundles/sc-launcher.jar:sc-bundles/util.jar:lib/" -Djna.library.path=native -Djava.library.path=native -Dfelix.config.properties=file:./lib/felix.client.run.properties -Djava.util.logging.config.file=lib/logging.properties net.java.sip.communicator.launcher.SIPCommunicator
${JAVA_HOME}/bin/java -classpath "lib/felix.jar:sc-bundles/sc-launcher.jar:sc-bundles/dnsjava.jar:sc-bundles/util.jar:lib/" -Djna.library.path=native -Djava.library.path=native -Dfelix.config.properties=file:./lib/felix.client.run.properties -Djava.util.logging.config.file=lib/logging.properties net.java.sip.communicator.launcher.SIPCommunicator

@ -113,6 +113,7 @@ sed -i -e "s/\/usr\/lib\/jni/\$LIBPATH\/native/" $RPM_BUILD_ROOT/usr/bin/jitsi
sed -i -e "s/\/usr\/share\/java\/jdic\.jar/\$LIBPATH\/jdic_stub\.jar:\$LIBPATH\/jdic-all\.jar/" $RPM_BUILD_ROOT/usr/bin/jitsi
sed -i -e "s/\/usr\/share\/java\/org\.apache\.felix\.framework\.jar/\$LIBPATH\/felix\.jar/" $RPM_BUILD_ROOT/usr/bin/jitsi
sed -i -e "s/\/usr\/share\/java\/org\.apache\.felix\.main\.jar://" $RPM_BUILD_ROOT/usr/bin/jitsi
sed -i -e "s/\/usr\/share\/java\/dnsjava\.jar://" $RPM_BUILD_ROOT/usr/bin/jitsi
sed -i -e "s/\/launchutils.jar//" $RPM_BUILD_ROOT/usr/bin/jitsi
%clean

@ -533,34 +533,6 @@
</cc>
</target>
<target name="unbound"
description="Build libjunbound"
depends="init-native">
<cc outtype="shared"
name="g++"
outfile="${native_install_dir}/junbound"
objdir="${obj}">
<!-- common compiler flags -->
<compilerarg value="-Wall" />
<compilerarg value="-Wreturn-type" />
<compilerarg value="-fPIC"/>
<compilerarg value="-D_JNI_IMPLEMENTATION_" />
<compilerarg value="-I${system.JAVA_HOME}/include"
if="is.running.linux" />
<compilerarg value="-I${system.JAVA_HOME}/include/linux"
if="is.running.linux" />
<linkerarg value="-Wl,-z,relro" if="is.running.debian"/>
<linkerarg value="-shared"/>
<linkerarg value="-lunbound" if="is.running.linux"/>
<fileset dir="${src}/native/libjunbound/src"
includes="*.cpp"/>
</cc>
</target>
<!-- Cleanup object files and shared libraries -->
<target name="clean-native" description="Clean all object files and libraries.">
<delete failonerror="false" includeemptydirs="true">

@ -1,2 +0,0 @@
SUBDIRS = src
ACLOCAL_AMFLAGS = -I m4

@ -1,69 +0,0 @@
# Prelude.
AC_INIT([junbound], [1.0], [dev@jitsi.java.net])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])
AC_CONFIG_MACRO_DIR([m4])
LT_INIT
# Checks for programs.
AC_PROG_CXX
# Checks for libraries.
AC_CHECK_LIB([unbound], [ub_ctx_create], [], [AC_MSG_ERROR([libunbound not found (is libunbound-dev installed?)])])
# Checks for header files.
AC_MSG_CHECKING(for java include file jni.h)
AC_ARG_WITH(javaincl, [ --with-javaincl=path Set location of Java include directory], [JAVAINCDIR="$withval"], [JAVAINCDIR=])
if test -z "$JAVAINCDIR" ; then
JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /usr/lib/jvm/java*/include /usr/include/kaffe /usr/local/include/kaffe /usr/include"
# Add in default installation directory on Windows for Cygwin
case $host in
*-*-cygwin* | *-*-mingw*) JAVAINCDIR="c:/Program*Files/Java/jdk*/include d:/Program*Files/Java/jdk*/include c:/j2sdk*/include d:/j2sdk*/include c:/jdk*/include d:/jdk*/include $JAVAINCDIR";;
*-*-darwin*) JAVAINCDIR="/System/Library/Frameworks/JavaVM.framework/Headers $JAVAINCDIR";;
*);;
esac
fi
if test -z "$JAVA_HOME" ; then
JAVA_HOME=":" # Something completely invalid
fi
VS_JNI_INCLUDE=""
for d in "$JAVA_HOME/include" $JAVAINCDIR ; do
if test -r "$d/jni.h" ; then
AC_MSG_RESULT($d)
JAVAINCDIR=$d
VS_JNI_INCLUDE=-I\"$d\" #" quote here to fix nasty formatting bug in VIM
break
fi
done
if test "$VS_JNI_INCLUDE" = "" ; then
AC_MSG_RESULT(not found)
AC_MSG_FAILURE([Could not find required Java header file jni.h.
Try defining JAVA_HOME to point to where you've
installed the JAVA JDK])
else
# now look for <arch>/jni_md.h
AC_MSG_CHECKING(for java include file jni_md.h)
JAVAMDDIR=`find "$JAVAINCDIR" -follow -name jni_md.h -print`
if test "$JAVAMDDIR" = "" ; then
AC_MSG_RESULT(not found)
AC_MSG_FAILURE([Could not find required Java header file jni_md.h.
Try defining JAVA_HOME to point to where you've
installed the JAVA JDK])
else
JAVAMDDIR=`dirname "$JAVAMDDIR" | tail -1`
VS_JNI_INCLUDE="${VS_JNI_INCLUDE} -I\"$JAVAMDDIR\""
AC_MSG_RESULT($JAVAMDDIR)
fi
fi
AC_SUBST([VS_JNI_INCLUDE])
#AC_CHECK_HEADERS([jni.h], [], [AC_MSG_ERROR([JNI headers not found])])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
# Output files.
# AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT

@ -1,35 +0,0 @@
#!/bin/bash
set -e
out=`pwd`/build/linux
prefix=$out/libs
export JAVA_HOME=/usr/lib/jvm/default-java/
mkdir -p $out
mkdir -p $prefix
cd $out
expat=expat-2.1.0
unbound=unbound-1.5.1
wget -nc http://downloads.sourceforge.net/project/expat/expat/2.1.0/$expat.tar.gz
wget -nc http://unbound.net/downloads/$unbound.tar.gz
tar -xzvf $expat.tar.gz
tar -xzvf $unbound.tar.gz
cd $out/$expat
./configure --with-pic --prefix=$prefix
make
make install
cd $out/$unbound
patch -p 1 -i $out/../../unbound.patch
./configure --with-pic --prefix=$prefix --with-libexpat=$prefix
make
make install
cd $out
gcc $out/../../src/net_java_sip_communicator_impl_dns_UnboundApi.cpp -fpic -shared -o libjunbound.so -I$JAVA_HOME/include -Wl,-Bstatic -L$prefix/lib -lunbound -I$prefix/include -Wl,-Bdynamic -lcrypto -lssl
strip libjunbound.so

@ -1,76 +0,0 @@
#!/bin/bash
#-------------
#Note: To compile the PPC support, you must have XCode 3.x installed!
# Remove the "-arch ppc" arguments to build only for 32/64 bit
#-------------
set -e
out=`pwd`/build/mac
prefix=$out/libs
mkdir -p $out
mkdir -p $prefix/lib
#mkdir -p $prefix/include
cd $out
expat=expat-2.0.1
ldns=ldns-1.6.11
unbound=unbound-1.4.14
curl -L http://downloads.sourceforge.net/project/expat/expat/2.0.1/expat-2.0.1.tar.gz -o $expat.tar.gz
curl -L http://nlnetlabs.nl/downloads/ldns/$ldns.tar.gz -o $ldns.tar.gz
curl -L http://unbound.net/downloads/$unbound.tar.gz -o $unbound.tar.gz
tar -xzvf $expat.tar.gz
tar -xzvf $ldns.tar.gz
tar -xzvf $unbound.tar.gz
mv $expat expat
mv $ldns ldns
mv $unbound unbound
export MACOSX_DEPLOYMENT_TARGET=10.5
export CC="/usr/bin/gcc -arch i386 -arch x86_64 -mmacosx-version-min=10.5"
export CPP="/usr/bin/gcc -E"
function build_arch {
prefixarch="${prefix}_$1"
mkdir -p $prefixarch
cd $out/$2
./configure --with-ssl=/usr --disable-gost --with-pic --with-ldns=$prefixarch --with-expat=$prefixarch --prefix=$prefixarch
make clean
make
make install
}
function build_lib {
build_arch all $1
}
build_lib expat
build_lib ldns
build_lib unbound
cp -r ${prefix}_all/include $prefix/
# remove all dynamic libs as we do not use them and compile is first searching
# for them
rm ${prefix}_all/lib/*.dylib
cd $out
g++ -mmacosx-version-min=10.4 -arch x86_64 -arch i386 \
$out/../../src/net_java_sip_communicator_impl_dns_UnboundApi.cpp \
-D_JNI_IMPLEMENTATION_ \
-fPIC -shared -O2 -Wall \
-I/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers \
-I${prefix}_all/include \
-L${prefix}_all/lib \
-L/usr/lib \
-dynamiclib \
-lunbound -lldns -lcrypto \
-dynamic \
-lcrypto -lssl \
-o libjunbound.jnilib

@ -1,16 +0,0 @@
CC = g++ -O2
TARGET_BASENAME = libjunbound.so
CPPFLAGS = \
-Wall -Wreturn-type \
-fpic \
-DJNI_IMPLEMENTATION \
-I/usr/lib/jvm/java-6-openjdk/include
LDFLAGS = -shared
LIBS = -lunbound
TARGET = $(TARGET_BASENAME)
$(TARGET): src/*.cpp
$(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS)
-strip $(TARGET)

@ -1,25 +0,0 @@
CC = g++ -O2
TARGET_BASENAME = junbound.dll
TARGET_DIR ?= ../../../lib/native/windows
ifeq ($(wildcard /bin/cygpath.*),/bin/cygpath.exe)
target.dir := $(shell cygpath --mixed "$(TARGET_DIR)")
cygwin.target.dir := $(shell cygpath --unix "$(TARGET_DIR)")
else
target.dir := "$(TARGET_DIR)"
cygwin.target.dir := "$(TARGET_DIR)"
endif
CPPFLAGS = \
-Wall -Wreturn-type \
-DWINVER=0x0502 -D_WIN32_WINNT=0x0502 \
-DJNI_IMPLEMENTATION \
-I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/win32" -Iwindows32
LDFLAGS = -shared -static -Wl,--kill-at -Wl,--subsystem,windows
LIBS = -Lwindows32 -lunbound -lldns -lcrypto -lws2_32 -lgdi32 -liphlpapi
TARGET = $(TARGET_DIR)/$(TARGET_BASENAME)
$(TARGET): src/*.cpp
$(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS)
-strip $(TARGET)

@ -1,26 +0,0 @@
CC = g++ -O2
TARGET_BASENAME = junbound.dll
TARGET_DIR ?= ../../../lib/native/windows-64
JAVA_HOME = C:/Program Files/Java/jdk6
ifeq ($(wildcard /bin/cygpath.*),/bin/cygpath.exe)
target.dir := $(shell cygpath --mixed "$(TARGET_DIR)")
cygwin.target.dir := $(shell cygpath --unix "$(TARGET_DIR)")
else
target.dir := "$(TARGET_DIR)"
cygwin.target.dir := "$(TARGET_DIR)"
endif
CPPFLAGS = \
-Wall -Wreturn-type \
-DWINVER=0x0502 -D_WIN32_WINNT=0x0502 \
-DJNI_IMPLEMENTATION \
-I"$(JAVA_HOME)/include" -I"$(JAVA_HOME)/include/win32" -Iwindows64
LDFLAGS = -shared -static -Wl,--kill-at -Wl,--subsystem,windows
LIBS = -Lwindows64 -lunbound -lldns -lcrypto -lws2_32 -lgdi32 -liphlpapi
TARGET = $(TARGET_DIR)/$(TARGET_BASENAME)
$(TARGET): src/*.cpp
$(CC) $(CPPFLAGS) $^ $(LDFLAGS) -o $@ $(LIBS)
-strip $(TARGET)

@ -1,40 +0,0 @@
To compile libjunbound
Linux (libunbound, libldns and lcrypto shared):
----------------------------------------------
a) With autoconf
autoreconf --install
./configure
make
cp ./libs/libjunbound.so ../../lib/native/linux
b) With manual makefile
make -f makefile.linux
Linux (libunbound statically linked, lcrypto shared):
----------------------------------------------------
Use make-linux.sh
Mac:
---
Use make-mac.sh
Windows:
-------
- Get ldns, libexpat, unbound and compile them
- make -f makefile.w32
Expat Win64:
./configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32
Unbound Win64:
The configure script wrongly detects getaddrinfo as Unix. Break the detection
script at line 16085 (1.4.12)
OpenSSL Win64:
configure mingw64 -no-capieng -no-asm
make
make check (http://stackoverflow.com/questions/7256087/error-compiling-openssl-with-mingw-msys)
mkdir lib
cp libcrypto.a lib
cp libssl.a lib

@ -1,3 +0,0 @@
lib_LTLIBRARIES = libjunbound.la
libjunbound_la_SOURCES = net_java_sip_communicator_impl_dns_UnboundApi.cpp
AM_CPPFLAGS = ${includedirs} ${VS_JNI_INCLUDE} -DJNI_IMPLEMENTATION

@ -1,284 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <jni.h>
#include <unbound.h>
#include "net_java_sip_communicator_impl_dns_UnboundApi.h"
void ub_async_cb(void* my_arg, int err, struct ub_result* result);
jobject createUnboundResult(JNIEnv* env, ub_result* resolveResult);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: setDebugLevel
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setDebugLevel
(JNIEnv* env, jclass clazz, jlong context, jint level)
{
int result = ub_ctx_debuglevel((ub_ctx*)context, level);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return;
}
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: createContext
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_createContext
(JNIEnv* env, jclass clazz)
{
return (jlong)ub_ctx_create();
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: deleteContext
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_deleteContext
(JNIEnv* env, jclass clazz, jlong context)
{
ub_ctx_delete((ub_ctx*)context);
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: setForwarder
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setForwarder
(JNIEnv* env, jclass clazz, jlong context, jstring server)
{
char* chars = (char*)env->GetStringUTFChars(server, NULL);
int result = ub_ctx_set_fwd((ub_ctx*)context, chars);
env->ReleaseStringUTFChars(server, chars);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return;
}
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: addTrustAnchor
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_addTrustAnchor
(JNIEnv* env, jclass clazz, jlong context, jstring anchor)
{
char* chars = (char*)env->GetStringUTFChars(anchor, NULL);
int result = ub_ctx_add_ta((ub_ctx*)context, chars);
env->ReleaseStringUTFChars(anchor, chars);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return;
}
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: resolve
* Signature: (JLjava/lang/String;II)Lnet/java/sip/communicator/impl/dns/UnboundResult;
*/
JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolve
(JNIEnv* env, jclass clazz, jlong context, jstring name, jint rrtype, jint rrclass)
{
char* chars = (char*)env->GetStringUTFChars(name, NULL);
ub_result* resolveResult;
int result = ub_resolve((ub_ctx*)context, chars, rrtype, rrclass, &resolveResult);
env->ReleaseStringUTFChars(name, chars);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return NULL;
}
return createUnboundResult(env, resolveResult);
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: resolveAsync
* Signature: (JLjava/lang/String;IILnet/java/sip/communicator/impl/dns/UnboundApi/UnboundCallback;)J
*/
JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolveAsync
(JNIEnv* env, jclass clazz, jlong context, jstring name, jint rrtype, jint rrclass, jobject data, jobject cb)
{
JavaVM* jvm;
if(env->GetJavaVM(&jvm) != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), "Unable to obtain Java VM pointer");
return 0;
}
int result = ub_ctx_async((ub_ctx*)context, true);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return 0;
}
//ensure the objects stay alive when this method leaves
void** cbData = new void*[3];
cbData[0] = env->NewGlobalRef(data);
cbData[1] = env->NewGlobalRef(cb);
cbData[2] = jvm;
int asyncId;
char* chars = (char*)env->GetStringUTFChars(name, NULL);
result = ub_resolve_async((ub_ctx*)context, chars, rrtype, rrclass, cbData, &ub_async_cb, &asyncId);
env->ReleaseStringUTFChars(name, chars);
if(result != 0)
{
delete[] cbData;
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return 0;
}
return asyncId;
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: cancelAsync
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_cancelAsync
(JNIEnv* env, jclass clazz, jlong context, jint asyncId)
{
int result = ub_cancel((ub_ctx*)context, asyncId);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return;
}
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: errorCodeToString
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_errorCodeToString
(JNIEnv* env, jclass clazz, jint code)
{
return env->NewStringUTF(ub_strerror(code));
}
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: processAsync
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_processAsync
(JNIEnv* env, jclass clazz, jlong context)
{
int result = ub_wait((ub_ctx*)context);
if(result != 0)
{
env->ThrowNew(env->FindClass("net/java/sip/communicator/impl/dns/UnboundException"), ub_strerror(result));
return;
}
}
void ub_async_cb(void* my_arg, int err, struct ub_result* result)
{
void** cbData = (void**)my_arg;
JavaVM* jvm = ((JavaVM*)cbData[2]);
JNIEnv* env;
if(jvm->AttachCurrentThreadAsDaemon((void**)&env, NULL) == 0)
{
jobject data = (jobject)cbData[0];
jobject cb = (jobject)cbData[1];
delete[] cbData;
jobject ubResult = NULL;
if(err == 0)
{
ubResult = createUnboundResult(env, result);
}
env->CallVoidMethod(
cb, env->GetMethodID(
env->FindClass("net/java/sip/communicator/impl/dns/UnboundApi$UnboundCallback"),
"UnboundResolveCallback",
"(Ljava/lang/Object;ILnet/java/sip/communicator/impl/dns/UnboundResult;)V"
), data, (jint)err, ubResult
);
env->DeleteGlobalRef(data);
env->DeleteGlobalRef(cb);
env->DeleteLocalRef(ubResult);
}
jvm->DetachCurrentThread();
}
jobject createUnboundResult(JNIEnv* env, ub_result* resolveResult)
{
jclass ubResultClass = env->FindClass("net/java/sip/communicator/impl/dns/UnboundResult");
jmethodID constructor = env->GetMethodID(ubResultClass, "<init>", "()V");
jobject ubResult = env->NewObject(ubResultClass, constructor);
//copy data
//int numData = 0;
//char** data = resolveResult->data;
//while(*(data++) != NULL)
// numData++;
//jobjectArray dataArray = env->NewObjectArray(numData, env->FindClass("[B"), NULL);
//for(int i = 0; i < numData; i++)
//{
// jbyteArray dataEntry = env->NewByteArray(resolveResult->len[i]);
// env->SetByteArrayRegion(dataEntry, 0, resolveResult->len[i], (jbyte*)resolveResult->data[i]);
// env->SetObjectArrayElement(dataArray, i, dataEntry);
// env->DeleteLocalRef(dataEntry);
//}
//copy answer packet
jbyteArray answerPacket = env->NewByteArray(resolveResult->answer_len);
env->SetByteArrayRegion(answerPacket, 0, resolveResult->answer_len, (jbyte*)resolveResult->answer_packet);
//set fields
env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "qname", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->qname));
env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "qtype", "I"), resolveResult->qtype);
env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "qclass", "I"), resolveResult->qclass);
//env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "data", "[[B"), dataArray);
//env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "canonname", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->canonname));
env->SetIntField( ubResult, env->GetFieldID(ubResultClass, "rcode", "I"), resolveResult->rcode);
env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "answerPacket", "[B"), answerPacket);
env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "haveData", "Z"), resolveResult->havedata);
env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "nxDomain", "Z"), resolveResult->nxdomain);
env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "secure", "Z"), resolveResult->secure);
env->SetBooleanField(ubResult, env->GetFieldID(ubResultClass, "bogus", "Z"), resolveResult->bogus);
env->SetObjectField( ubResult, env->GetFieldID(ubResultClass, "whyBogus", "Ljava/lang/String;"), env->NewStringUTF(resolveResult->why_bogus));
ub_resolve_free(resolveResult);
return ubResult;
}

@ -1,94 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_java_sip_communicator_impl_dns_UnboundApi */
#ifndef _Included_net_java_sip_communicator_impl_dns_UnboundApi
#define _Included_net_java_sip_communicator_impl_dns_UnboundApi
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: setDebugLevel
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setDebugLevel
(JNIEnv *, jclass, jlong, jint);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: createContext
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_createContext
(JNIEnv *, jclass);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: deleteContext
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_deleteContext
(JNIEnv *, jclass, jlong);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: setForwarder
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_setForwarder
(JNIEnv *, jclass, jlong, jstring);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: addTrustAnchor
* Signature: (JLjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_addTrustAnchor
(JNIEnv *, jclass, jlong, jstring);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: resolve
* Signature: (JLjava/lang/String;II)Lnet/java/sip/communicator/impl/dns/UnboundResult;
*/
JNIEXPORT jobject JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolve
(JNIEnv *, jclass, jlong, jstring, jint, jint);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: resolveAsync
* Signature: (JLjava/lang/String;IILjava/lang/Object;Lnet/java/sip/communicator/impl/dns/UnboundApi/UnboundCallback;)I
*/
JNIEXPORT jint JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_resolveAsync
(JNIEnv *, jclass, jlong, jstring, jint, jint, jobject, jobject);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: cancelAsync
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_cancelAsync
(JNIEnv *, jclass, jlong, jint);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: errorCodeToString
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_errorCodeToString
(JNIEnv *, jclass, jint);
/*
* Class: net_java_sip_communicator_impl_dns_UnboundApi
* Method: processAsync
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_net_java_sip_communicator_impl_dns_UnboundApi_processAsync
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif

@ -1,13 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback */
#ifndef _Included_net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback
#define _Included_net_java_sip_communicator_impl_dns_UnboundApi_UnboundCallback
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

@ -1,54 +0,0 @@
diff -u -r unbound-1.5.1-orig/libunbound/context.c unbound-1.5.1/libunbound/context.c
--- unbound-1.5.1-orig/libunbound/context.c 2014-02-07 14:28:39.000000000 +0100
+++ unbound-1.5.1/libunbound/context.c 2015-02-09 11:55:02.000000000 +0100
@@ -125,7 +125,7 @@
}
struct ctx_query*
-context_new(struct ub_ctx* ctx, const char* name, int rrtype, int rrclass,
+context_create(struct ub_ctx* ctx, const char* name, int rrtype, int rrclass,
ub_callback_t cb, void* cbarg)
{
struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
diff -u -r unbound-1.5.1-orig/libunbound/context.h unbound-1.5.1/libunbound/context.h
--- unbound-1.5.1-orig/libunbound/context.h 2014-02-07 14:28:39.000000000 +0100
+++ unbound-1.5.1/libunbound/context.h 2015-02-09 11:54:44.000000000 +0100
@@ -241,7 +241,7 @@
* @param cbarg: user arg for async queries.
* @return new ctx_query or NULL for malloc failure.
*/
-struct ctx_query* context_new(struct ub_ctx* ctx, const char* name, int rrtype,
+struct ctx_query* context_create(struct ub_ctx* ctx, const char* name, int rrtype,
int rrclass, ub_callback_t cb, void* cbarg);
/**
diff -u -r unbound-1.5.1-orig/libunbound/libunbound.c unbound-1.5.1/libunbound/libunbound.c
--- unbound-1.5.1-orig/libunbound/libunbound.c 2014-11-04 10:11:59.000000000 +0100
+++ unbound-1.5.1/libunbound/libunbound.c 2015-02-09 11:55:20.000000000 +0100
@@ -634,7 +634,7 @@
}
/* create new ctx_query and attempt to add to the list */
lock_basic_unlock(&ctx->cfglock);
- q = context_new(ctx, name, rrtype, rrclass, NULL, NULL);
+ q = context_create(ctx, name, rrtype, rrclass, NULL, NULL);
if(!q)
return UB_NOMEM;
/* become a resolver thread for a bit */
@@ -687,7 +687,7 @@
}
/* create new ctx_query and attempt to add to the list */
- q = context_new(ctx, name, rrtype, rrclass, (ub_callback_t)callback,
+ q = context_create(ctx, name, rrtype, rrclass, (ub_callback_t)callback,
mydata);
if(!q)
return UB_NOMEM;
@@ -733,7 +733,7 @@
}
/* create new ctx_query and attempt to add to the list */
- q = context_new(ctx, name, rrtype, rrclass, callback, mydata);
+ q = context_create(ctx, name, rrtype, rrclass, callback, mydata);
if(!q)
return UB_NOMEM;

@ -1,534 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright (c) 2007, NLnet Labs. All rights reserved.
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* \file
*
* This file contains functions to resolve DNS queries and
* validate the answers. Synchonously and asynchronously.
*
* Several ways to use this interface from an application wishing
* to perform (validated) DNS lookups.
*
* All start with
* ctx = ub_ctx_create();
* err = ub_ctx_add_ta(ctx, "...");
* err = ub_ctx_add_ta(ctx, "...");
* ... some lookups
* ... call ub_ctx_delete(ctx); when you want to stop.
*
* Application not threaded. Blocking.
* int err = ub_resolve(ctx, "www.example.com", ...
* if(err) fprintf(stderr, "lookup error: %s\n", ub_strerror(err));
* ... use the answer
*
* Application not threaded. Non-blocking ('asynchronous').
* err = ub_resolve_async(ctx, "www.example.com", ... my_callback);
* ... application resumes processing ...
* ... and when either ub_poll(ctx) is true
* ... or when the file descriptor ub_fd(ctx) is readable,
* ... or whenever, the app calls ...
* ub_process(ctx);
* ... if no result is ready, the app resumes processing above,
* ... or process() calls my_callback() with results.
*
* ... if the application has nothing more to do, wait for answer
* ub_wait(ctx);
*
* Application threaded. Blocking.
* Blocking, same as above. The current thread does the work.
* Multiple threads can use the *same context*, each does work and uses
* shared cache data from the context.
*
* Application threaded. Non-blocking ('asynchronous').
* ... setup threaded-asynchronous config option
* err = ub_ctx_async(ctx, 1);
* ... same as async for non-threaded
* ... the callbacks are called in the thread that calls process(ctx)
*
* If no threading is compiled in, the above async example uses fork(2) to
* create a process to perform the work. The forked process exits when the
* calling process exits, or ctx_delete() is called.
* Otherwise, for asynchronous with threading, a worker thread is created.
*
* The blocking calls use shared ctx-cache when threaded. Thus
* ub_resolve() and ub_resolve_async() && ub_wait() are
* not the same. The first makes the current thread do the work, setting
* up buffers, etc, to perform the work (but using shared cache data).
* The second calls another worker thread (or process) to perform the work.
* And no buffers need to be set up, but a context-switch happens.
*/
#ifndef _UB_UNBOUND_H
#define _UB_UNBOUND_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* The validation context is created to hold the resolver status,
* validation keys and a small cache (containing messages, rrsets,
* roundtrip times, trusted keys, lameness information).
*
* Its contents are internally defined.
*/
struct ub_ctx;
/**
* The validation and resolution results.
* Allocated by the resolver, and need to be freed by the application
* with ub_resolve_free().
*/
struct ub_result {
/** The original question, name text string. */
char* qname;
/** the type asked for */
int qtype;
/** the class asked for */
int qclass;
/**
* a list of network order DNS rdata items, terminated with a
* NULL pointer, so that data[0] is the first result entry,
* data[1] the second, and the last entry is NULL.
* If there was no data, data[0] is NULL.
*/
char** data;
/** the length in bytes of the data items, len[i] for data[i] */
int* len;
/**
* canonical name for the result (the final cname).
* zero terminated string.
* May be NULL if no canonical name exists.
*/
char* canonname;
/**
* DNS RCODE for the result. May contain additional error code if
* there was no data due to an error. 0 (NOERROR) if okay.
*/
int rcode;
/**
* The DNS answer packet. Network formatted. Can contain DNSSEC types.
*/
void* answer_packet;
/** length of the answer packet in octets. */
int answer_len;
/**
* If there is any data, this is true.
* If false, there was no data (nxdomain may be true, rcode can be set).
*/
int havedata;
/**
* If there was no data, and the domain did not exist, this is true.
* If it is false, and there was no data, then the domain name
* is purported to exist, but the requested data type is not available.
*/
int nxdomain;
/**
* True, if the result is validated securely.
* False, if validation failed or domain queried has no security info.
*
* It is possible to get a result with no data (havedata is false),
* and secure is true. This means that the non-existance of the data
* was cryptographically proven (with signatures).
*/
int secure;
/**
* If the result was not secure (secure==0), and this result is due
* to a security failure, bogus is true.
* This means the data has been actively tampered with, signatures
* failed, expected signatures were not present, timestamps on
* signatures were out of date and so on.
*
* If !secure and !bogus, this can happen if the data is not secure
* because security is disabled for that domain name.
* This means the data is from a domain where data is not signed.
*/
int bogus;
/**
* If the result is bogus this contains a string (zero terminated)
* that describes the failure. There may be other errors as well
* as the one described, the description may not be perfectly accurate.
* Is NULL if the result is not bogus.
*/
char* why_bogus;
};
/**
* Callback for results of async queries.
* The readable function definition looks like:
* void my_callback(void* my_arg, int err, struct ub_result* result);
* It is called with
* void* my_arg: your pointer to a (struct of) data of your choice,
* or NULL.
* int err: if 0 all is OK, otherwise an error occured and no results
* are forthcoming.
* struct result: pointer to more detailed result structure.
* This structure is allocated on the heap and needs to be
* freed with ub_resolve_free(result);
*/
typedef void (*ub_callback_t)(void*, int, struct ub_result*);
/**
* Create a resolving and validation context.
* The information from /etc/resolv.conf and /etc/hosts is not utilised by
* default. Use ub_ctx_resolvconf and ub_ctx_hosts to read them.
* @return a new context. default initialisation.
* returns NULL on error.
*/
struct ub_ctx* ub_ctx_create(void);
/**
* Destroy a validation context and free all its resources.
* Outstanding async queries are killed and callbacks are not called for them.
* @param ctx: context to delete.
*/
void ub_ctx_delete(struct ub_ctx* ctx);
/**
* Set an option for the context.
* @param ctx: context.
* @param opt: option name from the unbound.conf config file format.
* (not all settings applicable). The name includes the trailing ':'
* for example ub_ctx_set_option(ctx, "logfile:", "mylog.txt");
* This is a power-users interface that lets you specify all sorts
* of options.
* For some specific options, such as adding trust anchors, special
* routines exist.
* @param val: value of the option.
* @return: 0 if OK, else error.
*/
int ub_ctx_set_option(struct ub_ctx* ctx, char* opt, char* val);
/**
* Get an option from the context.
* @param ctx: context.
* @param opt: option name from the unbound.conf config file format.
* (not all settings applicable). The name excludes the trailing ':'
* for example ub_ctx_get_option(ctx, "logfile", &result);
* This is a power-users interface that lets you specify all sorts
* of options.
* @param str: the string is malloced and returned here. NULL on error.
* The caller must free() the string. In cases with multiple
* entries (auto-trust-anchor-file), a newline delimited list is
* returned in the string.
* @return 0 if OK else an error code (malloc failure, syntax error).
*/
int ub_ctx_get_option(struct ub_ctx* ctx, char* opt, char** str);
/**
* setup configuration for the given context.
* @param ctx: context.
* @param fname: unbound config file (not all settings applicable).
* This is a power-users interface that lets you specify all sorts
* of options.
* For some specific options, such as adding trust anchors, special
* routines exist.
* @return: 0 if OK, else error.
*/
int ub_ctx_config(struct ub_ctx* ctx, char* fname);
/**
* Set machine to forward DNS queries to, the caching resolver to use.
* IP4 or IP6 address. Forwards all DNS requests to that machine, which
* is expected to run a recursive resolver. If the proxy is not
* DNSSEC-capable, validation may fail. Can be called several times, in
* that case the addresses are used as backup servers.
*
* To read the list of nameservers from /etc/resolv.conf (from DHCP or so),
* use the call ub_ctx_resolvconf.
*
* @param ctx: context.
* At this time it is only possible to set configuration before the
* first resolve is done.
* @param addr: address, IP4 or IP6 in string format.
* If the addr is NULL, forwarding is disabled.
* @return 0 if OK, else error.
*/
int ub_ctx_set_fwd(struct ub_ctx* ctx, char* addr);
/**
* Read list of nameservers to use from the filename given.
* Usually "/etc/resolv.conf". Uses those nameservers as caching proxies.
* If they do not support DNSSEC, validation may fail.
*
* Only nameservers are picked up, the searchdomain, ndots and other
* settings from resolv.conf(5) are ignored.
*
* @param ctx: context.
* At this time it is only possible to set configuration before the
* first resolve is done.
* @param fname: file name string. If NULL "/etc/resolv.conf" is used.
* @return 0 if OK, else error.
*/
int ub_ctx_resolvconf(struct ub_ctx* ctx, char* fname);
/**
* Read list of hosts from the filename given.
* Usually "/etc/hosts".
* These addresses are not flagged as DNSSEC secure when queried for.
*
* @param ctx: context.
* At this time it is only possible to set configuration before the
* first resolve is done.
* @param fname: file name string. If NULL "/etc/hosts" is used.
* @return 0 if OK, else error.
*/
int ub_ctx_hosts(struct ub_ctx* ctx, char* fname);
/**
* Add a trust anchor to the given context.
* The trust anchor is a string, on one line, that holds a valid DNSKEY or
* DS RR.
* @param ctx: context.
* At this time it is only possible to add trusted keys before the
* first resolve is done.
* @param ta: string, with zone-format RR on one line.
* [domainname] [TTL optional] [type] [class optional] [rdata contents]
* @return 0 if OK, else error.
*/
int ub_ctx_add_ta(struct ub_ctx* ctx, char* ta);
/**
* Add trust anchors to the given context.
* Pass name of a file with DS and DNSKEY records (like from dig or drill).
* @param ctx: context.
* At this time it is only possible to add trusted keys before the
* first resolve is done.
* @param fname: filename of file with keyfile with trust anchors.
* @return 0 if OK, else error.
*/
int ub_ctx_add_ta_file(struct ub_ctx* ctx, char* fname);
/**
* Add trust anchors to the given context.
* Pass the name of a bind-style config file with trusted-keys{}.
* @param ctx: context.
* At this time it is only possible to add trusted keys before the
* first resolve is done.
* @param fname: filename of file with bind-style config entries with trust
* anchors.
* @return 0 if OK, else error.
*/
int ub_ctx_trustedkeys(struct ub_ctx* ctx, char* fname);
/**
* Set debug output (and error output) to the specified stream.
* Pass NULL to disable. Default is stderr.
* @param ctx: context.
* @param out: FILE* out file stream to log to.
* Type void* to avoid stdio dependency of this header file.
* @return 0 if OK, else error.
*/
int ub_ctx_debugout(struct ub_ctx* ctx, void* out);
/**
* Set debug verbosity for the context
* Output is directed to stderr.
* @param ctx: context.
* @param d: debug level, 0 is off, 1 is very minimal, 2 is detailed,
* and 3 is lots.
* @return 0 if OK, else error.
*/
int ub_ctx_debuglevel(struct ub_ctx* ctx, int d);
/**
* Set a context behaviour for asynchronous action.
* @param ctx: context.
* @param dothread: if true, enables threading and a call to resolve_async()
* creates a thread to handle work in the background.
* If false, a process is forked to handle work in the background.
* Changes to this setting after async() calls have been made have
* no effect (delete and re-create the context to change).
* @return 0 if OK, else error.
*/
int ub_ctx_async(struct ub_ctx* ctx, int dothread);
/**
* Poll a context to see if it has any new results
* Do not poll in a loop, instead extract the fd below to poll for readiness,
* and then check, or wait using the wait routine.
* @param ctx: context.
* @return: 0 if nothing to read, or nonzero if a result is available.
* If nonzero, call ctx_process() to do callbacks.
*/
int ub_poll(struct ub_ctx* ctx);
/**
* Wait for a context to finish with results. Calls ub_process() after
* the wait for you. After the wait, there are no more outstanding
* asynchronous queries.
* @param ctx: context.
* @return: 0 if OK, else error.
*/
int ub_wait(struct ub_ctx* ctx);
/**
* Get file descriptor. Wait for it to become readable, at this point
* answers are returned from the asynchronous validating resolver.
* Then call the ub_process to continue processing.
* This routine works immediately after context creation, the fd
* does not change.
* @param ctx: context.
* @return: -1 on error, or file descriptor to use select(2) with.
*/
int ub_fd(struct ub_ctx* ctx);
/**
* Call this routine to continue processing results from the validating
* resolver (when the fd becomes readable).
* Will perform necessary callbacks.
* @param ctx: context
* @return: 0 if OK, else error.
*/
int ub_process(struct ub_ctx* ctx);
/**
* Perform resolution and validation of the target name.
* @param ctx: context.
* The context is finalized, and can no longer accept config changes.
* @param name: domain name in text format (a zero terminated text string).
* @param rrtype: type of RR in host order, 1 is A (address).
* @param rrclass: class of RR in host order, 1 is IN (for internet).
* @param result: the result data is returned in a newly allocated result
* structure. May be NULL on return, return value is set to an error
* in that case (out of memory).
* @return 0 if OK, else error.
*/
int ub_resolve(struct ub_ctx* ctx, char* name, int rrtype,
int rrclass, struct ub_result** result);
/**
* Perform resolution and validation of the target name.
* Asynchronous, after a while, the callback will be called with your
* data and the result.
* @param ctx: context.
* If no thread or process has been created yet to perform the
* work in the background, it is created now.
* The context is finalized, and can no longer accept config changes.
* @param name: domain name in text format (a string).
* @param rrtype: type of RR in host order, 1 is A.
* @param rrclass: class of RR in host order, 1 is IN (for internet).
* @param mydata: this data is your own data (you can pass NULL),
* and is passed on to the callback function.
* @param callback: this is called on completion of the resolution.
* It is called as:
* void callback(void* mydata, int err, struct ub_result* result)
* with mydata: the same as passed here, you may pass NULL,
* with err: is 0 when a result has been found.
* with result: a newly allocated result structure.
* The result may be NULL, in that case err is set.
*
* If an error happens during processing, your callback will be called
* with error set to a nonzero value (and result==NULL).
* @param async_id: if you pass a non-NULL value, an identifier number is
* returned for the query as it is in progress. It can be used to
* cancel the query.
* @return 0 if OK, else error.
*/
int ub_resolve_async(struct ub_ctx* ctx, char* name, int rrtype,
int rrclass, void* mydata, ub_callback_t callback, int* async_id);
/**
* Cancel an async query in progress.
* Its callback will not be called.
*
* @param ctx: context.
* @param async_id: which query to cancel.
* @return 0 if OK, else error.
* This routine can return an error if the async_id passed does not exist
* or has already been delivered. If another thread is processing results
* at the same time, the result may be delivered at the same time and the
* cancel fails with an error. Also the cancel can fail due to a system
* error, no memory or socket failures.
*/
int ub_cancel(struct ub_ctx* ctx, int async_id);
/**
* Free storage associated with a result structure.
* @param result: to free
*/
void ub_resolve_free(struct ub_result* result);
/**
* Convert error value to a human readable string.
* @param err: error code from one of the ub_val* functions.
* @return pointer to constant text string, zero terminated.
*/
const char* ub_strerror(int err);
/**
* Debug routine. Print the local zone information to debug output.
* @param ctx: context. Is finalized by the routine.
* @return 0 if OK, else error.
*/
int ub_ctx_print_local_zones(struct ub_ctx* ctx);
/**
* Add a new zone with the zonetype to the local authority info of the
* library.
* @param ctx: context. Is finalized by the routine.
* @param zone_name: name of the zone in text, "example.com"
* If it already exists, the type is updated.
* @param zone_type: type of the zone (like for unbound.conf) in text.
* @return 0 if OK, else error.
*/
int ub_ctx_zone_add(struct ub_ctx* ctx, char *zone_name, char *zone_type);
/**
* Remove zone from local authority info of the library.
* @param ctx: context. Is finalized by the routine.
* @param zone_name: name of the zone in text, "example.com"
* If it does not exist, nothing happens.
* @return 0 if OK, else error.
*/
int ub_ctx_zone_remove(struct ub_ctx* ctx, char *zone_name);
/**
* Add localdata to the library local authority info.
* Similar to local-data config statement.
* @param ctx: context. Is finalized by the routine.
* @param data: the resource record in text format, for example
* "www.example.com IN A 127.0.0.1"
* @return 0 if OK, else error.
*/
int ub_ctx_data_add(struct ub_ctx* ctx, char *data);
/**
* Remove localdata from the library local authority info.
* @param ctx: context. Is finalized by the routine.
* @param data: the name to delete all data from, like "www.example.com".
* @return 0 if OK, else error.
*/
int ub_ctx_data_remove(struct ub_ctx* ctx, char *data);
#ifdef __cplusplus
}
#endif
#endif /* _UB_UNBOUND_H */

@ -1,534 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright (c) 2007, NLnet Labs. All rights reserved.
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* \file
*
* This file contains functions to resolve DNS queries and
* validate the answers. Synchonously and asynchronously.
*
* Several ways to use this interface from an application wishing
* to perform (validated) DNS lookups.
*
* All start with
* ctx = ub_ctx_create();
* err = ub_ctx_add_ta(ctx, "...");
* err = ub_ctx_add_ta(ctx, "...");
* ... some lookups
* ... call ub_ctx_delete(ctx); when you want to stop.
*
* Application not threaded. Blocking.
* int err = ub_resolve(ctx, "www.example.com", ...
* if(err) fprintf(stderr, "lookup error: %s\n", ub_strerror(err));
* ... use the answer
*
* Application not threaded. Non-blocking ('asynchronous').
* err = ub_resolve_async(ctx, "www.example.com", ... my_callback);
* ... application resumes processing ...
* ... and when either ub_poll(ctx) is true
* ... or when the file descriptor ub_fd(ctx) is readable,
* ... or whenever, the app calls ...
* ub_process(ctx);
* ... if no result is ready, the app resumes processing above,
* ... or process() calls my_callback() with results.
*
* ... if the application has nothing more to do, wait for answer
* ub_wait(ctx);
*
* Application threaded. Blocking.
* Blocking, same as above. The current thread does the work.
* Multiple threads can use the *same context*, each does work and uses
* shared cache data from the context.
*
* Application threaded. Non-blocking ('asynchronous').
* ... setup threaded-asynchronous config option
* err = ub_ctx_async(ctx, 1);
* ... same as async for non-threaded
* ... the callbacks are called in the thread that calls process(ctx)
*
* If no threading is compiled in, the above async example uses fork(2) to
* create a process to perform the work. The forked process exits when the
* calling process exits, or ctx_delete() is called.
* Otherwise, for asynchronous with threading, a worker thread is created.
*
* The blocking calls use shared ctx-cache when threaded. Thus
* ub_resolve() and ub_resolve_async() && ub_wait() are
* not the same. The first makes the current thread do the work, setting
* up buffers, etc, to perform the work (but using shared cache data).
* The second calls another worker thread (or process) to perform the work.
* And no buffers need to be set up, but a context-switch happens.
*/
#ifndef _UB_UNBOUND_H
#define _UB_UNBOUND_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* The validation context is created to hold the resolver status,
* validation keys and a small cache (containing messages, rrsets,
* roundtrip times, trusted keys, lameness information).
*
* Its contents are internally defined.
*/
struct ub_ctx;
/**
* The validation and resolution results.
* Allocated by the resolver, and need to be freed by the application
* with ub_resolve_free().
*/
struct ub_result {
/** The original question, name text string. */
char* qname;
/** the type asked for */
int qtype;
/** the class asked for */
int qclass;
/**
* a list of network order DNS rdata items, terminated with a
* NULL pointer, so that data[0] is the first result entry,
* data[1] the second, and the last entry is NULL.
* If there was no data, data[0] is NULL.
*/
char** data;
/** the length in bytes of the data items, len[i] for data[i] */
int* len;
/**
* canonical name for the result (the final cname).
* zero terminated string.
* May be NULL if no canonical name exists.
*/
char* canonname;
/**
* DNS RCODE for the result. May contain additional error code if
* there was no data due to an error. 0 (NOERROR) if okay.
*/
int rcode;
/**
* The DNS answer packet. Network formatted. Can contain DNSSEC types.
*/
void* answer_packet;
/** length of the answer packet in octets. */
int answer_len;
/**
* If there is any data, this is true.
* If false, there was no data (nxdomain may be true, rcode can be set).
*/
int havedata;
/**
* If there was no data, and the domain did not exist, this is true.
* If it is false, and there was no data, then the domain name
* is purported to exist, but the requested data type is not available.
*/
int nxdomain;
/**
* True, if the result is validated securely.
* False, if validation failed or domain queried has no security info.
*
* It is possible to get a result with no data (havedata is false),
* and secure is true. This means that the non-existance of the data
* was cryptographically proven (with signatures).
*/
int secure;
/**
* If the result was not secure (secure==0), and this result is due
* to a security failure, bogus is true.
* This means the data has been actively tampered with, signatures
* failed, expected signatures were not present, timestamps on
* signatures were out of date and so on.
*
* If !secure and !bogus, this can happen if the data is not secure
* because security is disabled for that domain name.
* This means the data is from a domain where data is not signed.
*/
int bogus;
/**
* If the result is bogus this contains a string (zero terminated)
* that describes the failure. There may be other errors as well
* as the one described, the description may not be perfectly accurate.
* Is NULL if the result is not bogus.
*/
char* why_bogus;
};
/**
* Callback for results of async queries.
* The readable function definition looks like:
* void my_callback(void* my_arg, int err, struct ub_result* result);
* It is called with
* void* my_arg: your pointer to a (struct of) data of your choice,
* or NULL.
* int err: if 0 all is OK, otherwise an error occured and no results
* are forthcoming.
* struct result: pointer to more detailed result structure.
* This structure is allocated on the heap and needs to be
* freed with ub_resolve_free(result);
*/
typedef void (*ub_callback_t)(void*, int, struct ub_result*);
/**
* Create a resolving and validation context.
* The information from /etc/resolv.conf and /etc/hosts is not utilised by
* default. Use ub_ctx_resolvconf and ub_ctx_hosts to read them.
* @return a new context. default initialisation.
* returns NULL on error.
*/
struct ub_ctx* ub_ctx_create(void);
/**
* Destroy a validation context and free all its resources.
* Outstanding async queries are killed and callbacks are not called for them.
* @param ctx: context to delete.
*/
void ub_ctx_delete(struct ub_ctx* ctx);
/**
* Set an option for the context.
* @param ctx: context.
* @param opt: option name from the unbound.conf config file format.
* (not all settings applicable). The name includes the trailing ':'
* for example ub_ctx_set_option(ctx, "logfile:", "mylog.txt");
* This is a power-users interface that lets you specify all sorts
* of options.
* For some specific options, such as adding trust anchors, special
* routines exist.
* @param val: value of the option.
* @return: 0 if OK, else error.
*/
int ub_ctx_set_option(struct ub_ctx* ctx, char* opt, char* val);
/**
* Get an option from the context.
* @param ctx: context.
* @param opt: option name from the unbound.conf config file format.
* (not all settings applicable). The name excludes the trailing ':'
* for example ub_ctx_get_option(ctx, "logfile", &result);
* This is a power-users interface that lets you specify all sorts
* of options.
* @param str: the string is malloced and returned here. NULL on error.
* The caller must free() the string. In cases with multiple
* entries (auto-trust-anchor-file), a newline delimited list is
* returned in the string.
* @return 0 if OK else an error code (malloc failure, syntax error).
*/
int ub_ctx_get_option(struct ub_ctx* ctx, char* opt, char** str);
/**
* setup configuration for the given context.
* @param ctx: context.
* @param fname: unbound config file (not all settings applicable).
* This is a power-users interface that lets you specify all sorts
* of options.
* For some specific options, such as adding trust anchors, special
* routines exist.
* @return: 0 if OK, else error.
*/
int ub_ctx_config(struct ub_ctx* ctx, char* fname);
/**
* Set machine to forward DNS queries to, the caching resolver to use.
* IP4 or IP6 address. Forwards all DNS requests to that machine, which
* is expected to run a recursive resolver. If the proxy is not
* DNSSEC-capable, validation may fail. Can be called several times, in
* that case the addresses are used as backup servers.
*
* To read the list of nameservers from /etc/resolv.conf (from DHCP or so),
* use the call ub_ctx_resolvconf.
*
* @param ctx: context.
* At this time it is only possible to set configuration before the
* first resolve is done.
* @param addr: address, IP4 or IP6 in string format.
* If the addr is NULL, forwarding is disabled.
* @return 0 if OK, else error.
*/
int ub_ctx_set_fwd(struct ub_ctx* ctx, char* addr);
/**
* Read list of nameservers to use from the filename given.
* Usually "/etc/resolv.conf". Uses those nameservers as caching proxies.
* If they do not support DNSSEC, validation may fail.
*
* Only nameservers are picked up, the searchdomain, ndots and other
* settings from resolv.conf(5) are ignored.
*
* @param ctx: context.
* At this time it is only possible to set configuration before the
* first resolve is done.
* @param fname: file name string. If NULL "/etc/resolv.conf" is used.
* @return 0 if OK, else error.
*/
int ub_ctx_resolvconf(struct ub_ctx* ctx, char* fname);
/**
* Read list of hosts from the filename given.
* Usually "/etc/hosts".
* These addresses are not flagged as DNSSEC secure when queried for.
*
* @param ctx: context.
* At this time it is only possible to set configuration before the
* first resolve is done.
* @param fname: file name string. If NULL "/etc/hosts" is used.
* @return 0 if OK, else error.
*/
int ub_ctx_hosts(struct ub_ctx* ctx, char* fname);
/**
* Add a trust anchor to the given context.
* The trust anchor is a string, on one line, that holds a valid DNSKEY or
* DS RR.
* @param ctx: context.
* At this time it is only possible to add trusted keys before the
* first resolve is done.
* @param ta: string, with zone-format RR on one line.
* [domainname] [TTL optional] [type] [class optional] [rdata contents]
* @return 0 if OK, else error.
*/
int ub_ctx_add_ta(struct ub_ctx* ctx, char* ta);
/**
* Add trust anchors to the given context.
* Pass name of a file with DS and DNSKEY records (like from dig or drill).
* @param ctx: context.
* At this time it is only possible to add trusted keys before the
* first resolve is done.
* @param fname: filename of file with keyfile with trust anchors.
* @return 0 if OK, else error.
*/
int ub_ctx_add_ta_file(struct ub_ctx* ctx, char* fname);
/**
* Add trust anchors to the given context.
* Pass the name of a bind-style config file with trusted-keys{}.
* @param ctx: context.
* At this time it is only possible to add trusted keys before the
* first resolve is done.
* @param fname: filename of file with bind-style config entries with trust
* anchors.
* @return 0 if OK, else error.
*/
int ub_ctx_trustedkeys(struct ub_ctx* ctx, char* fname);
/**
* Set debug output (and error output) to the specified stream.
* Pass NULL to disable. Default is stderr.
* @param ctx: context.
* @param out: FILE* out file stream to log to.
* Type void* to avoid stdio dependency of this header file.
* @return 0 if OK, else error.
*/
int ub_ctx_debugout(struct ub_ctx* ctx, void* out);
/**
* Set debug verbosity for the context
* Output is directed to stderr.
* @param ctx: context.
* @param d: debug level, 0 is off, 1 is very minimal, 2 is detailed,
* and 3 is lots.
* @return 0 if OK, else error.
*/
int ub_ctx_debuglevel(struct ub_ctx* ctx, int d);
/**
* Set a context behaviour for asynchronous action.
* @param ctx: context.
* @param dothread: if true, enables threading and a call to resolve_async()
* creates a thread to handle work in the background.
* If false, a process is forked to handle work in the background.
* Changes to this setting after async() calls have been made have
* no effect (delete and re-create the context to change).
* @return 0 if OK, else error.
*/
int ub_ctx_async(struct ub_ctx* ctx, int dothread);
/**
* Poll a context to see if it has any new results
* Do not poll in a loop, instead extract the fd below to poll for readiness,
* and then check, or wait using the wait routine.
* @param ctx: context.
* @return: 0 if nothing to read, or nonzero if a result is available.
* If nonzero, call ctx_process() to do callbacks.
*/
int ub_poll(struct ub_ctx* ctx);
/**
* Wait for a context to finish with results. Calls ub_process() after
* the wait for you. After the wait, there are no more outstanding
* asynchronous queries.
* @param ctx: context.
* @return: 0 if OK, else error.
*/
int ub_wait(struct ub_ctx* ctx);
/**
* Get file descriptor. Wait for it to become readable, at this point
* answers are returned from the asynchronous validating resolver.
* Then call the ub_process to continue processing.
* This routine works immediately after context creation, the fd
* does not change.
* @param ctx: context.
* @return: -1 on error, or file descriptor to use select(2) with.
*/
int ub_fd(struct ub_ctx* ctx);
/**
* Call this routine to continue processing results from the validating
* resolver (when the fd becomes readable).
* Will perform necessary callbacks.
* @param ctx: context
* @return: 0 if OK, else error.
*/
int ub_process(struct ub_ctx* ctx);
/**
* Perform resolution and validation of the target name.
* @param ctx: context.
* The context is finalized, and can no longer accept config changes.
* @param name: domain name in text format (a zero terminated text string).
* @param rrtype: type of RR in host order, 1 is A (address).
* @param rrclass: class of RR in host order, 1 is IN (for internet).
* @param result: the result data is returned in a newly allocated result
* structure. May be NULL on return, return value is set to an error
* in that case (out of memory).
* @return 0 if OK, else error.
*/
int ub_resolve(struct ub_ctx* ctx, char* name, int rrtype,
int rrclass, struct ub_result** result);
/**
* Perform resolution and validation of the target name.
* Asynchronous, after a while, the callback will be called with your
* data and the result.
* @param ctx: context.
* If no thread or process has been created yet to perform the
* work in the background, it is created now.
* The context is finalized, and can no longer accept config changes.
* @param name: domain name in text format (a string).
* @param rrtype: type of RR in host order, 1 is A.
* @param rrclass: class of RR in host order, 1 is IN (for internet).
* @param mydata: this data is your own data (you can pass NULL),
* and is passed on to the callback function.
* @param callback: this is called on completion of the resolution.
* It is called as:
* void callback(void* mydata, int err, struct ub_result* result)
* with mydata: the same as passed here, you may pass NULL,
* with err: is 0 when a result has been found.
* with result: a newly allocated result structure.
* The result may be NULL, in that case err is set.
*
* If an error happens during processing, your callback will be called
* with error set to a nonzero value (and result==NULL).
* @param async_id: if you pass a non-NULL value, an identifier number is
* returned for the query as it is in progress. It can be used to
* cancel the query.
* @return 0 if OK, else error.
*/
int ub_resolve_async(struct ub_ctx* ctx, char* name, int rrtype,
int rrclass, void* mydata, ub_callback_t callback, int* async_id);
/**
* Cancel an async query in progress.
* Its callback will not be called.
*
* @param ctx: context.
* @param async_id: which query to cancel.
* @return 0 if OK, else error.
* This routine can return an error if the async_id passed does not exist
* or has already been delivered. If another thread is processing results
* at the same time, the result may be delivered at the same time and the
* cancel fails with an error. Also the cancel can fail due to a system
* error, no memory or socket failures.
*/
int ub_cancel(struct ub_ctx* ctx, int async_id);
/**
* Free storage associated with a result structure.
* @param result: to free
*/
void ub_resolve_free(struct ub_result* result);
/**
* Convert error value to a human readable string.
* @param err: error code from one of the ub_val* functions.
* @return pointer to constant text string, zero terminated.
*/
const char* ub_strerror(int err);
/**
* Debug routine. Print the local zone information to debug output.
* @param ctx: context. Is finalized by the routine.
* @return 0 if OK, else error.
*/
int ub_ctx_print_local_zones(struct ub_ctx* ctx);
/**
* Add a new zone with the zonetype to the local authority info of the
* library.
* @param ctx: context. Is finalized by the routine.
* @param zone_name: name of the zone in text, "example.com"
* If it already exists, the type is updated.
* @param zone_type: type of the zone (like for unbound.conf) in text.
* @return 0 if OK, else error.
*/
int ub_ctx_zone_add(struct ub_ctx* ctx, char *zone_name, char *zone_type);
/**
* Remove zone from local authority info of the library.
* @param ctx: context. Is finalized by the routine.
* @param zone_name: name of the zone in text, "example.com"
* If it does not exist, nothing happens.
* @return 0 if OK, else error.
*/
int ub_ctx_zone_remove(struct ub_ctx* ctx, char *zone_name);
/**
* Add localdata to the library local authority info.
* Similar to local-data config statement.
* @param ctx: context. Is finalized by the routine.
* @param data: the resource record in text format, for example
* "www.example.com IN A 127.0.0.1"
* @return 0 if OK, else error.
*/
int ub_ctx_data_add(struct ub_ctx* ctx, char *data);
/**
* Remove localdata from the library local authority info.
* @param ctx: context. Is finalized by the routine.
* @param data: the name to delete all data from, like "www.example.com".
* @return 0 if OK, else error.
*/
int ub_ctx_data_remove(struct ub_ctx* ctx, char *data);
#ifdef __cplusplus
}
#endif
#endif /* _UB_UNBOUND_H */

@ -525,6 +525,7 @@ Run_getJavaVMOptionStrings
= {
_T("lib\\felix.jar"),
_T("sc-bundles\\sc-launcher.jar"),
_T("sc-bundles\\dnsjava.jar"),
_T("sc-bundles\\util.jar"),
_T("lib"),
NULL

@ -19,7 +19,10 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
@ -28,6 +31,7 @@
import net.java.sip.communicator.util.Logger;
import net.java.sip.communicator.plugin.desktoputil.*;
import org.jitsi.dnssec.validator.ValidatingResolver;
import org.jitsi.service.configuration.*;
import org.jitsi.service.resources.*;
import org.jitsi.util.*;
@ -40,7 +44,8 @@
* @author Ingo Bauersachs
*/
public class ConfigurableDnssecResolver
extends UnboundResolver
extends ValidatingResolver
implements CustomResolver
{
private final static Logger logger
= Logger.getLogger(ConfigurableDnssecResolver.class);
@ -67,13 +72,38 @@ public class ConfigurableDnssecResolver
private Map<String, Date> lastNotifications
= new HashMap<String, Date>();
private ExtendedResolver headResolver;
/**
* Creates a new instance of this class. Tries to use the system's
* default forwarders.
*/
public ConfigurableDnssecResolver()
public ConfigurableDnssecResolver(ExtendedResolver headResolver)
{
super();
super(headResolver);
List<String> propNames
= config.getPropertyNamesByPrefix("org.jitsi.dnssec", false);
Properties config = new Properties();
for (String propName : propNames)
{
String value = config.getProperty(propName);
if (!StringUtils.isNullOrEmpty(value))
{
config.put(propName, value);
}
}
try
{
super.init(config);
}
catch (IOException e)
{
logger.error("Extended dnssec properties contained an error", e);
}
this.headResolver = headResolver;
reset();
Lookup.setDefaultResolver(this);
@ -92,8 +122,8 @@ public ConfigurableDnssecResolver()
* did not choose to ignore it.
*/
@Override
protected void validateMessage(SecureMessage msg)
throws DnssecRuntimeException
public Message send(Message query)
throws DnssecRuntimeException, IOException
{
//---------------------------------------------------------------------
// || 1 | 2 | 3 | 4 | 5
@ -105,6 +135,7 @@ protected void validateMessage(SecureMessage msg)
//c) 0 | 0 || ok | nok | ok | ok | ask
//---------------------------------------------------------------------
SecureMessage msg = new SecureMessage(super.send(query));
String fqdn = msg.getQuestion().getName().toString();
String type = Type.string(msg.getQuestion().getType());
String propName = createPropNameUnsigned(fqdn, type);
@ -129,7 +160,7 @@ protected void validateMessage(SecureMessage msg)
//[abc]1, a[2-5]
if(pinned == SecureResolveMode.IgnoreDnssec || msg.isSecure())
return;
return msg;
if(
//b2, c2
@ -152,16 +183,17 @@ protected void validateMessage(SecureMessage msg)
null);
lastNotifications.put(text, new Date());
}
throw new DnssecRuntimeException(text);
}
//c3
if(pinned == SecureResolveMode.SecureOrUnsigned && !msg.isBogus())
return;
return msg;
//c4
if(pinned == SecureResolveMode.WarnIfBogus && !msg.isBogus())
return;
return msg;
//b4, b5, c5
String reason = msg.isBogus()
@ -190,6 +222,8 @@ protected void validateMessage(SecureMessage msg)
config.setProperty(propName, SecureResolveMode.SecureOnly);
throw new DnssecRuntimeException(getExceptionMessage(msg));
}
return msg;
}
/**
@ -372,22 +406,66 @@ public void reset()
{
if(logger.isTraceEnabled())
{
logger.trace("Setting DNSSEC forwarders to: "
+ Arrays.toString(forwarders.split(",")));
logger.trace("Setting DNSSEC forwarders to: " + forwarders);
}
synchronized (Lookup.class)
{
Lookup.refreshDefault();
String[] fwds = forwarders.split(",");
Resolver[] rs = headResolver.getResolvers();
for (Resolver r : rs)
{
headResolver.deleteResolver(r);
}
for (String fwd : fwds)
{
try
{
SimpleResolver sr = new SimpleResolver(fwd);
// these properties are normally set by the
// ValidatingResolver in the constructor
sr.setEDNS(0, 0, ExtendedFlags.DO, null);
sr.setIgnoreTruncation(false);
headResolver.addResolver(sr);
}
catch (UnknownHostException e)
{
logger.error("Invalid forwarder, ignoring", e);
}
}
Lookup.setDefaultResolver(this);
}
super.setForwarders(forwarders.split(","));
}
StringBuilder sb = new StringBuilder();
for(int i = 1;;i++)
{
String anchor = DnsUtilActivator.getResources().getSettingsString(
"net.java.sip.communicator.util.dns.DS_ROOT." + i);
if(anchor == null)
{
break;
clearTrustAnchors();
addTrustAnchor(anchor);
if(logger.isTraceEnabled())
logger.trace("Loaded trust anchor " + anchor);
}
sb.append(anchor);
sb.append('\n');
}
try
{
super.loadTrustAnchors(new ByteArrayInputStream(
sb.toString().getBytes("ASCII")));
}
catch (IOException e)
{
logger.error("Could not load the trust anchors", e);
}
if(logger.isTraceEnabled())
logger.trace("Loaded trust anchors " + sb.toString());
}
}

@ -150,7 +150,7 @@ public void start(BundleContext context)
{
bundleContext.registerService(
CustomResolver.class.getName(),
new ConfigurableDnssecResolver(),
new ConfigurableDnssecResolver(new ExtendedResolver()),
null);
logger.info("DnssecResolver ... [REGISTERED]");
}

@ -19,6 +19,7 @@
import java.io.*;
import org.jitsi.dnssec.validator.*;
import org.xbill.DNS.*;
/**
@ -34,18 +35,24 @@ public class SecureMessage
private String bogusReason;
/**
* Creates a new instance of this class based on data received from an
* Unbound resolve.
* Creates a new instance of this class based on data received from a
* dnssecjava resolve.
*
* @param msg The answer of the Unbound resolver.
* @param msg The answer of the dnssecjava resolver.
* @throws IOException
*/
public SecureMessage(UnboundResult msg) throws IOException
public SecureMessage(Message msg) throws IOException
{
super(msg.answerPacket);
secure = msg.secure;
bogus = msg.bogus;
bogusReason = msg.whyBogus;
super(msg.toWire());
secure = msg.getHeader().getFlag(Flags.AD);
bogus = !secure && msg.getRcode() == Rcode.SERVFAIL;
for (RRset set : msg.getSectionRRsets(Section.ADDITIONAL)) {
if (set.getName().equals(Name.root) && set.getType() == Type.TXT
&& set.getDClass() == ValidatingResolver.VALIDATION_REASON_QCLASS)
{
bogusReason = ((TXTRecord)set.first()).getStrings().get(0).toString();
}
}
}
/**

@ -1,239 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.dns;
/**
* Wrapper for the JUnbound JNI wrapper.
* <p>
* The JavaDoc of these methods is directly copied from libunbound, licensed as
* follows:
* <p>
* Copyright (c) 2007, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Ingo Bauersachs
*/
public class UnboundApi
{
private static boolean isAvailable;
private static final Object syncRoot = new Object();
static
{
tryLoadUnbound();
}
/**
* Attempts to load the Unbound native library. When successful,
* {@link #isAvailable()} returns true.
*/
public static void tryLoadUnbound()
{
synchronized(syncRoot)
{
try
{
System.loadLibrary("junbound");
isAvailable = true;
}
catch(UnsatisfiedLinkError e)
{
isAvailable = false;
}
}
}
/**
* Indicates whether the Unbound library is loaded.
* @return True when the JNI wrapper could be loaded, false otherwise.
*/
public static boolean isAvailable()
{
return isAvailable;
}
/**
* Set debug verbosity for the context. Output is directed to stderr. Higher
* debug level gives more output.
*
* @param context context.
* @param level The debug level.
*/
public static native void setDebugLevel(long context, int level);
/**
* Create a resolving and validation context.
* @return a new context. default initialization. returns NULL on error.
*/
public static native long createContext();
/**
* Destroy a validation context and free all its resources. Outstanding
* async queries are killed and callbacks are not called for them.
*
* @param context context to delete
*/
public static native void deleteContext(long context);
/**
* Set machine to forward DNS queries to, the caching resolver to use.
* <p>
* IP4 or IP6 address. Forwards all DNS requests to that machine, which is
* expected to run a recursive resolver. If the proxy is not DNSSEC-capable,
* validation may fail. Can be called several times, in that case the
* addresses are used as backup servers.
*
* @param context context. At this time it is only possible to set
* configuration before the first resolve is done.
* @param server address, IP4 or IP6 in string format. If the server is
* NULL, forwarding is disabled.
*/
public static native void setForwarder(long context, String server);
/**
* Add a trust anchor to the given context.
* <p>
* The trust anchor is a string, on one line, that holds a valid DNSKEY or
* DS RR.
*
* @param context context. At this time it is only possible to add trusted
* keys before the first resolve is done.
* @param anchor string, with zone-format RR on one line. [domainname] [TTL
* optional] [type] [class optional] [rdata contents]
*/
public static native void addTrustAnchor(long context, String anchor);
/**
* Perform resolution and validation of the target name.
*
* @param context context. The context is finalized, and can no longer
* accept config changes.
* @param name domain name in text format (a zero terminated text string).
* @param rrtype type of RR in host order, 1 is A (address).
* @param rrclass class of RR in host order, 1 is IN (for internet).
* @return the result data is returned in a newly allocated result
* structure. May be NULL on return, return value is set to an error
* in that case (out of memory).
* @throws UnboundException when an error occurred.
*/
public static native UnboundResult resolve(long context, String name,
int rrtype, int rrclass) throws UnboundException;
/**
* Perform resolution and validation of the target name.
* <p>
* Asynchronous, after a while, the callback will be called with your data
* and the result.
*
* @param context context. If no thread or process has been created yet to
* perform the work in the background, it is created now. The
* context is finalized, and can no longer accept config changes.
* @param name domain name in text format (a string).
* @param rrtype type of RR in host order, 1 is A.
* @param rrclass class of RR in host order, 1 is IN (for internet).
* @param data this data is your own data (you can pass null), and is passed
* on to the callback function.
* @param cb this is called on completion of the resolution.
* @return an identifier number is returned for the query as it is in
* progress. It can be used to cancel the query.
* @throws UnboundException when an error occurred.
*/
public static native int resolveAsync(long context, String name,
int rrtype, int rrclass, Object data, UnboundCallback cb)
throws UnboundException;
/**
* Cancel an async query in progress. Its callback will not be called.
*
* @param context context.
* @param asyncId which query to cancel.
* @throws UnboundException This routine can error if the async_id passed
* does not exist or has already been delivered. If another
* thread is processing results at the same time, the result may
* be delivered at the same time and the cancel fails with an
* error. Also the cancel can fail due to a system error, no
* memory or socket failures.
*/
public static native void cancelAsync(long context, int asyncId)
throws UnboundException;
/**
* Convert error value to a human readable string.
*
* @param code error code from one of the Unbound functions.
* @return text string of the error code.
*/
public static native String errorCodeToString(int code);
/**
* Wait for a context to finish with results. Call this routine to continue
* processing results from the validating resolver. After the wait, there
* are no more outstanding asynchronous queries.
*
* @param context context.
* @throws UnboundException when an error occurred.
*/
public static native void processAsync(long context)
throws UnboundException;
/**
* Interface for the async resolve callback.
*/
public interface UnboundCallback
{
/**
* Called on completion of the async resolution.
*
* @param data the same object as passed to
* {@link UnboundApi#resolveAsync(long, String, int, int,
* Object, UnboundCallback)}
* @param err 0 when a result has been found, an Unbound error code
* otherwise
* @param result a newly allocated result structure. The result may be
* null, in that case err is set.
*/
public void UnboundResolveCallback(Object data, int err,
UnboundResult result);
}
}

@ -1,42 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.dns;
/**
* Exception that is being thrown when native Unbound code resulted in an error.
*
* @author Ingo Bauersachs
*/
public class UnboundException
extends Exception
{
/**
* Serial version UID.
*/
private static final long serialVersionUID = 0L;
/**
* Creates a new instance of this class.
*
* @param message the detail message.
*/
public UnboundException(String message)
{
super(message);
}
}

@ -1,410 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.dns;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
import net.java.sip.communicator.service.dns.*;
import net.java.sip.communicator.util.*;
import org.xbill.DNS.*;
/**
* Implementation of the {@link Resolver} interface, wrapping the native NLnet
* Labs Unbound resolver. Only the basic methods for queries are supported.
*
* @author Ingo Bauersachs
*/
public class UnboundResolver
implements CustomResolver
{
private final static Logger logger =
Logger.getLogger(UnboundResolver.class);
/**
* Helper class to synchronize on asynchronous queries.
*/
private static class CallbackData
{
/**
* The resolver consumer that wishes to be informed when the request
* completed.
*/
ResolverListener listener;
/**
* The unbound session context.
*/
long context;
/**
* The ID of the unbound async query.
*/
int asyncId;
/**
* Java synchronization on top of unbound.
*/
CountDownLatch sync = new CountDownLatch(1);
}
/**
* Timeout for DNS queries.
*/
private int timeout = 10000;
/**
* The recursive DNS servers answering our queries.
*/
private String[] forwarders;
/**
* DNSSEC trust anchors for signed zones (usually for the root zone).
*/
private List<String> trustAnchors = new LinkedList<String>();
/**
* Pool that executes our queries.
*/
private ExecutorService threadPool;
/**
* Creates a new instance of this class.
*/
public UnboundResolver()
{
threadPool = Executors.newCachedThreadPool();
}
/**
* Sets a list of forwarders to use instead of the system default.
*
* @param forwarders list of servers to use for our queries.
*/
public void setForwarders(String[] forwarders)
{
this.forwarders = forwarders;
}
/**
* Clears any existing trust anchors previously added.
*/
public void clearTrustAnchors()
{
trustAnchors.clear();
}
/**
* Adds a DNSSEC trust anchor validation of the DNSKEYs.
*
* @param anchor trust anchor in the form of
* "'zone' IN DS 'key tag' 'algorithm' 'digest type' 'digest'"
*/
public void addTrustAnchor(String anchor)
{
trustAnchors.add(anchor);
}
/**
* {@inheritDoc}
*/
public SecureMessage send(final Message query) throws IOException
{
Future<SecureMessage> future = threadPool.submit(
new Callable<SecureMessage>()
{
public SecureMessage call() throws Exception
{
if(logger.isDebugEnabled())
logger.debug(query);
SecureMessage secureMessage = null;
final long context = prepareContext();
try
{
UnboundResult result = UnboundApi.resolve(
context,
query.getQuestion().getName().toString(),
query.getQuestion().getType(),
query.getQuestion().getDClass()
);
secureMessage = new SecureMessage(result);
validateMessage(secureMessage);
}
finally
{
UnboundApi.deleteContext(context);
if(logger.isDebugEnabled() && secureMessage != null)
logger.debug(secureMessage);
}
return secureMessage;
}
});
try
{
return future.get(timeout, TimeUnit.SECONDS);
}
catch (InterruptedException e)
{
logger.error(e);
throw new IOException(e.getMessage());
}
catch (ExecutionException e)
{
if(e.getCause() instanceof DnssecRuntimeException)
throw new DnssecRuntimeException(e.getCause().getMessage());
logger.error(e);
throw new IOException(e.getMessage());
}
catch (TimeoutException e)
{
throw new SocketTimeoutException(e.getMessage());
}
}
/**
* Method to allow overriders to inspect the message. This class'
* implementation does nothing.
*
* @param msg The message to inspect.
* @throws DnssecRuntimeException if the inspector does not want the code to
* continue normal processing of the answer.
*/
protected void validateMessage(SecureMessage msg)
throws DnssecRuntimeException
{
}
/**
* Prepares a unbound session context initialized with forwarders and trust
* anchors.
*
* @return The context id
*/
private long prepareContext()
{
final long context = UnboundApi.createContext();
if(logger.isTraceEnabled())
UnboundApi.setDebugLevel(context, 100);
for(String fwd : forwarders == null
? ResolverConfig.getCurrentConfig().servers()
: forwarders)
{
fwd = fwd.trim();
if(NetworkUtils.isValidIPAddress(fwd))
{
if(fwd.startsWith("["))
fwd = fwd.substring(1, fwd.length() - 1);
UnboundApi.setForwarder(context, fwd);
}
}
for(String anchor : trustAnchors)
{
UnboundApi.addTrustAnchor(context, anchor);
}
return context;
}
/**
* Cleans up an Unbound session context.
*
* @param cbData The helper object of the asynchronous call.
* @param cancelAsync Whether an outstanding asynchronous unbound query
* should be canceled.
*/
private static synchronized void deleteContext(CallbackData cbData,
boolean cancelAsync)
{
if(cbData.context == 0)
return;
if(cancelAsync)
{
try
{
UnboundApi.cancelAsync(cbData.context, cbData.asyncId);
}
catch (UnboundException ignore)
{}
}
UnboundApi.deleteContext(cbData.context);
cbData.context = 0;
}
/*
* (non-Javadoc)
*
* @see org.xbill.DNS.Resolver#sendAsync(org.xbill.DNS.Message,
* org.xbill.DNS.ResolverListener)
*/
public CallbackData sendAsync(Message query, ResolverListener listener)
{
if(listener == null)
throw new IllegalArgumentException("listener cannot be null");
final long context = prepareContext();
final CallbackData cbData = new CallbackData();
cbData.listener = listener;
cbData.context = context;
int asyncId;
try
{
asyncId = UnboundApi.resolveAsync(
context,
query.getQuestion().getName().toString(),
query.getQuestion().getType(),
query.getQuestion().getDClass(),
cbData,
new UnboundApi.UnboundCallback()
{
public void UnboundResolveCallback(Object data, int err,
UnboundResult result)
{
CallbackData cbData = (CallbackData)data;
deleteContext(cbData, false);
ResolverListener l = cbData.listener;
if(err == 0)
{
try
{
l.receiveMessage(data,
new SecureMessage(result));
}
catch (IOException e)
{
l.handleException(data, e);
}
}
else
l.handleException(data,
new Exception(
UnboundApi.errorCodeToString(err)));
cbData.sync.countDown();
}
}
);
}
catch (UnboundException e)
{
listener.handleException(null, e);
return null;
}
cbData.asyncId = asyncId;
threadPool.execute(new Runnable()
{
public void run()
{
try
{
UnboundApi.processAsync(context);
}
catch(UnboundException ex)
{
cbData.listener.handleException(this, ex);
deleteContext(cbData, false);
cbData.sync.countDown();
}
}
});
return cbData;
}
/**
* Not supported.
* @throws UnsupportedOperationException
*/
public void setEDNS(int level)
{
throw new UnsupportedOperationException();
}
/**
* Not supported.
* @throws UnsupportedOperationException
*/
@SuppressWarnings("rawtypes")
public void setEDNS(int level, int payloadSize, int flags, List options)
{
throw new UnsupportedOperationException();
}
/**
* Not supported.
* @throws UnsupportedOperationException
*/
public void setIgnoreTruncation(boolean flag)
{
throw new UnsupportedOperationException();
}
/**
* Not supported.
* @throws UnsupportedOperationException
*/
public void setPort(int port)
{
throw new UnsupportedOperationException();
}
/**
* Not supported.
* @throws UnsupportedOperationException
*/
public void setTCP(boolean flag)
{
throw new UnsupportedOperationException();
}
/**
* Not supported.
* @throws UnsupportedOperationException
*/
public void setTSIGKey(TSIG key)
{
throw new UnsupportedOperationException();
}
/* (non-Javadoc)
* @see org.xbill.DNS.Resolver#setTimeout(int)
*/
public void setTimeout(int secs)
{
timeout = secs * 1000;
}
/* (non-Javadoc)
* @see org.xbill.DNS.Resolver#setTimeout(int, int)
*/
public void setTimeout(int secs, int msecs)
{
timeout = secs * 1000 + msecs;
}
/**
* Does nothing.
*/
public void reset()
{
}
}

@ -1,128 +0,0 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.impl.dns;
/**
* Class that contains the answer to query processed by the native Unbound
* resolver. Corresponds to the <a
* href="http://unbound.net/documentation/doxygen/structub__result.html"
* >ub_result</a> data structure.
*
* The fields {@link #data} and {@link #canonname} are not filled.
* <p>
* The JavaDoc of these fields is directly copied from libunbound, licensed as
* follows:
* <p>
* Copyright (c) 2007, NLnet Labs. All rights reserved.
*
* This software is open source.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the NLNET LABS nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @author Ingo Bauersachs
*/
public class UnboundResult
{
/**
* The original question, name text string.
*/
String qname;
/**
* the type asked for
*/
int qtype;
/**
* the type asked for
*/
int qclass;
/**
* a list of network order DNS rdata items, terminated with a NULL pointer,
* so that data[0] is the first result entry, data[1] the second, and the
* last entry is NULL.
*/
byte[][] data;
/**
* canonical name for the result (the final cname).
*/
String canonname;
/**
* DNS RCODE for the result.
*/
int rcode;
/**
* The DNS answer packet.
*/
byte[] answerPacket;
/**
* If there is any data, this is true.
*/
boolean haveData;
/**
* If there was no data, and the domain did not exist, this is true.
*/
boolean nxDomain;
/**
* True, if the result is validated securely.
*/
boolean secure;
/**
* If the result was not secure ({@link #secure} == false), and this result
* is due to a security failure, bogus is true.
*/
boolean bogus;
/**
* If the result is bogus this contains a string (zero terminated) that
* describes the failure.
*/
String whyBogus;
}

@ -8,6 +8,8 @@ Import-Package: org.jitsi.util,
org.osgi.framework,
net.java.sip.communicator.util,
net.java.sip.communicator.plugin.desktoputil,
org.jitsi.dnssec,
org.jitsi.dnssec.validator,
org.jitsi.service.resources,
org.jitsi.service.fileaccess,
net.java.sip.communicator.service.resources,

@ -118,7 +118,7 @@ public static void main(String[] args)
{
System.setProperty(
"sun.net.spi.nameservice.provider.1",
"dns,dnsjava");
"dns,jitsi");
}
if (version.startsWith("1.5") || vmVendor.startsWith("Gnu") ||

@ -267,7 +267,7 @@ public void actionPerformed(ActionEvent e)
if(chkEnabled.isSelected())
{
if(!f.createNewFile() && !f.exists())
chkEnabled.setSelected(UnboundApi.isAvailable());
chkEnabled.setSelected(false);
}
else
{

@ -0,0 +1,151 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2016 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.util;
import java.lang.reflect.Method;
import java.net.*;
import org.xbill.DNS.*;
import sun.net.spi.nameservice.*;
/**
* JNDI DNS service to send DNS lookup through the dnsjava <tt>Lookup</tt>
* infrastructure. This is needed to catch lookups that are not made
* through the DNSSEC-aware <tt>NetworkUtils</tt>.
*
* @author Ingo Bauersachs
*/
public class JitsiDnsNameService
implements NameService
{
private static boolean v6first;
private static Name localhostName = null;
private static InetAddress[] localhostAddresses = null;
private static InetAddress[] localhostNamedAddresses = null;
private static boolean addressesLoaded = false;
static
{
v6first = Boolean.getBoolean("java.net.preferIPv6Addresses");
try
{
// retrieve the name from the system that is used as localhost
Class<?> inClass = Class.forName("java.net.InetAddressImplFactory");
Method create = inClass.getDeclaredMethod("create");
create.setAccessible(true);
Object impl = create.invoke(null);
Class<?> clazz = Class.forName("java.net.InetAddressImpl");
Method hostname = clazz.getMethod("getLocalHostName");
hostname.setAccessible(true);
localhostName = new Name((String) hostname.invoke(impl));
Method lookup = clazz.getMethod("lookupAllHostAddr", String.class);
lookup.setAccessible(true);
localhostNamedAddresses = (InetAddress[])lookup.invoke(impl,
localhostName.toString());
localhostAddresses = (InetAddress[])lookup.invoke(impl,
"localhost");
addressesLoaded = true;
}
catch (Exception e)
{
System.err.println("Could not obtain localhost: " + e);
}
}
@Override
public String getHostByAddr(final byte[] bytes)
throws UnknownHostException
{
InetAddress addr = InetAddress.getByAddress(bytes);
if (addr.isLoopbackAddress())
{
return "localhost";
}
Name name = ReverseMap.fromAddress(addr);
Lookup l = new Lookup(name, Type.PTR);
Record[] records = l.run();
if (records == null)
{
throw new UnknownHostException();
}
return ((PTRRecord) records[0]).getTarget().toString();
}
@Override
public InetAddress[] lookupAllHostAddr(final String host)
throws UnknownHostException
{
Name n;
try
{
n = new Name(host);
// Avoid sending queries to a nameserver for localhost
// and the machine's hostname. Unless in an enterprise environment
// the nameserver wouldn't know about that machine name anyway.
if (addressesLoaded)
{
if (n.equals(localhostName))
{
return localhostNamedAddresses;
}
else if (host.equals("localhost"))
{
return localhostAddresses;
}
}
}
catch (TextParseException e)
{
throw new UnknownHostException(host);
}
Lookup l = new Lookup(n, v6first ? Type.AAAA : Type.A);
Record[] r = l.run();
if (r == null || r.length == 0)
{
l = new Lookup(n, v6first ? Type.A : Type.AAAA);
r = l.run();
}
if (r == null || r.length == 0)
{
throw new UnknownHostException(host);
}
InetAddress[] results = new InetAddress[r.length];
for (int i = 0; i < r.length; i++)
{
if (r[i] instanceof AAAARecord)
{
results[i] = ((AAAARecord) r[i]).getAddress();
}
else if (r[i] instanceof ARecord)
{
results[i] = ((ARecord) r[i]).getAddress();
}
}
return results;
}
}

@ -0,0 +1,58 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Copyright @ 2016 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.java.sip.communicator.util;
import sun.net.spi.nameservice.*;
/**
* A name service descriptor for Jitsi's DNS service. It is instantiated by the
* JRE when DNSSEC is enabled in Jitsi's options.
*
* @author Ingo Bauersachs
*/
public class JitsiDnsNameServiceDescriptor
implements NameServiceDescriptor
{
/**
* Gets and creates an instance of the Jitsi's name service.
*
* @return an instance of the Jitsi's name service.
*/
public NameService createNameService()
{
return new JitsiDnsNameService();
}
/**
* Gets the type of this name service.
* @return the string <tt>dns</tt>
*/
public String getType()
{
return "dns";
}
/**
* Gets the name of this name service.
* @return the string <tt>jitsi</tt>
*/
public String getProviderName()
{
return "jitsi";
}
}

@ -56,8 +56,7 @@ Import-Package: com.sun.awt,
sun.awt.shell,
sun.net.dns,
sun.net.util
Export-Package: org.xbill.DNS,
net.java.sip.communicator.util,
Export-Package: net.java.sip.communicator.util,
net.java.sip.communicator.util.launchutils,
net.java.sip.communicator.util.skin,
net.java.sip.communicator.util.xml,

Loading…
Cancel
Save