Store some global variables in a new struct

Instead of storing our file descriptors, etc, in static variables, we now
store them in a BuxtonDaemon struct, enabling us to pass this BuxtonDaemon
struct around. This will also facilitate breaking up the main loop
into smaller functions, and even split into multiple files.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Store our client list within BuxtonDaemon

Last step in enabling the split of functionality from the main loop into
separate functions and files.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Move client handling into new handle_client function

Each client_list_item now has its own data buffer, which is currently
fixed to a length of 256. In the near future this will be allocated
when needed, and realloc'd to accomodate multiple messages being split
across multiple packets.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Add skeleton files for wire protocol implementation

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Use a direct BuxtonClient within bt-daemon

This enables two-way usage of the libbuxton API. Note however that this
will fail if the buxton socket already exists, which will be rectified
in future commits.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Begin implementation of wire protocol

We'll handle all protocol implementation within the new protocol part
of the library. This required moving BuxtonDaemon into the header file
so that we can use typedef'd pointers to internal functions, to ensure
we do not expose these members publicly or export the symbols.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Add new buxton_client_close function

In order to enable correct communication we need a method to close
the socket once we're finished. Eventually we'll most likely deal
with this internally within libbuxton using our exit handlers.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Begin implementation of set_value via wire protocol

The only thing missing from this commit is the ability to parse a returned
message but that will require further changes to the serialization code, so
they will be kept as separate changes.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Fix segfault when determining message size

We cannot use malloc_usable_size on out-of-process data, instead we'll use
the size of the recieved data from the socket as the size to check when
deserializing the recieved data.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
Implement buxton_wire_get_response

This commit fleshes out the reusable function buxton_wire_get_response,
which will be used within the set and get wire functions, enabling quick
access to the returned deserialized data.

Signed-off-by: Michael Ikey Doherty <michael.i.doherty@intel.com>
core: Add TODOs

Signed-off-by: William Douglas <william.douglas@intel.com>
core: Handle unlink failure during startup

When starting the daemon without systemd, if the unlink step fails and
it is for a reason other than the socket doesn't exist then bail out
with an error exit status.

Signed-off-by: William Douglas <william.douglas@intel.com>
libbuxton: Fix missing goto

When changing libbuxton to not always close after opening via socket
connect, there was a goto that was left out causing the return value
to be set to true even after a failure during connect.

Signed-off-by: William Douglas <william.douglas@intel.com>
libbuxton: Don't test for BUXTON_SOCKET in direct open

Because the server uses buxton_direct_open, falling back to a socket
based connection if the BUXTON_SOCKET exists will not work. Just
remove the check and note that multiple separate clients may connect
directly at the same time causing access errors if one tries to open a
db another client (or server) already has open.

Signed-off-by: William Douglas <william.douglas@intel.com>
shared: Fix types and casting for wire set_value

Use the right type for serialization data and recast char * from const
to avoid gcc warnings (as the data will not be getting changed just
copied). Also rename layer to layer_name for clarity.

Signed-off-by: William Douglas <william.douglas@intel.com>
shared: Update types and style

Change response type to match what deserialization expects, this is
fine as we always expect 8 bit bytes and 8 bit chars.

Also annotate an unused variable and fix style to checking a
function's return value after assigning it to a local variable.

Signed-off-by: William Douglas <william.douglas@intel.com>
shared: Fix formatting

Signed-off-by: William Douglas <william.douglas@intel.com>
shared: Fix incorrect check of deserialize's return

The deserialization function returns the number of items it added to
the list array it was passed. Store that value for looping through
freeing the result and verify serialization didn't have an error
before continuing.

Signed-off-by: William Douglas <william.douglas@intel.com>
shared: Update variable name for clarity

Signed-off-by: William Douglas <william.douglas@intel.com>
makefile: Update libs needed for check daemon

Signed-off-by: William Douglas <william.douglas@intel.com>