Fix checkresult output processing.

Checkresult output submitted through files is stored as a single line
with newlines (and backslashes) escaped so Core can read the complete
output as one line. The corresponding unescaping was not performed when
reading back from the files. These changes correct this by unescaping
the output after it is read from the checkresult file, and before any
further processing. We now use one newline-delimited format internally
for output data from all sources (checkresults spool, command file,
workers).

Perfdata from the first line was not being concatenated correctly to
following lines. A space is now concatenated before additional lines,
and a terminal space is not added to only be trimmed off later.

In support of these changes a new unescape_newlines() functions was
added to base/utils.c that performs the converse of the existing
escape_newlines(). Both of these functions allocate exactly the memory
needed for the new string they return, and not assume a worst case.
Using the improved escape_newlines() to escape the long_output at the
end of parse_check_output() eliminates an unnecessary malloc()/free()
pair.

The line processing code in parse_check_output() was strdup()ing each
line it processed, and then memmove()ing the remaining input to the
beginning of its buffer. As the memove() and earlier processing modify
the input buffer anyway, this alloc/copy/free/move is entirely unneeded:
the per-line processing can use the input buf directly. Modifying the
line processing loop to update buf to point at the next line to process
eliminates the extra memory movement.

Additionally, the checkresults spool directory is now installed with the
same ownership and permissions as the external command directory. This
allows members of the Nagios Command group (nagcmd by default) to submit
checkresults by default, and also keeps reinstalls or upgrades from
resetting the ownership and permissions.

All checkresult output, single or multiple line, and from all sources,
should now be parsed correctly (and more efficiently) by Core.
Don't crash with no perfdata on first line.

Check db2.buf is not NULL before dereferencing. Since dbuf_init()
initializes an empty dbuf, the buf member will be NULL until it is
allocated in dbuf_strcat().
Hanndle empty short output more sensibly.

When the first line of output contained perfdata but no short output,
the perfdata portion of the line was used as the short output. The
short output is now taken to be an empty string in these cases.

Cases where the first output line is entirely empty (no whitespace)
are still handled as "(No output returned from plugin)", whether or
not additional lines follow.

These situations are unusual, and likely indicate a misbehaving check,
but are not disallowed by our documented output format.

Additionally: avoid no-op iterations of the line processing loop on
empty input or end of input; and clarify/cleanup some comments.
Rename base/utils.c:unescape_newlines() to avoid confusion and conflicts, and make it static for now.
Merge remote branch 'remotes/origin/fix-0616-checkresult-output'
All lib/test-* targets now build and pass.
Added iobreg and iobregarg stub arguments needed by runcmd_open() so lib/test-runcmd builds.
Add and attribute latest changes.
Prep for 4.0.7 release.
Archive JSON: Handle absence of plugin output.

This commit fixes a segfault that happened when there was no plugin
output in the log file for any type of log entry that could have
plugin output.
JSON: Added json_object_add_member() function

This commit increases code reuse by adding the json_object_add_member()
function whose functionality was formerly repeated numerous times in
jsonutils.c.
JSON CGIs: Removed 8 kB string size limitation

There were two places in jsonutils.c where a static 8 kB buffer was
allocated for string processing. This buffer is now dynamically
allocated and string sizes are only limited by the amount of RAM
on a system.
Tests: new tests in test_checks

test_checks has been updated with a handful of new tests that will. In
addition, the tests have been update to support future testing of passive
passive checks.
Tests: added passive checks to test_checks
JSON: Added json_escape_string() function

This commit adds a json_escape_string() function to escape strings based
on a passed set of replacement pairs. The variable argument functionality
in json_string() was also removed because it is never used and has been
demonstrated to cause problems with strings containing % signs.
JSON: Escape percent signs in most strings

A printf-family function is used for flexibility reasons when adding
a string to the JSON structure. For this reason any percent signs in
strings generated external to the JSON code (object attributes, plugin
output, etc.) should have percent signs escaped (to "%%") before being
added in the json_*_append_string() functions to prevent the % sign
from being interpreted as a format specifier.

This commit accomplishes that by passing a structure with the escapes
to the json_*_append_string() functions where escaping is desired and
a NULL when it is not desired. When json_object_append_string() sees a
non-null structure, it calls json_escape_string() on the string before
it calls the printf-family function.
Merge branch 'master' of https://github.com/NagiosEnterprises/nagioscore