Exemple #1
0
/*
 * call-seq:
 *   secret.value(flags=0) -> String
 *
 * Call virSecretGetValue[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetValue]
 * to retrieve the value from this secret.
 */
static VALUE libvirt_secret_value(int argc, VALUE *argv, VALUE s)
{
    VALUE flags, ret;
    unsigned char *val;
    size_t value_size;
    int exception = 0;
    struct ruby_libvirt_str_new_arg args;

    rb_scan_args(argc, argv, "01", &flags);

    val = virSecretGetValue(secret_get(s), &value_size,
                            ruby_libvirt_value_to_uint(flags));

    ruby_libvirt_raise_error_if(val == NULL, e_RetrieveError,
                                "virSecretGetValue",
                                ruby_libvirt_connect_get(s));

    args.val = (char *)val;
    args.size = value_size;
    ret = rb_protect(ruby_libvirt_str_new_wrap, (VALUE)&args, &exception);
    free(val);
    if (exception) {
        rb_jump_tag(exception);
    }

    return ret;
}
Exemple #2
0
/*
 * call-seq:
 *   secret.value = value,flags=0
 *
 * Call virSecretSetValue[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue]
 * to set a new value in this secret.
 */
static VALUE libvirt_secret_value_equal(VALUE s, VALUE in)
{
    VALUE flags, value;

    if (TYPE(in) == T_STRING) {
        value = in;
        flags = INT2NUM(0);
    }
    else if (TYPE(in) == T_ARRAY) {
        if (RARRAY_LEN(in) != 2) {
            rb_raise(rb_eArgError, "wrong number of arguments (%ld for 2)",
                     RARRAY_LEN(in));
        }
        value = rb_ary_entry(in, 0);
        flags = rb_ary_entry(in, 1);
    }
    else {
        rb_raise(rb_eTypeError,
                 "wrong argument type (expected Number or Array)");
    }

    StringValue(value);

    ruby_libvirt_generate_call_nil(virSecretSetValue,
                                   ruby_libvirt_connect_get(s),
                                   secret_get(s),
                                   (unsigned char *)RSTRING_PTR(value),
                                   RSTRING_LEN(value), NUM2UINT(flags));
}
Exemple #3
0
VALUE ruby_libvirt_get_parameters(VALUE d, unsigned int flags, void *opaque,
                                  unsigned int typesize,
                                  const char *(*nparams_cb)(VALUE d,
                                                            unsigned int flags,
                                                            void *opaque,
                                                            int *nparams),
                                  const char *(*get_cb)(VALUE d,
                                                        unsigned int flags,
                                                        void *voidparams,
                                                        int *nparams,
                                                        void *opaque),
                                  void (*hash_set)(void *voidparams, int i,
                                                   VALUE result))
{
    int nparams = 0;
    void *params;
    VALUE result;
    const char *errname;
    int i;

    errname = nparams_cb(d, flags, opaque, &nparams);
    ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname,
                                ruby_libvirt_connect_get(d));

    result = rb_hash_new();

    if (nparams == 0) {
        return result;
    }

    params = alloca(typesize * nparams);

    errname = get_cb(d, flags, params, &nparams, opaque);
    ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname,
                                ruby_libvirt_connect_get(d));

    for (i = 0; i < nparams; i++) {
        hash_set(params, i, result);
    }

    return result;
}
Exemple #4
0
/*
 * call-seq:
 *   secret.xml_desc(flags=0) -> String
 *
 * Call virSecretGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetXMLDesc]
 * to retrieve the XML for this secret.
 */
static VALUE libvirt_secret_xml_desc(int argc, VALUE *argv, VALUE s)
{
    VALUE flags;

    rb_scan_args(argc, argv, "01", &flags);

    ruby_libvirt_generate_call_string(virSecretGetXMLDesc,
                                      ruby_libvirt_connect_get(s), 1,
                                      secret_get(s),
                                      ruby_libvirt_value_to_uint(flags));
}
Exemple #5
0
/*
 * call-seq:
 *   secret.set_value(value, flags=0) -> nil
 *
 * Call virSecretSetValue[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue]
 * to set a new value in this secret.  Deprecated; use secret.value= instead.
 */
static VALUE libvirt_secret_set_value(int argc, VALUE *argv, VALUE s)
{
    VALUE flags, value;

    rb_scan_args(argc, argv, "11", &value, &flags);

    StringValue(value);

    ruby_libvirt_generate_call_nil(virSecretSetValue,
                                   ruby_libvirt_connect_get(s),
                                   secret_get(s),
                                   (unsigned char *)RSTRING_PTR(value),
                                   RSTRING_LEN(value),
                                   ruby_libvirt_value_to_uint(flags));
}
Exemple #6
0
VALUE ruby_libvirt_set_typed_parameters(VALUE d, VALUE input,
                                        unsigned int flags, void *opaque,
                                        struct ruby_libvirt_typed_param *allowed,
                                        unsigned int num_allowed,
                                        const char *(*set_cb)(VALUE d,
                                                              unsigned int flags,
                                                              virTypedParameterPtr params,
                                                              int nparams,
                                                              void *opaque))
{
    const char *errname;
    struct ruby_libvirt_parameter_assign_args args;
    unsigned long hashsize;

    /* make sure input is a hash */
    Check_Type(input, T_HASH);

    hashsize = RHASH_SIZE(input);

    if (hashsize == 0) {
        return Qnil;
    }

    args.allowed = allowed;
    args.num_allowed = num_allowed;
    args.params = alloca(sizeof(virTypedParameter) * hashsize);
    args.i = 0;

    rb_hash_foreach(input, ruby_libvirt_typed_parameter_assign, (VALUE)&args);

    errname = set_cb(d, flags, args.params, args.i, opaque);
    ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname,
                                ruby_libvirt_connect_get(d));

    return Qnil;
}
Exemple #7
0
/*
 * call-seq:
 *   secret.usageid -> String
 *
 * Call virSecretGetUsageID[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageID]
 * to retrieve the usageid for this secret.
 */
static VALUE libvirt_secret_usageid(VALUE s)
{
    ruby_libvirt_generate_call_string(virSecretGetUsageID,
                                      ruby_libvirt_connect_get(s), 0,
                                      secret_get(s));
}
Exemple #8
0
/*
 * call-seq:
 *   secret.usagetype -> Fixnum
 *
 * Call virSecretGetUsageType[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageType]
 * to retrieve the usagetype for this secret.
 */
static VALUE libvirt_secret_usagetype(VALUE s)
{
    ruby_libvirt_generate_call_int(virSecretGetUsageType,
                                   ruby_libvirt_connect_get(s),
                                   secret_get(s));
}
Exemple #9
0
/*
 * call-seq:
 *   secret.uuid -> String
 *
 * Call virSecretGetUUIDString[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUUIDString]
 * to retrieve the UUID for this secret.
 */
static VALUE libvirt_secret_uuid(VALUE s)
{
    ruby_libvirt_generate_uuid(virSecretGetUUIDString,
                               ruby_libvirt_connect_get(s), secret_get(s));
}
Exemple #10
0
/*
 * call-seq:
 *   secret.undefine -> nil
 *
 * Call virSecretUndefine[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretUndefine]
 * to undefine this secret.
 */
static VALUE libvirt_secret_undefine(VALUE s)
{
    ruby_libvirt_generate_call_nil(virSecretUndefine,
                                   ruby_libvirt_connect_get(s),
                                   secret_get(s));
}