ovirt-engine-sdk 4.0.1 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2015-2016 Red Hat, Inc.
2
+ Copyright (c) 2015-2017 Red Hat, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@ limitations under the License.
16
16
 
17
17
  #include <ruby.h>
18
18
 
19
- #include <stdbool.h>
20
19
  #include <libxml/xmlwriter.h>
21
20
 
22
21
  #include "ov_module.h"
@@ -31,57 +30,76 @@ static ID STRING_ID;
31
30
  static ID STRING_IO_ID;
32
31
  static ID WRITE_ID;
33
32
 
34
- typedef struct {
35
- VALUE io;
36
- xmlTextWriterPtr writer;
37
- } ov_xml_writer_object;
38
-
39
- static void ov_xml_writer_check_closed(ov_xml_writer_object* object) {
40
- if (object->writer == NULL) {
33
+ static void ov_xml_writer_check_closed(ov_xml_writer_object* ptr) {
34
+ if (ptr->writer == NULL) {
41
35
  rb_raise(ov_error_class, "The writer is already closed");
42
36
  }
43
37
  }
44
38
 
45
- static void ov_xml_writer_mark(ov_xml_writer_object *object) {
46
- /* Mark the IO object as reachable: */
47
- if (!NIL_P(object->io)) {
48
- rb_gc_mark(object->io);
49
- }
39
+ static void ov_xml_writer_mark(void* vptr) {
40
+ ov_xml_writer_object* ptr;
41
+
42
+ ptr = vptr;
43
+ rb_gc_mark(ptr->io);
50
44
  }
51
45
 
52
- static void ov_xml_writer_free(ov_xml_writer_object *object) {
46
+ static void ov_xml_writer_free(void* vptr) {
47
+ ov_xml_writer_object* ptr;
48
+
49
+ /* Get the pointer: */
50
+ ptr = vptr;
51
+
53
52
  /* Free the libxml writer, the buffer is automatically closed: */
54
- if (object->writer != NULL) {
55
- xmlTextWriterPtr tmp = object->writer;
56
- object->writer = NULL;
53
+ if (ptr->writer != NULL) {
54
+ xmlTextWriterPtr tmp = ptr->writer;
55
+ ptr->writer = NULL;
57
56
  xmlFreeTextWriter(tmp);
58
57
  }
59
58
 
60
59
  /* Free this object: */
61
- xfree(object);
60
+ xfree(ptr);
62
61
  }
63
62
 
63
+ rb_data_type_t ov_xml_writer_type = {
64
+ .wrap_struct_name = "OVXMLWRITER",
65
+ .function = {
66
+ .dmark = ov_xml_writer_mark,
67
+ .dfree = ov_xml_writer_free,
68
+ .dsize = NULL,
69
+ .reserved = { NULL, NULL }
70
+ },
71
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
72
+ .parent = NULL,
73
+ .data = NULL,
74
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
75
+ #endif
76
+ };
77
+
64
78
  static VALUE ov_xml_writer_alloc(VALUE klass) {
65
- ov_xml_writer_object* object = NULL;
79
+ ov_xml_writer_object* ptr;
66
80
 
67
- object = ALLOC(ov_xml_writer_object);
68
- memset(object, 0, sizeof(ov_xml_writer_object));
69
- return Data_Wrap_Struct(klass, ov_xml_writer_mark, ov_xml_writer_free, object);
81
+ ptr = ALLOC(ov_xml_writer_object);
82
+ ptr->io = Qnil;
83
+ ptr->writer = NULL;
84
+ return TypedData_Wrap_Struct(klass, &ov_xml_writer_type, ptr);
70
85
  }
71
86
 
72
87
  static int ov_xml_writer_callback(void *context, const char *buffer, int length) {
73
88
  VALUE count;
74
89
  VALUE data;
75
- ov_xml_writer_object *object = (ov_xml_writer_object*) context;
90
+ ov_xml_writer_object* ptr;
91
+
92
+ /* Get the pointer: */
93
+ ptr = context;
76
94
 
77
95
  /* Do nothing if the writer is already closed: */
78
- if (object->writer == NULL) {
96
+ if (ptr->writer == NULL) {
79
97
  return 0;
80
98
  }
81
99
 
82
100
  /* Convert the buffer to a Ruby string and write it to the IO object, using the "write" method: */
83
101
  data = rb_str_new(buffer, length);
84
- count = rb_funcall(object->io, WRITE_ID, 1, data);
102
+ count = rb_funcall(ptr->io, WRITE_ID, 1, data);
85
103
 
86
104
  return NUM2INT(count);
87
105
  }
@@ -99,11 +117,11 @@ static VALUE ov_xml_writer_initialize(int argc, VALUE* argv, VALUE self) {
99
117
  VALUE indent;
100
118
  VALUE io;
101
119
  VALUE io_class;
102
- ov_xml_writer_object* object = NULL;
103
- xmlOutputBufferPtr buffer = NULL;
120
+ ov_xml_writer_object* ptr;
121
+ xmlOutputBufferPtr buffer;
104
122
 
105
123
  /* Get the pointer to the object: */
106
- Data_Get_Struct(self, ov_xml_writer_object, object);
124
+ ov_xml_writer_ptr(self, ptr);
107
125
 
108
126
  /* Get the values of the parameters: */
109
127
  if (argc > 2) {
@@ -115,12 +133,12 @@ static VALUE ov_xml_writer_initialize(int argc, VALUE* argv, VALUE self) {
115
133
  /* The first parameter can be an IO object or nil. If it is nil then we need to create a IO object where we can
116
134
  write the generated XML. */
117
135
  if (NIL_P(io)) {
118
- object->io = ov_xml_writer_create_string_io();
136
+ ptr->io = ov_xml_writer_create_string_io();
119
137
  }
120
138
  else {
121
139
  io_class = rb_class_of(io);
122
140
  if (io_class == rb_cIO) {
123
- object->io = io;
141
+ ptr->io = io;
124
142
  }
125
143
  else {
126
144
  rb_raise(
@@ -132,50 +150,50 @@ static VALUE ov_xml_writer_initialize(int argc, VALUE* argv, VALUE self) {
132
150
  }
133
151
 
134
152
  /* Create the libxml buffer that writes to the IO object: */
135
- buffer = xmlOutputBufferCreateIO(ov_xml_writer_callback, NULL, object, NULL);
153
+ buffer = xmlOutputBufferCreateIO(ov_xml_writer_callback, NULL, ptr, NULL);
136
154
  if (buffer == NULL) {
137
155
  rb_raise(ov_error_class, "Can't create XML buffer");
138
156
  }
139
157
 
140
158
  /* Create the libxml writer: */
141
- object->writer = xmlNewTextWriter(buffer);
142
- if (object->writer == NULL) {
159
+ ptr->writer = xmlNewTextWriter(buffer);
160
+ if (ptr->writer == NULL) {
143
161
  xmlOutputBufferClose(buffer);
144
162
  rb_raise(ov_error_class, "Can't create XML writer");
145
163
  }
146
164
 
147
165
  /* Enable indentation: */
148
166
  if (RTEST(indent)) {
149
- xmlTextWriterSetIndent(object->writer, 1);
150
- xmlTextWriterSetIndentString(object->writer, BAD_CAST " ");
167
+ xmlTextWriterSetIndent(ptr->writer, 1);
168
+ xmlTextWriterSetIndentString(ptr->writer, BAD_CAST " ");
151
169
  }
152
170
 
153
171
  return self;
154
172
  }
155
173
 
156
174
  static VALUE ov_xml_writer_string(VALUE self) {
157
- int rc = 0;
158
- ov_xml_writer_object* object = NULL;
175
+ int rc;
176
+ ov_xml_writer_object* ptr;
159
177
 
160
- Data_Get_Struct(self, ov_xml_writer_object, object);
161
- ov_xml_writer_check_closed(object);
162
- rc = xmlTextWriterFlush(object->writer);
178
+ ov_xml_writer_ptr(self, ptr);
179
+ ov_xml_writer_check_closed(ptr);
180
+ rc = xmlTextWriterFlush(ptr->writer);
163
181
  if (rc < 0) {
164
182
  rb_raise(ov_error_class, "Can't flush XML writer");
165
183
  }
166
- return rb_funcall(object->io, STRING_ID, 0, NULL);
184
+ return rb_funcall(ptr->io, STRING_ID, 0, NULL);
167
185
  }
168
186
 
169
187
  static VALUE ov_xml_writer_write_start(VALUE self, VALUE name) {
170
- char* c_name = NULL;
171
- int rc = 0;
172
- ov_xml_writer_object* object = NULL;
188
+ char* c_name;
189
+ int rc;
190
+ ov_xml_writer_object* ptr;
173
191
 
174
- Data_Get_Struct(self, ov_xml_writer_object, object);
175
- ov_xml_writer_check_closed(object);
192
+ ov_xml_writer_ptr(self, ptr);
193
+ ov_xml_writer_check_closed(ptr);
176
194
  Check_Type(name, T_STRING);
177
195
  c_name = StringValueCStr(name);
178
- rc = xmlTextWriterStartElement(object->writer, BAD_CAST c_name);
196
+ rc = xmlTextWriterStartElement(ptr->writer, BAD_CAST c_name);
179
197
  if (rc < 0) {
180
198
  rb_raise(ov_error_class, "Can't start XML element");
181
199
  }
@@ -183,12 +201,12 @@ static VALUE ov_xml_writer_write_start(VALUE self, VALUE name) {
183
201
  }
184
202
 
185
203
  static VALUE ov_xml_writer_write_end(VALUE self) {
186
- int rc = 0;
187
- ov_xml_writer_object* object = NULL;
204
+ int rc;
205
+ ov_xml_writer_object* ptr;
188
206
 
189
- Data_Get_Struct(self, ov_xml_writer_object, object);
190
- ov_xml_writer_check_closed(object);
191
- rc = xmlTextWriterEndElement(object->writer);
207
+ ov_xml_writer_ptr(self, ptr);
208
+ ov_xml_writer_check_closed(ptr);
209
+ rc = xmlTextWriterEndElement(ptr->writer);
192
210
  if (rc < 0) {
193
211
  rb_raise(ov_error_class, "Can't end XML element");
194
212
  }
@@ -196,18 +214,18 @@ static VALUE ov_xml_writer_write_end(VALUE self) {
196
214
  }
197
215
 
198
216
  static VALUE ov_xml_writer_write_attribute(VALUE self, VALUE name, VALUE value) {
199
- char* c_name = NULL;
200
- char* c_value = NULL;
201
- int rc = 0;
202
- ov_xml_writer_object* object = NULL;
217
+ char* c_name;
218
+ char* c_value;
219
+ int rc;
220
+ ov_xml_writer_object* ptr;
203
221
 
204
- Data_Get_Struct(self, ov_xml_writer_object, object);
205
- ov_xml_writer_check_closed(object);
222
+ ov_xml_writer_ptr(self, ptr);
223
+ ov_xml_writer_check_closed(ptr);
206
224
  Check_Type(name, T_STRING);
207
225
  Check_Type(value, T_STRING);
208
226
  c_name = StringValueCStr(name);
209
227
  c_value = StringValueCStr(value);
210
- rc = xmlTextWriterWriteAttribute(object->writer, BAD_CAST c_name, BAD_CAST c_value);
228
+ rc = xmlTextWriterWriteAttribute(ptr->writer, BAD_CAST c_name, BAD_CAST c_value);
211
229
  if (rc < 0) {
212
230
  rb_raise(ov_error_class, "Can't write attribute with name \"%s\" and value \"%s\"", c_name, c_value);
213
231
  }
@@ -215,18 +233,18 @@ static VALUE ov_xml_writer_write_attribute(VALUE self, VALUE name, VALUE value)
215
233
  }
216
234
 
217
235
  static VALUE ov_xml_writer_write_element(VALUE self, VALUE name, VALUE value) {
218
- char* c_name = NULL;
219
- char* c_value = NULL;
220
- int rc = 0;
221
- ov_xml_writer_object* object = NULL;
236
+ char* c_name;
237
+ char* c_value;
238
+ int rc;
239
+ ov_xml_writer_object* ptr;
222
240
 
223
- Data_Get_Struct(self, ov_xml_writer_object, object);
224
- ov_xml_writer_check_closed(object);
241
+ ov_xml_writer_ptr(self, ptr);
242
+ ov_xml_writer_check_closed(ptr);
225
243
  Check_Type(name, T_STRING);
226
244
  Check_Type(value, T_STRING);
227
245
  c_name = StringValueCStr(name);
228
246
  c_value = StringValueCStr(value);
229
- rc = xmlTextWriterWriteElement(object->writer, BAD_CAST c_name, BAD_CAST c_value);
247
+ rc = xmlTextWriterWriteElement(ptr->writer, BAD_CAST c_name, BAD_CAST c_value);
230
248
  if (rc < 0) {
231
249
  rb_raise(ov_error_class, "Can't write element with name \"%s\" and value \"%s\"", c_name, c_value);
232
250
  }
@@ -234,12 +252,12 @@ static VALUE ov_xml_writer_write_element(VALUE self, VALUE name, VALUE value) {
234
252
  }
235
253
 
236
254
  static VALUE ov_xml_writer_flush(VALUE self) {
237
- ov_xml_writer_object* object = NULL;
238
- int rc = 0;
255
+ int rc;
256
+ ov_xml_writer_object* ptr;
239
257
 
240
- Data_Get_Struct(self, ov_xml_writer_object, object);
241
- ov_xml_writer_check_closed(object);
242
- rc = xmlTextWriterFlush(object->writer);
258
+ ov_xml_writer_ptr(self, ptr);
259
+ ov_xml_writer_check_closed(ptr);
260
+ rc = xmlTextWriterFlush(ptr->writer);
243
261
  if (rc < 0) {
244
262
  rb_raise(ov_error_class, "Can't flush XML writer");
245
263
  }
@@ -247,12 +265,12 @@ static VALUE ov_xml_writer_flush(VALUE self) {
247
265
  }
248
266
 
249
267
  static VALUE ov_xml_writer_close(VALUE self) {
250
- ov_xml_writer_object* object = NULL;
268
+ ov_xml_writer_object* ptr;
251
269
 
252
- Data_Get_Struct(self, ov_xml_writer_object, object);
253
- ov_xml_writer_check_closed(object);
254
- xmlFreeTextWriter(object->writer);
255
- object->writer = NULL;
270
+ ov_xml_writer_ptr(self, ptr);
271
+ ov_xml_writer_check_closed(ptr);
272
+ xmlFreeTextWriter(ptr->writer);
273
+ ptr->writer = NULL;
256
274
  return Qnil;
257
275
  }
258
276
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2015-2016 Red Hat, Inc.
2
+ Copyright (c) 2015-2017 Red Hat, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -17,10 +17,25 @@ limitations under the License.
17
17
  #ifndef __OV_XML_WRITER_H__
18
18
  #define __OV_XML_WRITER_H__
19
19
 
20
- // Classes:
20
+ #include <ruby.h>
21
+
22
+ #include <libxml/xmlwriter.h>
23
+
24
+ /* Data type and class: */
25
+ extern rb_data_type_t ov_xml_writer_type;
21
26
  extern VALUE ov_xml_writer_class;
22
27
 
23
- // Initialization function:
28
+ /* Content: */
29
+ typedef struct {
30
+ VALUE io;
31
+ xmlTextWriterPtr writer;
32
+ } ov_xml_writer_object;
33
+
34
+ /* Macro to get the pointer: */
35
+ #define ov_xml_writer_ptr(object, ptr) \
36
+ TypedData_Get_Struct((object), ov_xml_writer_object, &ov_xml_writer_type, (ptr))
37
+
38
+ /* Initialization function: */
24
39
  extern void ov_xml_writer_define(void);
25
40
 
26
41
  #endif
@@ -18,15 +18,23 @@ limitations under the License.
18
18
 
19
19
  #include "ov_module.h"
20
20
  #include "ov_error.h"
21
+ #include "ov_http_client.h"
22
+ #include "ov_http_request.h"
23
+ #include "ov_http_response.h"
24
+ #include "ov_http_transfer.h"
21
25
  #include "ov_xml_reader.h"
22
26
  #include "ov_xml_writer.h"
23
27
 
24
28
  void Init_ovirtsdk4c(void) {
25
- // Define the module:
29
+ /* Define the module: */
26
30
  ov_module_define();
27
31
 
28
- // Define the classes:
32
+ /* Define the classes: */
29
33
  ov_error_define();
34
+ ov_http_client_define();
35
+ ov_http_request_define();
36
+ ov_http_response_define();
37
+ ov_http_transfer_define();
30
38
  ov_xml_reader_define();
31
39
  ov_xml_writer_define();
32
40
  }