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.
@@ -0,0 +1,210 @@
1
+ /*
2
+ Copyright (c) 2016-2017 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
+ /* The class: */
24
+ VALUE ov_http_response_class;
25
+
26
+ static VALUE BODY_SYMBOL;
27
+ static VALUE CODE_SYMBOL;
28
+ static VALUE HEADERS_SYMBOL;
29
+ static VALUE MESSAGE_SYMBOL;
30
+
31
+ static void ov_http_response_mark(void* vptr) {
32
+ ov_http_response_object* ptr;
33
+
34
+ ptr = vptr;
35
+ rb_gc_mark(ptr->body);
36
+ rb_gc_mark(ptr->code);
37
+ rb_gc_mark(ptr->headers);
38
+ rb_gc_mark(ptr->message);
39
+ }
40
+
41
+ static void ov_http_response_free(void* vptr) {
42
+ ov_http_response_object* ptr;
43
+
44
+ ptr = vptr;
45
+ xfree(ptr);
46
+ }
47
+
48
+ rb_data_type_t ov_http_response_type = {
49
+ .wrap_struct_name = "OVHTTPRESPONSE",
50
+ .function = {
51
+ .dmark = ov_http_response_mark,
52
+ .dfree = ov_http_response_free,
53
+ .dsize = NULL,
54
+ .reserved = { NULL, NULL }
55
+ },
56
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
57
+ .parent = NULL,
58
+ .data = NULL,
59
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
60
+ #endif
61
+ };
62
+
63
+ static VALUE ov_http_response_alloc(VALUE klass) {
64
+ ov_http_response_object* ptr;
65
+
66
+ ptr = ALLOC(ov_http_response_object);
67
+ ptr->body = Qnil;
68
+ ptr->code = Qnil;
69
+ ptr->headers = Qnil;
70
+ ptr->message = Qnil;
71
+ return TypedData_Wrap_Struct(klass, &ov_http_response_type, ptr);
72
+ }
73
+
74
+ static VALUE ov_http_response_get_body(VALUE self) {
75
+ ov_http_response_object* ptr;
76
+
77
+ ov_http_response_ptr(self, ptr);
78
+ return ptr->body;
79
+ }
80
+
81
+ static VALUE ov_http_response_set_body(VALUE self, VALUE value) {
82
+ ov_http_response_object* ptr;
83
+
84
+ ov_http_response_ptr(self, ptr);
85
+ if (!NIL_P(value)) {
86
+ Check_Type(value, T_STRING);
87
+ }
88
+ ptr->body = value;
89
+ return Qnil;
90
+ }
91
+
92
+ static VALUE ov_http_response_get_code(VALUE self) {
93
+ ov_http_response_object* ptr;
94
+
95
+ ov_http_response_ptr(self, ptr);
96
+ return ptr->code;
97
+ }
98
+
99
+ static VALUE ov_http_response_set_code(VALUE self, VALUE value) {
100
+ ov_http_response_object* ptr;
101
+
102
+ ov_http_response_ptr(self, ptr);
103
+ if (!NIL_P(value)) {
104
+ Check_Type(value, T_FIXNUM);
105
+ }
106
+ ptr->code = value;
107
+ return Qnil;
108
+ }
109
+
110
+ static VALUE ov_http_response_get_headers(VALUE self) {
111
+ ov_http_response_object* ptr;
112
+
113
+ ov_http_response_ptr(self, ptr);
114
+ return ptr->headers;
115
+ }
116
+
117
+ static VALUE ov_http_response_set_headers(VALUE self, VALUE value) {
118
+ ov_http_response_object* ptr;
119
+
120
+ ov_http_response_ptr(self, ptr);
121
+ if (NIL_P(value)) {
122
+ ptr->headers = rb_hash_new();
123
+ }
124
+ else {
125
+ Check_Type(value, T_HASH);
126
+ ptr->headers = value;
127
+ }
128
+ return Qnil;
129
+ }
130
+
131
+ static VALUE ov_http_response_get_message(VALUE self) {
132
+ ov_http_response_object* ptr;
133
+
134
+ ov_http_response_ptr(self, ptr);
135
+ return ptr->message;
136
+ }
137
+
138
+ static VALUE ov_http_response_set_message(VALUE self, VALUE value) {
139
+ ov_http_response_object* ptr;
140
+
141
+ ov_http_response_ptr(self, ptr);
142
+ if (!NIL_P(value)) {
143
+ Check_Type(value, T_STRING);
144
+ }
145
+ ptr->message = value;
146
+ return Qnil;
147
+ }
148
+
149
+ static VALUE ov_http_response_inspect(VALUE self) {
150
+ ov_http_response_object* ptr;
151
+
152
+ ov_http_response_ptr(self, ptr);
153
+ return rb_sprintf(
154
+ "#<%"PRIsVALUE":%"PRIsVALUE" %"PRIsVALUE">",
155
+ ov_http_response_class,
156
+ ptr->code,
157
+ ptr->message
158
+ );
159
+ }
160
+
161
+ static VALUE ov_http_response_initialize(int argc, VALUE* argv, VALUE self) {
162
+ VALUE opts;
163
+
164
+ /* Check the number of arguments: */
165
+ if (argc > 1) {
166
+ rb_raise(ov_error_class, "Expected at most one argument, 'opts', but received %d", argc);
167
+ }
168
+ opts = argc > 0? argv[0]: Qnil;
169
+ if (NIL_P(opts)) {
170
+ opts = rb_hash_new();
171
+ }
172
+ else {
173
+ Check_Type(opts, T_HASH);
174
+ }
175
+
176
+ /* Get the values of the options: */
177
+ ov_http_response_set_body(self, rb_hash_aref(opts, BODY_SYMBOL));
178
+ ov_http_response_set_headers(self, rb_hash_aref(opts, HEADERS_SYMBOL));
179
+ ov_http_response_set_code(self, rb_hash_aref(opts, CODE_SYMBOL));
180
+ ov_http_response_set_message(self, rb_hash_aref(opts, MESSAGE_SYMBOL));
181
+
182
+ return self;
183
+ }
184
+
185
+ void ov_http_response_define(void) {
186
+ /* Define the class: */
187
+ ov_http_response_class = rb_define_class_under(ov_module, "HttpResponse", rb_cData);
188
+
189
+ /* Define the constructor: */
190
+ rb_define_alloc_func(ov_http_response_class, ov_http_response_alloc);
191
+ rb_define_method(ov_http_response_class, "initialize", ov_http_response_initialize, -1);
192
+
193
+ /* Define the methods: */
194
+ rb_define_method(ov_http_response_class, "body", ov_http_response_get_body, 0);
195
+ rb_define_method(ov_http_response_class, "body=", ov_http_response_set_body, 1);
196
+ rb_define_method(ov_http_response_class, "code", ov_http_response_get_code, 0);
197
+ rb_define_method(ov_http_response_class, "code=", ov_http_response_set_code, 1);
198
+ rb_define_method(ov_http_response_class, "headers", ov_http_response_get_headers, 0);
199
+ rb_define_method(ov_http_response_class, "headers=", ov_http_response_set_headers, 1);
200
+ rb_define_method(ov_http_response_class, "message", ov_http_response_get_message, 0);
201
+ rb_define_method(ov_http_response_class, "message=", ov_http_response_set_message, 1);
202
+ rb_define_method(ov_http_response_class, "inspect", ov_http_response_inspect, 0);
203
+ rb_define_method(ov_http_response_class, "to_s", ov_http_response_inspect, 0);
204
+
205
+ /* Define the symbols: */
206
+ BODY_SYMBOL = ID2SYM(rb_intern("body"));
207
+ CODE_SYMBOL = ID2SYM(rb_intern("code"));
208
+ HEADERS_SYMBOL = ID2SYM(rb_intern("headers"));
209
+ MESSAGE_SYMBOL = ID2SYM(rb_intern("message"));
210
+ }
@@ -0,0 +1,41 @@
1
+ /*
2
+ Copyright (c) 2016-2017 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_RESPONSE_H__
18
+ #define __OV_HTTP_RESPONSE_H__
19
+
20
+ #include <ruby.h>
21
+
22
+ /* Data type and class: */
23
+ extern rb_data_type_t ov_http_response_type;
24
+ extern VALUE ov_http_response_class;
25
+
26
+ /* Content: */
27
+ typedef struct {
28
+ VALUE body; /* String */
29
+ VALUE code; /* Integer */
30
+ VALUE headers; /* Hash<String, String> */
31
+ VALUE message; /* String */
32
+ } ov_http_response_object;
33
+
34
+ /* Macro to get the pointer: */
35
+ #define ov_http_response_ptr(object, ptr) \
36
+ TypedData_Get_Struct((object), ov_http_response_object, &ov_http_response_type, (ptr))
37
+
38
+ /* Initialization function: */
39
+ extern void ov_http_response_define(void);
40
+
41
+ #endif
@@ -0,0 +1,91 @@
1
+ /*
2
+ Copyright (c) 2017 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 <stdbool.h>
20
+
21
+ #include "ov_module.h"
22
+ #include "ov_http_transfer.h"
23
+
24
+ /* Class: */
25
+ VALUE ov_http_transfer_class;
26
+
27
+ static void ov_http_transfer_mark(void* vptr) {
28
+ ov_http_transfer_object* ptr;
29
+
30
+ ptr = vptr;
31
+ rb_gc_mark(ptr->client);
32
+ rb_gc_mark(ptr->request);
33
+ rb_gc_mark(ptr->response);
34
+ rb_gc_mark(ptr->in);
35
+ rb_gc_mark(ptr->out);
36
+ }
37
+
38
+ static void ov_http_transfer_free(void* vptr) {
39
+ ov_http_transfer_object* ptr;
40
+
41
+ ptr = vptr;
42
+ xfree(ptr);
43
+ }
44
+
45
+ rb_data_type_t ov_http_transfer_type = {
46
+ .wrap_struct_name = "OVHTTPTRANSFER",
47
+ .function = {
48
+ .dmark = ov_http_transfer_mark,
49
+ .dfree = ov_http_transfer_free,
50
+ .dsize = NULL,
51
+ .reserved = { NULL, NULL }
52
+ },
53
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
54
+ .parent = NULL,
55
+ .data = NULL,
56
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY,
57
+ #endif
58
+ };
59
+
60
+ static VALUE ov_http_transfer_alloc(VALUE klass) {
61
+ ov_http_transfer_object* ptr;
62
+
63
+ ptr = ALLOC(ov_http_transfer_object);
64
+ ptr->client = Qnil;
65
+ ptr->request = Qnil;
66
+ ptr->response = Qnil;
67
+ ptr->in = Qnil;
68
+ ptr->out = Qnil;
69
+ ptr->headers = NULL;
70
+ ptr->cancel = false;
71
+ return TypedData_Wrap_Struct(klass, &ov_http_transfer_type, ptr);
72
+ }
73
+
74
+ static VALUE ov_http_transfer_inspect(VALUE self) {
75
+ ov_http_transfer_object* ptr;
76
+
77
+ ov_http_transfer_ptr(self, ptr);
78
+ return rb_sprintf("#<%"PRIsVALUE":%p>", ov_http_transfer_class, ptr);
79
+ }
80
+
81
+ void ov_http_transfer_define(void) {
82
+ /* Define the class: */
83
+ ov_http_transfer_class = rb_define_class_under(ov_module, "HttpTransfer", rb_cData);
84
+
85
+ /* Define the constructor: */
86
+ rb_define_alloc_func(ov_http_transfer_class, ov_http_transfer_alloc);
87
+
88
+ /* Define the methods: */
89
+ rb_define_method(ov_http_transfer_class, "inspect", ov_http_transfer_inspect, 0);
90
+ rb_define_method(ov_http_transfer_class, "to_s", ov_http_transfer_inspect, 0);
91
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ Copyright (c) 2017 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_TRANSFER_H__
18
+ #define __OV_HTTP_TRANSFER_H__
19
+
20
+ #include <ruby.h>
21
+
22
+ #include <stdbool.h>
23
+ #include <curl/curl.h>
24
+
25
+ /* Data type and class: */
26
+ extern rb_data_type_t ov_http_transfer_type;
27
+ extern VALUE ov_http_transfer_class;
28
+
29
+ /* Content: */
30
+ typedef struct {
31
+ VALUE client; /* HttpClient */
32
+ VALUE request; /* HttpRequest */
33
+ VALUE response; /* HttpResponse */
34
+ VALUE in; /* IO */
35
+ VALUE out; /* IO */
36
+ struct curl_slist* headers;
37
+ bool cancel;
38
+ } ov_http_transfer_object;
39
+
40
+ /* Macro to get the pointer: */
41
+ #define ov_http_transfer_ptr(object, ptr) \
42
+ TypedData_Get_Struct((object), ov_http_transfer_object, &ov_http_transfer_type, (ptr))
43
+
44
+ /* Initialization function: */
45
+ extern void ov_http_transfer_define(void);
46
+
47
+ #endif
@@ -17,10 +17,10 @@ limitations under the License.
17
17
  #ifndef __OV_MODULE_H__
18
18
  #define __OV_MODULE_H__
19
19
 
20
- // Module:
20
+ /* Module: */
21
21
  extern VALUE ov_module;
22
22
 
23
- // Initialization function:
23
+ /* Initialization function: */
24
24
  extern void ov_module_define(void);
25
25
 
26
26
  #endif
@@ -0,0 +1,43 @@
1
+ /*
2
+ Copyright (c) 2017 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
+ #include <string.h>
19
+
20
+ #include "ov_string.h"
21
+
22
+ char* ov_string_dup(VALUE str) {
23
+ long len = 0;
24
+ char* raw = NULL;
25
+ char* ptr = NULL;
26
+
27
+ if (!NIL_P(str)) {
28
+ Check_Type(str, T_STRING);
29
+ len = RSTRING_LEN(str);
30
+ raw = RSTRING_PTR(str);
31
+ ptr = (char*) ALLOC_N(char, len + 1);
32
+ strncpy(ptr, raw, len);
33
+ ptr[len] = '\0';
34
+ }
35
+ return ptr;
36
+ }
37
+
38
+ void ov_string_free(char* ptr) {
39
+ if (ptr != NULL) {
40
+ xfree(ptr);
41
+ }
42
+ }
43
+
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright (c) 2017 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_STRING_H__
18
+ #define __OV_STRING_H__
19
+
20
+ #include <ruby.h>
21
+
22
+ extern char* ov_string_dup(VALUE str);
23
+ extern void ov_string_free(char* str);
24
+
25
+ #endif