static ebb_connection_info *ebb_connection_info_create(void)
{
    ebb_connection_info *conninfo;

    if (NULL == (conninfo = (ebb_connection_info *)calloc(1, sizeof(ebb_connection_info))))
        goto fail;
    if (NULL == (conninfo->streamids = idset_create()))
        goto fail;
    if (NULL == (conninfo->rsp_q = tailq_create()))
        goto fail;
    conninfo->rsp_q->magic = true;

    return conninfo;
fail:
    ebb_connection_info_destroy(conninfo);
    return NULL;
}
Example #2
0
struct idset *idset_decode (const char *str)
{
    struct idset *idset;
    char *cpy = NULL;
    char *tok, *saveptr, *a1;
    int saved_errno;

    if (!str) {
        errno = EINVAL;
        return NULL;
    }
    if (!(idset = idset_create (0, IDSET_FLAG_AUTOGROW)))
        return NULL;
    if (!(cpy = strdup (str)))
        goto error;
    a1 = trim_brackets (cpy);
    saveptr = NULL;
    while ((tok = strtok_r (a1, ",", &saveptr))) {
        unsigned int hi, lo, i;
        if (parse_range (tok, &hi, &lo) < 0)
            goto inval;
        /* Count backwards so that idset_set() can grow the
         * idset to the maximum size on the first access,
         * rather than possibly doing it multiple times.
         */
        for (i = hi; i >= lo && i != UINT_MAX; i--) {
            if (idset_set (idset, i) < 0)
                goto error;
        }
        a1 = NULL;
    }
    free (cpy);
    return idset;
inval:
    errno = EINVAL;
error:
    saved_errno = errno;
    idset_destroy (idset);
    free (cpy);
    errno = saved_errno;
    return NULL;
}