ruby-libvirt 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9298c7723ec78226f314dc726eba72b89a2aecbb
4
+ data.tar.gz: 7c34d1dfeafb9eebb3cc4543fc131bc240ae251b
5
+ SHA512:
6
+ metadata.gz: 07c97eb6629972c30f1e001cfce9ae92e720dc96c34d4f688e560276ab61adda14c6795e5585a552e07b24581d72144522f8f2db1744545295174301553c8c24
7
+ data.tar.gz: e6d8ff0575e44d17959b9ee81d7b9c908f0cfaf3e3e83bd857f2d1b2004040dd5a23f8d04c96a644e6c6075dd61baad3700c3280694c8e8b173f88840c2d3c8e
data/NEWS CHANGED
@@ -1,3 +1,13 @@
1
+ 2013-12-09 0.5.0
2
+ * Updated Network class, implementing almost all libvirt APIs
3
+ * Updated Domain class, implementing almost all libvirt APIs
4
+ * Updated Connection class, implementing almost all libvirt APIs
5
+ * Updated DomainSnapshot class, implementing almost all libvirt APIs
6
+ * Updated NodeDevice class, implementing almost all libvirt APIs
7
+ * Updated Storage class, implementing almost all libvirt APIs
8
+ * Add constants for almost all libvirt defines
9
+ * Improved performance in the library by using alloca
10
+
1
11
  2011-07-27 0.4.0
2
12
  * Updated Domain class, implementing dom.memory_parameters=,
3
13
  dom.memory_parameters, dom.updated?, dom.migrate2, dom.migrate_to_uri2,
data/README CHANGED
@@ -27,26 +27,193 @@ toplevel of your source checkout):
27
27
 
28
28
  Notes
29
29
  -----
30
- As of June 24, 2011, the ruby-libvirt bindings support all of the libvirt
31
- APIs up to libvirt commit hash 2c5ded6e8269463d2daab3dfa0ecae1477730ee2
30
+ As of October 26, 2013, the ruby-libvirt bindings support all of the libvirt
31
+ APIs up to libvirt commit hash b695aeebd52bcbd0d260893bddd5bfe1e486e980
32
32
  with the following exceptions:
33
33
 
34
- - virConnectRef
35
- - virDomainGetConnect
36
- - virDomainRef
37
- - virDomainOpenConsole
38
- - virNetworkGetConnect
39
- - virNetworkRef
40
- - virInterfaceGetConnect
41
- - virInterfaceRef
42
- - virStoragePoolGetConnect
43
- - virStoragePoolRef
44
- - virStorageVolGetConnect
45
- - virStorageVolRef
46
- - virNodeDeviceRef
47
- - virSecretGetConnect
48
- - virSecretRef
49
- - virStreamRef
50
- - virNWFilterRef
51
- - virEventRegisterDefaultImpl
52
- - virEventRunDefaultImpl
34
+ VIR_DOMAIN_LAST
35
+ VIR_DOMAIN_NOSTATE_LAST
36
+ VIR_DOMAIN_RUNNING_LAST
37
+ VIR_DOMAIN_BLOCKED_LAST
38
+ VIR_DOMAIN_PAUSED_LAST
39
+ VIR_DOMAIN_SHUTDOWN_LAST
40
+ VIR_DOMAIN_SHUTOFF_LAST
41
+ VIR_DOMAIN_CRASHED_LAST
42
+ VIR_DOMAIN_PMSUSPENDED_LAST
43
+ VIR_DOMAIN_PMSUSPENDED_DISK_LAST
44
+ VIR_DOMAIN_CONTROL_LAST
45
+ VIR_DOMAIN_NONE
46
+ VIR_NODE_SUSPEND_TARGET_LAST
47
+ VIR_TYPED_PARAM_LAST
48
+ VIR_TYPED_PARAM_STRING_OKAY
49
+ VIR_DOMAIN_MEMORY_STAT_NR
50
+ VIR_DOMAIN_MEMORY_STAT_LAST
51
+ VIR_CRED_LAST
52
+ VIR_EXPORT_VAR
53
+ VIR_CONNECT_CLOSE_REASON_ERROR
54
+ VIR_CONNECT_CLOSE_REASON_EOF
55
+ VIR_CONNECT_CLOSE_REASON_KEEPALIVE
56
+ VIR_CONNECT_CLOSE_REASON_CLIENT
57
+ VIR_CONNECT_CLOSE_REASON_LAST
58
+ VIR_DOMAIN_NUMATUNE_MEM_STRICT
59
+ VIR_DOMAIN_NUMATUNE_MEM_PREFERRED
60
+ VIR_DOMAIN_NUMATUNE_MEM_INTERLEAVE
61
+ VIR_DOMAIN_NUMATUNE_MEM_LAST
62
+ VIR_DOMAIN_METADATA_LAST
63
+ VIR_VCPU_LAST
64
+ VIR_DOMAIN_BLOCK_JOB_TYPE_LAST
65
+ VIR_DOMAIN_DISK_ERROR_LAST
66
+ VIR_NETWORK_UPDATE_COMMAND_LAST
67
+ VIR_NETWORK_SECTION_LAST
68
+ VIR_STORAGE_POOL_STATE_LAST
69
+ VIR_STORAGE_VOL_LAST
70
+ VIR_STORAGE_VOL_WIPE_ALG_LAST
71
+ VIR_KEYCODE_SET_LAST
72
+ VIR_DOMAIN_PROCESS_SIGNAL_LAST
73
+ VIR_DOMAIN_EVENT_LAST
74
+ VIR_DOMAIN_EVENT_DEFINED_LAST
75
+ VIR_DOMAIN_EVENT_UNDEFINED_LAST
76
+ VIR_DOMAIN_EVENT_STARTED_LAST
77
+ VIR_DOMAIN_EVENT_SUSPENDED_LAST
78
+ VIR_DOMAIN_EVENT_RESUMED_LAST
79
+ VIR_DOMAIN_EVENT_STOPPED_LAST
80
+ VIR_DOMAIN_EVENT_SHUTDOWN_LAST
81
+ VIR_DOMAIN_EVENT_PMSUSPENDED_LAST
82
+ VIR_DOMAIN_EVENT_CRASHED_LAST
83
+ VIR_SECRET_USAGE_TYPE_LAST
84
+ VIR_CPU_COMPARE_LAST
85
+ VIR_DOMAIN_JOB_LAST
86
+ VIR_DOMAIN_EVENT_WATCHDOG_LAST
87
+ VIR_DOMAIN_EVENT_IO_ERROR_LAST
88
+ VIR_DOMAIN_EVENT_GRAPHICS_LAST
89
+ VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST
90
+ VIR_DOMAIN_BLOCK_JOB_LAST
91
+ VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START
92
+ VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START
93
+ VIR_DOMAIN_EVENT_DISK_CHANGE_LAST
94
+ VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN
95
+ VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE
96
+ VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST
97
+ VIR_DOMAIN_EVENT_ID_BLOCK_JOB
98
+ VIR_DOMAIN_EVENT_ID_DISK_CHANGE
99
+ VIR_DOMAIN_EVENT_ID_TRAY_CHANGE
100
+ VIR_DOMAIN_EVENT_ID_PMWAKEUP
101
+ VIR_DOMAIN_EVENT_ID_PMSUSPEND
102
+ VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE
103
+ VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK
104
+ VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED
105
+ VIR_DOMAIN_EVENT_ID_LAST
106
+ VIR_DOMAIN_BLKIO_PARAM_INT
107
+ VIR_DOMAIN_BLKIO_PARAM_UINT
108
+ VIR_DOMAIN_BLKIO_PARAM_LLONG
109
+ VIR_DOMAIN_BLKIO_PARAM_ULLONG
110
+ VIR_DOMAIN_BLKIO_PARAM_DOUBLE
111
+ VIR_DOMAIN_BLKIO_PARAM_BOOLEAN
112
+ VIR_DOMAIN_MEMORY_PARAM_INT
113
+ VIR_DOMAIN_MEMORY_PARAM_UINT
114
+ VIR_DOMAIN_MEMORY_PARAM_LLONG
115
+ VIR_DOMAIN_MEMORY_PARAM_ULLONG
116
+ VIR_DOMAIN_MEMORY_PARAM_DOUBLE
117
+ VIR_DOMAIN_MEMORY_PARAM_BOOLEAN
118
+ VIR_DEPRECATED
119
+ VIR_DEPRECATED
120
+ VIR_EXPORT_VAR
121
+ VIR_EXPORT_VAR
122
+ VIR_EXPORT_VAR
123
+ VIR_EXPORT_VAR
124
+ VIR_SECURITY_LABEL_BUFLEN
125
+ VIR_SECURITY_MODEL_BUFLEN
126
+ VIR_SECURITY_DOI_BUFLEN
127
+ VIR_NODE_CPU_STATS_FIELD_LENGTH
128
+ VIR_NODE_CPU_STATS_KERNEL
129
+ VIR_NODE_CPU_STATS_USER
130
+ VIR_NODE_CPU_STATS_IDLE
131
+ VIR_NODE_CPU_STATS_IOWAIT
132
+ VIR_NODE_CPU_STATS_UTILIZATION
133
+ VIR_NODE_MEMORY_STATS_FIELD_LENGTH
134
+ VIR_NODE_MEMORY_STATS_TOTAL
135
+ VIR_NODE_MEMORY_STATS_FREE
136
+ VIR_NODE_MEMORY_STATS_BUFFERS
137
+ VIR_NODE_MEMORY_STATS_CACHED
138
+ VIR_DOMAIN_BLOCK_STATS_FIELD_LENGTH
139
+ VIR_DOMAIN_BLOCK_STATS_READ_BYTES
140
+ VIR_DOMAIN_BLOCK_STATS_READ_REQ
141
+ VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES
142
+ VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES
143
+ VIR_DOMAIN_BLOCK_STATS_WRITE_REQ
144
+ VIR_DOMAIN_BLOCK_STATS_WRITE_TOTAL_TIMES
145
+ VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ
146
+ VIR_DOMAIN_BLOCK_STATS_FLUSH_TOTAL_TIMES
147
+ VIR_DOMAIN_BLOCK_STATS_ERRS
148
+ VIR_UUID_BUFLEN
149
+ LIBVIR_VERSION_NUMBER
150
+ VIR_DOMAIN_CPU_STATS_CPUTIME
151
+ VIR_DOMAIN_CPU_STATS_USERTIME
152
+ VIR_DOMAIN_CPU_STATS_SYSTEMTIME
153
+ VIR_DOMAIN_CPU_STATS_VCPUTIME
154
+ VIR_UNUSE_CPU
155
+ VIR_COPY_CPUMAP
156
+ VIR_GET_CPUMAP
157
+ VIR_DOMAIN_SEND_KEY_MAX_KEYS
158
+ VIR_DOMAIN_JOB_TIME_ELAPSED
159
+ VIR_DOMAIN_JOB_TIME_REMAINING
160
+ VIR_DOMAIN_JOB_DOWNTIME
161
+ VIR_DOMAIN_JOB_DATA_TOTAL
162
+ VIR_DOMAIN_JOB_DATA_PROCESSED
163
+ VIR_DOMAIN_JOB_DATA_REMAINING
164
+ VIR_DOMAIN_JOB_MEMORY_TOTAL
165
+ VIR_DOMAIN_JOB_MEMORY_PROCESSED
166
+ VIR_DOMAIN_JOB_MEMORY_REMAINING
167
+ VIR_DOMAIN_JOB_MEMORY_CONSTANT
168
+ VIR_DOMAIN_JOB_MEMORY_NORMAL
169
+ VIR_DOMAIN_JOB_MEMORY_NORMAL_BYTES
170
+ VIR_DOMAIN_JOB_DISK_TOTAL
171
+ VIR_DOMAIN_JOB_DISK_PROCESSED
172
+ VIR_DOMAIN_JOB_DISK_REMAINING
173
+ VIR_DOMAIN_JOB_COMPRESSION_CACHE
174
+ VIR_DOMAIN_JOB_COMPRESSION_BYTES
175
+ VIR_DOMAIN_JOB_COMPRESSION_PAGES
176
+ VIR_DOMAIN_JOB_COMPRESSION_CACHE_MISSES
177
+ VIR_DOMAIN_JOB_COMPRESSION_OVERFLOW
178
+ VIR_DOMAIN_SCHED_FIELD_LENGTH
179
+ VIR_DOMAIN_BLKIO_FIELD_LENGTH
180
+ VIR_DOMAIN_MEMORY_FIELD_LENGTH
181
+ virTypedParamsGet
182
+ virTypedParamsGetInt
183
+ virTypedParamsGetUInt
184
+ virTypedParamsGetLLong
185
+ virTypedParamsGetULLong
186
+ virTypedParamsGetDouble
187
+ virTypedParamsGetBoolean
188
+ virTypedParamsGetString
189
+ virTypedParamsAddInt
190
+ virTypedParamsAddUInt
191
+ virTypedParamsAddLLong
192
+ virTypedParamsAddULLong
193
+ virTypedParamsAddDouble
194
+ virTypedParamsAddBoolean
195
+ virTypedParamsAddString
196
+ virTypedParamsAddFromString
197
+ virTypedParamsClear
198
+ virConnectRef
199
+ virConnectRegisterCloseCallback
200
+ virConnectUnregisterCloseCallback
201
+ virDomainGetConnect
202
+ virDomainRef
203
+ virDomainRestoreFlags
204
+ virNetworkGetConnect
205
+ virNetworkRef
206
+ virInterfaceGetConnect
207
+ virInterfaceRef
208
+ virStoragePoolGetConnect
209
+ virStorageVolGetConnect
210
+ virStorageVolRef
211
+ virNodeDeviceRef
212
+ virSecretGetConnect
213
+ virSecretRef
214
+ virStreamRef
215
+ virDomainSnapshotGetDomain
216
+ virDomainSnapshotGetConnect
217
+ virDomainSnapshotRef
218
+ virNWFilterRef
219
+ VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
  # Rakefile: build ruby libvirt bindings
3
3
  #
4
4
  # Copyright (C) 2007,2010 Red Hat, Inc.
5
+ # Copyright (C) 2013 Chris Lalancette <clalancette@gmail.com>
5
6
  #
6
7
  # Distributed under the GNU Lesser General Public License v2.1 or later.
7
8
  # See COPYING for details
@@ -10,13 +11,13 @@
10
11
 
11
12
  # Rakefile for ruby-rpm -*- ruby -*-
12
13
  require 'rake/clean'
13
- require 'rake/rdoctask'
14
+ require 'rdoc/task'
14
15
  require 'rake/testtask'
15
- require 'rake/gempackagetask'
16
+ require 'rubygems/package_task'
16
17
  require 'rbconfig'
17
18
 
18
19
  PKG_NAME='ruby-libvirt'
19
- PKG_VERSION='0.4.0'
20
+ PKG_VERSION='0.5.0'
20
21
 
21
22
  EXT_CONF='ext/libvirt/extconf.rb'
22
23
  MAKEFILE="ext/libvirt/Makefile"
@@ -29,12 +30,14 @@ LIBVIRT_SRC << MAKEFILE
29
30
  # Additional files for clean/clobber
30
31
  #
31
32
 
32
- CLEAN.include [ "ext/**/*.o", LIBVIRT_MODULE,
33
- "ext/**/depend" ]
33
+ CLEAN.include [ "ext/**/*.o", LIBVIRT_MODULE, "ext/**/depend", "ext/**/*.gcda",
34
+ "ext/**/*.gcno", "ext/**/*.gcov" ]
34
35
 
35
36
  CLOBBER.include [ "config.save", "ext/**/mkmf.log", "ext/**/extconf.h",
36
37
  MAKEFILE ]
37
38
 
39
+ task :default => :build
40
+
38
41
  #
39
42
  # Build locally
40
43
  #
@@ -72,7 +75,7 @@ Rake::TestTask.new(:test) do |t|
72
75
  'tests/test_interface.rb', 'tests/test_network.rb',
73
76
  'tests/test_nodedevice.rb', 'tests/test_nwfilter.rb',
74
77
  'tests/test_open.rb', 'tests/test_secret.rb',
75
- 'tests/test_storage.rb' ]
78
+ 'tests/test_storage.rb', 'tests/test_stream.rb' ]
76
79
  t.libs = [ 'lib', 'ext/libvirt' ]
77
80
  end
78
81
  task :test => :build
@@ -139,9 +142,10 @@ SPEC = Gem::Specification.new do |s|
139
142
  s.author = "David Lutterkort, Chris Lalancette"
140
143
  s.rubyforge_project = "None"
141
144
  s.description = "Ruby bindings for libvirt."
145
+ s.license = "LGPLv2"
142
146
  end
143
147
 
144
- Rake::GemPackageTask.new(SPEC) do |pkg|
148
+ Gem::PackageTask.new(SPEC) do |pkg|
145
149
  pkg.need_tar = true
146
150
  pkg.need_zip = true
147
151
  end
@@ -2,6 +2,7 @@
2
2
  * libvirt.c: Ruby bindings for libvirt
3
3
  *
4
4
  * Copyright (C) 2007,2010 Red Hat Inc.
5
+ * Copyright (C) 2013 Chris Lalancette <clalancette@gmail.com>
5
6
  *
6
7
  * This library is free software; you can redistribute it and/or
7
8
  * modify it under the terms of the GNU Lesser General Public
@@ -23,6 +24,9 @@
23
24
  #include <ruby.h>
24
25
  #include <libvirt/libvirt.h>
25
26
  #include <libvirt/virterror.h>
27
+ #if HAVE_VIRDOMAINLXCENTERSECURITYLABEL
28
+ #include <libvirt/libvirt-lxc.h>
29
+ #endif
26
30
  #include "extconf.h"
27
31
  #include "common.h"
28
32
  #include "storage.h"
@@ -47,97 +51,94 @@ VALUE e_Error;
47
51
  VALUE e_NoSupportError;
48
52
 
49
53
  /* custom error function to suppress libvirt printing to stderr */
50
- static void rubyLibvirtErrorFunc(void *userdata, virErrorPtr err){
54
+ static void rubyLibvirtErrorFunc(void *userdata, virErrorPtr err)
55
+ {
51
56
  }
52
57
 
53
58
  /*
54
59
  * call-seq:
55
60
  * Libvirt::version(type=nil) -> [ libvirt_version, type_version ]
56
61
  *
57
- * Call
58
- * +virGetVersion+[http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion]
62
+ * Call virGetVersion[http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion]
59
63
  * to get the version of libvirt and of the hypervisor TYPE.
60
64
  */
61
- static VALUE libvirt_version(int argc, VALUE *argv, VALUE m) {
62
- unsigned long libVer;
63
- VALUE type;
64
- unsigned long typeVer;
65
+ static VALUE libvirt_version(int argc, VALUE *argv, VALUE m)
66
+ {
67
+ unsigned long libVer, typeVer;
68
+ VALUE type, result, rargv[2];
65
69
  int r;
66
- VALUE result, rargv[2];
67
70
 
68
71
  rb_scan_args(argc, argv, "01", &type);
69
72
 
70
- r = virGetVersion(&libVer, get_string_or_nil(type), &typeVer);
71
- _E(r < 0, create_error(rb_eArgError, "virGetVersion", NULL));
73
+ r = virGetVersion(&libVer, ruby_libvirt_get_cstring_or_null(type),
74
+ &typeVer);
75
+ ruby_libvirt_raise_error_if(r < 0, rb_eArgError, "virGetVersion", NULL);
72
76
 
73
77
  result = rb_ary_new2(2);
74
78
  rargv[0] = rb_str_new2("libvirt");
75
79
  rargv[1] = ULONG2NUM(libVer);
76
- rb_ary_push(result, rb_class_new_instance(2, rargv, c_libvirt_version));
80
+ rb_ary_store(result, 0, rb_class_new_instance(2, rargv, c_libvirt_version));
77
81
  rargv[0] = type;
78
82
  rargv[1] = ULONG2NUM(typeVer);
79
- rb_ary_push(result, rb_class_new_instance(2, rargv, c_libvirt_version));
83
+ rb_ary_store(result, 1, rb_class_new_instance(2, rargv, c_libvirt_version));
80
84
  return result;
81
85
  }
82
86
 
83
- static VALUE internal_open(int argc, VALUE *argv, VALUE m, int readonly)
87
+ /*
88
+ * call-seq:
89
+ * Libvirt::open(uri=nil) -> Libvirt::Connect
90
+ *
91
+ * Call virConnectOpen[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpen]
92
+ * to open a connection to a URL.
93
+ */
94
+ static VALUE libvirt_open(int argc, VALUE *argv, VALUE m)
84
95
  {
85
96
  VALUE uri;
86
- char *uri_c;
87
97
  virConnectPtr conn;
88
98
 
89
99
  rb_scan_args(argc, argv, "01", &uri);
90
100
 
91
- uri_c = get_string_or_nil(uri);
101
+ conn = virConnectOpen(ruby_libvirt_get_cstring_or_null(uri));
102
+ ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError,
103
+ "virConnectOpen", NULL);
92
104
 
93
- if (readonly)
94
- conn = virConnectOpenReadOnly(uri_c);
95
- else
96
- conn = virConnectOpen(uri_c);
97
-
98
- _E(conn == NULL, create_error(e_ConnectionError,
99
- readonly ? "virConnectOpenReadOnly" : "virConnectOpen",
100
- NULL));
101
-
102
- return connect_new(conn);
103
- }
104
-
105
- /*
106
- * call-seq:
107
- * Libvirt::open(uri=nil) -> Libvirt::Connect
108
- *
109
- * Call
110
- * +virConnectOpen+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpen]
111
- * to open a connection to a URL.
112
- */
113
- static VALUE libvirt_open(int argc, VALUE *argv, VALUE m) {
114
- return internal_open(argc, argv, m, 0);
105
+ return ruby_libvirt_connect_new(conn);
115
106
  }
116
107
 
117
108
  /*
118
109
  * call-seq:
119
110
  * Libvirt::open_read_only(uri=nil) -> Libvirt::Connect
120
111
  *
121
- * Call
122
- * +virConnectOpenReadOnly+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpenReadOnly]
112
+ * Call virConnectOpenReadOnly[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpenReadOnly]
123
113
  * to open a read-only connection to a URL.
124
114
  */
125
- static VALUE libvirt_open_read_only(int argc, VALUE *argv, VALUE m) {
126
- return internal_open(argc, argv, m, 1);
115
+ static VALUE libvirt_open_read_only(int argc, VALUE *argv, VALUE m)
116
+ {
117
+ VALUE uri;
118
+ virConnectPtr conn;
119
+
120
+ rb_scan_args(argc, argv, "01", &uri);
121
+
122
+ conn = virConnectOpenReadOnly(ruby_libvirt_get_cstring_or_null(uri));
123
+
124
+ ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError,
125
+ "virConnectOpenReadOnly", NULL);
126
+
127
+ return ruby_libvirt_connect_new(conn);
127
128
  }
128
129
 
129
130
  #if HAVE_VIRCONNECTOPENAUTH
130
131
  static int libvirt_auth_callback_wrapper(virConnectCredentialPtr cred,
131
- unsigned int ncred, void *cbdata) {
132
- VALUE userdata;
133
- VALUE newcred;
132
+ unsigned int ncred, void *cbdata)
133
+ {
134
+ VALUE userdata, newcred, result;
134
135
  int i;
135
- VALUE result;
136
136
 
137
137
  userdata = (VALUE)cbdata;
138
138
 
139
- if (!rb_block_given_p())
139
+ if (!rb_block_given_p()) {
140
140
  rb_raise(rb_eRuntimeError, "No block given, this should never happen!\n");
141
+ }
141
142
 
142
143
  for (i = 0; i < ncred; i++) {
143
144
  newcred = rb_hash_new();
@@ -145,16 +146,20 @@ static int libvirt_auth_callback_wrapper(virConnectCredentialPtr cred,
145
146
  rb_hash_aset(newcred, rb_str_new2("type"), INT2NUM(cred[i].type));
146
147
  rb_hash_aset(newcred, rb_str_new2("prompt"),
147
148
  rb_str_new2(cred[i].prompt));
148
- if (cred[i].challenge)
149
+ if (cred[i].challenge) {
149
150
  rb_hash_aset(newcred, rb_str_new2("challenge"),
150
151
  rb_str_new2(cred[i].challenge));
151
- else
152
+ }
153
+ else {
152
154
  rb_hash_aset(newcred, rb_str_new2("challenge"), Qnil);
153
- if (cred[i].defresult)
155
+ }
156
+ if (cred[i].defresult) {
154
157
  rb_hash_aset(newcred, rb_str_new2("defresult"),
155
158
  rb_str_new2(cred[i].defresult));
156
- else
159
+ }
160
+ else {
157
161
  rb_hash_aset(newcred, rb_str_new2("defresult"), Qnil);
162
+ }
158
163
  rb_hash_aset(newcred, rb_str_new2("result"), Qnil);
159
164
  rb_hash_aset(newcred, rb_str_new2("userdata"), userdata);
160
165
 
@@ -172,29 +177,11 @@ static int libvirt_auth_callback_wrapper(virConnectCredentialPtr cred,
172
177
  return 0;
173
178
  }
174
179
 
175
-
176
- struct wrap_callout {
177
- char *uri;
178
- virConnectAuthPtr auth;
179
- unsigned int flags;
180
- };
181
-
182
- static VALUE rb_open_auth_wrap(VALUE arg) {
183
- struct wrap_callout *e = (struct wrap_callout *)arg;
184
-
185
- return (VALUE)virConnectOpenAuth(e->uri, e->auth, e->flags);
186
- }
187
-
188
- static VALUE rb_num2int_wrap(VALUE arg) {
189
- return NUM2INT(arg);
190
- }
191
-
192
180
  /*
193
181
  * call-seq:
194
182
  * Libvirt::open_auth(uri=nil, credlist=nil, userdata=nil, flags=0) {|...| authentication block} -> Libvirt::Connect
195
183
  *
196
- * Call
197
- * +virConnectOpenAuth+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpenAuth]
184
+ * Call virConnectOpenAuth[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpenAuth]
198
185
  * to open a connection to a libvirt URI, with a possible authentication block.
199
186
  * If an authentication block is desired, then credlist should be an array that
200
187
  * specifies which credentials the authentication block is willing to support;
@@ -224,66 +211,35 @@ static VALUE rb_num2int_wrap(VALUE arg) {
224
211
  * The authentication block should return the result of collecting the
225
212
  * information; these results will then be sent to libvirt for authentication.
226
213
  */
227
- static VALUE libvirt_open_auth(int argc, VALUE *argv, VALUE m) {
214
+ static VALUE libvirt_open_auth(int argc, VALUE *argv, VALUE m)
215
+ {
228
216
  virConnectAuthPtr auth;
229
- VALUE uri;
230
- VALUE credlist;
231
- VALUE userdata;
232
- VALUE flags_val;
233
- char *uri_c;
234
- virConnectPtr conn = NULL;
235
- unsigned int flags;
236
- int auth_alloc;
217
+ VALUE uri, credlist, userdata, flags, tmp;
218
+ virConnectPtr conn;
237
219
  int i;
238
- VALUE tmp;
239
- int exception = 0;
240
- struct rb_ary_entry_arg args;
241
- struct wrap_callout callargs;
242
220
 
243
- rb_scan_args(argc, argv, "04", &uri, &credlist, &userdata, &flags_val);
244
-
245
- /* handle the optional URI */
246
- uri_c = get_string_or_nil(uri);
247
-
248
- /* handle the optional flags */
249
- if (NIL_P(flags_val))
250
- flags = 0;
251
- else
252
- flags = NUM2UINT(flags_val);
221
+ rb_scan_args(argc, argv, "04", &uri, &credlist, &userdata, &flags);
253
222
 
254
223
  if (rb_block_given_p()) {
255
- auth = ALLOC(virConnectAuth);
256
- auth_alloc = 1;
224
+ auth = alloca(sizeof(virConnectAuth));
257
225
 
258
- if (TYPE(credlist) == T_NIL)
226
+ if (TYPE(credlist) == T_NIL) {
259
227
  auth->ncredtype = 0;
260
- else if (TYPE(credlist) == T_ARRAY)
228
+ }
229
+ else if (TYPE(credlist) == T_ARRAY) {
261
230
  auth->ncredtype = RARRAY_LEN(credlist);
262
- else
263
- rb_raise(rb_eTypeError, "wrong argument type (expected Array or nil)");
231
+ }
232
+ else {
233
+ rb_raise(rb_eTypeError,
234
+ "wrong argument type (expected Array or nil)");
235
+ }
264
236
  auth->credtype = NULL;
265
237
  if (auth->ncredtype > 0) {
266
- /* we don't use ALLOC_N here because that can throw an exception,
267
- * and leak the auth pointer. Instead we use normal malloc
268
- * (which has a slightly higher chance of returning NULL), and
269
- * then properly cleanup if it fails
270
- */
271
- auth->credtype = malloc(sizeof(int) * auth->ncredtype);
272
- if (auth->credtype == NULL) {
273
- xfree(auth);
274
- rb_memerror();
275
- }
238
+ auth->credtype = alloca(sizeof(int) * auth->ncredtype);
239
+
276
240
  for (i = 0; i < auth->ncredtype; i++) {
277
- args.arr = credlist;
278
- args.elem = i;
279
- tmp = rb_protect(rb_ary_entry_wrap, (VALUE)&args, &exception);
280
- if (exception)
281
- goto do_cleanup;
282
-
283
- auth->credtype[i] = rb_protect(rb_num2int_wrap, tmp,
284
- &exception);
285
- if (exception)
286
- goto do_cleanup;
241
+ tmp = rb_ary_entry(credlist, i);
242
+ auth->credtype[i] = NUM2INT(tmp);
287
243
  }
288
244
  }
289
245
 
@@ -292,29 +248,15 @@ static VALUE libvirt_open_auth(int argc, VALUE *argv, VALUE m) {
292
248
  }
293
249
  else {
294
250
  auth = virConnectAuthPtrDefault;
295
- auth_alloc = 0;
296
- }
297
-
298
- callargs.uri = uri_c;
299
- callargs.auth = auth;
300
- callargs.flags = flags;
301
-
302
- conn = (virConnectPtr)rb_protect(rb_open_auth_wrap, (VALUE)&callargs,
303
- &exception);
304
-
305
- do_cleanup:
306
- if (auth_alloc) {
307
- free(auth->credtype);
308
- xfree(auth);
309
251
  }
310
252
 
311
- if (exception)
312
- rb_jump_tag(exception);
253
+ conn = virConnectOpenAuth(ruby_libvirt_get_cstring_or_null(uri), auth,
254
+ ruby_libvirt_value_to_uint(flags));
313
255
 
314
- _E(conn == NULL, create_error(e_ConnectionError, "virConnectOpenAuth",
315
- NULL));
256
+ ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError,
257
+ "virConnectOpenAuth", NULL);
316
258
 
317
- return connect_new(conn);
259
+ return ruby_libvirt_connect_new(conn);
318
260
  }
319
261
  #endif
320
262
 
@@ -337,36 +279,23 @@ static VALUE add_timeout, update_timeout, remove_timeout;
337
279
  *
338
280
  * Libvirt::event_invoke_handle_callback takes 4 arguments:
339
281
  *
340
- * handle
341
- * an application specific handle ID. This can be any integer, but
342
- * must be unique from all other libvirt handles in the application.
343
- * fd
344
- * the file descriptor of interest. This was given to the application
345
- * as a callback to add_handle of Libvirt::event_register_impl
346
- * events
347
- * the events that have occured on the fd. Note that the events are
348
- * libvirt specific, and are some combination of
349
- * Libvirt::EVENT_HANDLE_READABLE, Libvirt::EVENT_HANDLE_WRITABLE,
350
- * Libvirt::EVENT_HANDLE_ERROR, Libvirt::EVENT_HANDLE_HANGUP. To
351
- * notify libvirt of more than one event at a time, these values should
352
- * be logically OR'ed together.
353
- * opaque
354
- * the opaque data passed from libvirt during the
355
- * Libvirt::event_register_impl add_handle callback. To ensure proper
356
- * operation this data must be passed through to
357
- * event_invoke_handle_callback without modification.
282
+ * handle - an application specific handle ID. This can be any integer, but must be unique from all other libvirt handles in the application.
283
+ *
284
+ * fd - the file descriptor of interest. This was given to the application as a callback to add_handle of Libvirt::event_register_impl
285
+ *
286
+ * events - the events that have occured on the fd. Note that the events are libvirt specific, and are some combination of Libvirt::EVENT_HANDLE_READABLE, Libvirt::EVENT_HANDLE_WRITABLE, Libvirt::EVENT_HANDLE_ERROR, Libvirt::EVENT_HANDLE_HANGUP. To notify libvirt of more than one event at a time, these values should be logically OR'ed together.
287
+ *
288
+ * opaque - the opaque data passed from libvirt during the Libvirt::event_register_impl add_handle callback. To ensure proper operation this data must be passed through to event_invoke_handle_callback without modification.
358
289
  */
359
290
  static VALUE libvirt_event_invoke_handle_callback(VALUE m, VALUE handle,
360
291
  VALUE fd, VALUE events,
361
- VALUE opaque) {
292
+ VALUE opaque)
293
+ {
362
294
  virEventHandleCallback cb;
363
295
  void *op;
364
- VALUE libvirt_cb;
365
- VALUE libvirt_opaque;
296
+ VALUE libvirt_cb, libvirt_opaque;
366
297
 
367
- if (TYPE(opaque) != T_HASH)
368
- rb_raise(rb_eTypeError,
369
- "wrong event callback argument type (expected Hash)");
298
+ Check_Type(opaque, T_HASH);
370
299
 
371
300
  libvirt_cb = rb_hash_aref(opaque, rb_str_new2("libvirt_cb"));
372
301
 
@@ -399,25 +328,18 @@ static VALUE libvirt_event_invoke_handle_callback(VALUE m, VALUE handle,
399
328
  *
400
329
  * Libvirt::event_invoke_timeout_callback takes 2 arguments:
401
330
  *
402
- * handle
403
- * an application specific timer ID. This can be any integer, but
404
- * must be unique from all other libvirt timers in the application.
405
- * opaque
406
- * the opaque data passed from libvirt during the
407
- * Libvirt::event_register_impl add_handle callback. To ensure proper
408
- * operation this data must be passed through to
409
- * event_invoke_handle_callback without modification.
331
+ * handle - an application specific timer ID. This can be any integer, but must be unique from all other libvirt timers in the application.
332
+ *
333
+ * opaque - the opaque data passed from libvirt during the Libvirt::event_register_impl add_handle callback. To ensure proper operation this data must be passed through to event_invoke_handle_callback without modification.
410
334
  */
411
335
  static VALUE libvirt_event_invoke_timeout_callback(VALUE m, VALUE timer,
412
- VALUE opaque) {
336
+ VALUE opaque)
337
+ {
413
338
  virEventTimeoutCallback cb;
414
339
  void *op;
415
- VALUE libvirt_cb;
416
- VALUE libvirt_opaque;
340
+ VALUE libvirt_cb, libvirt_opaque;
417
341
 
418
- if (TYPE(opaque) != T_HASH)
419
- rb_raise(rb_eTypeError,
420
- "wrong event callback argument type (expected Hash)");
342
+ Check_Type(opaque, T_HASH);
421
343
 
422
344
  libvirt_cb = rb_hash_aref(opaque, rb_str_new2("libvirt_cb"));
423
345
 
@@ -438,9 +360,9 @@ static VALUE libvirt_event_invoke_timeout_callback(VALUE m, VALUE timer,
438
360
 
439
361
  static int internal_add_handle_func(int fd, int events,
440
362
  virEventHandleCallback cb, void *opaque,
441
- virFreeCallback ff) {
442
- VALUE rubyargs;
443
- VALUE res;
363
+ virFreeCallback ff)
364
+ {
365
+ VALUE rubyargs, res;
444
366
 
445
367
  rubyargs = rb_hash_new();
446
368
  rb_hash_aset(rubyargs, rb_str_new2("libvirt_cb"),
@@ -451,56 +373,67 @@ static int internal_add_handle_func(int fd, int events,
451
373
  Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, ff));
452
374
 
453
375
  /* call out to the ruby object */
454
- if (strcmp(rb_obj_classname(add_handle), "Symbol") == 0)
376
+ if (strcmp(rb_obj_classname(add_handle), "Symbol") == 0) {
455
377
  res = rb_funcall(rb_class_of(add_handle), rb_to_id(add_handle), 3,
456
378
  INT2NUM(fd), INT2NUM(events), rubyargs);
457
- else if (strcmp(rb_obj_classname(add_handle), "Proc") == 0)
379
+ }
380
+ else if (strcmp(rb_obj_classname(add_handle), "Proc") == 0) {
458
381
  res = rb_funcall(add_handle, rb_intern("call"), 3, INT2NUM(fd),
459
382
  INT2NUM(events), rubyargs);
460
- else
383
+ }
384
+ else {
461
385
  rb_raise(rb_eTypeError,
462
386
  "wrong add handle callback argument type (expected Symbol or Proc)");
387
+ }
463
388
 
464
- if (TYPE(res) != T_FIXNUM)
389
+ if (TYPE(res) != T_FIXNUM) {
465
390
  rb_raise(rb_eTypeError,
466
391
  "expected integer return from add_handle callback");
392
+ }
467
393
 
468
394
  return NUM2INT(res);
469
395
  }
470
396
 
471
- static void internal_update_handle_func(int watch, int event) {
397
+ static void internal_update_handle_func(int watch, int event)
398
+ {
472
399
  /* call out to the ruby object */
473
- if (strcmp(rb_obj_classname(update_handle), "Symbol") == 0)
400
+ if (strcmp(rb_obj_classname(update_handle), "Symbol") == 0) {
474
401
  rb_funcall(rb_class_of(update_handle), rb_to_id(update_handle), 2,
475
402
  INT2NUM(watch), INT2NUM(event));
476
- else if (strcmp(rb_obj_classname(update_handle), "Proc") == 0)
403
+ }
404
+ else if (strcmp(rb_obj_classname(update_handle), "Proc") == 0) {
477
405
  rb_funcall(update_handle, rb_intern("call"), 2, INT2NUM(watch),
478
406
  INT2NUM(event));
479
- else
407
+ }
408
+ else {
480
409
  rb_raise(rb_eTypeError,
481
410
  "wrong update handle callback argument type (expected Symbol or Proc)");
411
+ }
482
412
  }
483
413
 
484
- static int internal_remove_handle_func(int watch) {
485
- VALUE res;
414
+ static int internal_remove_handle_func(int watch)
415
+ {
416
+ VALUE res, libvirt_opaque, ff;
486
417
  virFreeCallback ff_cb;
487
418
  void *op;
488
- VALUE libvirt_opaque;
489
- VALUE ff;
490
419
 
491
420
  /* call out to the ruby object */
492
- if (strcmp(rb_obj_classname(remove_handle), "Symbol") == 0)
421
+ if (strcmp(rb_obj_classname(remove_handle), "Symbol") == 0) {
493
422
  res = rb_funcall(rb_class_of(remove_handle), rb_to_id(remove_handle),
494
423
  1, INT2NUM(watch));
495
- else if (strcmp(rb_obj_classname(remove_handle), "Proc") == 0)
424
+ }
425
+ else if (strcmp(rb_obj_classname(remove_handle), "Proc") == 0) {
496
426
  res = rb_funcall(remove_handle, rb_intern("call"), 1, INT2NUM(watch));
497
- else
427
+ }
428
+ else {
498
429
  rb_raise(rb_eTypeError,
499
430
  "wrong remove handle callback argument type (expected Symbol or Proc)");
431
+ }
500
432
 
501
- if (TYPE(res) != T_HASH)
433
+ if (TYPE(res) != T_HASH) {
502
434
  rb_raise(rb_eTypeError,
503
435
  "expected opaque hash returned from remove_handle callback");
436
+ }
504
437
 
505
438
  ff = rb_hash_aref(res, rb_str_new2("free_func"));
506
439
  if (!NIL_P(ff)) {
@@ -521,9 +454,9 @@ static int internal_remove_handle_func(int watch) {
521
454
  }
522
455
 
523
456
  static int internal_add_timeout_func(int interval, virEventTimeoutCallback cb,
524
- void *opaque, virFreeCallback ff) {
525
- VALUE rubyargs;
526
- VALUE res;
457
+ void *opaque, virFreeCallback ff)
458
+ {
459
+ VALUE rubyargs, res;
527
460
 
528
461
  rubyargs = rb_hash_new();
529
462
 
@@ -536,56 +469,67 @@ static int internal_add_timeout_func(int interval, virEventTimeoutCallback cb,
536
469
  Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL, ff));
537
470
 
538
471
  /* call out to the ruby object */
539
- if (strcmp(rb_obj_classname(add_timeout), "Symbol") == 0)
472
+ if (strcmp(rb_obj_classname(add_timeout), "Symbol") == 0) {
540
473
  res = rb_funcall(rb_class_of(add_timeout), rb_to_id(add_timeout), 2,
541
474
  INT2NUM(interval), rubyargs);
542
- else if (strcmp(rb_obj_classname(add_timeout), "Proc") == 0)
475
+ }
476
+ else if (strcmp(rb_obj_classname(add_timeout), "Proc") == 0) {
543
477
  res = rb_funcall(add_timeout, rb_intern("call"), 2, INT2NUM(interval),
544
478
  rubyargs);
545
- else
479
+ }
480
+ else {
546
481
  rb_raise(rb_eTypeError,
547
482
  "wrong add timeout callback argument type (expected Symbol or Proc)");
483
+ }
548
484
 
549
- if (TYPE(res) != T_FIXNUM)
485
+ if (TYPE(res) != T_FIXNUM) {
550
486
  rb_raise(rb_eTypeError,
551
487
  "expected integer return from add_timeout callback");
488
+ }
552
489
 
553
490
  return NUM2INT(res);
554
491
  }
555
492
 
556
- static void internal_update_timeout_func(int timer, int timeout) {
493
+ static void internal_update_timeout_func(int timer, int timeout)
494
+ {
557
495
  /* call out to the ruby object */
558
- if (strcmp(rb_obj_classname(update_timeout), "Symbol") == 0)
496
+ if (strcmp(rb_obj_classname(update_timeout), "Symbol") == 0) {
559
497
  rb_funcall(rb_class_of(update_timeout), rb_to_id(update_timeout), 2,
560
498
  INT2NUM(timer), INT2NUM(timeout));
561
- else if (strcmp(rb_obj_classname(update_timeout), "Proc") == 0)
499
+ }
500
+ else if (strcmp(rb_obj_classname(update_timeout), "Proc") == 0) {
562
501
  rb_funcall(update_timeout, rb_intern("call"), 2, INT2NUM(timer),
563
502
  INT2NUM(timeout));
564
- else
503
+ }
504
+ else {
565
505
  rb_raise(rb_eTypeError,
566
506
  "wrong update timeout callback argument type (expected Symbol or Proc)");
507
+ }
567
508
  }
568
509
 
569
- static int internal_remove_timeout_func(int timer) {
570
- VALUE res;
510
+ static int internal_remove_timeout_func(int timer)
511
+ {
512
+ VALUE res, libvirt_opaque, ff;
571
513
  virFreeCallback ff_cb;
572
514
  void *op;
573
- VALUE libvirt_opaque;
574
- VALUE ff;
575
515
 
576
516
  /* call out to the ruby object */
577
- if (strcmp(rb_obj_classname(remove_timeout), "Symbol") == 0)
517
+ if (strcmp(rb_obj_classname(remove_timeout), "Symbol") == 0) {
578
518
  res = rb_funcall(rb_class_of(remove_timeout), rb_to_id(remove_timeout),
579
519
  1, INT2NUM(timer));
580
- else if (strcmp(rb_obj_classname(remove_timeout), "Proc") == 0)
520
+ }
521
+ else if (strcmp(rb_obj_classname(remove_timeout), "Proc") == 0) {
581
522
  res = rb_funcall(remove_timeout, rb_intern("call"), 1, INT2NUM(timer));
582
- else
523
+ }
524
+ else {
583
525
  rb_raise(rb_eTypeError,
584
526
  "wrong remove timeout callback argument type (expected Symbol or Proc)");
527
+ }
585
528
 
586
- if (TYPE(res) != T_HASH)
529
+ if (TYPE(res) != T_HASH) {
587
530
  rb_raise(rb_eTypeError,
588
531
  "expected opaque hash returned from remove_timeout callback");
532
+ }
589
533
 
590
534
  ff = rb_hash_aref(res, rb_str_new2("free_func"));
591
535
  if (!NIL_P(ff)) {
@@ -607,24 +551,27 @@ static int internal_remove_timeout_func(int timer) {
607
551
 
608
552
  #define set_event_func_or_null(type) \
609
553
  do { \
610
- if (NIL_P(type)) \
554
+ if (NIL_P(type)) { \
611
555
  type##_temp = NULL; \
612
- else \
556
+ } \
557
+ else { \
613
558
  type##_temp = internal_##type##_func; \
559
+ } \
614
560
  } while(0)
615
561
 
616
- static int is_symbol_proc_or_nil(VALUE handle) {
617
- if (NIL_P(handle))
562
+ static int is_symbol_proc_or_nil(VALUE handle)
563
+ {
564
+ if (NIL_P(handle)) {
618
565
  return 1;
619
- return is_symbol_or_proc(handle);
566
+ }
567
+ return ruby_libvirt_is_symbol_or_proc(handle);
620
568
  }
621
569
 
622
570
  /*
623
571
  * call-seq:
624
572
  * Libvirt::event_register_impl(add_handle=nil, update_handle=nil, remove_handle=nil, add_timeout=nil, update_timeout=nil, remove_timeout=nil) -> Qnil
625
573
  *
626
- * Call
627
- * +virEventRegisterImpl+[http://www.libvirt.org/html/libvirt-libvirt.html#virEventRegisterImpl]
574
+ * Call virEventRegisterImpl[http://www.libvirt.org/html/libvirt-libvirt.html#virEventRegisterImpl]
628
575
  * to register callback handlers for handles and timeouts. These handles and
629
576
  * timeouts are used as part of the libvirt infrastructure for generating
630
577
  * domain events. Each callback must be a Symbol (that is the name of a
@@ -652,7 +599,8 @@ static int is_symbol_proc_or_nil(VALUE handle) {
652
599
  * passed to the event_invoke_handle_callback and event_invoke_timeout_callback
653
600
  * module methods; see the documentation for those methods for more details.
654
601
  */
655
- static VALUE libvirt_conn_event_register_impl(int argc, VALUE *argv, VALUE c) {
602
+ static VALUE libvirt_conn_event_register_impl(int argc, VALUE *argv, VALUE c)
603
+ {
656
604
  virEventAddHandleFunc add_handle_temp;
657
605
  virEventUpdateHandleFunc update_handle_temp;
658
606
  virEventRemoveHandleFunc remove_handle_temp;
@@ -673,9 +621,10 @@ static VALUE libvirt_conn_event_register_impl(int argc, VALUE *argv, VALUE c) {
673
621
  !is_symbol_proc_or_nil(remove_handle) ||
674
622
  !is_symbol_proc_or_nil(add_timeout) ||
675
623
  !is_symbol_proc_or_nil(update_timeout) ||
676
- !is_symbol_proc_or_nil(remove_timeout))
624
+ !is_symbol_proc_or_nil(remove_timeout)) {
677
625
  rb_raise(rb_eTypeError,
678
626
  "wrong argument type (expected Symbol, Proc, or nil)");
627
+ }
679
628
 
680
629
  set_event_func_or_null(add_handle);
681
630
  set_event_func_or_null(update_handle);
@@ -693,10 +642,67 @@ static VALUE libvirt_conn_event_register_impl(int argc, VALUE *argv, VALUE c) {
693
642
  }
694
643
  #endif
695
644
 
645
+ #if HAVE_VIRDOMAINLXCENTERSECURITYLABEL
646
+ /*
647
+ * call-seq:
648
+ * Libvirt::lxc_enter_security_label(model, label, flags=0) -> Libvirt::Domain::SecurityLabel
649
+ *
650
+ * Call virDomainLxcEnterSecurityLabel[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLxcEnterSecurityLabel]
651
+ * to attach to the security label specified by label in the security model
652
+ * specified by model. The return object is a Libvirt::Domain::SecurityLabel
653
+ * which may be able to be used to move back to the previous label.
654
+ */
655
+ static VALUE libvirt_domain_lxc_enter_security_label(int argc, VALUE *argv,
656
+ VALUE c)
657
+ {
658
+ VALUE model, label, flags, result, modiv, doiiv, labiv;
659
+ virSecurityModel mod;
660
+ char *modstr, *doistr, *labstr;
661
+ virSecurityLabel lab, oldlab;
662
+ int ret;
663
+
664
+ rb_scan_args(argc, argv, "21", &model, &label, &flags);
665
+
666
+ if (rb_class_of(model) != c_node_security_model) {
667
+ rb_raise(rb_eTypeError,
668
+ "wrong argument type (expected Libvirt::Connect::NodeSecurityModel)");
669
+ }
670
+
671
+ if (rb_class_of(label) != c_domain_security_label) {
672
+ rb_raise(rb_eTypeError,
673
+ "wrong argument type (expected Libvirt::Domain::SecurityLabel)");
674
+ }
675
+
676
+ modiv = rb_iv_get(model, "@model");
677
+ modstr = StringValueCStr(modiv);
678
+ memcpy(mod.model, modstr, strlen(modstr));
679
+ doiiv = rb_iv_get(model, "@doi");
680
+ doistr = StringValueCStr(doiiv);
681
+ memcpy(mod.doi, doistr, strlen(doistr));
682
+
683
+ labiv = rb_iv_get(label, "@label");
684
+ labstr = StringValueCStr(labiv);
685
+ memcpy(lab.label, labstr, strlen(labstr));
686
+ lab.enforcing = NUM2INT(rb_iv_get(label, "@enforcing"));
687
+
688
+ ret = virDomainLxcEnterSecurityLabel(&mod, &lab, &oldlab,
689
+ ruby_libvirt_value_to_uint(flags));
690
+ ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError,
691
+ "virDomainLxcEnterSecurityLabel", NULL);
692
+
693
+ result = rb_class_new_instance(0, NULL, c_domain_security_label);
694
+ rb_iv_set(result, "@label", rb_str_new2(oldlab.label));
695
+ rb_iv_set(result, "@enforcing", INT2NUM(oldlab.enforcing));
696
+
697
+ return result;
698
+ }
699
+ #endif
700
+
696
701
  /*
697
702
  * Module Libvirt
698
703
  */
699
- void Init__libvirt() {
704
+ void Init__libvirt(void)
705
+ {
700
706
  m_libvirt = rb_define_module("Libvirt");
701
707
  c_libvirt_version = rb_define_class_under(m_libvirt, "Version",
702
708
  rb_cObject);
@@ -710,11 +716,17 @@ void Init__libvirt() {
710
716
  rb_define_const(m_libvirt, "CRED_CNONCE", INT2NUM(VIR_CRED_CNONCE));
711
717
  rb_define_const(m_libvirt, "CRED_PASSPHRASE", INT2NUM(VIR_CRED_PASSPHRASE));
712
718
  rb_define_const(m_libvirt, "CRED_ECHOPROMPT", INT2NUM(VIR_CRED_ECHOPROMPT));
713
- rb_define_const(m_libvirt, "CRED_NOECHOPROMPT", INT2NUM(VIR_CRED_NOECHOPROMPT));
719
+ rb_define_const(m_libvirt, "CRED_NOECHOPROMPT",
720
+ INT2NUM(VIR_CRED_NOECHOPROMPT));
714
721
  rb_define_const(m_libvirt, "CRED_REALM", INT2NUM(VIR_CRED_REALM));
715
722
  rb_define_const(m_libvirt, "CRED_EXTERNAL", INT2NUM(VIR_CRED_EXTERNAL));
716
723
  #endif
717
724
 
725
+ #if HAVE_CONST_VIR_CONNECT_NO_ALIASES
726
+ rb_define_const(m_libvirt, "CONNECT_NO_ALIASES",
727
+ INT2NUM(VIR_CONNECT_NO_ALIASES));
728
+ #endif
729
+
718
730
  /*
719
731
  * Libvirt Errors
720
732
  */
@@ -993,18 +1005,24 @@ void Init__libvirt() {
993
1005
  libvirt_event_invoke_timeout_callback, 2);
994
1006
  #endif
995
1007
 
996
- init_connect();
997
- init_storage();
998
- init_network();
999
- init_nodedevice();
1000
- init_secret();
1001
- init_nwfilter();
1002
- init_interface();
1003
- init_domain();
1004
- init_stream();
1008
+ #if HAVE_VIRDOMAINLXCENTERSECURITYLABEL
1009
+ rb_define_method(m_libvirt, "lxc_enter_security_label",
1010
+ libvirt_domain_lxc_enter_security_label, -1);
1011
+ #endif
1012
+
1013
+ ruby_libvirt_connect_init();
1014
+ ruby_libvirt_storage_init();
1015
+ ruby_libvirt_network_init();
1016
+ ruby_libvirt_nodedevice_init();
1017
+ ruby_libvirt_secret_init();
1018
+ ruby_libvirt_nwfilter_init();
1019
+ ruby_libvirt_interface_init();
1020
+ ruby_libvirt_domain_init();
1021
+ ruby_libvirt_stream_init();
1005
1022
 
1006
1023
  virSetErrorFunc(NULL, rubyLibvirtErrorFunc);
1007
1024
 
1008
- if (virInitialize() < 0)
1025
+ if (virInitialize() < 0) {
1009
1026
  rb_raise(rb_eSystemCallError, "virInitialize failed");
1027
+ }
1010
1028
  }