ovirt-engine-sdk 4.0.0.alpha11 → 4.0.0.alpha12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191883f8dedae81116c21bacbbd76842a24bd4dd
4
- data.tar.gz: 4d495588ffdc4ed4a148aeffef41ce4a8619c946
3
+ metadata.gz: a910fa355950cb5a7ae1e1263fa42de439a4388d
4
+ data.tar.gz: a5da7ba22f549c6f20e27d11011ecf6da33b7abf
5
5
  SHA512:
6
- metadata.gz: 1e7275a18726e7c3cca952cdccadca40dd6bc728056906337ef4dc2e339f39b4a40d528f5e75b1e0172b9a44c9635e04b25643a609e98f3c0950f7fdcc733b5a
7
- data.tar.gz: e977a9cc0ce518facde71d617d1f42e29cf463fe8b452d519f5b88b5916982199909594d688511728bb4beb4217189d5ae4498e71bb9914e8a65dc3167732c29
6
+ metadata.gz: e662f4df3c0254d86f05bceedb55e40e1d08fd8108912b9f46f36f95e1f5e7980a35c2e2e498df8788b544cd39114d0248626e63ed1e0e4f05a7da1bd41230d7
7
+ data.tar.gz: 282472f9d5e04d8d4c0120f80f9607fef94e7ebcf1f0466a91d0f320e211cfdcdd8090cea098ded44b1f4049d0384f6d52301db6128b1567361c9c74f9b2cf4d
@@ -27,11 +27,9 @@ limitations under the License.
27
27
  #include "ov_error.h"
28
28
  #include "ov_xml_reader.h"
29
29
 
30
- // Symbols:
31
- static VALUE IO_SYMBOL;
32
-
33
30
  // Method identifiers:
34
31
  static ID READ_ID;
32
+ static ID STRING_IO_ID;
35
33
 
36
34
  typedef struct {
37
35
  VALUE io;
@@ -46,39 +44,46 @@ static void ov_xml_reader_check_closed(ov_xml_reader_object* object) {
46
44
  }
47
45
 
48
46
  static void ov_xml_reader_mark(ov_xml_reader_object *object) {
49
- // Mark the IO object as reachable:
47
+ /* Mark the IO object as reachable: */
50
48
  if (!NIL_P(object->io)) {
51
49
  rb_gc_mark(object->io);
52
50
  }
53
51
  }
54
52
 
55
53
  static void ov_xml_reader_free(ov_xml_reader_object *object) {
56
- // Free the libxml reader:
54
+ /* Free the libxml reader: */
57
55
  if (!object->closed) {
58
- xmlFreeTextReader(object->reader);
56
+ if (object->reader != NULL) {
57
+ xmlFreeTextReader(object->reader);
58
+ }
59
59
  object->reader = NULL;
60
60
  object->closed = true;
61
61
  }
62
62
 
63
- // Free this object:
63
+ /* Free this object: */
64
64
  xfree(object);
65
65
  }
66
66
 
67
67
  static VALUE ov_xml_reader_alloc(VALUE klass) {
68
- ov_xml_reader_object *object = ALLOC(ov_xml_reader_object);
68
+ ov_xml_reader_object* object = NULL;
69
+
70
+ object = ALLOC(ov_xml_reader_object);
71
+ memset(object, 0, sizeof(ov_xml_reader_object));
69
72
  return Data_Wrap_Struct(klass, ov_xml_reader_mark, ov_xml_reader_free, object);
70
73
  }
71
74
 
72
75
  static int ov_xml_reader_callback(void *context, char *buffer, int length) {
73
- ov_xml_reader_object *object = (ov_xml_reader_object*) context;
76
+ VALUE data;
77
+ ov_xml_reader_object* object = NULL;
74
78
 
75
- // Do nothing if the reader is already closed:
79
+ /* Do nothing if the reader is already closed: */
80
+ object = (ov_xml_reader_object*) context;
76
81
  if (object->closed) {
77
82
  return -1;
78
83
  }
79
84
 
80
- // Read from the Ruby IO object, and copy the result to the buffer:
81
- VALUE data = rb_funcall(object->io, READ_ID, 1, INT2NUM(length));
85
+ /* Read from the Ruby IO object, and copy the result to the buffer: */
86
+ data = rb_funcall(object->io, READ_ID, 1, INT2NUM(length));
82
87
  if (NIL_P(data)) {
83
88
  return 0;
84
89
  }
@@ -88,32 +93,51 @@ static int ov_xml_reader_callback(void *context, char *buffer, int length) {
88
93
  return length;
89
94
  }
90
95
 
91
- static VALUE ov_xml_reader_initialize(VALUE self, VALUE options) {
92
- // Initialize the reader:
93
- ov_xml_reader_object *object;
96
+ static VALUE ov_xml_reader_create_string_io(VALUE text) {
97
+ VALUE sio_class;
98
+ VALUE sio_obj;
99
+
100
+ sio_class = rb_const_get(rb_cObject, STRING_IO_ID);
101
+ sio_obj = rb_class_new_instance(1, &text, sio_class);
102
+ return sio_obj;
103
+ }
104
+
105
+ static VALUE ov_xml_reader_initialize(VALUE self, VALUE io) {
106
+ VALUE io_class;
107
+ int rc = 0;
108
+ ov_xml_reader_object* object = NULL;
109
+
110
+ /* Get the pointer to the object: */
94
111
  Data_Get_Struct(self, ov_xml_reader_object, object);
95
112
 
96
- // Get the options, and assign default values:
97
- Check_Type(options, T_HASH);
98
- VALUE io = rb_hash_aref(options, IO_SYMBOL);
99
- if (NIL_P(io)) {
100
- rb_raise(ov_error_class, "The \"io\" parameter is mandatory and can't be nil");
113
+ /* The parameter of the constructor can be a string or an IO object. If it is a string then we need to create aa
114
+ IO object to read from it. */
115
+ io_class = rb_class_of(io);
116
+ if (io_class == rb_cString) {
117
+ object->io = ov_xml_reader_create_string_io(io);
118
+ }
119
+ else if (io_class == rb_cIO) {
120
+ object->io = io;
121
+ }
122
+ else {
123
+ rb_raise(
124
+ ov_error_class,
125
+ "The type of the 'io' parameter must be 'String' or 'IO', but it is '%"PRIsVALUE"'",
126
+ io_class
127
+ );
101
128
  }
102
129
 
103
- // Save the IO object:
104
- object->io = io;
105
-
106
- // Clear the closed flag:
130
+ /* Clear the closed flag: */
107
131
  object->closed = false;
108
132
 
109
- // Create the libxml reader:
133
+ /* Create the libxml reader: */
110
134
  object->reader = xmlReaderForIO(ov_xml_reader_callback, NULL, object, NULL, NULL, 0);
111
135
  if (object->reader == NULL) {
112
136
  rb_raise(ov_error_class, "Can't create reader");
113
137
  }
114
138
 
115
- // Move the cursor to the first node:
116
- int rc = xmlTextReaderRead(object->reader);
139
+ /* Move the cursor to the first node: */
140
+ rc = xmlTextReaderRead(object->reader);
117
141
  if (rc == -1) {
118
142
  rb_raise(ov_error_class, "Can't read first node");
119
143
  }
@@ -121,17 +145,13 @@ static VALUE ov_xml_reader_initialize(VALUE self, VALUE options) {
121
145
  return self;
122
146
  }
123
147
 
124
- static VALUE ov_xml_reader_io(VALUE self) {
125
- ov_xml_reader_object *object;
126
- Data_Get_Struct(self, ov_xml_reader_object, object);
127
- return object->io;
128
- }
129
-
130
148
  static VALUE ov_xml_reader_read(VALUE self) {
131
- ov_xml_reader_object *object;
149
+ int rc = 0;
150
+ ov_xml_reader_object* object = NULL;
151
+
132
152
  Data_Get_Struct(self, ov_xml_reader_object, object);
133
153
  ov_xml_reader_check_closed(object);
134
- int rc = xmlTextReaderRead(object->reader);
154
+ rc = xmlTextReaderRead(object->reader);
135
155
  if (rc == 0) {
136
156
  return Qfalse;
137
157
  }
@@ -171,34 +191,42 @@ static VALUE ov_xml_reader_forward(VALUE self) {
171
191
  }
172
192
 
173
193
  static VALUE ov_xml_reader_node_name(VALUE self) {
174
- ov_xml_reader_object *object;
194
+ VALUE name;
195
+ const xmlChar* c_name = NULL;
196
+ ov_xml_reader_object* object = NULL;
197
+
175
198
  Data_Get_Struct(self, ov_xml_reader_object, object);
176
199
  ov_xml_reader_check_closed(object);
177
- const xmlChar *c_name = xmlTextReaderConstName(object->reader);
200
+ c_name = xmlTextReaderConstName(object->reader);
178
201
  if (c_name == NULL) {
179
202
  return Qnil;
180
203
  }
181
- VALUE name = rb_str_new_cstr((char*) c_name);
204
+ name = rb_str_new_cstr((char*) c_name);
182
205
  return name;
183
206
  }
184
207
 
185
208
  static VALUE ov_xml_reader_empty_element(VALUE self) {
186
- ov_xml_reader_object *object;
209
+ ov_xml_reader_object* object = NULL;
210
+
187
211
  Data_Get_Struct(self, ov_xml_reader_object, object);
188
212
  ov_xml_reader_check_closed(object);
189
213
  return xmlTextReaderIsEmptyElement(object->reader)? Qtrue: Qfalse;
190
214
  }
191
215
 
192
216
  static VALUE ov_xml_reader_get_attribute(VALUE self, VALUE name) {
193
- ov_xml_reader_object *object;
217
+ VALUE value;
218
+ ov_xml_reader_object* object = NULL;
219
+ xmlChar* c_name = NULL;
220
+ xmlChar* c_value = NULL;
221
+
194
222
  Data_Get_Struct(self, ov_xml_reader_object, object);
195
223
  ov_xml_reader_check_closed(object);
196
- xmlChar *c_name = (xmlChar*) StringValueCStr(name);
197
- xmlChar *c_value = xmlTextReaderGetAttribute(object->reader, c_name);
224
+ c_name = (xmlChar*) StringValueCStr(name);
225
+ c_value = xmlTextReaderGetAttribute(object->reader, c_name);
198
226
  if (c_value == NULL) {
199
227
  return Qnil;
200
228
  }
201
- VALUE value = rb_str_new_cstr((char*) c_value);
229
+ value = rb_str_new_cstr((char*) c_value);
202
230
  xmlFree(c_value);
203
231
  return value;
204
232
  }
@@ -295,10 +323,12 @@ static VALUE ov_xml_reader_read_elements(VALUE self) {
295
323
  }
296
324
 
297
325
  static VALUE ov_xml_reader_next_element(VALUE self) {
298
- ov_xml_reader_object *object;
326
+ int rc = 0;
327
+ ov_xml_reader_object* object = NULL;
328
+
299
329
  Data_Get_Struct(self, ov_xml_reader_object, object);
300
330
  ov_xml_reader_check_closed(object);
301
- int rc = xmlTextReaderNext(object->reader);
331
+ rc = xmlTextReaderNext(object->reader);
302
332
  if (rc == 0) {
303
333
  return Qfalse;
304
334
  }
@@ -309,7 +339,8 @@ static VALUE ov_xml_reader_next_element(VALUE self) {
309
339
  }
310
340
 
311
341
  static VALUE ov_xml_reader_close(VALUE self) {
312
- ov_xml_reader_object *object;
342
+ ov_xml_reader_object* object = NULL;
343
+
313
344
  Data_Get_Struct(self, ov_xml_reader_object, object);
314
345
  ov_xml_reader_check_closed(object);
315
346
  xmlFreeTextReader(object->reader);
@@ -319,16 +350,18 @@ static VALUE ov_xml_reader_close(VALUE self) {
319
350
  }
320
351
 
321
352
  void ov_xml_reader_define(void) {
322
- // Define the class:
353
+ /* Load required modules: */
354
+ rb_require("stringio");
355
+
356
+ /* Define the class: */
323
357
  ov_xml_reader_class = rb_define_class_under(ov_module, "XmlReader", rb_cObject);
324
358
 
325
- // Define the constructor:
359
+ /* Define the constructor: */
326
360
  rb_define_alloc_func(ov_xml_reader_class, ov_xml_reader_alloc);
327
361
  rb_define_method(ov_xml_reader_class, "initialize", ov_xml_reader_initialize, 1);
328
362
 
329
- // Define the methods:
363
+ /* Define the methods: */
330
364
  rb_define_method(ov_xml_reader_class, "forward", ov_xml_reader_forward, 0);
331
- rb_define_method(ov_xml_reader_class, "io", ov_xml_reader_io, 0);
332
365
  rb_define_method(ov_xml_reader_class, "read", ov_xml_reader_read, 0);
333
366
  rb_define_method(ov_xml_reader_class, "node_name", ov_xml_reader_node_name, 0);
334
367
  rb_define_method(ov_xml_reader_class, "empty_element?", ov_xml_reader_empty_element, 0);
@@ -338,9 +371,7 @@ void ov_xml_reader_define(void) {
338
371
  rb_define_method(ov_xml_reader_class, "next_element", ov_xml_reader_next_element, 0);
339
372
  rb_define_method(ov_xml_reader_class, "close", ov_xml_reader_close, 0);
340
373
 
341
- // Create symbols:
342
- IO_SYMBOL = ID2SYM(rb_intern("io"));
343
-
344
- // Create method identifiers:
374
+ /* Create method identifiers: */
345
375
  READ_ID = rb_intern("read");
376
+ STRING_IO_ID = rb_intern("StringIO");
346
377
  }
@@ -23,11 +23,9 @@ limitations under the License.
23
23
  #include "ov_error.h"
24
24
  #include "ov_xml_writer.h"
25
25
 
26
- // Symbols:
27
- static VALUE IO_SYMBOL;
28
- static VALUE INDENT_SYMBOL;
29
-
30
- // Method identifiers:
26
+ /* Identifiers: */
27
+ static ID STRING_ID;
28
+ static ID STRING_IO_ID;
31
29
  static ID WRITE_ID;
32
30
 
33
31
  typedef struct {
@@ -42,77 +40,108 @@ static void ov_xml_writer_check_closed(ov_xml_writer_object* object) {
42
40
  }
43
41
 
44
42
  static void ov_xml_writer_mark(ov_xml_writer_object *object) {
45
- // Mark the IO object as reachable:
43
+ /* Mark the IO object as reachable: */
46
44
  if (!NIL_P(object->io)) {
47
45
  rb_gc_mark(object->io);
48
46
  }
49
47
  }
50
48
 
51
49
  static void ov_xml_writer_free(ov_xml_writer_object *object) {
52
- // Free the libxml writer, the buffer is automatically closed:
50
+ /* Free the libxml writer, the buffer is automatically closed: */
53
51
  if (object->writer != NULL) {
54
52
  xmlTextWriterPtr tmp = object->writer;
55
53
  object->writer = NULL;
56
54
  xmlFreeTextWriter(tmp);
57
55
  }
58
56
 
59
- // Free this object:
57
+ /* Free this object: */
60
58
  xfree(object);
61
59
  }
62
60
 
63
61
  static VALUE ov_xml_writer_alloc(VALUE klass) {
64
- ov_xml_writer_object *object = ALLOC(ov_xml_writer_object);
62
+ ov_xml_writer_object* object = NULL;
63
+
64
+ object = ALLOC(ov_xml_writer_object);
65
+ memset(object, 0, sizeof(ov_xml_writer_object));
65
66
  return Data_Wrap_Struct(klass, ov_xml_writer_mark, ov_xml_writer_free, object);
66
67
  }
67
68
 
68
69
  static int ov_xml_writer_callback(void *context, const char *buffer, int length) {
70
+ VALUE count;
71
+ VALUE data;
69
72
  ov_xml_writer_object *object = (ov_xml_writer_object*) context;
70
73
 
71
- // Do nothing if the writer is already closed:
74
+ /* Do nothing if the writer is already closed: */
72
75
  if (object->writer == NULL) {
73
76
  return 0;
74
77
  }
75
78
 
76
- // Convert the buffer to a Ruby string and write it to the IO object, using the "write" method:
77
- VALUE data = rb_str_new(buffer, length);
78
- VALUE count = rb_funcall(object->io, WRITE_ID, 1, data);
79
+ /* Convert the buffer to a Ruby string and write it to the IO object, using the "write" method: */
80
+ data = rb_str_new(buffer, length);
81
+ count = rb_funcall(object->io, WRITE_ID, 1, data);
79
82
 
80
83
  return NUM2INT(count);
81
84
  }
82
85
 
83
- static VALUE ov_xml_writer_initialize(VALUE self, VALUE options) {
84
- // Initialize the writer:
85
- ov_xml_writer_object *object;
86
+ static VALUE ov_xml_writer_create_string_io() {
87
+ VALUE sio_class;
88
+ VALUE sio_obj;
89
+
90
+ sio_class = rb_const_get(rb_cObject, STRING_IO_ID);
91
+ sio_obj = rb_class_new_instance(0, NULL, sio_class);
92
+ return sio_obj;
93
+ }
94
+
95
+ static VALUE ov_xml_writer_initialize(int argc, VALUE* argv, VALUE self) {
96
+ VALUE indent;
97
+ VALUE io;
98
+ VALUE io_class;
99
+ ov_xml_writer_object* object = NULL;
100
+ xmlOutputBufferPtr buffer = NULL;
101
+
102
+ /* Get the pointer to the object: */
86
103
  Data_Get_Struct(self, ov_xml_writer_object, object);
87
104
 
88
- // Get the options, and assign default values:
89
- Check_Type(options, T_HASH);
90
- VALUE io = rb_hash_aref(options, IO_SYMBOL);
105
+ /* Get the values of the parameters: */
106
+ if (argc > 2) {
107
+ rb_raise(ov_error_class, "Expected at most two arguments, 'io' and 'indent', but received %d", argc);
108
+ }
109
+ io = argc > 0? argv[0]: Qnil;
110
+ indent = argc > 1? argv[1]: Qnil;
111
+
112
+ /* 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
113
+ write the generated XML. */
91
114
  if (NIL_P(io)) {
92
- rb_raise(ov_error_class, "The \"io\" parameter is mandatory and can't be nil");
115
+ object->io = ov_xml_writer_create_string_io();
93
116
  }
94
- VALUE indent = rb_hash_aref(options, INDENT_SYMBOL);
95
- if (NIL_P(indent)) {
96
- indent = Qfalse;
117
+ else {
118
+ io_class = rb_class_of(io);
119
+ if (io_class == rb_cIO) {
120
+ object->io = io;
121
+ }
122
+ else {
123
+ rb_raise(
124
+ ov_error_class,
125
+ "The type of the 'io' parameter must be 'IO', but it is '%"PRIsVALUE"'",
126
+ io_class
127
+ );
128
+ }
97
129
  }
98
130
 
99
- // Save the IO object:
100
- object->io = io;
101
-
102
- // Create the libxml buffer that writes to the IO object:
103
- xmlOutputBufferPtr buffer = xmlOutputBufferCreateIO(ov_xml_writer_callback, NULL, object, NULL);
131
+ /* Create the libxml buffer that writes to the IO object: */
132
+ buffer = xmlOutputBufferCreateIO(ov_xml_writer_callback, NULL, object, NULL);
104
133
  if (buffer == NULL) {
105
134
  rb_raise(ov_error_class, "Can't create XML buffer");
106
135
  }
107
136
 
108
- // Create the libxml writer:
137
+ /* Create the libxml writer: */
109
138
  object->writer = xmlNewTextWriter(buffer);
110
139
  if (object->writer == NULL) {
111
140
  xmlOutputBufferClose(buffer);
112
141
  rb_raise(ov_error_class, "Can't create XML writer");
113
142
  }
114
143
 
115
- // Enable indentation:
144
+ /* Enable indentation: */
116
145
  if (RTEST(indent)) {
117
146
  xmlTextWriterSetIndent(object->writer, 1);
118
147
  xmlTextWriterSetIndentString(object->writer, BAD_CAST " ");
@@ -121,19 +150,29 @@ static VALUE ov_xml_writer_initialize(VALUE self, VALUE options) {
121
150
  return self;
122
151
  }
123
152
 
124
- static VALUE ov_xml_writer_io(VALUE self) {
125
- ov_xml_writer_object *object;
153
+ static VALUE ov_xml_writer_string(VALUE self) {
154
+ int rc = 0;
155
+ ov_xml_writer_object* object = NULL;
156
+
126
157
  Data_Get_Struct(self, ov_xml_writer_object, object);
127
- return object->io;
158
+ ov_xml_writer_check_closed(object);
159
+ rc = xmlTextWriterFlush(object->writer);
160
+ if (rc < 0) {
161
+ rb_raise(ov_error_class, "Can't flush XML writer");
162
+ }
163
+ return rb_funcall(object->io, STRING_ID, 0, NULL);
128
164
  }
129
165
 
130
166
  static VALUE ov_xml_writer_write_start(VALUE self, VALUE name) {
131
- ov_xml_writer_object *object;
167
+ char* c_name = NULL;
168
+ int rc = 0;
169
+ ov_xml_writer_object* object = NULL;
170
+
132
171
  Data_Get_Struct(self, ov_xml_writer_object, object);
133
172
  ov_xml_writer_check_closed(object);
134
173
  Check_Type(name, T_STRING);
135
- char *c_name = StringValueCStr(name);
136
- int rc = xmlTextWriterStartElement(object->writer, BAD_CAST c_name);
174
+ c_name = StringValueCStr(name);
175
+ rc = xmlTextWriterStartElement(object->writer, BAD_CAST c_name);
137
176
  if (rc < 0) {
138
177
  rb_raise(ov_error_class, "Can't start XML element");
139
178
  }
@@ -141,10 +180,12 @@ static VALUE ov_xml_writer_write_start(VALUE self, VALUE name) {
141
180
  }
142
181
 
143
182
  static VALUE ov_xml_writer_write_end(VALUE self) {
144
- ov_xml_writer_object *object;
183
+ int rc = 0;
184
+ ov_xml_writer_object* object = NULL;
185
+
145
186
  Data_Get_Struct(self, ov_xml_writer_object, object);
146
187
  ov_xml_writer_check_closed(object);
147
- int rc = xmlTextWriterEndElement(object->writer);
188
+ rc = xmlTextWriterEndElement(object->writer);
148
189
  if (rc < 0) {
149
190
  rb_raise(ov_error_class, "Can't end XML element");
150
191
  }
@@ -152,14 +193,18 @@ static VALUE ov_xml_writer_write_end(VALUE self) {
152
193
  }
153
194
 
154
195
  static VALUE ov_xml_writer_write_attribute(VALUE self, VALUE name, VALUE value) {
155
- ov_xml_writer_object *object;
196
+ char* c_name = NULL;
197
+ char* c_value = NULL;
198
+ int rc = 0;
199
+ ov_xml_writer_object* object = NULL;
200
+
156
201
  Data_Get_Struct(self, ov_xml_writer_object, object);
157
202
  ov_xml_writer_check_closed(object);
158
203
  Check_Type(name, T_STRING);
159
204
  Check_Type(value, T_STRING);
160
- char *c_name = StringValueCStr(name);
161
- char *c_value = StringValueCStr(value);
162
- int rc = xmlTextWriterWriteAttribute(object->writer, BAD_CAST c_name, BAD_CAST c_value);
205
+ c_name = StringValueCStr(name);
206
+ c_value = StringValueCStr(value);
207
+ rc = xmlTextWriterWriteAttribute(object->writer, BAD_CAST c_name, BAD_CAST c_value);
163
208
  if (rc < 0) {
164
209
  rb_raise(ov_error_class, "Can't write attribute with name \"%s\" and value \"%s\"", c_name, c_value);
165
210
  }
@@ -167,14 +212,18 @@ static VALUE ov_xml_writer_write_attribute(VALUE self, VALUE name, VALUE value)
167
212
  }
168
213
 
169
214
  static VALUE ov_xml_writer_write_element(VALUE self, VALUE name, VALUE value) {
170
- ov_xml_writer_object *object;
215
+ char* c_name = NULL;
216
+ char* c_value = NULL;
217
+ int rc = 0;
218
+ ov_xml_writer_object* object = NULL;
219
+
171
220
  Data_Get_Struct(self, ov_xml_writer_object, object);
172
221
  ov_xml_writer_check_closed(object);
173
222
  Check_Type(name, T_STRING);
174
223
  Check_Type(value, T_STRING);
175
- char *c_name = StringValueCStr(name);
176
- char *c_value = StringValueCStr(value);
177
- int rc = xmlTextWriterWriteElement(object->writer, BAD_CAST c_name, BAD_CAST c_value);
224
+ c_name = StringValueCStr(name);
225
+ c_value = StringValueCStr(value);
226
+ rc = xmlTextWriterWriteElement(object->writer, BAD_CAST c_name, BAD_CAST c_value);
178
227
  if (rc < 0) {
179
228
  rb_raise(ov_error_class, "Can't write element with name \"%s\" and value \"%s\"", c_name, c_value);
180
229
  }
@@ -182,10 +231,12 @@ static VALUE ov_xml_writer_write_element(VALUE self, VALUE name, VALUE value) {
182
231
  }
183
232
 
184
233
  static VALUE ov_xml_writer_flush(VALUE self) {
185
- ov_xml_writer_object *object;
234
+ ov_xml_writer_object* object = NULL;
235
+ int rc = 0;
236
+
186
237
  Data_Get_Struct(self, ov_xml_writer_object, object);
187
238
  ov_xml_writer_check_closed(object);
188
- int rc = xmlTextWriterFlush(object->writer);
239
+ rc = xmlTextWriterFlush(object->writer);
189
240
  if (rc < 0) {
190
241
  rb_raise(ov_error_class, "Can't flush XML writer");
191
242
  }
@@ -193,7 +244,8 @@ static VALUE ov_xml_writer_flush(VALUE self) {
193
244
  }
194
245
 
195
246
  static VALUE ov_xml_writer_close(VALUE self) {
196
- ov_xml_writer_object *object;
247
+ ov_xml_writer_object* object = NULL;
248
+
197
249
  Data_Get_Struct(self, ov_xml_writer_object, object);
198
250
  ov_xml_writer_check_closed(object);
199
251
  xmlFreeTextWriter(object->writer);
@@ -202,26 +254,27 @@ static VALUE ov_xml_writer_close(VALUE self) {
202
254
  }
203
255
 
204
256
  void ov_xml_writer_define(void) {
205
- // Define the class:
257
+ /* Load required modules: */
258
+ rb_require("stringio");
259
+
260
+ /* Define the class: */
206
261
  ov_xml_writer_class = rb_define_class_under(ov_module, "XmlWriter", rb_cObject);
207
262
 
208
- // Define the constructor:
263
+ /* Define the constructor: */
209
264
  rb_define_alloc_func(ov_xml_writer_class, ov_xml_writer_alloc);
210
- rb_define_method(ov_xml_writer_class, "initialize", ov_xml_writer_initialize, 1);
265
+ rb_define_method(ov_xml_writer_class, "initialize", ov_xml_writer_initialize, -1);
211
266
 
212
- // Define the methods:
213
- rb_define_method(ov_xml_writer_class, "io", ov_xml_writer_io, 0);
214
- rb_define_method(ov_xml_writer_class, "write_start", ov_xml_writer_write_start, 1);
215
- rb_define_method(ov_xml_writer_class, "write_end", ov_xml_writer_write_end, 0);
267
+ /* Define the methods: */
268
+ rb_define_method(ov_xml_writer_class, "close", ov_xml_writer_close, 0);
269
+ rb_define_method(ov_xml_writer_class, "flush", ov_xml_writer_flush, 0);
270
+ rb_define_method(ov_xml_writer_class, "string", ov_xml_writer_string, 0);
216
271
  rb_define_method(ov_xml_writer_class, "write_attribute", ov_xml_writer_write_attribute, 2);
217
272
  rb_define_method(ov_xml_writer_class, "write_element", ov_xml_writer_write_element, 2);
218
- rb_define_method(ov_xml_writer_class, "flush", ov_xml_writer_flush, 0);
219
- rb_define_method(ov_xml_writer_class, "close", ov_xml_writer_close, 0);
220
-
221
- // Create symbols:
222
- IO_SYMBOL = ID2SYM(rb_intern("io"));
223
- INDENT_SYMBOL = ID2SYM(rb_intern("indent"));
273
+ rb_define_method(ov_xml_writer_class, "write_end", ov_xml_writer_write_end, 0);
274
+ rb_define_method(ov_xml_writer_class, "write_start", ov_xml_writer_write_start, 1);
224
275
 
225
- // Create method identifiers:
276
+ /* Create method identifiers: */
277
+ STRING_ID = rb_intern("string");
278
+ STRING_IO_ID = rb_intern("StringIO");
226
279
  WRITE_ID = rb_intern("write");
227
280
  }