Include khash.h macro library

Included khash.h with `calloc`, `malloc` and `realloc` references replaced by
our own x-* versions.

While the khash.h library already provides an indirection layer to override the
allocation functions, they have been changed directly in the header so the
library can be used without the override boilerplate.
Add teardown function for the event.c module

Also move the `job_teardown` call from os_unix.c to the event module
Fix update of pending_reqs in `write_cb`
Refactor API types

Use specialized String/Array types that map more easily to msgpack
Add channel module

- Add channel module that exposes the API over arbitrary streams
- Add `xmemdup` for duplicating memory chunks
- Make job exit callback optional
Add server module for accepting API connections
Add --with-pic flag to msgpack configuration