Allocation improvements, fix memory leaks, use header file.

This commit adds proper array-style allocation functions that deliberately check
for integer overflow, fixes a number of memory leaks discovered with Valgrind,
and splits out many of the `#typedef` directives to `gammu-json.h`.