doc: Document the new rest-json1 payload

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Add cockpit_pipe_get_buffer() function

This allows us to access the input buffer of a pipe even when we're
not in the 'read' event. It can change during the main loop.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Implement a generic cockpit_pipe_connect() constructor

We'll have multiple things connecting to pipes, so implement the
connection logic in CockpitPipe.

Also make it async and connect in the main loop where possible.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Add a cockpit_pipe_skip() function

For skipping bytes in a data buffer without returning them or doing
anything with them. Useful for channels that operate directly on
the bytes in the buffer.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Add cockpit_json_get_string() and cockpit_json_get_int()

These functions are safe wrappers for getting strings and int fields
of JSON objects. Rather than repeating this code everywhere, consolidate
it into one place.

JSON GLib is a bit tricky here because we have to check the types, and
a bit of conversion is possible (such as double -> int).

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Add cockpit_json_int_hash() and cockpit_json_int_equal()

These are for putting the gint64 type that JSON GLib uses for integers
into GHashTable.

Note these are similar to g_int_hash() and g_int_equal() in that they
take a pointer to a gint64. They are not like g_direct_hash() and
g_direct_equal() which take a pointer (and possibly an int cast to
a pointer).

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Add cockpit_json_skip() function for splitting JSON

Some services like Docker return multiple JSON blocks in their
REST JSON output. We have to split these apart before passing them
to the JSON parser.

The cockpit_json_skip() function allows this, including finding
whitespace and so on.

It does not validate the JSON blocks. It assumes that the blocks
are valid and/or will be parsed to find errors.

This is part of: Fix #265

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Verify that JsonParser trims whitespace

Our REST JSON code depends on the fact that JsonParser trims
whitespace before and after parsing. Verify this in our tests so we can
catch it if it changes.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
cockpit: Add cockpit_json_equal() which checks for equality

This function checks for logical equality between two JSON nodes.
If the nodes are of different types, then the equality fails, even
if they can be converted to the same type.

Part of fix #267

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Implement CockpitRestJson and the 'rest-json1' payload type

This is an implementation of the REST JSON payload type. It's fairly
complete, supporting streaming, monitoring, and other necessary
things.

Monitoring currently is only driven by an interval, where it could
also be driven off of output from another request.

Part of fix for #268, #267 and #265

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
web: Allow Channel.close() to accept a problem

Even though it's on the web side, we should allow Channel.close()
to accept a problem code which listeners can then react to. This allows
a consistent flow of problem codes no matter where they come from.
The problem code doesn't need to be sent to the web service or agent.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
web: Use new rest-json1 protocol to implement web rest client

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
web: Add Rest.poll() and req.cancel() req.restart()

Add Rest.poll() function for setting up a REST JSON poll. In addition
we add the ability to restart() requests and cancel() them. The latter
are neccessary to restart the requests that the poll() is watching,
with the same cookie.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
web: Use new REST functionality to watch Docker /events

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
web: Show Docker failures near the top of the page

Rather than inline in the tables. Then the tables can be data driven.
web: Migrate DockerClient to a DOM for containers and images

This is a simple DOM, it would be nice to do more work here later
and use angular.

Moved the table headings into index.html, where they should
live, and use a proper <thead> to make the headings bold.

Use a simple system to check if /events can reconnect. If we get
at least one successful response from something since the last
time /events tried to connect, then we permit it to try again
to reconnect.