The new struct tree_iterator and associated start/get/next/free
functions replace the recursive walk() function, removing the need for a
callback when iterating over all nodes in the tree, and allowing
iteration to be suspended while other pseudo-threads are run. This
allows an HTTP REST request to keep a tree_iterator in its state struct
and potentially simplifies other areas of the code.
The iterator free()s any empty internal tree nodes that it encounters,
as did the original tree_walk() function. To support the existence of
multiple iterators at once, a reference count has been added to the
tree_node struct, to prevent any iterator from free()ing a node while
any other iterators point to it; only the last iterator to pop out of an
empty node will free() it.
The tree_walk() and tree_walk_prefix() functions have been
re-implemented to use an iterator state object internally. This
resolves an outstanding TODO to perform tree-node freeing during a
prefix walk, and simplifies the code considerably.
Renamed some function parameters and struct members to make the
nibble-tree API a little more self-explanatory.
Added a nibble-tree test to the 'serval-tests' utility.
The new 'cmd_cleanup' trigger replaces the old command_cleanup()
function, which was causing linking problems on OS X and inverted strict
dependency. The keyring cmd_cleanup calls keyring_free(global_keyring),
instead of merely asserting keyring == NULL, so the error exit cases of
many CLI functions have been simplified.
The CLI and server main loop now have no conditional JNI code. All JNI
code has been moved into separate source files, which #include the new
"jni_common.h" instead of <jni.h>. The "cli.h" header no longer
includes <jni.h>, so the rest of the Serval source code is now
unaffected by JNI definitions.
The 'cf_limbo' global variable is now thread-local, so that each thread
has its own independent copy of the loaded configuration. The JNI
server entry point now calls cf_init() once. The new 'cf_initialised'
flag prevents clobbering the config state by redundant calls to
cf_init().
The CLI "stop" command now sends SIGHUP to the specific thread in which
the server is running. This is achieved by writing the PID and TID
(Linux Thread ID) into the pidfile, separated by a space, on systems
that support the Linux gettid() and tgkill() system calls. The server's
signal handler has been overhauled, and its logging improved.