Ejemplo n.º 1
0
static const char *load_libs(loader_t *l)
{
    char  path[PATH_MAX], *err;
    void *h;
    int   i, j;

    for (i = 0; i < l->nlib; i++) {
        for (j = 0; j < l->ndir; j++) {
            mrp_log_info("Looking for %s in %s...", l->libs[i], l->dirs[j]);

            if (find_matching(path, sizeof(path), l->dirs[j], l->libs[i])) {
                h = dlopen(path, RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND);

                if (h != NULL) {
                    mrp_log_info("Preloaded %s.", path);
                    l->handles[i] = h;
                    break;
                }
                else {
                    err = dlerror();
                    mrp_log_warning("Failed to load %s (error: %s).",
                                    l->libs[i], err ? err : "unknown");
                }
            }
        }

        if (l->handles[i] == NULL) {
            mrp_log_error("Failed to preload %s.", l->libs[i]);
            return l->libs[i];
        }
    }

    return NULL;
}
Ejemplo n.º 2
0
static void ping_request(context_t *c)
{
    uint32_t seq;

    if (c->cid != 0) {
        mrp_log_warning("Previous ping request still unanswered...");
        return;
    }

    seq    = c->seqno++;
    c->cid = mrp_dbus_call(c->dbus,
                           SERVER_NAME, SERVER_PATH, SERVER_INTERFACE,
                           PING, 500, ping_reply, c,
                           DBUS_TYPE_UINT32, &seq,
                           DBUS_TYPE_INVALID);

    if (c->cid > 0)
        mrp_log_info("<- ping request #%u", seq);
    else
        mrp_log_warning("Failed to send ping request #%u.", seq);
}
Ejemplo n.º 3
0
static void glib_log(const gchar *domain, GLogLevelFlags level,
                     const gchar *message, gpointer user_data)
{
    MRP_UNUSED(user_data);

    switch (level & G_LOG_LEVEL_MASK) {
    case G_LOG_LEVEL_DEBUG:
        mrp_debug("[%s] %s", domain ? domain : "APP", message);
        break;
    case G_LOG_LEVEL_INFO:
        mrp_log_info("[%s] %s", domain ? domain : "APP", message);
        break;
    case G_LOG_LEVEL_WARNING:
        mrp_log_warning("[%s] %s", domain ? domain : "APP", message);
        break;
    case G_LOG_LEVEL_ERROR:
        mrp_log_error("[%s] %s", domain ? domain : "APP", message);
        break;
    }
}
Ejemplo n.º 4
0
static tracklist_t *tracklist_parse(const char *path)
{
#define CHECK_STRTAG(_tag, _member)             \
    if (!strcasecmp(tag, _tag)) {               \
        mrp_free(t->_member);                   \
        t->_member = mrp_strdup(value);         \
        continue;                               \
    }

#define CHECK_INTTAG(_tag, _member)                             \
    if (!strcasecmp(tag, _tag)) {                               \
        t->_member = (int)strtoul(value, &e, 10);               \
        if (e && *e)                                            \
            goto invalid;                                       \
        continue;                                               \
    }

    tracklist_t *t;
    char         buf[16 * 1024], *tag, *sep, *value, *p, *e;
    int          fd, n;

    fd = open(path, O_RDONLY);

    if (fd < 0)
        goto failed;

    n = read(fd, buf, sizeof(buf) - 1);

    close(fd);

    if (n < 0)
        goto failed;

    if (n >= (int)sizeof(buf) - 1)
        goto nospace;

    buf[n] = '\0';

    t = mrp_allocz(sizeof(*t));

    if (t == NULL)
        goto nomem;

    p = buf;
    while (p && *p) {
        while (*p == ' ' || *p == '\t')
            p++;

        if (*p == '\n') {
            p++;
            continue;
        }

        tag = p;

        while (*p && *p != ':' && *p != '.' && *p != '\n')
            p++;

        if (*p == '\n')
            goto invalid;

        sep = p;
        p++;

        while (*p == ' ' || *p == '\t')
            p++;

        value = p;

        while (*p && *p != '\n')
            p++;

        if (p != '\0')
            *p++ = '\0';

        e = p - 1;
        while (e > value && (*e == ' ' || *e == '\t'))
            *e-- = '\0';

        if (*sep == ':') {
            *sep = '\0';

            CHECK_STRTAG("Album" , album);
            CHECK_STRTAG("Artist", artist);
            CHECK_STRTAG("Genre" , genre);
            CHECK_INTTAG("Year"  , year);

            mrp_log_warning("Ignoring unknown tag '%s'...", tag);
            continue;
        }

        if (*sep == '.') {
            *sep = '\0';

            n = strtoul(tag, &e, 10);

            if (e && *e)
                goto invalid;

            if (n < 1 || n > 99)         /* max. CDDA tracks */
                goto invalid;

            if (n > t->ntrack) {
                if (!mrp_reallocz(t->tracks, t->ntrack, n))
                    goto nomem;
                t->ntrack = n;
            }

            mrp_free(t->tracks[n - 1]);
            t->tracks[n - 1] = mrp_strdup(value);
        }
    }

    return t;

 nospace:
    errno = ENOBUFS;
 failed:
 nomem:
    return NULL;

 invalid:
    errno = EINVAL;
    tracklist_free(t);
    return NULL;
}
Ejemplo n.º 5
0
int mrp_fragbuf_pull(mrp_fragbuf_t *buf, void **datap, size_t *sizep)
{
    void     *data;
    uint32_t  size;

    if (buf == NULL || buf->used <= 0)
        return FALSE;

    if (MRP_UNLIKELY(*datap &&
                     (*datap < buf->data || *datap > buf->data + buf->used))) {
        mrp_log_warning("%s(): *** looks like we're called with an unreset "
                        "datap pointer... ***", __FUNCTION__);
    }

    /* start of iteration */
    if (*datap == NULL) {
        if (!buf->framed) {
            *datap = buf->data;
            *sizep = buf->used;

            return TRUE;
        }
        else {
            if (buf->used < (int)sizeof(size))
                return FALSE;

            size = be32toh(*(uint32_t *)buf->data);

            if (buf->used >= (int)(sizeof(size) + size)) {
                *datap = buf->data + sizeof(size);
                *sizep = size;

                return TRUE;
            }
            else
                return FALSE;
        }
    }
    /* continue iteration */
    else {
        if (!buf->framed) {
            data = *datap + *sizep;

            if (buf->data <= data && data < buf->data + buf->used) {
                memmove(buf->data, data, buf->used - (data - buf->data));
                buf->used -= (data - buf->data);

                *datap = buf->data;
                *sizep = buf->used;

                return TRUE;
            }
            else {
                if (data == buf->data + buf->used)
                    buf->used = 0;

                return FALSE;
            }
        }
        else {
            if (*datap != buf->data + sizeof(size))
                return FALSE;

            size = be32toh(*(uint32_t *)buf->data);

            if ((int)(size + sizeof(size)) <= buf->used) {
                memmove(buf->data, buf->data + size + sizeof(size),
                        buf->used - (size + sizeof(size)));
                buf->used -= size + sizeof(size);
            }
            else
                return FALSE;

            if (buf->used <= (int)sizeof(size))
                return FALSE;

            size = be32toh(*(uint32_t *)buf->data);
            data = buf->data + sizeof(size);

            if (buf->used >= (int)(size + sizeof(size))) {
                *datap = data;
                *sizep = size;

                return TRUE;
            }

            return FALSE;
        }
    }
}