X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=libvirt%2Flibvirt_c_epilogue.c;h=29656a479574b95e3199f04feaef0c9d0a16d4d9;hb=HEAD;hp=fa592c93da703c9ba02df4542f71be06b0b69c3c;hpb=8853f5a49587f00a7d2a5c8c7e52480a16bbdb02;p=ocaml-libvirt.git diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c index fa592c9..29656a4 100644 --- a/libvirt/libvirt_c_epilogue.c +++ b/libvirt/libvirt_c_epilogue.c @@ -1,6 +1,6 @@ /* OCaml bindings for libvirt. * (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc. - * http://libvirt.org/ + * https://libvirt.org/ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -20,7 +20,7 @@ /* Please read libvirt/README file. */ -static char * +static const char * Optstring_val (value strv) { if (strv == Val_int (0)) /* None */ @@ -45,6 +45,22 @@ Val_opt (void *ptr, Val_ptr_t Val_ptr) CAMLreturn (optv); } +static value +Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr) +{ + CAMLparam0 (); + CAMLlocal2 (optv, ptrv); + + if (ptr) { /* Some ptr */ + optv = caml_alloc (1, 0); + ptrv = Val_ptr (ptr); + Store_field (optv, 0, ptrv); + } else /* None */ + optv = Val_int (0); + + CAMLreturn (optv); +} + #if 0 static value option_default (value option, value deflt) @@ -84,6 +100,36 @@ _raise_virterror (const char *fn) (void) caml__frame; } +static int +_list_length (value listv) +{ + CAMLparam1 (listv); + int len = 0; + + for (; listv != Val_emptylist; listv = Field (listv, 1), ++len) {} + + CAMLreturnT (int, len); +} + +static value +Val_virconnectcredential (const virConnectCredentialPtr cred) +{ + CAMLparam0 (); + CAMLlocal1 (rv); + + rv = caml_alloc (4, 0); + Store_field (rv, 0, Val_int (cred->type - 1)); + Store_field (rv, 1, caml_copy_string (cred->prompt)); + Store_field (rv, 2, + Val_opt_const (cred->challenge, + (Val_const_ptr_t) caml_copy_string)); + Store_field (rv, 3, + Val_opt_const (cred->defresult, + (Val_const_ptr_t) caml_copy_string)); + + CAMLreturn (rv); +} + /* Convert the virErrorNumber, virErrorDomain and virErrorLevel enums * into values (longs because they are variants in OCaml). * @@ -97,8 +143,8 @@ _raise_virterror (const char *fn) * to convert it into VIR_*_UNKNOWN (code). */ -#define MAX_VIR_CODE 50 /* VIR_ERR_NO_STORAGE_VOL */ -#define MAX_VIR_DOMAIN 17 /* VIR_FROM_STORAGE */ +#define MAX_VIR_CODE 101 /* VIR_ERR_NO_NWFILTER_BINDING */ +#define MAX_VIR_DOMAIN 67 /* VIR_FROM_RESCTRL */ #define MAX_VIR_LEVEL VIR_ERR_ERROR static inline value @@ -180,9 +226,10 @@ static void dom_finalize (value); static void net_finalize (value); static void pol_finalize (value); static void vol_finalize (value); +static void sec_finalize (value); static struct custom_operations conn_custom_operations = { - "conn_custom_operations", + (char *) "conn_custom_operations", conn_finalize, custom_compare_default, custom_hash_default, @@ -191,7 +238,7 @@ static struct custom_operations conn_custom_operations = { }; static struct custom_operations dom_custom_operations = { - "dom_custom_operations", + (char *) "dom_custom_operations", dom_finalize, custom_compare_default, custom_hash_default, @@ -201,7 +248,7 @@ static struct custom_operations dom_custom_operations = { }; static struct custom_operations net_custom_operations = { - "net_custom_operations", + (char *) "net_custom_operations", net_finalize, custom_compare_default, custom_hash_default, @@ -210,7 +257,7 @@ static struct custom_operations net_custom_operations = { }; static struct custom_operations pol_custom_operations = { - "pol_custom_operations", + (char *) "pol_custom_operations", pol_finalize, custom_compare_default, custom_hash_default, @@ -219,7 +266,7 @@ static struct custom_operations pol_custom_operations = { }; static struct custom_operations vol_custom_operations = { - "vol_custom_operations", + (char *) "vol_custom_operations", vol_finalize, custom_compare_default, custom_hash_default, @@ -227,6 +274,15 @@ static struct custom_operations vol_custom_operations = { custom_deserialize_default }; +static struct custom_operations sec_custom_operations = { + (char *) "sec_custom_operations", + sec_finalize, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default +}; + static value Val_connect (virConnectPtr conn) { @@ -282,6 +338,17 @@ Val_vol (virStorageVolPtr vol) CAMLreturn (rv); } +static value +Val_sec (virSecretPtr sec) +{ + CAMLparam0 (); + CAMLlocal1 (rv); + rv = caml_alloc_custom (&sec_custom_operations, + sizeof (virSecretPtr), 0, 1); + Sec_val (rv) = sec; + CAMLreturn (rv); +} + /* This wraps up the (dom, conn) pair (Domain.t). */ static value Val_domain (virDomainPtr dom, value connv) @@ -338,6 +405,20 @@ Val_volume (virStorageVolPtr vol, value connv) CAMLreturn (rv); } +/* This wraps up the (sec, conn) pair (Secret.t). */ +static value +Val_secret (virSecretPtr sec, value connv) +{ + CAMLparam1 (connv); + CAMLlocal2 (rv, v); + + rv = caml_alloc_tuple (2); + v = Val_sec (sec); + Store_field (rv, 0, v); + Store_field (rv, 1, connv); + CAMLreturn (rv); +} + static void conn_finalize (value connv) { @@ -372,3 +453,10 @@ vol_finalize (value volv) virStorageVolPtr vol = Vol_val (volv); if (vol) (void) virStorageVolFree (vol); } + +static void +sec_finalize (value secv) +{ + virSecretPtr sec = Sec_val (secv); + if (sec) (void) virSecretFree (sec); +}