Avoid VLAs with size depending on user input
[ocaml-libvirt.git] / libvirt / libvirt_c.c
1 /* !!! WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!
2  *
3  * THIS FILE IS AUTOMATICALLY GENERATED BY 'generator.pl'.
4  *
5  * Any changes you make to this file may be overwritten.
6  */
7
8 /* OCaml bindings for libvirt.
9  * (C) Copyright 2007-2015 Richard W.M. Jones, Red Hat Inc.
10  * http://libvirt.org/
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version,
16  * with the OCaml linking exception described in ../COPYING.LIB.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this library; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
26  */
27
28 #include "config.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <libvirt/libvirt.h>
35 #include <libvirt/virterror.h>
36
37 #include <caml/config.h>
38 #include <caml/alloc.h>
39 #include <caml/callback.h>
40 #include <caml/custom.h>
41 #include <caml/fail.h>
42 #include <caml/memory.h>
43 #include <caml/misc.h>
44 #include <caml/mlvalues.h>
45 #include <caml/signals.h>
46
47 #include "libvirt_c_prologue.c"
48
49 #include "libvirt_c_oneoffs.c"
50
51 /* Automatically generated binding for virConnectClose.
52  * In generator.pl this function has signature "conn : free".
53  */
54
55 CAMLprim value
56 ocaml_libvirt_connect_close (value connv)
57 {
58   CAMLparam1 (connv);
59
60   virConnectPtr conn = Connect_val (connv);
61   int r;
62
63   NONBLOCKING (r = virConnectClose (conn));
64   CHECK_ERROR (r == -1, "virConnectClose");
65
66   /* So that we don't double-free in the finalizer: */
67   Connect_val (connv) = NULL;
68
69   CAMLreturn (Val_unit);
70 }
71
72 /* Automatically generated binding for virConnectGetHostname.
73  * In generator.pl this function has signature "conn : string".
74  */
75
76 CAMLprim value
77 ocaml_libvirt_connect_get_hostname (value connv)
78 {
79   CAMLparam1 (connv);
80
81   CAMLlocal1 (rv);
82   virConnectPtr conn = Connect_val (connv);
83   char *r;
84
85   NONBLOCKING (r = virConnectGetHostname (conn));
86   CHECK_ERROR (!r, "virConnectGetHostname");
87
88   rv = caml_copy_string (r);
89   free (r);
90   CAMLreturn (rv);
91 }
92
93 /* Automatically generated binding for virConnectGetURI.
94  * In generator.pl this function has signature "conn : string".
95  */
96
97 CAMLprim value
98 ocaml_libvirt_connect_get_uri (value connv)
99 {
100   CAMLparam1 (connv);
101
102   CAMLlocal1 (rv);
103   virConnectPtr conn = Connect_val (connv);
104   char *r;
105
106   NONBLOCKING (r = virConnectGetURI (conn));
107   CHECK_ERROR (!r, "virConnectGetURI");
108
109   rv = caml_copy_string (r);
110   free (r);
111   CAMLreturn (rv);
112 }
113
114 /* Automatically generated binding for virConnectGetType.
115  * In generator.pl this function has signature "conn : static string".
116  */
117
118 CAMLprim value
119 ocaml_libvirt_connect_get_type (value connv)
120 {
121   CAMLparam1 (connv);
122
123   CAMLlocal1 (rv);
124   virConnectPtr conn = Connect_val (connv);
125   const char *r;
126
127   NONBLOCKING (r = virConnectGetType (conn));
128   CHECK_ERROR (!r, "virConnectGetType");
129
130   rv = caml_copy_string (r);
131   CAMLreturn (rv);
132 }
133
134 /* Automatically generated binding for virConnectNumOfDomains.
135  * In generator.pl this function has signature "conn : int".
136  */
137
138 CAMLprim value
139 ocaml_libvirt_connect_num_of_domains (value connv)
140 {
141   CAMLparam1 (connv);
142
143   virConnectPtr conn = Connect_val (connv);
144   int r;
145
146   NONBLOCKING (r = virConnectNumOfDomains (conn));
147   CHECK_ERROR (r == -1, "virConnectNumOfDomains");
148
149   CAMLreturn (Val_int (r));
150 }
151
152 /* Automatically generated binding for virConnectListDomains.
153  * In generator.pl this function has signature "conn, int : int array".
154  */
155
156 CAMLprim value
157 ocaml_libvirt_connect_list_domains (value connv, value iv)
158 {
159   CAMLparam2 (connv, iv);
160
161   CAMLlocal1 (rv);
162   virConnectPtr conn = Connect_val (connv);
163   int i = Int_val (iv);
164   int *ids, r;
165
166   /* Some libvirt List* functions still throw exceptions if i == 0,
167    * so catch that and return an empty array directly.  This changes
168    * the semantics slightly (masking other failures) but it's
169    * unlikely anyone will care.  RWMJ 2008/06/10
170    */
171   if (i == 0) {
172     rv = caml_alloc (0, 0);
173     CAMLreturn (rv);
174   }
175
176   ids = malloc (sizeof (*ids) * i);
177   if (ids == NULL)
178     caml_raise_out_of_memory ();
179
180   NONBLOCKING (r = virConnectListDomains (conn, ids, i));
181   CHECK_ERROR_CLEANUP (r == -1, free (ids), "virConnectListDomains");
182
183   rv = caml_alloc (r, 0);
184   for (i = 0; i < r; ++i)
185     Store_field (rv, i, Val_int (ids[i]));
186   free (ids);
187
188   CAMLreturn (rv);
189 }
190
191 /* Automatically generated binding for virConnectNumOfDefinedDomains.
192  * In generator.pl this function has signature "conn : int".
193  */
194
195 CAMLprim value
196 ocaml_libvirt_connect_num_of_defined_domains (value connv)
197 {
198   CAMLparam1 (connv);
199
200   virConnectPtr conn = Connect_val (connv);
201   int r;
202
203   NONBLOCKING (r = virConnectNumOfDefinedDomains (conn));
204   CHECK_ERROR (r == -1, "virConnectNumOfDefinedDomains");
205
206   CAMLreturn (Val_int (r));
207 }
208
209 /* Automatically generated binding for virConnectListDefinedDomains.
210  * In generator.pl this function has signature "conn, int : string array".
211  */
212
213 CAMLprim value
214 ocaml_libvirt_connect_list_defined_domains (value connv, value iv)
215 {
216   CAMLparam2 (connv, iv);
217
218   CAMLlocal2 (rv, strv);
219   virConnectPtr conn = Connect_val (connv);
220   int i = Int_val (iv);
221   char **names;
222   int r;
223
224   /* Some libvirt List* functions still throw exceptions if i == 0,
225    * so catch that and return an empty array directly.  This changes
226    * the semantics slightly (masking other failures) but it's
227    * unlikely anyone will care.  RWMJ 2008/06/10
228    */
229   if (i == 0) {
230     rv = caml_alloc (0, 0);
231     CAMLreturn (rv);
232   }
233
234   names = malloc (sizeof (*names) * i);
235   if (names == NULL)
236     caml_raise_out_of_memory ();
237
238   NONBLOCKING (r = virConnectListDefinedDomains (conn, names, i));
239   CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListDefinedDomains");
240
241   rv = caml_alloc (r, 0);
242   for (i = 0; i < r; ++i) {
243     strv = caml_copy_string (names[i]);
244     Store_field (rv, i, strv);
245     free (names[i]);
246   }
247   free (names);
248
249   CAMLreturn (rv);
250 }
251
252 /* Automatically generated binding for virConnectNumOfNetworks.
253  * In generator.pl this function has signature "conn : int".
254  */
255
256 CAMLprim value
257 ocaml_libvirt_connect_num_of_networks (value connv)
258 {
259   CAMLparam1 (connv);
260
261   virConnectPtr conn = Connect_val (connv);
262   int r;
263
264   NONBLOCKING (r = virConnectNumOfNetworks (conn));
265   CHECK_ERROR (r == -1, "virConnectNumOfNetworks");
266
267   CAMLreturn (Val_int (r));
268 }
269
270 /* Automatically generated binding for virConnectListNetworks.
271  * In generator.pl this function has signature "conn, int : string array".
272  */
273
274 CAMLprim value
275 ocaml_libvirt_connect_list_networks (value connv, value iv)
276 {
277   CAMLparam2 (connv, iv);
278
279   CAMLlocal2 (rv, strv);
280   virConnectPtr conn = Connect_val (connv);
281   int i = Int_val (iv);
282   char **names;
283   int r;
284
285   /* Some libvirt List* functions still throw exceptions if i == 0,
286    * so catch that and return an empty array directly.  This changes
287    * the semantics slightly (masking other failures) but it's
288    * unlikely anyone will care.  RWMJ 2008/06/10
289    */
290   if (i == 0) {
291     rv = caml_alloc (0, 0);
292     CAMLreturn (rv);
293   }
294
295   names = malloc (sizeof (*names) * i);
296   if (names == NULL)
297     caml_raise_out_of_memory ();
298
299   NONBLOCKING (r = virConnectListNetworks (conn, names, i));
300   CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListNetworks");
301
302   rv = caml_alloc (r, 0);
303   for (i = 0; i < r; ++i) {
304     strv = caml_copy_string (names[i]);
305     Store_field (rv, i, strv);
306     free (names[i]);
307   }
308   free (names);
309
310   CAMLreturn (rv);
311 }
312
313 /* Automatically generated binding for virConnectNumOfDefinedNetworks.
314  * In generator.pl this function has signature "conn : int".
315  */
316
317 CAMLprim value
318 ocaml_libvirt_connect_num_of_defined_networks (value connv)
319 {
320   CAMLparam1 (connv);
321
322   virConnectPtr conn = Connect_val (connv);
323   int r;
324
325   NONBLOCKING (r = virConnectNumOfDefinedNetworks (conn));
326   CHECK_ERROR (r == -1, "virConnectNumOfDefinedNetworks");
327
328   CAMLreturn (Val_int (r));
329 }
330
331 /* Automatically generated binding for virConnectListDefinedNetworks.
332  * In generator.pl this function has signature "conn, int : string array".
333  */
334
335 CAMLprim value
336 ocaml_libvirt_connect_list_defined_networks (value connv, value iv)
337 {
338   CAMLparam2 (connv, iv);
339
340   CAMLlocal2 (rv, strv);
341   virConnectPtr conn = Connect_val (connv);
342   int i = Int_val (iv);
343   char **names;
344   int r;
345
346   /* Some libvirt List* functions still throw exceptions if i == 0,
347    * so catch that and return an empty array directly.  This changes
348    * the semantics slightly (masking other failures) but it's
349    * unlikely anyone will care.  RWMJ 2008/06/10
350    */
351   if (i == 0) {
352     rv = caml_alloc (0, 0);
353     CAMLreturn (rv);
354   }
355
356   names = malloc (sizeof (*names) * i);
357   if (names == NULL)
358     caml_raise_out_of_memory ();
359
360   NONBLOCKING (r = virConnectListDefinedNetworks (conn, names, i));
361   CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListDefinedNetworks");
362
363   rv = caml_alloc (r, 0);
364   for (i = 0; i < r; ++i) {
365     strv = caml_copy_string (names[i]);
366     Store_field (rv, i, strv);
367     free (names[i]);
368   }
369   free (names);
370
371   CAMLreturn (rv);
372 }
373
374 /* Automatically generated binding for virConnectNumOfStoragePools.
375  * In generator.pl this function has signature "conn : int".
376  */
377
378 CAMLprim value
379 ocaml_libvirt_connect_num_of_storage_pools (value connv)
380 {
381   CAMLparam1 (connv);
382
383   virConnectPtr conn = Connect_val (connv);
384   int r;
385
386   NONBLOCKING (r = virConnectNumOfStoragePools (conn));
387   CHECK_ERROR (r == -1, "virConnectNumOfStoragePools");
388
389   CAMLreturn (Val_int (r));
390 }
391
392 /* Automatically generated binding for virConnectListStoragePools.
393  * In generator.pl this function has signature "conn, int : string array".
394  */
395
396 CAMLprim value
397 ocaml_libvirt_connect_list_storage_pools (value connv, value iv)
398 {
399   CAMLparam2 (connv, iv);
400
401   CAMLlocal2 (rv, strv);
402   virConnectPtr conn = Connect_val (connv);
403   int i = Int_val (iv);
404   char **names;
405   int r;
406
407   /* Some libvirt List* functions still throw exceptions if i == 0,
408    * so catch that and return an empty array directly.  This changes
409    * the semantics slightly (masking other failures) but it's
410    * unlikely anyone will care.  RWMJ 2008/06/10
411    */
412   if (i == 0) {
413     rv = caml_alloc (0, 0);
414     CAMLreturn (rv);
415   }
416
417   names = malloc (sizeof (*names) * i);
418   if (names == NULL)
419     caml_raise_out_of_memory ();
420
421   NONBLOCKING (r = virConnectListStoragePools (conn, names, i));
422   CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListStoragePools");
423
424   rv = caml_alloc (r, 0);
425   for (i = 0; i < r; ++i) {
426     strv = caml_copy_string (names[i]);
427     Store_field (rv, i, strv);
428     free (names[i]);
429   }
430   free (names);
431
432   CAMLreturn (rv);
433 }
434
435 /* Automatically generated binding for virConnectNumOfDefinedStoragePools.
436  * In generator.pl this function has signature "conn : int".
437  */
438
439 CAMLprim value
440 ocaml_libvirt_connect_num_of_defined_storage_pools (value connv)
441 {
442   CAMLparam1 (connv);
443
444   virConnectPtr conn = Connect_val (connv);
445   int r;
446
447   NONBLOCKING (r = virConnectNumOfDefinedStoragePools (conn));
448   CHECK_ERROR (r == -1, "virConnectNumOfDefinedStoragePools");
449
450   CAMLreturn (Val_int (r));
451 }
452
453 /* Automatically generated binding for virConnectListDefinedStoragePools.
454  * In generator.pl this function has signature "conn, int : string array".
455  */
456
457 CAMLprim value
458 ocaml_libvirt_connect_list_defined_storage_pools (value connv, value iv)
459 {
460   CAMLparam2 (connv, iv);
461
462   CAMLlocal2 (rv, strv);
463   virConnectPtr conn = Connect_val (connv);
464   int i = Int_val (iv);
465   char **names;
466   int r;
467
468   /* Some libvirt List* functions still throw exceptions if i == 0,
469    * so catch that and return an empty array directly.  This changes
470    * the semantics slightly (masking other failures) but it's
471    * unlikely anyone will care.  RWMJ 2008/06/10
472    */
473   if (i == 0) {
474     rv = caml_alloc (0, 0);
475     CAMLreturn (rv);
476   }
477
478   names = malloc (sizeof (*names) * i);
479   if (names == NULL)
480     caml_raise_out_of_memory ();
481
482   NONBLOCKING (r = virConnectListDefinedStoragePools (conn, names, i));
483   CHECK_ERROR_CLEANUP (r == -1, free (names), "virConnectListDefinedStoragePools");
484
485   rv = caml_alloc (r, 0);
486   for (i = 0; i < r; ++i) {
487     strv = caml_copy_string (names[i]);
488     Store_field (rv, i, strv);
489     free (names[i]);
490   }
491   free (names);
492
493   CAMLreturn (rv);
494 }
495
496 /* Automatically generated binding for virConnectGetCapabilities.
497  * In generator.pl this function has signature "conn : string".
498  */
499
500 CAMLprim value
501 ocaml_libvirt_connect_get_capabilities (value connv)
502 {
503   CAMLparam1 (connv);
504
505   CAMLlocal1 (rv);
506   virConnectPtr conn = Connect_val (connv);
507   char *r;
508
509   NONBLOCKING (r = virConnectGetCapabilities (conn));
510   CHECK_ERROR (!r, "virConnectGetCapabilities");
511
512   rv = caml_copy_string (r);
513   free (r);
514   CAMLreturn (rv);
515 }
516
517 /* Automatically generated binding for virConnectDomainEventDeregisterAny.
518  * In generator.pl this function has signature "conn, int : unit".
519  */
520
521 CAMLprim value
522 ocaml_libvirt_connect_domain_event_deregister_any (value connv, value iv)
523 {
524   CAMLparam2 (connv, iv);
525
526   virConnectPtr conn = Connect_val (connv);
527   int i = Int_val (iv);
528   int r;
529
530   NONBLOCKING (r = virConnectDomainEventDeregisterAny (conn, i));
531   CHECK_ERROR (r == -1, "virConnectDomainEventDeregisterAny");
532
533   CAMLreturn (Val_unit);
534 }
535
536 /* Automatically generated binding for virDomainCreateLinux.
537  * In generator.pl this function has signature "conn, string, 0U : dom".
538  */
539
540 CAMLprim value
541 ocaml_libvirt_domain_create_linux (value connv, value strv)
542 {
543   CAMLparam2 (connv, strv);
544
545   CAMLlocal1 (rv);
546   virConnectPtr conn = Connect_val (connv);
547   char *str = String_val (strv);
548   virDomainPtr r;
549
550   NONBLOCKING (r = virDomainCreateLinux (conn, str, 0));
551   CHECK_ERROR (!r, "virDomainCreateLinux");
552
553   rv = Val_domain (r, connv);
554
555   CAMLreturn (rv);
556 }
557
558 /* Automatically generated binding for virDomainCreateXML.
559  * In generator.pl this function has signature "conn, string, unsigned : dom".
560  */
561
562 CAMLprim value
563 ocaml_libvirt_domain_create_xml (value connv, value strv, value uv)
564 {
565   CAMLparam3 (connv, strv, uv);
566
567   CAMLlocal1 (rv);
568   virConnectPtr conn = Connect_val (connv);
569   char *str = String_val (strv);
570   unsigned int u = Int_val (uv);
571   virDomainPtr r;
572
573   NONBLOCKING (r = virDomainCreateXML (conn, str, u));
574   CHECK_ERROR (!r, "virDomainCreateXML");
575
576   rv = Val_domain (r, connv);
577
578   CAMLreturn (rv);
579 }
580
581 /* Automatically generated binding for virDomainFree.
582  * In generator.pl this function has signature "dom : free".
583  */
584
585 CAMLprim value
586 ocaml_libvirt_domain_free (value domv)
587 {
588   CAMLparam1 (domv);
589
590   virDomainPtr dom = Domain_val (domv);
591   int r;
592
593   NONBLOCKING (r = virDomainFree (dom));
594   CHECK_ERROR (r == -1, "virDomainFree");
595
596   /* So that we don't double-free in the finalizer: */
597   Domain_val (domv) = NULL;
598
599   CAMLreturn (Val_unit);
600 }
601
602 /* Automatically generated binding for virDomainDestroy.
603  * In generator.pl this function has signature "dom : free".
604  */
605
606 CAMLprim value
607 ocaml_libvirt_domain_destroy (value domv)
608 {
609   CAMLparam1 (domv);
610
611   virDomainPtr dom = Domain_val (domv);
612   int r;
613
614   NONBLOCKING (r = virDomainDestroy (dom));
615   CHECK_ERROR (r == -1, "virDomainDestroy");
616
617   /* So that we don't double-free in the finalizer: */
618   Domain_val (domv) = NULL;
619
620   CAMLreturn (Val_unit);
621 }
622
623 /* Automatically generated binding for virDomainLookupByName.
624  * In generator.pl this function has signature "conn, string : dom".
625  */
626
627 CAMLprim value
628 ocaml_libvirt_domain_lookup_by_name (value connv, value strv)
629 {
630   CAMLparam2 (connv, strv);
631
632   CAMLlocal1 (rv);
633   virConnectPtr conn = Connect_val (connv);
634   char *str = String_val (strv);
635   virDomainPtr r;
636
637   NONBLOCKING (r = virDomainLookupByName (conn, str));
638   CHECK_ERROR (!r, "virDomainLookupByName");
639
640   rv = Val_domain (r, connv);
641
642   CAMLreturn (rv);
643 }
644
645 /* Automatically generated binding for virDomainLookupByID.
646  * In generator.pl this function has signature "conn, int : dom".
647  */
648
649 CAMLprim value
650 ocaml_libvirt_domain_lookup_by_id (value connv, value iv)
651 {
652   CAMLparam2 (connv, iv);
653
654   CAMLlocal1 (rv);
655   virConnectPtr conn = Connect_val (connv);
656   int i = Int_val (iv);
657   virDomainPtr r;
658
659   NONBLOCKING (r = virDomainLookupByID (conn, i));
660   CHECK_ERROR (!r, "virDomainLookupByID");
661
662   rv = Val_domain (r, connv);
663
664   CAMLreturn (rv);
665 }
666
667 /* Automatically generated binding for virDomainLookupByUUID.
668  * In generator.pl this function has signature "conn, uuid : dom".
669  */
670
671 CAMLprim value
672 ocaml_libvirt_domain_lookup_by_uuid (value connv, value uuidv)
673 {
674   CAMLparam2 (connv, uuidv);
675
676   CAMLlocal1 (rv);
677   virConnectPtr conn = Connect_val (connv);
678   unsigned char *uuid = (unsigned char *) String_val (uuidv);
679   virDomainPtr r;
680
681   NONBLOCKING (r = virDomainLookupByUUID (conn, uuid));
682   CHECK_ERROR (!r, "virDomainLookupByUUID");
683
684   rv = Val_domain (r, connv);
685
686   CAMLreturn (rv);
687 }
688
689 /* Automatically generated binding for virDomainLookupByUUIDString.
690  * In generator.pl this function has signature "conn, string : dom".
691  */
692
693 CAMLprim value
694 ocaml_libvirt_domain_lookup_by_uuid_string (value connv, value strv)
695 {
696   CAMLparam2 (connv, strv);
697
698   CAMLlocal1 (rv);
699   virConnectPtr conn = Connect_val (connv);
700   char *str = String_val (strv);
701   virDomainPtr r;
702
703   NONBLOCKING (r = virDomainLookupByUUIDString (conn, str));
704   CHECK_ERROR (!r, "virDomainLookupByUUIDString");
705
706   rv = Val_domain (r, connv);
707
708   CAMLreturn (rv);
709 }
710
711 /* Automatically generated binding for virDomainGetName.
712  * In generator.pl this function has signature "dom : static string".
713  */
714
715 CAMLprim value
716 ocaml_libvirt_domain_get_name (value domv)
717 {
718   CAMLparam1 (domv);
719
720   CAMLlocal1 (rv);
721   virDomainPtr dom = Domain_val (domv);
722   const char *r;
723
724   NONBLOCKING (r = virDomainGetName (dom));
725   CHECK_ERROR (!r, "virDomainGetName");
726
727   rv = caml_copy_string (r);
728   CAMLreturn (rv);
729 }
730
731 /* Automatically generated binding for virDomainGetOSType.
732  * In generator.pl this function has signature "dom : string".
733  */
734
735 CAMLprim value
736 ocaml_libvirt_domain_get_os_type (value domv)
737 {
738   CAMLparam1 (domv);
739
740   CAMLlocal1 (rv);
741   virDomainPtr dom = Domain_val (domv);
742   char *r;
743
744   NONBLOCKING (r = virDomainGetOSType (dom));
745   CHECK_ERROR (!r, "virDomainGetOSType");
746
747   rv = caml_copy_string (r);
748   free (r);
749   CAMLreturn (rv);
750 }
751
752 /* Automatically generated binding for virDomainGetXMLDesc.
753  * In generator.pl this function has signature "dom, 0 : string".
754  */
755
756 CAMLprim value
757 ocaml_libvirt_domain_get_xml_desc (value domv)
758 {
759   CAMLparam1 (domv);
760
761   CAMLlocal1 (rv);
762   virDomainPtr dom = Domain_val (domv);
763   char *r;
764
765   NONBLOCKING (r = virDomainGetXMLDesc (dom, 0));
766   CHECK_ERROR (!r, "virDomainGetXMLDesc");
767
768   rv = caml_copy_string (r);
769   free (r);
770   CAMLreturn (rv);
771 }
772
773 /* Automatically generated binding for virDomainGetUUID.
774  * In generator.pl this function has signature "dom : uuid".
775  */
776
777 CAMLprim value
778 ocaml_libvirt_domain_get_uuid (value domv)
779 {
780   CAMLparam1 (domv);
781
782   CAMLlocal1 (rv);
783   virDomainPtr dom = Domain_val (domv);
784   unsigned char uuid[VIR_UUID_BUFLEN];
785   int r;
786
787   NONBLOCKING (r = virDomainGetUUID (dom, uuid));
788   CHECK_ERROR (r == -1, "virDomainGetUUID");
789
790   /* UUIDs are byte arrays with a fixed length. */
791   rv = caml_alloc_string (VIR_UUID_BUFLEN);
792   memcpy (String_val (rv), uuid, VIR_UUID_BUFLEN);
793   CAMLreturn (rv);
794 }
795
796 /* Automatically generated binding for virDomainGetUUIDString.
797  * In generator.pl this function has signature "dom : uuid string".
798  */
799
800 CAMLprim value
801 ocaml_libvirt_domain_get_uuid_string (value domv)
802 {
803   CAMLparam1 (domv);
804
805   CAMLlocal1 (rv);
806   virDomainPtr dom = Domain_val (domv);
807   char uuid[VIR_UUID_STRING_BUFLEN];
808   int r;
809
810   NONBLOCKING (r = virDomainGetUUIDString (dom, uuid));
811   CHECK_ERROR (r == -1, "virDomainGetUUIDString");
812
813   rv = caml_copy_string (uuid);
814   CAMLreturn (rv);
815 }
816
817 /* Automatically generated binding for virDomainGetMaxVcpus.
818  * In generator.pl this function has signature "dom : int".
819  */
820
821 CAMLprim value
822 ocaml_libvirt_domain_get_max_vcpus (value domv)
823 {
824   CAMLparam1 (domv);
825
826   virDomainPtr dom = Domain_val (domv);
827   int r;
828
829   NONBLOCKING (r = virDomainGetMaxVcpus (dom));
830   CHECK_ERROR (r == -1, "virDomainGetMaxVcpus");
831
832   CAMLreturn (Val_int (r));
833 }
834
835 /* Automatically generated binding for virDomainSave.
836  * In generator.pl this function has signature "dom, string : unit".
837  */
838
839 CAMLprim value
840 ocaml_libvirt_domain_save (value domv, value strv)
841 {
842   CAMLparam2 (domv, strv);
843
844   virDomainPtr dom = Domain_val (domv);
845   char *str = String_val (strv);
846   int r;
847
848   NONBLOCKING (r = virDomainSave (dom, str));
849   CHECK_ERROR (r == -1, "virDomainSave");
850
851   CAMLreturn (Val_unit);
852 }
853
854 /* Automatically generated binding for virDomainRestore.
855  * In generator.pl this function has signature "conn, string : unit".
856  */
857
858 CAMLprim value
859 ocaml_libvirt_domain_restore (value connv, value strv)
860 {
861   CAMLparam2 (connv, strv);
862
863   virConnectPtr conn = Connect_val (connv);
864   char *str = String_val (strv);
865   int r;
866
867   NONBLOCKING (r = virDomainRestore (conn, str));
868   CHECK_ERROR (r == -1, "virDomainRestore");
869
870   CAMLreturn (Val_unit);
871 }
872
873 /* Automatically generated binding for virDomainCoreDump.
874  * In generator.pl this function has signature "dom, string, 0 : unit".
875  */
876
877 CAMLprim value
878 ocaml_libvirt_domain_core_dump (value domv, value strv)
879 {
880   CAMLparam2 (domv, strv);
881
882   CAMLlocal1 (rv);
883   virDomainPtr dom = Domain_val (domv);
884   char *str = String_val (strv);
885   int r;
886
887   NONBLOCKING (r = virDomainCoreDump (dom, str, 0));
888   CHECK_ERROR (!r, "virDomainCoreDump");
889
890   CAMLreturn (Val_unit);
891 }
892
893 /* Automatically generated binding for virDomainSuspend.
894  * In generator.pl this function has signature "dom : unit".
895  */
896
897 CAMLprim value
898 ocaml_libvirt_domain_suspend (value domv)
899 {
900   CAMLparam1 (domv);
901
902   virDomainPtr dom = Domain_val (domv);
903   int r;
904
905   NONBLOCKING (r = virDomainSuspend (dom));
906   CHECK_ERROR (r == -1, "virDomainSuspend");
907
908   CAMLreturn (Val_unit);
909 }
910
911 /* Automatically generated binding for virDomainResume.
912  * In generator.pl this function has signature "dom : unit".
913  */
914
915 CAMLprim value
916 ocaml_libvirt_domain_resume (value domv)
917 {
918   CAMLparam1 (domv);
919
920   virDomainPtr dom = Domain_val (domv);
921   int r;
922
923   NONBLOCKING (r = virDomainResume (dom));
924   CHECK_ERROR (r == -1, "virDomainResume");
925
926   CAMLreturn (Val_unit);
927 }
928
929 /* Automatically generated binding for virDomainShutdown.
930  * In generator.pl this function has signature "dom : unit".
931  */
932
933 CAMLprim value
934 ocaml_libvirt_domain_shutdown (value domv)
935 {
936   CAMLparam1 (domv);
937
938   virDomainPtr dom = Domain_val (domv);
939   int r;
940
941   NONBLOCKING (r = virDomainShutdown (dom));
942   CHECK_ERROR (r == -1, "virDomainShutdown");
943
944   CAMLreturn (Val_unit);
945 }
946
947 /* Automatically generated binding for virDomainReboot.
948  * In generator.pl this function has signature "dom, 0 : unit".
949  */
950
951 CAMLprim value
952 ocaml_libvirt_domain_reboot (value domv)
953 {
954   CAMLparam1 (domv);
955
956   virDomainPtr dom = Domain_val (domv);
957   int r;
958
959   NONBLOCKING (r = virDomainReboot (dom, 0));
960   CHECK_ERROR (r == -1, "virDomainReboot");
961
962   CAMLreturn (Val_unit);
963 }
964
965 /* Automatically generated binding for virDomainDefineXML.
966  * In generator.pl this function has signature "conn, string : dom".
967  */
968
969 CAMLprim value
970 ocaml_libvirt_domain_define_xml (value connv, value strv)
971 {
972   CAMLparam2 (connv, strv);
973
974   CAMLlocal1 (rv);
975   virConnectPtr conn = Connect_val (connv);
976   char *str = String_val (strv);
977   virDomainPtr r;
978
979   NONBLOCKING (r = virDomainDefineXML (conn, str));
980   CHECK_ERROR (!r, "virDomainDefineXML");
981
982   rv = Val_domain (r, connv);
983
984   CAMLreturn (rv);
985 }
986
987 /* Automatically generated binding for virDomainUndefine.
988  * In generator.pl this function has signature "dom : unit".
989  */
990
991 CAMLprim value
992 ocaml_libvirt_domain_undefine (value domv)
993 {
994   CAMLparam1 (domv);
995
996   virDomainPtr dom = Domain_val (domv);
997   int r;
998
999   NONBLOCKING (r = virDomainUndefine (dom));
1000   CHECK_ERROR (r == -1, "virDomainUndefine");
1001
1002   CAMLreturn (Val_unit);
1003 }
1004
1005 /* Automatically generated binding for virDomainCreate.
1006  * In generator.pl this function has signature "dom : unit".
1007  */
1008
1009 CAMLprim value
1010 ocaml_libvirt_domain_create (value domv)
1011 {
1012   CAMLparam1 (domv);
1013
1014   virDomainPtr dom = Domain_val (domv);
1015   int r;
1016
1017   NONBLOCKING (r = virDomainCreate (dom));
1018   CHECK_ERROR (r == -1, "virDomainCreate");
1019
1020   CAMLreturn (Val_unit);
1021 }
1022
1023 /* Automatically generated binding for virDomainAttachDevice.
1024  * In generator.pl this function has signature "dom, string : unit".
1025  */
1026
1027 CAMLprim value
1028 ocaml_libvirt_domain_attach_device (value domv, value strv)
1029 {
1030   CAMLparam2 (domv, strv);
1031
1032   virDomainPtr dom = Domain_val (domv);
1033   char *str = String_val (strv);
1034   int r;
1035
1036   NONBLOCKING (r = virDomainAttachDevice (dom, str));
1037   CHECK_ERROR (r == -1, "virDomainAttachDevice");
1038
1039   CAMLreturn (Val_unit);
1040 }
1041
1042 /* Automatically generated binding for virDomainDetachDevice.
1043  * In generator.pl this function has signature "dom, string : unit".
1044  */
1045
1046 CAMLprim value
1047 ocaml_libvirt_domain_detach_device (value domv, value strv)
1048 {
1049   CAMLparam2 (domv, strv);
1050
1051   virDomainPtr dom = Domain_val (domv);
1052   char *str = String_val (strv);
1053   int r;
1054
1055   NONBLOCKING (r = virDomainDetachDevice (dom, str));
1056   CHECK_ERROR (r == -1, "virDomainDetachDevice");
1057
1058   CAMLreturn (Val_unit);
1059 }
1060
1061 /* Automatically generated binding for virDomainGetAutostart.
1062  * In generator.pl this function has signature "dom : bool".
1063  */
1064
1065 CAMLprim value
1066 ocaml_libvirt_domain_get_autostart (value domv)
1067 {
1068   CAMLparam1 (domv);
1069
1070   virDomainPtr dom = Domain_val (domv);
1071   int r, b;
1072
1073   NONBLOCKING (r = virDomainGetAutostart (dom, &b));
1074   CHECK_ERROR (r == -1, "virDomainGetAutostart");
1075
1076   CAMLreturn (b ? Val_true : Val_false);
1077 }
1078
1079 /* Automatically generated binding for virDomainSetAutostart.
1080  * In generator.pl this function has signature "dom, bool : unit".
1081  */
1082
1083 CAMLprim value
1084 ocaml_libvirt_domain_set_autostart (value domv, value bv)
1085 {
1086   CAMLparam2 (domv, bv);
1087
1088   virDomainPtr dom = Domain_val (domv);
1089   int r, b;
1090
1091   b = bv == Val_true ? 1 : 0;
1092
1093   NONBLOCKING (r = virDomainSetAutostart (dom, b));
1094   CHECK_ERROR (r == -1, "virDomainSetAutostart");
1095
1096   CAMLreturn (Val_unit);
1097 }
1098
1099 /* Automatically generated binding for virNetworkFree.
1100  * In generator.pl this function has signature "net : free".
1101  */
1102
1103 CAMLprim value
1104 ocaml_libvirt_network_free (value netv)
1105 {
1106   CAMLparam1 (netv);
1107
1108   virNetworkPtr net = Network_val (netv);
1109   int r;
1110
1111   NONBLOCKING (r = virNetworkFree (net));
1112   CHECK_ERROR (r == -1, "virNetworkFree");
1113
1114   /* So that we don't double-free in the finalizer: */
1115   Network_val (netv) = NULL;
1116
1117   CAMLreturn (Val_unit);
1118 }
1119
1120 /* Automatically generated binding for virNetworkDestroy.
1121  * In generator.pl this function has signature "net : free".
1122  */
1123
1124 CAMLprim value
1125 ocaml_libvirt_network_destroy (value netv)
1126 {
1127   CAMLparam1 (netv);
1128
1129   virNetworkPtr net = Network_val (netv);
1130   int r;
1131
1132   NONBLOCKING (r = virNetworkDestroy (net));
1133   CHECK_ERROR (r == -1, "virNetworkDestroy");
1134
1135   /* So that we don't double-free in the finalizer: */
1136   Network_val (netv) = NULL;
1137
1138   CAMLreturn (Val_unit);
1139 }
1140
1141 /* Automatically generated binding for virNetworkLookupByName.
1142  * In generator.pl this function has signature "conn, string : net".
1143  */
1144
1145 CAMLprim value
1146 ocaml_libvirt_network_lookup_by_name (value connv, value strv)
1147 {
1148   CAMLparam2 (connv, strv);
1149
1150   CAMLlocal1 (rv);
1151   virConnectPtr conn = Connect_val (connv);
1152   char *str = String_val (strv);
1153   virNetworkPtr r;
1154
1155   NONBLOCKING (r = virNetworkLookupByName (conn, str));
1156   CHECK_ERROR (!r, "virNetworkLookupByName");
1157
1158   rv = Val_network (r, connv);
1159
1160   CAMLreturn (rv);
1161 }
1162
1163 /* Automatically generated binding for virNetworkLookupByUUID.
1164  * In generator.pl this function has signature "conn, uuid : net".
1165  */
1166
1167 CAMLprim value
1168 ocaml_libvirt_network_lookup_by_uuid (value connv, value uuidv)
1169 {
1170   CAMLparam2 (connv, uuidv);
1171
1172   CAMLlocal1 (rv);
1173   virConnectPtr conn = Connect_val (connv);
1174   unsigned char *uuid = (unsigned char *) String_val (uuidv);
1175   virNetworkPtr r;
1176
1177   NONBLOCKING (r = virNetworkLookupByUUID (conn, uuid));
1178   CHECK_ERROR (!r, "virNetworkLookupByUUID");
1179
1180   rv = Val_network (r, connv);
1181
1182   CAMLreturn (rv);
1183 }
1184
1185 /* Automatically generated binding for virNetworkLookupByUUIDString.
1186  * In generator.pl this function has signature "conn, string : net".
1187  */
1188
1189 CAMLprim value
1190 ocaml_libvirt_network_lookup_by_uuid_string (value connv, value strv)
1191 {
1192   CAMLparam2 (connv, strv);
1193
1194   CAMLlocal1 (rv);
1195   virConnectPtr conn = Connect_val (connv);
1196   char *str = String_val (strv);
1197   virNetworkPtr r;
1198
1199   NONBLOCKING (r = virNetworkLookupByUUIDString (conn, str));
1200   CHECK_ERROR (!r, "virNetworkLookupByUUIDString");
1201
1202   rv = Val_network (r, connv);
1203
1204   CAMLreturn (rv);
1205 }
1206
1207 /* Automatically generated binding for virNetworkGetName.
1208  * In generator.pl this function has signature "net : static string".
1209  */
1210
1211 CAMLprim value
1212 ocaml_libvirt_network_get_name (value netv)
1213 {
1214   CAMLparam1 (netv);
1215
1216   CAMLlocal1 (rv);
1217   virNetworkPtr net = Network_val (netv);
1218   const char *r;
1219
1220   NONBLOCKING (r = virNetworkGetName (net));
1221   CHECK_ERROR (!r, "virNetworkGetName");
1222
1223   rv = caml_copy_string (r);
1224   CAMLreturn (rv);
1225 }
1226
1227 /* Automatically generated binding for virNetworkGetXMLDesc.
1228  * In generator.pl this function has signature "net, 0 : string".
1229  */
1230
1231 CAMLprim value
1232 ocaml_libvirt_network_get_xml_desc (value netv)
1233 {
1234   CAMLparam1 (netv);
1235
1236   CAMLlocal1 (rv);
1237   virNetworkPtr net = Network_val (netv);
1238   char *r;
1239
1240   NONBLOCKING (r = virNetworkGetXMLDesc (net, 0));
1241   CHECK_ERROR (!r, "virNetworkGetXMLDesc");
1242
1243   rv = caml_copy_string (r);
1244   free (r);
1245   CAMLreturn (rv);
1246 }
1247
1248 /* Automatically generated binding for virNetworkGetBridgeName.
1249  * In generator.pl this function has signature "net : string".
1250  */
1251
1252 CAMLprim value
1253 ocaml_libvirt_network_get_bridge_name (value netv)
1254 {
1255   CAMLparam1 (netv);
1256
1257   CAMLlocal1 (rv);
1258   virNetworkPtr net = Network_val (netv);
1259   char *r;
1260
1261   NONBLOCKING (r = virNetworkGetBridgeName (net));
1262   CHECK_ERROR (!r, "virNetworkGetBridgeName");
1263
1264   rv = caml_copy_string (r);
1265   free (r);
1266   CAMLreturn (rv);
1267 }
1268
1269 /* Automatically generated binding for virNetworkGetUUID.
1270  * In generator.pl this function has signature "net : uuid".
1271  */
1272
1273 CAMLprim value
1274 ocaml_libvirt_network_get_uuid (value netv)
1275 {
1276   CAMLparam1 (netv);
1277
1278   CAMLlocal1 (rv);
1279   virNetworkPtr net = Network_val (netv);
1280   unsigned char uuid[VIR_UUID_BUFLEN];
1281   int r;
1282
1283   NONBLOCKING (r = virNetworkGetUUID (net, uuid));
1284   CHECK_ERROR (r == -1, "virNetworkGetUUID");
1285
1286   /* UUIDs are byte arrays with a fixed length. */
1287   rv = caml_alloc_string (VIR_UUID_BUFLEN);
1288   memcpy (String_val (rv), uuid, VIR_UUID_BUFLEN);
1289   CAMLreturn (rv);
1290 }
1291
1292 /* Automatically generated binding for virNetworkGetUUIDString.
1293  * In generator.pl this function has signature "net : uuid string".
1294  */
1295
1296 CAMLprim value
1297 ocaml_libvirt_network_get_uuid_string (value netv)
1298 {
1299   CAMLparam1 (netv);
1300
1301   CAMLlocal1 (rv);
1302   virNetworkPtr net = Network_val (netv);
1303   char uuid[VIR_UUID_STRING_BUFLEN];
1304   int r;
1305
1306   NONBLOCKING (r = virNetworkGetUUIDString (net, uuid));
1307   CHECK_ERROR (r == -1, "virNetworkGetUUIDString");
1308
1309   rv = caml_copy_string (uuid);
1310   CAMLreturn (rv);
1311 }
1312
1313 /* Automatically generated binding for virNetworkUndefine.
1314  * In generator.pl this function has signature "net : unit".
1315  */
1316
1317 CAMLprim value
1318 ocaml_libvirt_network_undefine (value netv)
1319 {
1320   CAMLparam1 (netv);
1321
1322   virNetworkPtr net = Network_val (netv);
1323   int r;
1324
1325   NONBLOCKING (r = virNetworkUndefine (net));
1326   CHECK_ERROR (r == -1, "virNetworkUndefine");
1327
1328   CAMLreturn (Val_unit);
1329 }
1330
1331 /* Automatically generated binding for virNetworkCreateXML.
1332  * In generator.pl this function has signature "conn, string : net".
1333  */
1334
1335 CAMLprim value
1336 ocaml_libvirt_network_create_xml (value connv, value strv)
1337 {
1338   CAMLparam2 (connv, strv);
1339
1340   CAMLlocal1 (rv);
1341   virConnectPtr conn = Connect_val (connv);
1342   char *str = String_val (strv);
1343   virNetworkPtr r;
1344
1345   NONBLOCKING (r = virNetworkCreateXML (conn, str));
1346   CHECK_ERROR (!r, "virNetworkCreateXML");
1347
1348   rv = Val_network (r, connv);
1349
1350   CAMLreturn (rv);
1351 }
1352
1353 /* Automatically generated binding for virNetworkDefineXML.
1354  * In generator.pl this function has signature "conn, string : net".
1355  */
1356
1357 CAMLprim value
1358 ocaml_libvirt_network_define_xml (value connv, value strv)
1359 {
1360   CAMLparam2 (connv, strv);
1361
1362   CAMLlocal1 (rv);
1363   virConnectPtr conn = Connect_val (connv);
1364   char *str = String_val (strv);
1365   virNetworkPtr r;
1366
1367   NONBLOCKING (r = virNetworkDefineXML (conn, str));
1368   CHECK_ERROR (!r, "virNetworkDefineXML");
1369
1370   rv = Val_network (r, connv);
1371
1372   CAMLreturn (rv);
1373 }
1374
1375 /* Automatically generated binding for virNetworkCreate.
1376  * In generator.pl this function has signature "net : unit".
1377  */
1378
1379 CAMLprim value
1380 ocaml_libvirt_network_create (value netv)
1381 {
1382   CAMLparam1 (netv);
1383
1384   virNetworkPtr net = Network_val (netv);
1385   int r;
1386
1387   NONBLOCKING (r = virNetworkCreate (net));
1388   CHECK_ERROR (r == -1, "virNetworkCreate");
1389
1390   CAMLreturn (Val_unit);
1391 }
1392
1393 /* Automatically generated binding for virNetworkGetAutostart.
1394  * In generator.pl this function has signature "net : bool".
1395  */
1396
1397 CAMLprim value
1398 ocaml_libvirt_network_get_autostart (value netv)
1399 {
1400   CAMLparam1 (netv);
1401
1402   virNetworkPtr net = Network_val (netv);
1403   int r, b;
1404
1405   NONBLOCKING (r = virNetworkGetAutostart (net, &b));
1406   CHECK_ERROR (r == -1, "virNetworkGetAutostart");
1407
1408   CAMLreturn (b ? Val_true : Val_false);
1409 }
1410
1411 /* Automatically generated binding for virNetworkSetAutostart.
1412  * In generator.pl this function has signature "net, bool : unit".
1413  */
1414
1415 CAMLprim value
1416 ocaml_libvirt_network_set_autostart (value netv, value bv)
1417 {
1418   CAMLparam2 (netv, bv);
1419
1420   virNetworkPtr net = Network_val (netv);
1421   int r, b;
1422
1423   b = bv == Val_true ? 1 : 0;
1424
1425   NONBLOCKING (r = virNetworkSetAutostart (net, b));
1426   CHECK_ERROR (r == -1, "virNetworkSetAutostart");
1427
1428   CAMLreturn (Val_unit);
1429 }
1430
1431 /* Automatically generated binding for virStoragePoolFree.
1432  * In generator.pl this function has signature "pool : free".
1433  */
1434
1435 CAMLprim value
1436 ocaml_libvirt_storage_pool_free (value poolv)
1437 {
1438   CAMLparam1 (poolv);
1439
1440   virStoragePoolPtr pool = Pool_val (poolv);
1441   int r;
1442
1443   NONBLOCKING (r = virStoragePoolFree (pool));
1444   CHECK_ERROR (r == -1, "virStoragePoolFree");
1445
1446   /* So that we don't double-free in the finalizer: */
1447   Pool_val (poolv) = NULL;
1448
1449   CAMLreturn (Val_unit);
1450 }
1451
1452 /* Automatically generated binding for virStoragePoolDestroy.
1453  * In generator.pl this function has signature "pool : free".
1454  */
1455
1456 CAMLprim value
1457 ocaml_libvirt_storage_pool_destroy (value poolv)
1458 {
1459   CAMLparam1 (poolv);
1460
1461   virStoragePoolPtr pool = Pool_val (poolv);
1462   int r;
1463
1464   NONBLOCKING (r = virStoragePoolDestroy (pool));
1465   CHECK_ERROR (r == -1, "virStoragePoolDestroy");
1466
1467   /* So that we don't double-free in the finalizer: */
1468   Pool_val (poolv) = NULL;
1469
1470   CAMLreturn (Val_unit);
1471 }
1472
1473 /* Automatically generated binding for virStoragePoolLookupByName.
1474  * In generator.pl this function has signature "conn, string : pool".
1475  */
1476
1477 CAMLprim value
1478 ocaml_libvirt_storage_pool_lookup_by_name (value connv, value strv)
1479 {
1480   CAMLparam2 (connv, strv);
1481
1482   CAMLlocal1 (rv);
1483   virConnectPtr conn = Connect_val (connv);
1484   char *str = String_val (strv);
1485   virStoragePoolPtr r;
1486
1487   NONBLOCKING (r = virStoragePoolLookupByName (conn, str));
1488   CHECK_ERROR (!r, "virStoragePoolLookupByName");
1489
1490   rv = Val_pool (r, connv);
1491
1492   CAMLreturn (rv);
1493 }
1494
1495 /* Automatically generated binding for virStoragePoolLookupByUUID.
1496  * In generator.pl this function has signature "conn, uuid : pool".
1497  */
1498
1499 CAMLprim value
1500 ocaml_libvirt_storage_pool_lookup_by_uuid (value connv, value uuidv)
1501 {
1502   CAMLparam2 (connv, uuidv);
1503
1504   CAMLlocal1 (rv);
1505   virConnectPtr conn = Connect_val (connv);
1506   unsigned char *uuid = (unsigned char *) String_val (uuidv);
1507   virStoragePoolPtr r;
1508
1509   NONBLOCKING (r = virStoragePoolLookupByUUID (conn, uuid));
1510   CHECK_ERROR (!r, "virStoragePoolLookupByUUID");
1511
1512   rv = Val_pool (r, connv);
1513
1514   CAMLreturn (rv);
1515 }
1516
1517 /* Automatically generated binding for virStoragePoolLookupByUUIDString.
1518  * In generator.pl this function has signature "conn, string : pool".
1519  */
1520
1521 CAMLprim value
1522 ocaml_libvirt_storage_pool_lookup_by_uuid_string (value connv, value strv)
1523 {
1524   CAMLparam2 (connv, strv);
1525
1526   CAMLlocal1 (rv);
1527   virConnectPtr conn = Connect_val (connv);
1528   char *str = String_val (strv);
1529   virStoragePoolPtr r;
1530
1531   NONBLOCKING (r = virStoragePoolLookupByUUIDString (conn, str));
1532   CHECK_ERROR (!r, "virStoragePoolLookupByUUIDString");
1533
1534   rv = Val_pool (r, connv);
1535
1536   CAMLreturn (rv);
1537 }
1538
1539 /* Automatically generated binding for virStoragePoolGetName.
1540  * In generator.pl this function has signature "pool : static string".
1541  */
1542
1543 CAMLprim value
1544 ocaml_libvirt_storage_pool_get_name (value poolv)
1545 {
1546   CAMLparam1 (poolv);
1547
1548   CAMLlocal1 (rv);
1549   virStoragePoolPtr pool = Pool_val (poolv);
1550   const char *r;
1551
1552   NONBLOCKING (r = virStoragePoolGetName (pool));
1553   CHECK_ERROR (!r, "virStoragePoolGetName");
1554
1555   rv = caml_copy_string (r);
1556   CAMLreturn (rv);
1557 }
1558
1559 /* Automatically generated binding for virStoragePoolGetXMLDesc.
1560  * In generator.pl this function has signature "pool, 0U : string".
1561  */
1562
1563 CAMLprim value
1564 ocaml_libvirt_storage_pool_get_xml_desc (value poolv)
1565 {
1566   CAMLparam1 (poolv);
1567
1568   CAMLlocal1 (rv);
1569   virStoragePoolPtr pool = Pool_val (poolv);
1570   char *r;
1571
1572   NONBLOCKING (r = virStoragePoolGetXMLDesc (pool, 0));
1573   CHECK_ERROR (!r, "virStoragePoolGetXMLDesc");
1574
1575   rv = caml_copy_string (r);
1576   free (r);
1577   CAMLreturn (rv);
1578 }
1579
1580 /* Automatically generated binding for virStoragePoolGetUUID.
1581  * In generator.pl this function has signature "pool : uuid".
1582  */
1583
1584 CAMLprim value
1585 ocaml_libvirt_storage_pool_get_uuid (value poolv)
1586 {
1587   CAMLparam1 (poolv);
1588
1589   CAMLlocal1 (rv);
1590   virStoragePoolPtr pool = Pool_val (poolv);
1591   unsigned char uuid[VIR_UUID_BUFLEN];
1592   int r;
1593
1594   NONBLOCKING (r = virStoragePoolGetUUID (pool, uuid));
1595   CHECK_ERROR (r == -1, "virStoragePoolGetUUID");
1596
1597   /* UUIDs are byte arrays with a fixed length. */
1598   rv = caml_alloc_string (VIR_UUID_BUFLEN);
1599   memcpy (String_val (rv), uuid, VIR_UUID_BUFLEN);
1600   CAMLreturn (rv);
1601 }
1602
1603 /* Automatically generated binding for virStoragePoolGetUUIDString.
1604  * In generator.pl this function has signature "pool : uuid string".
1605  */
1606
1607 CAMLprim value
1608 ocaml_libvirt_storage_pool_get_uuid_string (value poolv)
1609 {
1610   CAMLparam1 (poolv);
1611
1612   CAMLlocal1 (rv);
1613   virStoragePoolPtr pool = Pool_val (poolv);
1614   char uuid[VIR_UUID_STRING_BUFLEN];
1615   int r;
1616
1617   NONBLOCKING (r = virStoragePoolGetUUIDString (pool, uuid));
1618   CHECK_ERROR (r == -1, "virStoragePoolGetUUIDString");
1619
1620   rv = caml_copy_string (uuid);
1621   CAMLreturn (rv);
1622 }
1623
1624 /* Automatically generated binding for virStoragePoolCreateXML.
1625  * In generator.pl this function has signature "conn, string, 0U : pool".
1626  */
1627
1628 CAMLprim value
1629 ocaml_libvirt_storage_pool_create_xml (value connv, value strv)
1630 {
1631   CAMLparam2 (connv, strv);
1632
1633   CAMLlocal1 (rv);
1634   virConnectPtr conn = Connect_val (connv);
1635   char *str = String_val (strv);
1636   virStoragePoolPtr r;
1637
1638   NONBLOCKING (r = virStoragePoolCreateXML (conn, str, 0));
1639   CHECK_ERROR (!r, "virStoragePoolCreateXML");
1640
1641   rv = Val_pool (r, connv);
1642
1643   CAMLreturn (rv);
1644 }
1645
1646 /* Automatically generated binding for virStoragePoolDefineXML.
1647  * In generator.pl this function has signature "conn, string, 0U : pool".
1648  */
1649
1650 CAMLprim value
1651 ocaml_libvirt_storage_pool_define_xml (value connv, value strv)
1652 {
1653   CAMLparam2 (connv, strv);
1654
1655   CAMLlocal1 (rv);
1656   virConnectPtr conn = Connect_val (connv);
1657   char *str = String_val (strv);
1658   virStoragePoolPtr r;
1659
1660   NONBLOCKING (r = virStoragePoolDefineXML (conn, str, 0));
1661   CHECK_ERROR (!r, "virStoragePoolDefineXML");
1662
1663   rv = Val_pool (r, connv);
1664
1665   CAMLreturn (rv);
1666 }
1667
1668 /* Automatically generated binding for virStoragePoolBuild.
1669  * In generator.pl this function has signature "pool, uint : unit".
1670  */
1671
1672 CAMLprim value
1673 ocaml_libvirt_storage_pool_build (value poolv, value iv)
1674 {
1675   CAMLparam2 (poolv, iv);
1676
1677   virStoragePoolPtr pool = Pool_val (poolv);
1678   unsigned int i = Int_val (iv);
1679   int r;
1680
1681   NONBLOCKING (r = virStoragePoolBuild (pool, i));
1682   CHECK_ERROR (r == -1, "virStoragePoolBuild");
1683
1684   CAMLreturn (Val_unit);
1685 }
1686
1687 /* Automatically generated binding for virStoragePoolUndefine.
1688  * In generator.pl this function has signature "pool : unit".
1689  */
1690
1691 CAMLprim value
1692 ocaml_libvirt_storage_pool_undefine (value poolv)
1693 {
1694   CAMLparam1 (poolv);
1695
1696   virStoragePoolPtr pool = Pool_val (poolv);
1697   int r;
1698
1699   NONBLOCKING (r = virStoragePoolUndefine (pool));
1700   CHECK_ERROR (r == -1, "virStoragePoolUndefine");
1701
1702   CAMLreturn (Val_unit);
1703 }
1704
1705 /* Automatically generated binding for virStoragePoolCreate.
1706  * In generator.pl this function has signature "pool, 0U : unit".
1707  */
1708
1709 CAMLprim value
1710 ocaml_libvirt_storage_pool_create (value poolv)
1711 {
1712   CAMLparam1 (poolv);
1713
1714   virStoragePoolPtr pool = Pool_val (poolv);
1715   int r;
1716
1717   NONBLOCKING (r = virStoragePoolCreate (pool, 0));
1718   CHECK_ERROR (r == -1, "virStoragePoolCreate");
1719
1720   CAMLreturn (Val_unit);
1721 }
1722
1723 /* Automatically generated binding for virStoragePoolDelete.
1724  * In generator.pl this function has signature "pool, uint : unit".
1725  */
1726
1727 CAMLprim value
1728 ocaml_libvirt_storage_pool_delete (value poolv, value iv)
1729 {
1730   CAMLparam2 (poolv, iv);
1731
1732   virStoragePoolPtr pool = Pool_val (poolv);
1733   unsigned int i = Int_val (iv);
1734   int r;
1735
1736   NONBLOCKING (r = virStoragePoolDelete (pool, i));
1737   CHECK_ERROR (r == -1, "virStoragePoolDelete");
1738
1739   CAMLreturn (Val_unit);
1740 }
1741
1742 /* Automatically generated binding for virStoragePoolRefresh.
1743  * In generator.pl this function has signature "pool, 0U : unit".
1744  */
1745
1746 CAMLprim value
1747 ocaml_libvirt_storage_pool_refresh (value poolv)
1748 {
1749   CAMLparam1 (poolv);
1750
1751   virStoragePoolPtr pool = Pool_val (poolv);
1752   int r;
1753
1754   NONBLOCKING (r = virStoragePoolRefresh (pool, 0));
1755   CHECK_ERROR (r == -1, "virStoragePoolRefresh");
1756
1757   CAMLreturn (Val_unit);
1758 }
1759
1760 /* Automatically generated binding for virStoragePoolGetAutostart.
1761  * In generator.pl this function has signature "pool : bool".
1762  */
1763
1764 CAMLprim value
1765 ocaml_libvirt_storage_pool_get_autostart (value poolv)
1766 {
1767   CAMLparam1 (poolv);
1768
1769   virStoragePoolPtr pool = Pool_val (poolv);
1770   int r, b;
1771
1772   NONBLOCKING (r = virStoragePoolGetAutostart (pool, &b));
1773   CHECK_ERROR (r == -1, "virStoragePoolGetAutostart");
1774
1775   CAMLreturn (b ? Val_true : Val_false);
1776 }
1777
1778 /* Automatically generated binding for virStoragePoolSetAutostart.
1779  * In generator.pl this function has signature "pool, bool : unit".
1780  */
1781
1782 CAMLprim value
1783 ocaml_libvirt_storage_pool_set_autostart (value poolv, value bv)
1784 {
1785   CAMLparam2 (poolv, bv);
1786
1787   virStoragePoolPtr pool = Pool_val (poolv);
1788   int r, b;
1789
1790   b = bv == Val_true ? 1 : 0;
1791
1792   NONBLOCKING (r = virStoragePoolSetAutostart (pool, b));
1793   CHECK_ERROR (r == -1, "virStoragePoolSetAutostart");
1794
1795   CAMLreturn (Val_unit);
1796 }
1797
1798 /* Automatically generated binding for virStoragePoolNumOfVolumes.
1799  * In generator.pl this function has signature "pool : int".
1800  */
1801
1802 CAMLprim value
1803 ocaml_libvirt_storage_pool_num_of_volumes (value poolv)
1804 {
1805   CAMLparam1 (poolv);
1806
1807   virStoragePoolPtr pool = Pool_val (poolv);
1808   int r;
1809
1810   NONBLOCKING (r = virStoragePoolNumOfVolumes (pool));
1811   CHECK_ERROR (r == -1, "virStoragePoolNumOfVolumes");
1812
1813   CAMLreturn (Val_int (r));
1814 }
1815
1816 /* Automatically generated binding for virStoragePoolListVolumes.
1817  * In generator.pl this function has signature "pool, int : string array".
1818  */
1819
1820 CAMLprim value
1821 ocaml_libvirt_storage_pool_list_volumes (value poolv, value iv)
1822 {
1823   CAMLparam2 (poolv, iv);
1824
1825   CAMLlocal2 (rv, strv);
1826   virStoragePoolPtr pool = Pool_val (poolv);
1827   int i = Int_val (iv);
1828   char **names;
1829   int r;
1830
1831   /* Some libvirt List* functions still throw exceptions if i == 0,
1832    * so catch that and return an empty array directly.  This changes
1833    * the semantics slightly (masking other failures) but it's
1834    * unlikely anyone will care.  RWMJ 2008/06/10
1835    */
1836   if (i == 0) {
1837     rv = caml_alloc (0, 0);
1838     CAMLreturn (rv);
1839   }
1840
1841   names = malloc (sizeof (*names) * i);
1842   if (names == NULL)
1843     caml_raise_out_of_memory ();
1844
1845   NONBLOCKING (r = virStoragePoolListVolumes (pool, names, i));
1846   CHECK_ERROR_CLEANUP (r == -1, free (names), "virStoragePoolListVolumes");
1847
1848   rv = caml_alloc (r, 0);
1849   for (i = 0; i < r; ++i) {
1850     strv = caml_copy_string (names[i]);
1851     Store_field (rv, i, strv);
1852     free (names[i]);
1853   }
1854   free (names);
1855
1856   CAMLreturn (rv);
1857 }
1858
1859 /* Automatically generated binding for virStorageVolFree.
1860  * In generator.pl this function has signature "vol : free".
1861  */
1862
1863 CAMLprim value
1864 ocaml_libvirt_storage_vol_free (value volv)
1865 {
1866   CAMLparam1 (volv);
1867
1868   virStorageVolPtr vol = Volume_val (volv);
1869   int r;
1870
1871   NONBLOCKING (r = virStorageVolFree (vol));
1872   CHECK_ERROR (r == -1, "virStorageVolFree");
1873
1874   /* So that we don't double-free in the finalizer: */
1875   Volume_val (volv) = NULL;
1876
1877   CAMLreturn (Val_unit);
1878 }
1879
1880 /* Automatically generated binding for virStorageVolDelete.
1881  * In generator.pl this function has signature "vol, uint : unit".
1882  */
1883
1884 CAMLprim value
1885 ocaml_libvirt_storage_vol_delete (value volv, value iv)
1886 {
1887   CAMLparam2 (volv, iv);
1888
1889   virStorageVolPtr vol = Volume_val (volv);
1890   unsigned int i = Int_val (iv);
1891   int r;
1892
1893   NONBLOCKING (r = virStorageVolDelete (vol, i));
1894   CHECK_ERROR (r == -1, "virStorageVolDelete");
1895
1896   CAMLreturn (Val_unit);
1897 }
1898
1899 /* Automatically generated binding for virStorageVolLookupByName.
1900  * In generator.pl this function has signature "pool, string : vol from pool".
1901  */
1902
1903 CAMLprim value
1904 ocaml_libvirt_storage_vol_lookup_by_name (value poolv, value strv)
1905 {
1906   CAMLparam2 (poolv, strv);
1907
1908   CAMLlocal2 (rv, connv);
1909   virStoragePoolPtr pool = Pool_val (poolv);
1910   char *str = String_val (strv);
1911   virStorageVolPtr r;
1912
1913   NONBLOCKING (r = virStorageVolLookupByName (pool, str));
1914   CHECK_ERROR (!r, "virStorageVolLookupByName");
1915
1916   connv = Field (poolv, 1);
1917   rv = Val_volume (r, connv);
1918
1919   CAMLreturn (rv);
1920 }
1921
1922 /* Automatically generated binding for virStorageVolLookupByKey.
1923  * In generator.pl this function has signature "conn, string : vol".
1924  */
1925
1926 CAMLprim value
1927 ocaml_libvirt_storage_vol_lookup_by_key (value connv, value strv)
1928 {
1929   CAMLparam2 (connv, strv);
1930
1931   CAMLlocal1 (rv);
1932   virConnectPtr conn = Connect_val (connv);
1933   char *str = String_val (strv);
1934   virStorageVolPtr r;
1935
1936   NONBLOCKING (r = virStorageVolLookupByKey (conn, str));
1937   CHECK_ERROR (!r, "virStorageVolLookupByKey");
1938
1939   rv = Val_volume (r, connv);
1940
1941   CAMLreturn (rv);
1942 }
1943
1944 /* Automatically generated binding for virStorageVolLookupByPath.
1945  * In generator.pl this function has signature "conn, string : vol".
1946  */
1947
1948 CAMLprim value
1949 ocaml_libvirt_storage_vol_lookup_by_path (value connv, value strv)
1950 {
1951   CAMLparam2 (connv, strv);
1952
1953   CAMLlocal1 (rv);
1954   virConnectPtr conn = Connect_val (connv);
1955   char *str = String_val (strv);
1956   virStorageVolPtr r;
1957
1958   NONBLOCKING (r = virStorageVolLookupByPath (conn, str));
1959   CHECK_ERROR (!r, "virStorageVolLookupByPath");
1960
1961   rv = Val_volume (r, connv);
1962
1963   CAMLreturn (rv);
1964 }
1965
1966 /* Automatically generated binding for virStorageVolCreateXML.
1967  * In generator.pl this function has signature "pool, string, 0U : vol from pool".
1968  */
1969
1970 CAMLprim value
1971 ocaml_libvirt_storage_vol_create_xml (value poolv, value strv)
1972 {
1973   CAMLparam2 (poolv, strv);
1974
1975   CAMLlocal2 (rv, connv);
1976   virStoragePoolPtr pool = Pool_val (poolv);
1977   char *str = String_val (strv);
1978   virStorageVolPtr r;
1979
1980   NONBLOCKING (r = virStorageVolCreateXML (pool, str, 0));
1981   CHECK_ERROR (!r, "virStorageVolCreateXML");
1982
1983   connv = Field (poolv, 1);
1984   rv = Val_volume (r, connv);
1985
1986   CAMLreturn (rv);
1987 }
1988
1989 /* Automatically generated binding for virStorageVolGetXMLDesc.
1990  * In generator.pl this function has signature "vol, 0U : string".
1991  */
1992
1993 CAMLprim value
1994 ocaml_libvirt_storage_vol_get_xml_desc (value volv)
1995 {
1996   CAMLparam1 (volv);
1997
1998   CAMLlocal1 (rv);
1999   virStorageVolPtr vol = Volume_val (volv);
2000   char *r;
2001
2002   NONBLOCKING (r = virStorageVolGetXMLDesc (vol, 0));
2003   CHECK_ERROR (!r, "virStorageVolGetXMLDesc");
2004
2005   rv = caml_copy_string (r);
2006   free (r);
2007   CAMLreturn (rv);
2008 }
2009
2010 /* Automatically generated binding for virStorageVolGetPath.
2011  * In generator.pl this function has signature "vol : string".
2012  */
2013
2014 CAMLprim value
2015 ocaml_libvirt_storage_vol_get_path (value volv)
2016 {
2017   CAMLparam1 (volv);
2018
2019   CAMLlocal1 (rv);
2020   virStorageVolPtr vol = Volume_val (volv);
2021   char *r;
2022
2023   NONBLOCKING (r = virStorageVolGetPath (vol));
2024   CHECK_ERROR (!r, "virStorageVolGetPath");
2025
2026   rv = caml_copy_string (r);
2027   free (r);
2028   CAMLreturn (rv);
2029 }
2030
2031 /* Automatically generated binding for virStorageVolGetKey.
2032  * In generator.pl this function has signature "vol : static string".
2033  */
2034
2035 CAMLprim value
2036 ocaml_libvirt_storage_vol_get_key (value volv)
2037 {
2038   CAMLparam1 (volv);
2039
2040   CAMLlocal1 (rv);
2041   virStorageVolPtr vol = Volume_val (volv);
2042   const char *r;
2043
2044   NONBLOCKING (r = virStorageVolGetKey (vol));
2045   CHECK_ERROR (!r, "virStorageVolGetKey");
2046
2047   rv = caml_copy_string (r);
2048   CAMLreturn (rv);
2049 }
2050
2051 /* Automatically generated binding for virStorageVolGetName.
2052  * In generator.pl this function has signature "vol : static string".
2053  */
2054
2055 CAMLprim value
2056 ocaml_libvirt_storage_vol_get_name (value volv)
2057 {
2058   CAMLparam1 (volv);
2059
2060   CAMLlocal1 (rv);
2061   virStorageVolPtr vol = Volume_val (volv);
2062   const char *r;
2063
2064   NONBLOCKING (r = virStorageVolGetName (vol));
2065   CHECK_ERROR (!r, "virStorageVolGetName");
2066
2067   rv = caml_copy_string (r);
2068   CAMLreturn (rv);
2069 }
2070
2071 /* Automatically generated binding for virStoragePoolLookupByVolume.
2072  * In generator.pl this function has signature "vol : pool from vol".
2073  */
2074
2075 CAMLprim value
2076 ocaml_libvirt_storage_pool_lookup_by_volume (value volv)
2077 {
2078   CAMLparam1 (volv);
2079
2080   CAMLlocal2 (rv, connv);
2081   virStorageVolPtr vol = Volume_val (volv);
2082   virStoragePoolPtr r;
2083
2084   NONBLOCKING (r = virStoragePoolLookupByVolume (vol));
2085   CHECK_ERROR (!r, "virStoragePoolLookupByVolume");
2086
2087   connv = Field (volv, 1);
2088   rv = Val_pool (r, connv);
2089
2090   CAMLreturn (rv);
2091 }
2092
2093 #include "libvirt_c_epilogue.c"
2094
2095 /* EOF */