Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    struct ustring_dvbcsa_cw cw =
        ustring_to_dvbcsa_cw(ustring_from_str("112233445566"));
    assert(cw.str.len == 12);

    cw = ustring_to_dvbcsa_cw(ustring_from_str("1122330044556600"));
    assert(ustring_is_null(cw.str));

    cw = ustring_to_dvbcsa_cw(ustring_from_str("11223366445566FF"));
    assert(cw.str.len == 16);
    return 0;
}
Ejemplo n.º 2
0
static int attribute_iterate(const char **item,
                             struct ustring *name,
                             struct ustring *value)
{
    static const char name_set[] = { USTRING_ALPHA_UPPER, '-', '\0' };
    if (unlikely(!item) || unlikely(!*item))
        return UBASE_ERR_INVALID;

    struct ustring tmp = ustring_from_str(*item);
    if (unlikely(ustring_is_empty(tmp))) {
        *item = NULL;
        return UBASE_ERR_NONE;
    }

    *name = ustring_split_while(&tmp, name_set);
    if (unlikely(!ustring_match_str(tmp, "=")))
        return UBASE_ERR_INVALID;
    tmp = ustring_shift(tmp, 1);
    if (ustring_match_str(tmp, "\"")) {
        tmp = ustring_shift(tmp, 1);
        *value = ustring_split_until(&tmp, "\"");
        if (unlikely(!ustring_match_str(tmp, "\"")))
            return UBASE_ERR_INVALID;
        tmp = ustring_shift(tmp, 1);
    }
    else {
        *value = ustring_split_until(&tmp, ",");
    }
    if (ustring_match_str(tmp, ","))
        tmp = ustring_shift(tmp, 1);
    else if (!ustring_is_empty(tmp))
        return UBASE_ERR_INVALID;
    *item = tmp.at;
    return UBASE_ERR_NONE;
}
Ejemplo n.º 3
0
/** @internal @This sets the dvbcsa key.
 *
 * @param upipe description structure of the pipe
 * @param key dvbcsa key to set
 * @return an error code
 */
static int upipe_dvbcsa_enc_set_key(struct upipe *upipe, const char *key)
{
    struct upipe_dvbcsa_enc *upipe_dvbcsa_enc =
        upipe_dvbcsa_enc_from_upipe(upipe);

    dvbcsa_key_free(upipe_dvbcsa_enc->key);
    upipe_dvbcsa_enc->key = NULL;

    if (!key)
        return UBASE_ERR_NONE;

    struct ustring_dvbcsa_cw cw = ustring_to_dvbcsa_cw(ustring_from_str(key));
    if (unlikely(ustring_is_empty(cw.str) || strlen(key) != cw.str.len))
        return UBASE_ERR_INVALID;

    upipe_notice(upipe, "key chanhed");
    upipe_dvbcsa_enc->key = dvbcsa_key_alloc();
    UBASE_ALLOC_RETURN(upipe_dvbcsa_enc->key);
    dvbcsa_key_set(cw.value, upipe_dvbcsa_enc->key);
    return UBASE_ERR_NONE;
}