ovirt-engine-sdk 4.1.5 → 4.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2016 Red Hat, Inc.
2
+ Copyright (c) 2016-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,9 +17,46 @@ limitations under the License.
17
17
  #ifndef __OV_HTTP_CLIENT_H__
18
18
  #define __OV_HTTP_CLIENT_H__
19
19
 
20
- /* Class: */
20
+ #include <ruby.h>
21
+
22
+ #include <curl/curl.h>
23
+ #include <stdbool.h>
24
+
25
+ /* Data type and class: */
26
+ extern rb_data_type_t ov_http_client_type;
21
27
  extern VALUE ov_http_client_class;
22
28
 
29
+ /* Content: */
30
+ typedef struct {
31
+ /* The libcurl multi handle: */
32
+ CURLM* handle;
33
+
34
+ /* The logger: */
35
+ VALUE log;
36
+
37
+ /* This hash store the transfers that are pending. The key of the hash is the request that initiated the transfer,
38
+ and the value is the transfer itself. */
39
+ VALUE pending;
40
+
41
+ /* This hash stores the completed transfers. The key of the hash is the request, and the value is either the
42
+ response to that request, or else the exception that was generated while trying to process it. */
43
+ VALUE completed;
44
+
45
+ /* Copies of the options passed to the constructor: */
46
+ bool compress;
47
+ bool debug;
48
+ bool insecure;
49
+ char* ca_file;
50
+ char* proxy_url;
51
+ char* proxy_username;
52
+ char* proxy_password;
53
+ int timeout;
54
+ } ov_http_client_object;
55
+
56
+ /* Macro to get the pointer: */
57
+ #define ov_http_client_ptr(object, ptr) \
58
+ TypedData_Get_Struct((object), ov_http_client_object, &ov_http_client_type, (ptr))
59
+
23
60
  /* Initialization function: */
24
61
  extern void ov_http_client_define(void);
25
62
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2016 Red Hat, Inc.
2
+ Copyright (c) 2016-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.
@@ -39,219 +39,243 @@ static VALUE PASSWORD_SYMBOL;
39
39
  static VALUE TOKEN_SYMBOL;
40
40
  static VALUE KERBEROS_SYMBOL;
41
41
  static VALUE BODY_SYMBOL;
42
-
43
- static void ov_http_request_mark(ov_http_request_object *object) {
44
- if (!NIL_P(object->method)) {
45
- rb_gc_mark(object->method);
46
- }
47
- if (!NIL_P(object->url)) {
48
- rb_gc_mark(object->url);
49
- }
50
- if (!NIL_P(object->query)) {
51
- rb_gc_mark(object->query);
52
- }
53
- if (!NIL_P(object->headers)) {
54
- rb_gc_mark(object->headers);
55
- }
56
- if (!NIL_P(object->username)) {
57
- rb_gc_mark(object->username);
58
- }
59
- if (!NIL_P(object->password)) {
60
- rb_gc_mark(object->password);
61
- }
62
- if (!NIL_P(object->token)) {
63
- rb_gc_mark(object->token);
64
- }
65
- if (!NIL_P(object->kerberos)) {
66
- rb_gc_mark(object->kerberos);
67
- }
68
- if (!NIL_P(object->body)) {
69
- rb_gc_mark(object->body);
70
- }
42
+ static VALUE TIMEOUT_SYMBOL;
43
+
44
+ static void ov_http_request_mark(void* vptr) {
45
+ ov_http_request_object* ptr;
46
+
47
+ ptr = vptr;
48
+ rb_gc_mark(ptr->method);
49
+ rb_gc_mark(ptr->url);
50
+ rb_gc_mark(ptr->query);
51
+ rb_gc_mark(ptr->headers);
52
+ rb_gc_mark(ptr->username);
53
+ rb_gc_mark(ptr->password);
54
+ rb_gc_mark(ptr->token);
55
+ rb_gc_mark(ptr->kerberos);
56
+ rb_gc_mark(ptr->body);
57
+ rb_gc_mark(ptr->timeout);
71
58
  }
72
59
 
73
- static void ov_http_request_free(ov_http_request_object *object) {
74
- xfree(object);
60
+ static void ov_http_request_free(void* vptr) {
61
+ ov_http_request_object* ptr;
62
+
63
+ ptr = vptr;
64
+ xfree(ptr);
75
65
  }
76
66
 
67
+ rb_data_type_t ov_http_request_type = {
68
+ .wrap_struct_name = "OVHTTPREQUEST",
69
+ .function = {
70
+ .dmark = ov_http_request_mark,
71
+ .dfree = ov_http_request_free,
72
+ .dsize = NULL,
73
+ .reserved = { NULL, NULL }
74
+ },
75
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
76
+ .parent = NULL,
77
+ .data = NULL,
78
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
79
+ #endif
80
+ };
81
+
77
82
  static VALUE ov_http_request_alloc(VALUE klass) {
78
- ov_http_request_object* object = NULL;
79
-
80
- object = ALLOC(ov_http_request_object);
81
- object->method = Qnil;
82
- object->url = Qnil;
83
- object->query = Qnil;
84
- object->headers = Qnil;
85
- object->username = Qnil;
86
- object->password = Qnil;
87
- object->token = Qnil;
88
- object->kerberos = Qnil;
89
- object->body = Qnil;
90
- return Data_Wrap_Struct(klass, ov_http_request_mark, ov_http_request_free, object);
83
+ ov_http_request_object* ptr;
84
+
85
+ ptr = ALLOC(ov_http_request_object);
86
+ ptr->method = Qnil;
87
+ ptr->url = Qnil;
88
+ ptr->query = Qnil;
89
+ ptr->headers = Qnil;
90
+ ptr->username = Qnil;
91
+ ptr->password = Qnil;
92
+ ptr->token = Qnil;
93
+ ptr->kerberos = Qnil;
94
+ ptr->body = Qnil;
95
+ ptr->timeout = Qnil;
96
+ return TypedData_Wrap_Struct(klass, &ov_http_request_type, ptr);
91
97
  }
92
98
 
93
99
  static VALUE ov_http_request_get_method(VALUE self) {
94
- ov_http_request_object* object = NULL;
100
+ ov_http_request_object* ptr;
95
101
 
96
- Data_Get_Struct(self, ov_http_request_object, object);
97
- return object->method;
102
+ ov_http_request_ptr(self, ptr);
103
+ return ptr->method;
98
104
  }
99
105
 
100
106
  static VALUE ov_http_request_set_method(VALUE self, VALUE value) {
101
- ov_http_request_object* object = NULL;
107
+ ov_http_request_object* ptr;
102
108
 
103
- Data_Get_Struct(self, ov_http_request_object, object);
109
+ ov_http_request_ptr(self, ptr);
104
110
  if (NIL_P(value)) {
105
- object->method = GET_SYMBOL;
111
+ ptr->method = GET_SYMBOL;
106
112
  }
107
113
  else {
108
114
  Check_Type(value, T_SYMBOL);
109
- object->method = value;
115
+ ptr->method = value;
110
116
  }
111
117
  return Qnil;
112
118
  }
113
119
 
114
120
  static VALUE ov_http_request_get_url(VALUE self) {
115
- ov_http_request_object* object = NULL;
121
+ ov_http_request_object* ptr;
116
122
 
117
- Data_Get_Struct(self, ov_http_request_object, object);
118
- return object->url;
123
+ ov_http_request_ptr(self, ptr);
124
+ return ptr->url;
119
125
  }
120
126
 
121
127
  static VALUE ov_http_request_set_url(VALUE self, VALUE value) {
122
- ov_http_request_object* object = NULL;
128
+ ov_http_request_object* ptr;
123
129
 
124
- Data_Get_Struct(self, ov_http_request_object, object);
130
+ ov_http_request_ptr(self, ptr);
125
131
  if (!NIL_P(value)) {
126
132
  Check_Type(value, T_STRING);
127
133
  }
128
- object->url = value;
134
+ ptr->url = value;
129
135
  return Qnil;
130
136
  }
131
137
 
132
138
  static VALUE ov_http_request_get_query(VALUE self) {
133
- ov_http_request_object* object = NULL;
139
+ ov_http_request_object* ptr;
134
140
 
135
- Data_Get_Struct(self, ov_http_request_object, object);
136
- return object->query;
141
+ ov_http_request_ptr(self, ptr);
142
+ return ptr->query;
137
143
  }
138
144
 
139
145
  static VALUE ov_http_request_set_query(VALUE self, VALUE value) {
140
- ov_http_request_object* object = NULL;
146
+ ov_http_request_object* ptr;
141
147
 
142
- Data_Get_Struct(self, ov_http_request_object, object);
148
+ ov_http_request_ptr(self, ptr);
143
149
  if (!NIL_P(value)) {
144
150
  Check_Type(value, T_HASH);
145
151
  }
146
- object->query = value;
152
+ ptr->query = value;
147
153
  return Qnil;
148
154
  }
149
155
 
150
156
  static VALUE ov_http_request_get_headers(VALUE self) {
151
- ov_http_request_object* object = NULL;
157
+ ov_http_request_object* ptr;
152
158
 
153
- Data_Get_Struct(self, ov_http_request_object, object);
154
- return object->headers;
159
+ ov_http_request_ptr(self, ptr);
160
+ return ptr->headers;
155
161
  }
156
162
 
157
163
  static VALUE ov_http_request_set_headers(VALUE self, VALUE value) {
158
- ov_http_request_object* object = NULL;
164
+ ov_http_request_object* ptr;
159
165
 
160
- Data_Get_Struct(self, ov_http_request_object, object);
166
+ ov_http_request_ptr(self, ptr);
161
167
  if (NIL_P(value)) {
162
- object->headers = rb_hash_new();
168
+ ptr->headers = rb_hash_new();
163
169
  }
164
170
  else {
165
171
  Check_Type(value, T_HASH);
166
- object->headers = value;
172
+ ptr->headers = value;
167
173
  }
168
174
  return Qnil;
169
175
  }
170
176
 
171
177
  static VALUE ov_http_request_get_username(VALUE self) {
172
- ov_http_request_object* object = NULL;
178
+ ov_http_request_object* ptr;
173
179
 
174
- Data_Get_Struct(self, ov_http_request_object, object);
175
- return object->username;
180
+ ov_http_request_ptr(self, ptr);
181
+ return ptr->username;
176
182
  }
177
183
 
178
184
  static VALUE ov_http_request_set_username(VALUE self, VALUE value) {
179
- ov_http_request_object* object = NULL;
185
+ ov_http_request_object* ptr;
180
186
 
181
- Data_Get_Struct(self, ov_http_request_object, object);
187
+ ov_http_request_ptr(self, ptr);
182
188
  if (!NIL_P(value)) {
183
189
  Check_Type(value, T_STRING);
184
190
  }
185
- object->username = value;
191
+ ptr->username = value;
186
192
  return Qnil;
187
193
  }
188
194
 
189
195
  static VALUE ov_http_request_get_password(VALUE self) {
190
- ov_http_request_object* object = NULL;
196
+ ov_http_request_object* ptr;
191
197
 
192
- Data_Get_Struct(self, ov_http_request_object, object);
193
- return object->password;
198
+ ov_http_request_ptr(self, ptr);
199
+ return ptr->password;
194
200
  }
195
201
 
196
202
  static VALUE ov_http_request_set_password(VALUE self, VALUE value) {
197
- ov_http_request_object* object = NULL;
203
+ ov_http_request_object* ptr;
198
204
 
199
- Data_Get_Struct(self, ov_http_request_object, object);
205
+ ov_http_request_ptr(self, ptr);
200
206
  if (!NIL_P(value)) {
201
207
  Check_Type(value, T_STRING);
202
208
  }
203
- object->password = value;
209
+ ptr->password = value;
204
210
  return Qnil;
205
211
  }
206
212
 
207
213
  static VALUE ov_http_request_get_token(VALUE self) {
208
- ov_http_request_object* object = NULL;
214
+ ov_http_request_object* ptr;
209
215
 
210
- Data_Get_Struct(self, ov_http_request_object, object);
211
- return object->token;
216
+ ov_http_request_ptr(self, ptr);
217
+ return ptr->token;
212
218
  }
213
219
 
214
220
  static VALUE ov_http_request_set_token(VALUE self, VALUE value) {
215
- ov_http_request_object* object = NULL;
221
+ ov_http_request_object* ptr;
216
222
 
217
- Data_Get_Struct(self, ov_http_request_object, object);
223
+ ov_http_request_ptr(self, ptr);
218
224
  if (!NIL_P(value)) {
219
225
  Check_Type(value, T_STRING);
220
226
  }
221
- object->token = value;
227
+ ptr->token = value;
222
228
  return Qnil;
223
229
  }
224
230
 
225
231
  static VALUE ov_http_request_get_kerberos(VALUE self) {
226
- ov_http_request_object* object = NULL;
232
+ ov_http_request_object* ptr;
227
233
 
228
- Data_Get_Struct(self, ov_http_request_object, object);
229
- return object->kerberos;
234
+ ov_http_request_ptr(self, ptr);
235
+ return ptr->kerberos;
230
236
  }
231
237
 
232
238
  static VALUE ov_http_request_set_kerberos(VALUE self, VALUE value) {
233
- ov_http_request_object* object = NULL;
239
+ ov_http_request_object* ptr;
234
240
 
235
- Data_Get_Struct(self, ov_http_request_object, object);
236
- object->kerberos = RTEST(value);
241
+ ov_http_request_ptr(self, ptr);
242
+ ptr->kerberos = RTEST(value);
237
243
  return Qnil;
238
244
  }
239
245
 
240
246
  static VALUE ov_http_request_get_body(VALUE self) {
241
- ov_http_request_object* object = NULL;
247
+ ov_http_request_object* ptr;
242
248
 
243
- Data_Get_Struct(self, ov_http_request_object, object);
244
- return object->body;
249
+ ov_http_request_ptr(self, ptr);
250
+ return ptr->body;
245
251
  }
246
252
 
247
253
  static VALUE ov_http_request_set_body(VALUE self, VALUE value) {
248
- ov_http_request_object* object = NULL;
254
+ ov_http_request_object* ptr;
249
255
 
250
- Data_Get_Struct(self, ov_http_request_object, object);
256
+ ov_http_request_ptr(self, ptr);
251
257
  if (!NIL_P(value)) {
252
258
  Check_Type(value, T_STRING);
253
259
  }
254
- object->body = value;
260
+ ptr->body = value;
261
+ return Qnil;
262
+ }
263
+
264
+ static VALUE ov_http_request_get_timeout(VALUE self) {
265
+ ov_http_request_object* ptr;
266
+
267
+ ov_http_request_ptr(self, ptr);
268
+ return ptr->timeout;
269
+ }
270
+
271
+ static VALUE ov_http_request_set_timeout(VALUE self, VALUE value) {
272
+ ov_http_request_object* ptr;
273
+
274
+ ov_http_request_ptr(self, ptr);
275
+ if (!NIL_P(value)) {
276
+ Check_Type(value, T_FIXNUM);
277
+ }
278
+ ptr->timeout = value;
255
279
  return Qnil;
256
280
  }
257
281
 
@@ -279,13 +303,14 @@ static VALUE ov_http_request_initialize(int argc, VALUE* argv, VALUE self) {
279
303
  ov_http_request_set_password(self, rb_hash_aref(opts, PASSWORD_SYMBOL));
280
304
  ov_http_request_set_token(self, rb_hash_aref(opts, TOKEN_SYMBOL));
281
305
  ov_http_request_set_body(self, rb_hash_aref(opts, BODY_SYMBOL));
306
+ ov_http_request_set_timeout(self, rb_hash_aref(opts, TIMEOUT_SYMBOL));
282
307
 
283
308
  return self;
284
309
  }
285
310
 
286
311
  void ov_http_request_define(void) {
287
312
  /* Define the class: */
288
- ov_http_request_class = rb_define_class_under(ov_module, "HttpRequest", rb_cObject);
313
+ ov_http_request_class = rb_define_class_under(ov_module, "HttpRequest", rb_cData);
289
314
 
290
315
  /* Define the constructor: */
291
316
  rb_define_alloc_func(ov_http_request_class, ov_http_request_alloc);
@@ -310,6 +335,8 @@ void ov_http_request_define(void) {
310
335
  rb_define_method(ov_http_request_class, "kerberos=", ov_http_request_set_kerberos, 1);
311
336
  rb_define_method(ov_http_request_class, "body", ov_http_request_get_body, 0);
312
337
  rb_define_method(ov_http_request_class, "body=", ov_http_request_set_body, 1);
338
+ rb_define_method(ov_http_request_class, "timeout", ov_http_request_get_timeout, 0);
339
+ rb_define_method(ov_http_request_class, "timeout=", ov_http_request_set_timeout, 1);
313
340
 
314
341
  /* Define the symbols for the attributes: */
315
342
  URL_SYMBOL = ID2SYM(rb_intern("url"));
@@ -321,6 +348,7 @@ void ov_http_request_define(void) {
321
348
  TOKEN_SYMBOL = ID2SYM(rb_intern("token"));
322
349
  KERBEROS_SYMBOL = ID2SYM(rb_intern("kerberos"));
323
350
  BODY_SYMBOL = ID2SYM(rb_intern("body"));
351
+ TIMEOUT_SYMBOL = ID2SYM(rb_intern("timeout"));
324
352
 
325
353
  /* Define the symbols for the HTTP methods: */
326
354
  GET_SYMBOL = ID2SYM(rb_intern("GET"));
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2016 Red Hat, Inc.
2
+ Copyright (c) 2016-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,7 +17,10 @@ limitations under the License.
17
17
  #ifndef __OV_HTTP_REQUEST_H__
18
18
  #define __OV_HTTP_REQUEST_H__
19
19
 
20
- /* Class: */
20
+ #include <ruby.h>
21
+
22
+ /* Data type and class: */
23
+ extern rb_data_type_t ov_http_request_type;
21
24
  extern VALUE ov_http_request_class;
22
25
 
23
26
  /* Symbols for HTTP methods: */
@@ -37,8 +40,13 @@ typedef struct {
37
40
  VALUE token; /* String */
38
41
  VALUE kerberos; /* Boolean */
39
42
  VALUE body; /* String */
43
+ VALUE timeout; /* Integer */
40
44
  } ov_http_request_object;
41
45
 
46
+ /* Macro to get the pointer: */
47
+ #define ov_http_request_ptr(object, ptr) \
48
+ TypedData_Get_Struct((object), ov_http_request_object, &ov_http_request_type, (ptr))
49
+
42
50
  /* Initialization function: */
43
51
  extern void ov_http_request_define(void);
44
52