ws: Better debug logging when removing a channel from session

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Split out MockTransport into its own file

And move some tests to start using it.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Add cockpit_assert_bytes_eq() and cockpit_assert_data_eq()

These functions are used in tests to check if memory matches expected
and gives informative output if it doesn't match. This output could
be further enhanced to show a diff or some such, but for now it's just
a simple escaped listing.

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

This allows adding full JSON objects to channel close messages.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Implement agent support for modules and resource1 payload

This adds support to cockpit-agent for listing and loading module
resources.

See doc/modules.md for information about how modules are laid
out on the system.

doc/protocol.md contains information about the resource1 payload

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Add cockpit_web_response_abort() to stop streaming response

When we are streaming a web response, and half-way an error occurs
and we cannot get the remaining data to stream, we need to terminate
the web response.

cockpit_web_response_abort() does this by just disconnecting the
web response. The caller should be able to tell whether the data
is incomplete based on length header or chunking.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: cockpit_web_response_get_state() and expose web response state

Allow others to see what state a web response is currently in.
This helps prevent callers from having to carry around the identical
state.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Strip query string when handing HTTP requests

We never use a query string, and some callers like jQuery add one
automatically in certain cases.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Change how CockpitWebServer handle-resource signal detail works

To match subtrees, connect using detail handle-resource::/component/, to
match actual to level paths use detail handle-resource::/component

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
agent: Retain the correct SIGTERM exit code when terminated

When the agent is terminated, and we exit cleanly, re-raise the
same signal so that the caller will know we tere terminated.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: Broken Pipe is not a critical error for CockpitPipe

This can happen for a number of reasons, such as an agent being
terminated. We want to handle the real problem and not freak out
about the failed write() in this case.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
common: If 'internal-error' try to get better error from exit status

If our CockpitPipe fails with 'internal-error' and it's a process,
try to get a better error by looking at the exit status of the process.
Hopefully that will be more descriptive.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Don't guess mime-types for HTTP errors

These are usually HTML regardless of the path of the request,
and what kind of data was expected there.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Expose cockpit module resources via HTTP

This adds handlers under /res/ and /cache/ for loading cockpit
resources. These are served from data provided by cockpit-agent
and the resource1 channel payload.

In addition add code to load the full module listing including
manifests from a given cockpit-agent. We use this in the tests,
and in a later commit this is used to build the environment.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Serve the / HTTP path with its own handler

Since the response to / cannot be aggressively cached, unlike almost
everything else ... include dynamic content right in the response to
minimize server round trips.

Removed the unused avatar data url. If we do want an avatar on
the login page, it should be retrieved as a normal image and have
its own handler.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Add some debug messages to cockpit_web_response_file()
ws: Resolve static directory when testing handlers

This is because we have security checks to make sure that we don't
break out of the directory. Often the $srcdir that autotools generates
contains ../ and screws up these checks.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Handle favicon.ico and apple-touch-icon.png separately

These don't get handled via /static or the later resource1
payload channel. These are special cases.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
ws: Transfer login, module, host info using environment block

This is a JSON block called the environment which is used to pass the
necessary information to start up cockpit. It is received by the
javascript.

When not yet logged in, the environment contains very little
information, once logged in it is fully populated.

The environment is seeded in the '/' index handler, to avoid multiple
round trips. If a login occurs, then the full environment is transferred
as a response to the '/login' request.

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
static: Separate the login and boot code from shell module

We use the environment to load the cockpit-web as a single module
called 'shell'. This uses a simple module code, which is not
expected to be used to used with the later module loading.

In order to test this particular code you'll need to run:

ln -s /path/to/cockpit/src/web ~/.local/share/cockpit/shell

Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>
Signed-off-by: Marius Vollmer <marius.vollmer@redhat.com>
* Removed debugging output.