mainloop: Convert vpn_mainloop() into a library function

Rename to openconnect_mainloop() and allow the caller to specify
reconnection parameters.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
main: Introduce xstrdup() function

This will abort on error, instead of causing a segfault.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tun: Export setup_tun() functionality

Create three new setup_tun() library functions:

    openconnect_setup_tun_device - create a tun device
    openconnect_setup_tun_script - pass traffic through a script
    openconnect_setup_tun_fd - pass traffic through an existing fd

The latter is needed to support Android's VpnService API.

In all cases, the caller no longer needs to directly manipulate
vpninfo->vpnc_script or vpninfo->script_tun.  The former is treated as
a standard caller-allocated, library-freed string.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Move vpninfo default settings into library

This allows main.c to call openconnect_vpninfo_new() to create the
library instance.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Check for failed allocations in openconnect_vpninfo_new()

This is probably fatal anyway, but it is better to fail in a predictable
manner.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
dtls: Export setup_dtls() function

This is an optional call; the default is "no DTLS."

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
cstp: Export make_cstp_connection()

Just rename it and add it to openconnect.h.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Move the mainloop guts into libopenconnect

Now the standalone openconnect binary only consists of main.c and xml.c.

Unfortunately openconnect_CFLAGS still needs to include the whole kitchen
sink, until we can remove openconnect-internal.h as a dependency.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Update openconnect.pc.in

Add openssl + gnutls to Requires.private for the ssl_library=both case.
Add liboath to Requires.private.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
tun, cstp: Don't exit() on failure

These files are part of a library now so they should report errors back
to the caller.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Free zlib state

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
cstp: Clean up split include/exclude/DNS lists when freeing vpninfo

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Add get/set functions for servercert, ifname, reqmtu

This allows all connection parameters used by nm-openconnect to be set
through the library API.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Export VPN IP information to callers

Move the IP and split tunnel configuration into "struct oc_ip_info", and
make a new library call for obtaining it.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
library: Add protect_socket callback

In some situations (e.g. Android VpnService) it isn't possible to add a
routing table entry for the VPN gateway's IP.  Instead, it is necessary
to bind each individual file descriptor used for the tunnel to the default
interface before passing traffic on it.  Add an optional protect_socket
callback for this purpose.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
main: Add openconnect_vpninfo_free() on a couple of exit paths

This makes it easier to check for library memory leaks.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
buildsys: Allow overriding -W flags

For any given source file, automake will apply either
"$(AM_CFLAGS) $(CFLAGS)" or "$(objname_CFLAGS) $(CFLAGS)" [1].  Move the
warning flags into the former item so that they can be disabled on a per-
object basis.

[1] http://www.gnu.org/software/automake/manual/automake.html#Flag-Variables-Ordering

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
acinclude: Add AX_JNI_INCLUDE_DIR macro

AX_JNI_INCLUDE_DIR is used to locate jni.h for building the Java Native
Interface to libopenconnect.  Original source:

http://www.gnu.org/software/autoconf-archive/ax_jni_include_dir.html

This commit also includes two pending enhancements:

http://savannah.gnu.org/patch/?8154
http://savannah.gnu.org/patch/?8155

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
JNI: Initial commit of C wrapper functions

If the user runs "configure --with-java", a separate library is built
with Java native interface stubs and it can be loaded with:

    System.loadLibrary("openconnect-wrapper");

On a native build, it should autodetect the jni.h location by looking at
JAVA_HOME or the path to javac.  On a cross build,
--with-java=/java_home/include must be explicitly specified.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
JNI: Initial commit of Java library + example program

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>