direction: Add a couple of direction helper functions
introspect: Use pa_direction_valid() to validate port direction

There's no behavioral change, just nicer code.
sink/source: Initialize port before fixate hook (fixes volume/mute not saved)

In case a port has not yet been saved, which is e g often the case
if a sink/source has only one port, reading volume/mute will be done
without port, whereas writing volume/mute will be done with port.

Work around this by setting a default port before the fixate hook,
so module-device-restore can read volume/mute for the correct port.

BugLink: https://bugs.launchpad.net/bugs/1289515
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
pactl: Fix crash with older servers

Servers older than 0.9.15 don't know anything about cards, and card
operations will return a NULL pa_operation object when connected to
that old server. We must check the pa_operation pointer before passing
it to pa_operation_unref(), otherwise a NULL operation will result in
a crash.
util: Check that the home dir is an absolute path

Avoid unpredictable behaviour in case e.g. the HOME environment
variable is incorrectly set up for whatever reason.

I haven't seen non-absolute HOME anywhere, but this feels like a good
sanity check anyway.
client-conf: Remove redundant function parameters
client-conf: Don't create multiple cookie files

The old code loaded cookies at the time of loading the client
configuration, which could lead to creation of multiple cookie files.
For example, when pa_client_conf_load() was called, the default cookie
file was created, and then if PULSE_COOKIE was set,
pa_client_conf_env() would create another cookie file.

This patch moves the loading of the cookie to a separate function,
which pa_context calls just before needing the cookie, so the cookie
won't be loaded from the default file if PULSE_COOKIE is set. This
patch also splits the single cookie and cookie_file fields in
pa_client_conf into multiple fields, one for each possible cookie
source. That change allows falling back to another cookie source if
the primary source doesn't work.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=75006
zeroconf-publish: Don't assume any particular defer event ordering

Also, initialize userdata with zeros to avoid invalid pointers in
client_free().

This fixes a crash when client_free() is called before
create_client(). The whole issue could be avoided by using some other
mechanism than defer events for running the two functions, but I'll
do that change later (I have also other cleanups planned for
zeroconf-publish).

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=76184
module-switch-on-port-available: Don't switch profiles on uninitialized cards

This could cause the HDMI port to become the default on some systems
where analog output was available.

BugLink: https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1256511
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=73375
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
module-switch-on-port-available: Use port->card pointer

We now have a port->card pointer, we can use it instead of iterating
over cards to find the correct one.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
module-switch-on-port-available: Use new find best port function

Now that we have a generic function in device-port.h, we can use
it instead of the custom one.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>