Convert vpn_mainloop() into a library function

In order to make the mainloop a reusable library function, it should not
take over any POSIX signals.  Handle the signals in main.c instead, and
use the cancel_fd mechanism to tell the mainloop to exit.

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.

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>
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 --enable-jni", a separate library is built
with Java native interface stubs and it can be loaded with:

    System.loadLibrary("openconnect-wrapper");

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

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>