ovirt-engine-sdk 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ /*
2
+ Copyright (c) 2016 Red Hat, Inc.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ #ifndef __OV_HTTP_CLIENT_H__
18
+ #define __OV_HTTP_CLIENT_H__
19
+
20
+ /* Classes: */
21
+ VALUE ov_http_client_class;
22
+
23
+ /* Initialization function: */
24
+ extern void ov_http_client_define(void);
25
+
26
+ #endif
@@ -0,0 +1,321 @@
1
+ /*
2
+ Copyright (c) 2016 Red Hat, Inc.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ #include <ruby.h>
18
+
19
+ #include "ov_module.h"
20
+ #include "ov_error.h"
21
+ #include "ov_http_request.h"
22
+
23
+ /* Symbols for the attributes: */
24
+ static VALUE METHOD_SYMBOL;
25
+ static VALUE URL_SYMBOL;
26
+ static VALUE QUERY_SYMBOL;
27
+ static VALUE HEADERS_SYMBOL;
28
+ static VALUE USERNAME_SYMBOL;
29
+ static VALUE PASSWORD_SYMBOL;
30
+ static VALUE TOKEN_SYMBOL;
31
+ static VALUE KERBEROS_SYMBOL;
32
+ static VALUE BODY_SYMBOL;
33
+
34
+ static void ov_http_request_mark(ov_http_request_object *object) {
35
+ if (!NIL_P(object->method)) {
36
+ rb_gc_mark(object->method);
37
+ }
38
+ if (!NIL_P(object->url)) {
39
+ rb_gc_mark(object->url);
40
+ }
41
+ if (!NIL_P(object->query)) {
42
+ rb_gc_mark(object->query);
43
+ }
44
+ if (!NIL_P(object->headers)) {
45
+ rb_gc_mark(object->headers);
46
+ }
47
+ if (!NIL_P(object->username)) {
48
+ rb_gc_mark(object->username);
49
+ }
50
+ if (!NIL_P(object->password)) {
51
+ rb_gc_mark(object->password);
52
+ }
53
+ if (!NIL_P(object->token)) {
54
+ rb_gc_mark(object->token);
55
+ }
56
+ if (!NIL_P(object->kerberos)) {
57
+ rb_gc_mark(object->kerberos);
58
+ }
59
+ if (!NIL_P(object->body)) {
60
+ rb_gc_mark(object->body);
61
+ }
62
+ }
63
+
64
+ static void ov_http_request_free(ov_http_request_object *object) {
65
+ xfree(object);
66
+ }
67
+
68
+ static VALUE ov_http_request_alloc(VALUE klass) {
69
+ ov_http_request_object* object = NULL;
70
+
71
+ object = ALLOC(ov_http_request_object);
72
+ object->method = Qnil;
73
+ object->url = Qnil;
74
+ object->query = Qnil;
75
+ object->headers = Qnil;
76
+ object->username = Qnil;
77
+ object->password = Qnil;
78
+ object->token = Qnil;
79
+ object->kerberos = Qnil;
80
+ object->body = Qnil;
81
+ return Data_Wrap_Struct(klass, ov_http_request_mark, ov_http_request_free, object);
82
+ }
83
+
84
+ static VALUE ov_http_request_get_method(VALUE self) {
85
+ ov_http_request_object* object = NULL;
86
+
87
+ Data_Get_Struct(self, ov_http_request_object, object);
88
+ return object->method;
89
+ }
90
+
91
+ static VALUE ov_http_request_set_method(VALUE self, VALUE value) {
92
+ ov_http_request_object* object = NULL;
93
+
94
+ Data_Get_Struct(self, ov_http_request_object, object);
95
+ if (NIL_P(value)) {
96
+ object->method = GET_SYMBOL;
97
+ }
98
+ else {
99
+ Check_Type(value, T_SYMBOL);
100
+ object->method = value;
101
+ }
102
+ return Qnil;
103
+ }
104
+
105
+ static VALUE ov_http_request_get_url(VALUE self) {
106
+ ov_http_request_object* object = NULL;
107
+
108
+ Data_Get_Struct(self, ov_http_request_object, object);
109
+ return object->url;
110
+ }
111
+
112
+ static VALUE ov_http_request_set_url(VALUE self, VALUE value) {
113
+ ov_http_request_object* object = NULL;
114
+
115
+ Data_Get_Struct(self, ov_http_request_object, object);
116
+ if (!NIL_P(value)) {
117
+ Check_Type(value, T_STRING);
118
+ }
119
+ object->url = value;
120
+ return Qnil;
121
+ }
122
+
123
+ static VALUE ov_http_request_get_query(VALUE self) {
124
+ ov_http_request_object* object = NULL;
125
+
126
+ Data_Get_Struct(self, ov_http_request_object, object);
127
+ return object->query;
128
+ }
129
+
130
+ static VALUE ov_http_request_set_query(VALUE self, VALUE value) {
131
+ ov_http_request_object* object = NULL;
132
+
133
+ Data_Get_Struct(self, ov_http_request_object, object);
134
+ if (!NIL_P(value)) {
135
+ Check_Type(value, T_HASH);
136
+ }
137
+ object->query = value;
138
+ return Qnil;
139
+ }
140
+
141
+ static VALUE ov_http_request_get_headers(VALUE self) {
142
+ ov_http_request_object* object = NULL;
143
+
144
+ Data_Get_Struct(self, ov_http_request_object, object);
145
+ return object->headers;
146
+ }
147
+
148
+ static VALUE ov_http_request_set_headers(VALUE self, VALUE value) {
149
+ ov_http_request_object* object = NULL;
150
+
151
+ Data_Get_Struct(self, ov_http_request_object, object);
152
+ if (NIL_P(value)) {
153
+ object->headers = rb_hash_new();
154
+ }
155
+ else {
156
+ Check_Type(value, T_HASH);
157
+ object->headers = value;
158
+ }
159
+ return Qnil;
160
+ }
161
+
162
+ static VALUE ov_http_request_get_username(VALUE self) {
163
+ ov_http_request_object* object = NULL;
164
+
165
+ Data_Get_Struct(self, ov_http_request_object, object);
166
+ return object->username;
167
+ }
168
+
169
+ static VALUE ov_http_request_set_username(VALUE self, VALUE value) {
170
+ ov_http_request_object* object = NULL;
171
+
172
+ Data_Get_Struct(self, ov_http_request_object, object);
173
+ if (!NIL_P(value)) {
174
+ Check_Type(value, T_STRING);
175
+ }
176
+ object->username = value;
177
+ return Qnil;
178
+ }
179
+
180
+ static VALUE ov_http_request_get_password(VALUE self) {
181
+ ov_http_request_object* object = NULL;
182
+
183
+ Data_Get_Struct(self, ov_http_request_object, object);
184
+ return object->password;
185
+ }
186
+
187
+ static VALUE ov_http_request_set_password(VALUE self, VALUE value) {
188
+ ov_http_request_object* object = NULL;
189
+
190
+ Data_Get_Struct(self, ov_http_request_object, object);
191
+ if (!NIL_P(value)) {
192
+ Check_Type(value, T_STRING);
193
+ }
194
+ object->password = value;
195
+ return Qnil;
196
+ }
197
+
198
+ static VALUE ov_http_request_get_token(VALUE self) {
199
+ ov_http_request_object* object = NULL;
200
+
201
+ Data_Get_Struct(self, ov_http_request_object, object);
202
+ return object->token;
203
+ }
204
+
205
+ static VALUE ov_http_request_set_token(VALUE self, VALUE value) {
206
+ ov_http_request_object* object = NULL;
207
+
208
+ Data_Get_Struct(self, ov_http_request_object, object);
209
+ if (!NIL_P(value)) {
210
+ Check_Type(value, T_STRING);
211
+ }
212
+ object->token = value;
213
+ return Qnil;
214
+ }
215
+
216
+ static VALUE ov_http_request_get_kerberos(VALUE self) {
217
+ ov_http_request_object* object = NULL;
218
+
219
+ Data_Get_Struct(self, ov_http_request_object, object);
220
+ return object->kerberos;
221
+ }
222
+
223
+ static VALUE ov_http_request_set_kerberos(VALUE self, VALUE value) {
224
+ ov_http_request_object* object = NULL;
225
+
226
+ Data_Get_Struct(self, ov_http_request_object, object);
227
+ object->kerberos = RTEST(value);
228
+ return Qnil;
229
+ }
230
+
231
+ static VALUE ov_http_request_get_body(VALUE self) {
232
+ ov_http_request_object* object = NULL;
233
+
234
+ Data_Get_Struct(self, ov_http_request_object, object);
235
+ return object->body;
236
+ }
237
+
238
+ static VALUE ov_http_request_set_body(VALUE self, VALUE value) {
239
+ ov_http_request_object* object = NULL;
240
+
241
+ Data_Get_Struct(self, ov_http_request_object, object);
242
+ if (!NIL_P(value)) {
243
+ Check_Type(value, T_STRING);
244
+ }
245
+ object->body = value;
246
+ return Qnil;
247
+ }
248
+
249
+ static VALUE ov_http_request_initialize(int argc, VALUE* argv, VALUE self) {
250
+ VALUE opts;
251
+
252
+ /* Check the number of arguments: */
253
+ if (argc > 1) {
254
+ rb_raise(ov_error_class, "Expected at most one argument, 'opts', but received %d", argc);
255
+ }
256
+ opts = argc > 0? argv[0]: Qnil;
257
+ if (NIL_P(opts)) {
258
+ opts = rb_hash_new();
259
+ }
260
+ else {
261
+ Check_Type(opts, T_HASH);
262
+ }
263
+
264
+ /* Get the values of the options: */
265
+ ov_http_request_set_method(self, rb_hash_aref(opts, METHOD_SYMBOL));
266
+ ov_http_request_set_url(self, rb_hash_aref(opts, URL_SYMBOL));
267
+ ov_http_request_set_query(self, rb_hash_aref(opts, QUERY_SYMBOL));
268
+ ov_http_request_set_headers(self, rb_hash_aref(opts, HEADERS_SYMBOL));
269
+ ov_http_request_set_username(self, rb_hash_aref(opts, USERNAME_SYMBOL));
270
+ ov_http_request_set_password(self, rb_hash_aref(opts, PASSWORD_SYMBOL));
271
+ ov_http_request_set_token(self, rb_hash_aref(opts, TOKEN_SYMBOL));
272
+ ov_http_request_set_body(self, rb_hash_aref(opts, BODY_SYMBOL));
273
+
274
+ return self;
275
+ }
276
+
277
+ void ov_http_request_define(void) {
278
+ /* Define the class: */
279
+ ov_http_request_class = rb_define_class_under(ov_module, "HttpRequest", rb_cObject);
280
+
281
+ /* Define the constructor: */
282
+ rb_define_alloc_func(ov_http_request_class, ov_http_request_alloc);
283
+ rb_define_method(ov_http_request_class, "initialize", ov_http_request_initialize, -1);
284
+
285
+ /* Define the methods: */
286
+ rb_define_method(ov_http_request_class, "method", ov_http_request_get_method, 0);
287
+ rb_define_method(ov_http_request_class, "method=", ov_http_request_set_method, 1);
288
+ rb_define_method(ov_http_request_class, "url", ov_http_request_get_url, 0);
289
+ rb_define_method(ov_http_request_class, "url=", ov_http_request_set_url, 1);
290
+ rb_define_method(ov_http_request_class, "query", ov_http_request_get_query, 0);
291
+ rb_define_method(ov_http_request_class, "query=", ov_http_request_set_query, 1);
292
+ rb_define_method(ov_http_request_class, "headers", ov_http_request_get_headers, 0);
293
+ rb_define_method(ov_http_request_class, "headers=", ov_http_request_set_headers, 1);
294
+ rb_define_method(ov_http_request_class, "username", ov_http_request_get_username, 0);
295
+ rb_define_method(ov_http_request_class, "username=", ov_http_request_set_username, 1);
296
+ rb_define_method(ov_http_request_class, "password", ov_http_request_get_password, 0);
297
+ rb_define_method(ov_http_request_class, "password=", ov_http_request_set_password, 1);
298
+ rb_define_method(ov_http_request_class, "token", ov_http_request_get_token, 0);
299
+ rb_define_method(ov_http_request_class, "token=", ov_http_request_set_token, 1);
300
+ rb_define_method(ov_http_request_class, "kerberos", ov_http_request_get_kerberos, 0);
301
+ rb_define_method(ov_http_request_class, "kerberos=", ov_http_request_set_kerberos, 1);
302
+ rb_define_method(ov_http_request_class, "body", ov_http_request_get_body, 0);
303
+ rb_define_method(ov_http_request_class, "body=", ov_http_request_set_body, 1);
304
+
305
+ /* Define the symbols for the attributes: */
306
+ URL_SYMBOL = ID2SYM(rb_intern("url"));
307
+ METHOD_SYMBOL = ID2SYM(rb_intern("method"));
308
+ QUERY_SYMBOL = ID2SYM(rb_intern("query"));
309
+ HEADERS_SYMBOL = ID2SYM(rb_intern("headers"));
310
+ USERNAME_SYMBOL = ID2SYM(rb_intern("username"));
311
+ PASSWORD_SYMBOL = ID2SYM(rb_intern("password"));
312
+ TOKEN_SYMBOL = ID2SYM(rb_intern("token"));
313
+ KERBEROS_SYMBOL = ID2SYM(rb_intern("kerberos"));
314
+ BODY_SYMBOL = ID2SYM(rb_intern("body"));
315
+
316
+ /* Define the symbols for the HTTP methods: */
317
+ GET_SYMBOL = ID2SYM(rb_intern("GET"));
318
+ POST_SYMBOL = ID2SYM(rb_intern("POST"));
319
+ PUT_SYMBOL = ID2SYM(rb_intern("PUT"));
320
+ DELETE_SYMBOL = ID2SYM(rb_intern("DELETE"));
321
+ }
@@ -0,0 +1,45 @@
1
+ /*
2
+ Copyright (c) 2016 Red Hat, Inc.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ #ifndef __OV_HTTP_REQUEST_H__
18
+ #define __OV_HTTP_REQUEST_H__
19
+
20
+ /* Class: */
21
+ VALUE ov_http_request_class;
22
+
23
+ /* Symbols for HTTP methods: */
24
+ VALUE GET_SYMBOL;
25
+ VALUE POST_SYMBOL;
26
+ VALUE PUT_SYMBOL;
27
+ VALUE DELETE_SYMBOL;
28
+
29
+ /* Content: */
30
+ typedef struct {
31
+ VALUE method; /* Symbol */
32
+ VALUE url; /* String */
33
+ VALUE query; /* Hash<String, String> */
34
+ VALUE headers; /* Hash<String, String> */
35
+ VALUE username; /* String */
36
+ VALUE password; /* String */
37
+ VALUE token; /* String */
38
+ VALUE kerberos; /* Boolean */
39
+ VALUE body; /* String */
40
+ } ov_http_request_object;
41
+
42
+ /* Initialization function: */
43
+ extern void ov_http_request_define(void);
44
+
45
+ #endif
@@ -0,0 +1,180 @@
1
+ /*
2
+ Copyright (c) 2016 Red Hat, Inc.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ #include <ruby.h>
18
+
19
+ #include "ov_module.h"
20
+ #include "ov_error.h"
21
+ #include "ov_http_response.h"
22
+
23
+ static VALUE BODY_SYMBOL;
24
+ static VALUE CODE_SYMBOL;
25
+ static VALUE HEADERS_SYMBOL;
26
+ static VALUE MESSAGE_SYMBOL;
27
+
28
+ static void ov_http_response_mark(ov_http_response_object *object) {
29
+ if (!NIL_P(object->body)) {
30
+ rb_gc_mark(object->body);
31
+ }
32
+ if (!NIL_P(object->code)) {
33
+ rb_gc_mark(object->code);
34
+ }
35
+ if (!NIL_P(object->headers)) {
36
+ rb_gc_mark(object->headers);
37
+ }
38
+ if (!NIL_P(object->message)) {
39
+ rb_gc_mark(object->message);
40
+ }
41
+ }
42
+
43
+ static void ov_http_response_free(ov_http_response_object *object) {
44
+ xfree(object);
45
+ }
46
+
47
+ static VALUE ov_http_response_alloc(VALUE klass) {
48
+ ov_http_response_object* object = NULL;
49
+
50
+ object = ALLOC(ov_http_response_object);
51
+ object->body = Qnil;
52
+ object->code = Qnil;
53
+ object->headers = Qnil;
54
+ object->message = Qnil;
55
+ return Data_Wrap_Struct(klass, ov_http_response_mark, ov_http_response_free, object);
56
+ }
57
+
58
+ static VALUE ov_http_response_get_body(VALUE self) {
59
+ ov_http_response_object* object = NULL;
60
+
61
+ Data_Get_Struct(self, ov_http_response_object, object);
62
+ return object->body;
63
+ }
64
+
65
+ static VALUE ov_http_response_set_body(VALUE self, VALUE value) {
66
+ ov_http_response_object* object = NULL;
67
+
68
+ Data_Get_Struct(self, ov_http_response_object, object);
69
+ if (!NIL_P(value)) {
70
+ Check_Type(value, T_STRING);
71
+ }
72
+ object->body = value;
73
+ return Qnil;
74
+ }
75
+
76
+ static VALUE ov_http_response_get_code(VALUE self) {
77
+ ov_http_response_object* object = NULL;
78
+
79
+ Data_Get_Struct(self, ov_http_response_object, object);
80
+ return object->code;
81
+ }
82
+
83
+ static VALUE ov_http_response_set_code(VALUE self, VALUE value) {
84
+ ov_http_response_object* object = NULL;
85
+
86
+ Data_Get_Struct(self, ov_http_response_object, object);
87
+ if (!NIL_P(value)) {
88
+ Check_Type(value, T_FIXNUM);
89
+ }
90
+ object->code = value;
91
+ return Qnil;
92
+ }
93
+
94
+ static VALUE ov_http_response_get_headers(VALUE self) {
95
+ ov_http_response_object* object = NULL;
96
+
97
+ Data_Get_Struct(self, ov_http_response_object, object);
98
+ return object->headers;
99
+ }
100
+
101
+ static VALUE ov_http_response_set_headers(VALUE self, VALUE value) {
102
+ ov_http_response_object* object = NULL;
103
+
104
+ Data_Get_Struct(self, ov_http_response_object, object);
105
+ if (NIL_P(value)) {
106
+ object->headers = rb_hash_new();
107
+ }
108
+ else {
109
+ Check_Type(value, T_HASH);
110
+ object->headers = value;
111
+ }
112
+ return Qnil;
113
+ }
114
+
115
+ static VALUE ov_http_response_get_message(VALUE self) {
116
+ ov_http_response_object* object = NULL;
117
+
118
+ Data_Get_Struct(self, ov_http_response_object, object);
119
+ return object->message;
120
+ }
121
+
122
+ static VALUE ov_http_response_set_message(VALUE self, VALUE value) {
123
+ ov_http_response_object* object = NULL;
124
+
125
+ Data_Get_Struct(self, ov_http_response_object, object);
126
+ if (!NIL_P(value)) {
127
+ Check_Type(value, T_STRING);
128
+ }
129
+ object->message = value;
130
+ return Qnil;
131
+ }
132
+
133
+ static VALUE ov_http_response_initialize(int argc, VALUE* argv, VALUE self) {
134
+ VALUE opts;
135
+
136
+ /* Check the number of arguments: */
137
+ if (argc > 1) {
138
+ rb_raise(ov_error_class, "Expected at most one argument, 'opts', but received %d", argc);
139
+ }
140
+ opts = argc > 0? argv[0]: Qnil;
141
+ if (NIL_P(opts)) {
142
+ opts = rb_hash_new();
143
+ }
144
+ else {
145
+ Check_Type(opts, T_HASH);
146
+ }
147
+
148
+ /* Get the values of the options: */
149
+ ov_http_response_set_body(self, rb_hash_aref(opts, BODY_SYMBOL));
150
+ ov_http_response_set_headers(self, rb_hash_aref(opts, HEADERS_SYMBOL));
151
+ ov_http_response_set_code(self, rb_hash_aref(opts, CODE_SYMBOL));
152
+ ov_http_response_set_message(self, rb_hash_aref(opts, MESSAGE_SYMBOL));
153
+
154
+ return self;
155
+ }
156
+
157
+ void ov_http_response_define(void) {
158
+ /* Define the class: */
159
+ ov_http_response_class = rb_define_class_under(ov_module, "HttpResponse", rb_cObject);
160
+
161
+ /* Define the constructor: */
162
+ rb_define_alloc_func(ov_http_response_class, ov_http_response_alloc);
163
+ rb_define_method(ov_http_response_class, "initialize", ov_http_response_initialize, -1);
164
+
165
+ /* Define the methods: */
166
+ rb_define_method(ov_http_response_class, "body", ov_http_response_get_body, 0);
167
+ rb_define_method(ov_http_response_class, "body=", ov_http_response_set_body, 1);
168
+ rb_define_method(ov_http_response_class, "code", ov_http_response_get_code, 0);
169
+ rb_define_method(ov_http_response_class, "code=", ov_http_response_set_code, 1);
170
+ rb_define_method(ov_http_response_class, "headers", ov_http_response_get_headers, 0);
171
+ rb_define_method(ov_http_response_class, "headers=", ov_http_response_set_headers, 1);
172
+ rb_define_method(ov_http_response_class, "message", ov_http_response_get_message, 0);
173
+ rb_define_method(ov_http_response_class, "message=", ov_http_response_set_message, 1);
174
+
175
+ /* Define the symbols: */
176
+ BODY_SYMBOL = ID2SYM(rb_intern("body"));
177
+ CODE_SYMBOL = ID2SYM(rb_intern("code"));
178
+ HEADERS_SYMBOL = ID2SYM(rb_intern("headers"));
179
+ MESSAGE_SYMBOL = ID2SYM(rb_intern("message"));
180
+ }