SQLBOX_MSG_SET_DAT(3)

NAME
sqlbox_msg_set_dat - set message private data

LIBRARY
sqlbox

SYNOPSIS
#include <stdint.h>
#include <sqlbox.h>
void
sqlbox_msg_set_dat(struct sqlbox *box, const void *dat, size_t sz);

DESCRIPTION
Sets the ancillary data dat of size sz used by the logging functions assigned in struct sqlbox_msg, replacing whatever was passed to sqlbox_alloc(3). The data is copied out of dat, with the resulting allocation either freed during subsequent calls to sqlbox_msg_set_dat() or in sqlbox_free(3).

The fields of struct sqlbox_msg are as follows:

func
    Passed the message and dat. Messages are NUL-terminated but not newline terminated. The callback is run within the both the parent and protected child process when logging messages are emitted, so it should not include any side effects that might affect the database. Callbacks may not assume to have any network or file-system resources available.

func_short
    A short version of func useful for passing warnx(3) directly.

dat Auxiliary data passed to func.

The given binary data dat is of size sz. If passing strings, sz must include the NUL terminator. ~ Passing a size of 0 sets dat to NULL.

RETURN VALUES
Returns non-zero on success or zero if communication with box fails or memory allocation fails.

If sqlbox_msg_set_dat() fails, box is no longer accessible beyond sqlbox_ping(3) and sqlbox_free(3).

EXAMPLES
Let a long-form function be as follows:

    static void
    func(const char *buf, void *arg)
    {
      warnx("User %s: %s", (const char *)arg, buf);
    }

This function may have its pointer manipulated as follows:

    struct sqlbox *p;
    struct sqlbox_cfg cfg;
    const char *user;
    memset(&cfg, 0, sizeof(struct sqlbox_cfg));
    cfg.msg.func = func;
    cfg.msg.dat = (char *)"-";
    if ((p = sqlbox_alloc(&cfg)) == NULL)
      errx(EXIT_FAILURE, "sqlbox_alloc");
    /* Now the prefix "-" is used. */
    /* Get the username from somewhere... */
    user = get_user();
    if (!sqlbox_msg_set_dat(p, user, strlen(user) + 1))
      errx(EXIT_FAILURE, "sqlbox_msg_set_dat");