sfml3-rb 0.0.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +342 -0
- data/README.md +51 -14
- data/TODO.md +199 -0
- data/ext/audio/audio_enums.c +131 -0
- data/ext/audio/audio_enums.h +18 -0
- data/ext/audio/effect_processor.c +233 -0
- data/ext/audio/effect_processor.h +25 -0
- data/ext/audio/listener.c +83 -0
- data/ext/audio/listener.h +8 -0
- data/ext/audio/music.c +174 -0
- data/ext/audio/music.h +14 -0
- data/ext/audio/sound.c +139 -0
- data/ext/audio/sound.h +14 -0
- data/ext/audio/sound_buffer.c +274 -0
- data/ext/audio/sound_buffer.h +18 -0
- data/ext/audio/sound_buffer_recorder.c +109 -0
- data/ext/audio/sound_buffer_recorder.h +14 -0
- data/ext/audio/sound_recorder.c +268 -0
- data/ext/audio/sound_recorder.h +14 -0
- data/ext/audio/sound_source.h +13 -0
- data/ext/audio/sound_source.inc +271 -0
- data/ext/audio/sound_source_cone.c +138 -0
- data/ext/audio/sound_source_cone.h +20 -0
- data/ext/audio/sound_stream.c +294 -0
- data/ext/audio/sound_stream.h +14 -0
- data/ext/{exceptions.c → core/exceptions.c} +10 -8
- data/ext/{ext → core}/exceptions.h +3 -3
- data/ext/core/foreign_thread.c +149 -0
- data/ext/core/foreign_thread.h +31 -0
- data/ext/core/macros.h +8 -0
- data/ext/{ext → core}/sfml.h +5 -3
- data/ext/core/unicode.c +46 -0
- data/ext/core/unicode.h +25 -0
- data/ext/ext.c +125 -14
- data/ext/extconf.rb +51 -6
- data/ext/graphics/blend_mode.c +261 -0
- data/ext/graphics/blend_mode.h +18 -0
- data/ext/graphics/circle.c +319 -0
- data/ext/{ext/klass/drawable → graphics}/circle.h +3 -3
- data/ext/graphics/color.c +318 -0
- data/ext/graphics/color.h +37 -0
- data/ext/{drawable.c → graphics/drawable.c} +11 -11
- data/ext/graphics/drawable.h +10 -0
- data/ext/graphics/enums.c +123 -0
- data/ext/graphics/enums.h +20 -0
- data/ext/graphics/font.c +148 -0
- data/ext/graphics/font.h +14 -0
- data/ext/graphics/glyph.c +60 -0
- data/ext/graphics/glyph.h +14 -0
- data/ext/graphics/image.c +205 -0
- data/ext/graphics/image.h +16 -0
- data/ext/graphics/polygon.c +300 -0
- data/ext/graphics/polygon.h +10 -0
- data/ext/graphics/rect.c +287 -0
- data/ext/graphics/rect.h +30 -0
- data/ext/graphics/rectangle.c +302 -0
- data/ext/graphics/rectangle.h +10 -0
- data/ext/graphics/render_state.c +204 -0
- data/ext/graphics/render_state.h +18 -0
- data/ext/graphics/render_target.inc +181 -0
- data/ext/graphics/render_texture.c +182 -0
- data/ext/graphics/render_texture.h +14 -0
- data/ext/graphics/shader.c +540 -0
- data/ext/graphics/shader.h +14 -0
- data/ext/graphics/shape.c +311 -0
- data/ext/graphics/shape.h +10 -0
- data/ext/graphics/sprite.c +249 -0
- data/ext/graphics/sprite.h +10 -0
- data/ext/graphics/stencil_mode.c +211 -0
- data/ext/graphics/stencil_mode.h +18 -0
- data/ext/graphics/target.c +133 -0
- data/ext/graphics/target.h +40 -0
- data/ext/graphics/text.c +344 -0
- data/ext/graphics/text.h +10 -0
- data/ext/graphics/texture.c +379 -0
- data/ext/graphics/texture.h +16 -0
- data/ext/graphics/transform.c +372 -0
- data/ext/graphics/transform.h +35 -0
- data/ext/{transformable.c → graphics/transformable.c} +168 -144
- data/ext/{ext/klass → graphics}/transformable.h +3 -3
- data/ext/graphics/vertex.c +179 -0
- data/ext/graphics/vertex.h +23 -0
- data/ext/graphics/vertex_array.c +127 -0
- data/ext/graphics/vertex_array.h +10 -0
- data/ext/graphics/vertex_buffer.c +211 -0
- data/ext/graphics/vertex_buffer.h +14 -0
- data/ext/{view.c → graphics/view.c} +168 -169
- data/ext/{ext/klass → graphics}/view.h +3 -3
- data/ext/network/ftp.c +405 -0
- data/ext/network/ftp.h +20 -0
- data/ext/network/http.c +243 -0
- data/ext/network/http.h +18 -0
- data/ext/network/ip_address.c +164 -0
- data/ext/network/ip_address.h +20 -0
- data/ext/network/network_enums.c +298 -0
- data/ext/network/network_enums.h +26 -0
- data/ext/network/packet.c +189 -0
- data/ext/network/packet.h +14 -0
- data/ext/network/socket_selector.c +142 -0
- data/ext/network/socket_selector.h +14 -0
- data/ext/network/tcp_listener.c +115 -0
- data/ext/network/tcp_listener.h +14 -0
- data/ext/network/tcp_socket.c +199 -0
- data/ext/network/tcp_socket.h +17 -0
- data/ext/network/udp_socket.c +190 -0
- data/ext/network/udp_socket.h +14 -0
- data/ext/ports.rb +97 -21
- data/ext/system/buffer.c +77 -0
- data/ext/system/buffer.h +14 -0
- data/ext/system/clock.c +100 -0
- data/ext/{ext/klass → system}/clock.h +3 -3
- data/ext/system/input_stream.c +229 -0
- data/ext/system/input_stream.h +23 -0
- data/ext/system/sleep.c +16 -0
- data/ext/system/sleep.h +8 -0
- data/ext/system/time.c +218 -0
- data/ext/system/time.h +18 -0
- data/ext/system/vec2.c +251 -0
- data/ext/system/vec2.h +55 -0
- data/ext/system/vec3.c +219 -0
- data/ext/system/vec3.h +18 -0
- data/ext/window/clipboard.c +89 -0
- data/ext/window/clipboard.h +8 -0
- data/ext/window/context.c +70 -0
- data/ext/window/context.h +8 -0
- data/ext/window/context_settings.c +220 -0
- data/ext/window/context_settings.h +18 -0
- data/ext/window/cursor.c +56 -0
- data/ext/window/cursor.h +14 -0
- data/ext/window/event.c +216 -0
- data/ext/window/event.h +14 -0
- data/ext/{event_name.c → window/event_name.c} +2 -2
- data/ext/window/event_name.h +8 -0
- data/ext/window/input_enums.c +261 -0
- data/ext/window/input_enums.h +36 -0
- data/ext/window/joystick.c +60 -0
- data/ext/window/joystick.h +8 -0
- data/ext/{keyboard.c → window/keyboard.c} +74 -2
- data/ext/window/keyboard.h +12 -0
- data/ext/window/mouse.c +70 -0
- data/ext/window/mouse.h +8 -0
- data/ext/window/sensor.c +30 -0
- data/ext/window/sensor.h +8 -0
- data/ext/window/touch.c +49 -0
- data/ext/window/touch.h +8 -0
- data/ext/window/video_mode.c +133 -0
- data/ext/window/video_mode.h +14 -0
- data/ext/window/vulkan.c +44 -0
- data/ext/window/vulkan.h +8 -0
- data/ext/window/window.c +414 -0
- data/ext/{ext/klass → window}/window.h +3 -3
- data/lib/sfml/version.rb +4 -2
- data/lib/sfml.rb +2 -0
- metadata +163 -56
- data/ext/circle.c +0 -198
- data/ext/clock.c +0 -65
- data/ext/color.c +0 -43
- data/ext/event.c +0 -148
- data/ext/ext/klass/color.h +0 -26
- data/ext/ext/klass/drawable/image.h +0 -4
- data/ext/ext/klass/drawable/polygon.h +0 -4
- data/ext/ext/klass/drawable/rectangle.h +0 -4
- data/ext/ext/klass/drawable/sprite.h +0 -4
- data/ext/ext/klass/drawable/texture.h +0 -4
- data/ext/ext/klass/event/event_name.h +0 -8
- data/ext/ext/klass/event.h +0 -12
- data/ext/ext/klass/keyboard.h +0 -8
- data/ext/ext/klass/render_state.h +0 -16
- data/ext/ext/klass/target.h +0 -18
- data/ext/ext/klass/transform.h +0 -17
- data/ext/ext/klass/video_mode.h +0 -12
- data/ext/ext/module/drawable/drawable.h +0 -10
- data/ext/ext/module/transform.h +0 -18
- data/ext/ext/module.h +0 -10
- data/ext/ext/rect.h +0 -16
- data/ext/ext/style_name.h +0 -11
- data/ext/ext/vec2.h +0 -38
- data/ext/image.c +0 -5
- data/ext/polygon.c +0 -5
- data/ext/rect.c +0 -26
- data/ext/rectangle.c +0 -5
- data/ext/render_state.c +0 -109
- data/ext/sprite.c +0 -5
- data/ext/style_name.c +0 -15
- data/ext/target.c +0 -106
- data/ext/texture.c +0 -5
- data/ext/transform.c +0 -107
- data/ext/vec2.c +0 -42
- data/ext/video_mode.c +0 -78
- data/ext/window.c +0 -274
data/ext/network/ftp.c
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
#include "network/ftp.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "core/macros.h"
|
|
7
|
+
#include "core/unicode.h"
|
|
8
|
+
#include "network/ip_address.h"
|
|
9
|
+
#include "network/network_enums.h"
|
|
10
|
+
#include "system/time.h"
|
|
11
|
+
|
|
12
|
+
typedef struct {
|
|
13
|
+
sfFtp* handle;
|
|
14
|
+
} Ftp;
|
|
15
|
+
|
|
16
|
+
typedef struct {
|
|
17
|
+
sfFtpResponse* handle;
|
|
18
|
+
} FtpResponse;
|
|
19
|
+
|
|
20
|
+
typedef struct {
|
|
21
|
+
sfFtpDirectoryResponse* handle;
|
|
22
|
+
} FtpDirectoryResponse;
|
|
23
|
+
|
|
24
|
+
typedef struct {
|
|
25
|
+
sfFtpListingResponse* handle;
|
|
26
|
+
} FtpListingResponse;
|
|
27
|
+
|
|
28
|
+
static VALUE rb_cFtp;
|
|
29
|
+
static VALUE rb_cFtpResponse;
|
|
30
|
+
static VALUE rb_cFtpDirectoryResponse;
|
|
31
|
+
static VALUE rb_cFtpListingResponse;
|
|
32
|
+
|
|
33
|
+
static void Ftp_free(void* ptr) {
|
|
34
|
+
Ftp* ftp = ptr;
|
|
35
|
+
|
|
36
|
+
sfFtp_destroy(ftp->handle);
|
|
37
|
+
free(ftp);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static void FtpResponse_free(void* ptr) {
|
|
41
|
+
FtpResponse* response = ptr;
|
|
42
|
+
|
|
43
|
+
sfFtpResponse_destroy(response->handle);
|
|
44
|
+
free(response);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static void FtpDirectoryResponse_free(void* ptr) {
|
|
48
|
+
FtpDirectoryResponse* response = ptr;
|
|
49
|
+
|
|
50
|
+
sfFtpDirectoryResponse_destroy(response->handle);
|
|
51
|
+
free(response);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static void FtpListingResponse_free(void* ptr) {
|
|
55
|
+
FtpListingResponse* response = ptr;
|
|
56
|
+
|
|
57
|
+
sfFtpListingResponse_destroy(response->handle);
|
|
58
|
+
free(response);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static const rb_data_type_t Ftp_data_type = {
|
|
62
|
+
.wrap_struct_name = "SFML::Ftp",
|
|
63
|
+
.function = {.dmark = NULL, .dfree = Ftp_free, .dsize = NULL},
|
|
64
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
65
|
+
|
|
66
|
+
static const rb_data_type_t FtpResponse_data_type = {
|
|
67
|
+
.wrap_struct_name = "SFML::FtpResponse",
|
|
68
|
+
.function = {.dmark = NULL, .dfree = FtpResponse_free, .dsize = NULL},
|
|
69
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
70
|
+
|
|
71
|
+
static const rb_data_type_t FtpDirectoryResponse_data_type = {
|
|
72
|
+
.wrap_struct_name = "SFML::FtpDirectoryResponse",
|
|
73
|
+
.function = {.dmark = NULL, .dfree = FtpDirectoryResponse_free, .dsize = NULL},
|
|
74
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
75
|
+
|
|
76
|
+
static const rb_data_type_t FtpListingResponse_data_type = {
|
|
77
|
+
.wrap_struct_name = "SFML::FtpListingResponse",
|
|
78
|
+
.function = {.dmark = NULL, .dfree = FtpListingResponse_free, .dsize = NULL},
|
|
79
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY};
|
|
80
|
+
|
|
81
|
+
static VALUE Ftp_wrap(sfFtp* handle) {
|
|
82
|
+
Ftp* ptr;
|
|
83
|
+
|
|
84
|
+
if (handle == NULL) {
|
|
85
|
+
rb_raise(rb_eRuntimeError, "failed to create FTP client");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
ptr = malloc(sizeof(Ftp));
|
|
89
|
+
ptr->handle = handle;
|
|
90
|
+
|
|
91
|
+
return TypedData_Wrap_Struct(rb_cFtp, &Ftp_data_type, ptr);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static VALUE FtpResponse_wrap(sfFtpResponse* handle) {
|
|
95
|
+
FtpResponse* ptr;
|
|
96
|
+
|
|
97
|
+
if (handle == NULL) {
|
|
98
|
+
rb_raise(rb_eRuntimeError, "FTP request failed");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
ptr = malloc(sizeof(FtpResponse));
|
|
102
|
+
ptr->handle = handle;
|
|
103
|
+
|
|
104
|
+
return TypedData_Wrap_Struct(rb_cFtpResponse, &FtpResponse_data_type, ptr);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static VALUE FtpDirectoryResponse_wrap(sfFtpDirectoryResponse* handle) {
|
|
108
|
+
FtpDirectoryResponse* ptr;
|
|
109
|
+
|
|
110
|
+
if (handle == NULL) {
|
|
111
|
+
rb_raise(rb_eRuntimeError, "FTP request failed");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
ptr = malloc(sizeof(FtpDirectoryResponse));
|
|
115
|
+
ptr->handle = handle;
|
|
116
|
+
|
|
117
|
+
return TypedData_Wrap_Struct(rb_cFtpDirectoryResponse, &FtpDirectoryResponse_data_type, ptr);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static VALUE FtpListingResponse_wrap(sfFtpListingResponse* handle) {
|
|
121
|
+
FtpListingResponse* ptr;
|
|
122
|
+
|
|
123
|
+
if (handle == NULL) {
|
|
124
|
+
rb_raise(rb_eRuntimeError, "FTP request failed");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
ptr = malloc(sizeof(FtpListingResponse));
|
|
128
|
+
ptr->handle = handle;
|
|
129
|
+
|
|
130
|
+
return TypedData_Wrap_Struct(rb_cFtpListingResponse, &FtpListingResponse_data_type, ptr);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static VALUE Ftp_new(VALUE klass) {
|
|
134
|
+
return Ftp_wrap(sfFtp_create());
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static VALUE Ftp_connect(int argc, VALUE* argv, VALUE self) {
|
|
138
|
+
VALUE rb_address, rb_port, rb_timeout;
|
|
139
|
+
sfTime timeout = sfTime_Zero;
|
|
140
|
+
unsigned short port = 21;
|
|
141
|
+
|
|
142
|
+
rb_scan_args(argc, argv, "12", &rb_address, &rb_port, &rb_timeout);
|
|
143
|
+
|
|
144
|
+
if (!NIL_P(rb_port)) {
|
|
145
|
+
port = (unsigned short)NUM2INT(rb_port);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (!NIL_P(rb_timeout)) {
|
|
149
|
+
timeout = time_from_rb(rb_timeout);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return FtpResponse_wrap(sfFtp_connect(
|
|
153
|
+
Get_Ftp_Struct(self), ip_address_from_rb(rb_address, sfIpAddress_None), port, timeout));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static VALUE Ftp_login_anonymous(VALUE self) {
|
|
157
|
+
return FtpResponse_wrap(sfFtp_loginAnonymous(Get_Ftp_Struct(self)));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static VALUE Ftp_login(VALUE self, VALUE rb_name, VALUE rb_password) {
|
|
161
|
+
return FtpResponse_wrap(
|
|
162
|
+
sfFtp_login(Get_Ftp_Struct(self), StringValueCStr(rb_name), StringValueCStr(rb_password)));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static VALUE Ftp_disconnect(VALUE self) {
|
|
166
|
+
return FtpResponse_wrap(sfFtp_disconnect(Get_Ftp_Struct(self)));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static VALUE Ftp_keep_alive(VALUE self) {
|
|
170
|
+
return FtpResponse_wrap(sfFtp_keepAlive(Get_Ftp_Struct(self)));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
static VALUE Ftp_working_directory(VALUE self) {
|
|
174
|
+
return FtpDirectoryResponse_wrap(sfFtp_getWorkingDirectory(Get_Ftp_Struct(self)));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
static VALUE Ftp_directory_listing(int argc, VALUE* argv, VALUE self) {
|
|
178
|
+
VALUE rb_directory;
|
|
179
|
+
|
|
180
|
+
rb_scan_args(argc, argv, "01", &rb_directory);
|
|
181
|
+
|
|
182
|
+
return FtpListingResponse_wrap(sfFtp_getDirectoryListing(
|
|
183
|
+
Get_Ftp_Struct(self), NIL_P(rb_directory) ? NULL : StringValueCStr(rb_directory)));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static VALUE Ftp_change_directory(VALUE self, VALUE rb_directory) {
|
|
187
|
+
return FtpResponse_wrap(
|
|
188
|
+
sfFtp_changeDirectory(Get_Ftp_Struct(self), StringValueCStr(rb_directory)));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static VALUE Ftp_parent_directory(VALUE self) {
|
|
192
|
+
return FtpResponse_wrap(sfFtp_parentDirectory(Get_Ftp_Struct(self)));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
static VALUE Ftp_create_directory(VALUE self, VALUE rb_name) {
|
|
196
|
+
return FtpResponse_wrap(sfFtp_createDirectory(Get_Ftp_Struct(self), StringValueCStr(rb_name)));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static VALUE Ftp_delete_directory(VALUE self, VALUE rb_name) {
|
|
200
|
+
return FtpResponse_wrap(sfFtp_deleteDirectory(Get_Ftp_Struct(self), StringValueCStr(rb_name)));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static VALUE Ftp_rename_file(VALUE self, VALUE rb_file, VALUE rb_new_name) {
|
|
204
|
+
return FtpResponse_wrap(sfFtp_renameFile(Get_Ftp_Struct(self), StringValueCStr(rb_file),
|
|
205
|
+
StringValueCStr(rb_new_name)));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static VALUE Ftp_delete_file(VALUE self, VALUE rb_name) {
|
|
209
|
+
return FtpResponse_wrap(sfFtp_deleteFile(Get_Ftp_Struct(self), StringValueCStr(rb_name)));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static VALUE Ftp_download(int argc, VALUE* argv, VALUE self) {
|
|
213
|
+
VALUE rb_remote, rb_local, rb_mode;
|
|
214
|
+
sfFtpTransferMode mode = sfFtpBinary;
|
|
215
|
+
|
|
216
|
+
rb_scan_args(argc, argv, "21", &rb_remote, &rb_local, &rb_mode);
|
|
217
|
+
|
|
218
|
+
if (!NIL_P(rb_mode)) {
|
|
219
|
+
mode = ftp_transfer_mode_from_rb(rb_mode);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return FtpResponse_wrap(sfFtp_download(Get_Ftp_Struct(self), StringValueCStr(rb_remote),
|
|
223
|
+
StringValueCStr(rb_local), mode));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static VALUE Ftp_upload(int argc, VALUE* argv, VALUE self) {
|
|
227
|
+
VALUE rb_local, rb_remote, rb_mode, rb_append;
|
|
228
|
+
sfFtpTransferMode mode = sfFtpBinary;
|
|
229
|
+
bool append = false;
|
|
230
|
+
|
|
231
|
+
rb_scan_args(argc, argv, "22", &rb_local, &rb_remote, &rb_mode, &rb_append);
|
|
232
|
+
|
|
233
|
+
if (!NIL_P(rb_mode)) {
|
|
234
|
+
mode = ftp_transfer_mode_from_rb(rb_mode);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!NIL_P(rb_append)) {
|
|
238
|
+
append = RTEST(rb_append);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return FtpResponse_wrap(sfFtp_upload(Get_Ftp_Struct(self), StringValueCStr(rb_local),
|
|
242
|
+
StringValueCStr(rb_remote), mode, append));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static VALUE Ftp_send_command(int argc, VALUE* argv, VALUE self) {
|
|
246
|
+
VALUE rb_command, rb_parameter;
|
|
247
|
+
|
|
248
|
+
rb_scan_args(argc, argv, "11", &rb_command, &rb_parameter);
|
|
249
|
+
|
|
250
|
+
return FtpResponse_wrap(
|
|
251
|
+
sfFtp_sendCommand(Get_Ftp_Struct(self), StringValueCStr(rb_command),
|
|
252
|
+
NIL_P(rb_parameter) ? NULL : StringValueCStr(rb_parameter)));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
static VALUE FtpResponse_ok(VALUE self) {
|
|
256
|
+
return BOOL2RB(sfFtpResponse_isOk(Get_FtpResponse_Struct(self)));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
static VALUE FtpResponse_status(VALUE self) {
|
|
260
|
+
return INT2NUM(sfFtpResponse_getStatus(Get_FtpResponse_Struct(self)));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static VALUE FtpResponse_status_name(VALUE self) {
|
|
264
|
+
return ID2SYM(
|
|
265
|
+
rb_intern(ftp_status_name(sfFtpResponse_getStatus(Get_FtpResponse_Struct(self)))));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static VALUE FtpResponse_message(VALUE self) {
|
|
269
|
+
return rb_str_new_cstr(sfFtpResponse_getMessage(Get_FtpResponse_Struct(self)));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
static VALUE FtpDirectoryResponse_ok(VALUE self) {
|
|
273
|
+
return BOOL2RB(sfFtpDirectoryResponse_isOk(Get_FtpDirectoryResponse_Struct(self)));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
static VALUE FtpDirectoryResponse_status(VALUE self) {
|
|
277
|
+
return INT2NUM(sfFtpDirectoryResponse_getStatus(Get_FtpDirectoryResponse_Struct(self)));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
static VALUE FtpDirectoryResponse_status_name(VALUE self) {
|
|
281
|
+
return ID2SYM(rb_intern(
|
|
282
|
+
ftp_status_name(sfFtpDirectoryResponse_getStatus(Get_FtpDirectoryResponse_Struct(self)))));
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
static VALUE FtpDirectoryResponse_message(VALUE self) {
|
|
286
|
+
return rb_str_new_cstr(
|
|
287
|
+
sfFtpDirectoryResponse_getMessage(Get_FtpDirectoryResponse_Struct(self)));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/* Through the UTF-32 entry point, so a path with non-ASCII characters survives
|
|
291
|
+
the trip; the plain getter re-encodes it through the C locale. */
|
|
292
|
+
static VALUE FtpDirectoryResponse_directory(VALUE self) {
|
|
293
|
+
return utf32_to_rb(
|
|
294
|
+
sfFtpDirectoryResponse_getDirectoryUnicode(Get_FtpDirectoryResponse_Struct(self)));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static VALUE FtpListingResponse_ok(VALUE self) {
|
|
298
|
+
return BOOL2RB(sfFtpListingResponse_isOk(Get_FtpListingResponse_Struct(self)));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
static VALUE FtpListingResponse_status(VALUE self) {
|
|
302
|
+
return INT2NUM(sfFtpListingResponse_getStatus(Get_FtpListingResponse_Struct(self)));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
static VALUE FtpListingResponse_status_name(VALUE self) {
|
|
306
|
+
return ID2SYM(rb_intern(
|
|
307
|
+
ftp_status_name(sfFtpListingResponse_getStatus(Get_FtpListingResponse_Struct(self)))));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
static VALUE FtpListingResponse_message(VALUE self) {
|
|
311
|
+
return rb_str_new_cstr(sfFtpListingResponse_getMessage(Get_FtpListingResponse_Struct(self)));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static VALUE FtpListingResponse_count(VALUE self) {
|
|
315
|
+
return SIZET2NUM(sfFtpListingResponse_getCount(Get_FtpListingResponse_Struct(self)));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
static VALUE FtpListingResponse_name(VALUE self, VALUE rb_index) {
|
|
319
|
+
return rb_str_new_cstr(sfFtpListingResponse_getName(Get_FtpListingResponse_Struct(self),
|
|
320
|
+
(size_t)NUM2SIZET(rb_index)));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
void Init_Ftp(VALUE rb_module) {
|
|
324
|
+
rb_cFtp = rb_define_class_under(rb_module, "Ftp", rb_cObject);
|
|
325
|
+
rb_cFtpResponse = rb_define_class_under(rb_module, "FtpResponse", rb_cObject);
|
|
326
|
+
rb_cFtpDirectoryResponse = rb_define_class_under(rb_module, "FtpDirectoryResponse", rb_cObject);
|
|
327
|
+
rb_cFtpListingResponse = rb_define_class_under(rb_module, "FtpListingResponse", rb_cObject);
|
|
328
|
+
|
|
329
|
+
rb_define_singleton_method(rb_cFtp, "new", Ftp_new, 0);
|
|
330
|
+
|
|
331
|
+
rb_define_method(rb_cFtp, "connect", Ftp_connect, -1);
|
|
332
|
+
rb_define_method(rb_cFtp, "login_anonymous", Ftp_login_anonymous, 0);
|
|
333
|
+
rb_define_method(rb_cFtp, "login", Ftp_login, 2);
|
|
334
|
+
rb_define_method(rb_cFtp, "disconnect", Ftp_disconnect, 0);
|
|
335
|
+
rb_define_method(rb_cFtp, "keep_alive", Ftp_keep_alive, 0);
|
|
336
|
+
rb_define_method(rb_cFtp, "working_directory", Ftp_working_directory, 0);
|
|
337
|
+
rb_define_method(rb_cFtp, "directory_listing", Ftp_directory_listing, -1);
|
|
338
|
+
rb_define_method(rb_cFtp, "change_directory", Ftp_change_directory, 1);
|
|
339
|
+
rb_define_method(rb_cFtp, "parent_directory", Ftp_parent_directory, 0);
|
|
340
|
+
rb_define_method(rb_cFtp, "create_directory", Ftp_create_directory, 1);
|
|
341
|
+
rb_define_method(rb_cFtp, "delete_directory", Ftp_delete_directory, 1);
|
|
342
|
+
rb_define_method(rb_cFtp, "rename_file", Ftp_rename_file, 2);
|
|
343
|
+
rb_define_method(rb_cFtp, "delete_file", Ftp_delete_file, 1);
|
|
344
|
+
rb_define_method(rb_cFtp, "download", Ftp_download, -1);
|
|
345
|
+
rb_define_method(rb_cFtp, "upload", Ftp_upload, -1);
|
|
346
|
+
rb_define_method(rb_cFtp, "send_command", Ftp_send_command, -1);
|
|
347
|
+
|
|
348
|
+
rb_define_method(rb_cFtpResponse, "ok?", FtpResponse_ok, 0);
|
|
349
|
+
rb_define_method(rb_cFtpResponse, "status", FtpResponse_status, 0);
|
|
350
|
+
rb_define_method(rb_cFtpResponse, "status_name", FtpResponse_status_name, 0);
|
|
351
|
+
rb_define_method(rb_cFtpResponse, "message", FtpResponse_message, 0);
|
|
352
|
+
|
|
353
|
+
rb_define_method(rb_cFtpDirectoryResponse, "ok?", FtpDirectoryResponse_ok, 0);
|
|
354
|
+
rb_define_method(rb_cFtpDirectoryResponse, "status", FtpDirectoryResponse_status, 0);
|
|
355
|
+
rb_define_method(rb_cFtpDirectoryResponse, "status_name", FtpDirectoryResponse_status_name, 0);
|
|
356
|
+
rb_define_method(rb_cFtpDirectoryResponse, "message", FtpDirectoryResponse_message, 0);
|
|
357
|
+
rb_define_method(rb_cFtpDirectoryResponse, "directory", FtpDirectoryResponse_directory, 0);
|
|
358
|
+
|
|
359
|
+
rb_define_method(rb_cFtpListingResponse, "ok?", FtpListingResponse_ok, 0);
|
|
360
|
+
rb_define_method(rb_cFtpListingResponse, "status", FtpListingResponse_status, 0);
|
|
361
|
+
rb_define_method(rb_cFtpListingResponse, "status_name", FtpListingResponse_status_name, 0);
|
|
362
|
+
rb_define_method(rb_cFtpListingResponse, "message", FtpListingResponse_message, 0);
|
|
363
|
+
rb_define_method(rb_cFtpListingResponse, "count", FtpListingResponse_count, 0);
|
|
364
|
+
rb_define_method(rb_cFtpListingResponse, "name", FtpListingResponse_name, 1);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
VALUE Get_Klass_Ftp(void) {
|
|
368
|
+
return rb_cFtp;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
VALUE Get_Klass_FtpResponse(void) {
|
|
372
|
+
return rb_cFtpResponse;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
VALUE Get_Klass_FtpDirectoryResponse(void) {
|
|
376
|
+
return rb_cFtpDirectoryResponse;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
VALUE Get_Klass_FtpListingResponse(void) {
|
|
380
|
+
return rb_cFtpListingResponse;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
void* Get_Ftp_Struct(VALUE self) {
|
|
384
|
+
Ftp* ptr;
|
|
385
|
+
TypedData_Get_Struct(self, Ftp, &Ftp_data_type, ptr);
|
|
386
|
+
return ptr->handle;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
void* Get_FtpResponse_Struct(VALUE self) {
|
|
390
|
+
FtpResponse* ptr;
|
|
391
|
+
TypedData_Get_Struct(self, FtpResponse, &FtpResponse_data_type, ptr);
|
|
392
|
+
return ptr->handle;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
void* Get_FtpDirectoryResponse_Struct(VALUE self) {
|
|
396
|
+
FtpDirectoryResponse* ptr;
|
|
397
|
+
TypedData_Get_Struct(self, FtpDirectoryResponse, &FtpDirectoryResponse_data_type, ptr);
|
|
398
|
+
return ptr->handle;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
void* Get_FtpListingResponse_Struct(VALUE self) {
|
|
402
|
+
FtpListingResponse* ptr;
|
|
403
|
+
TypedData_Get_Struct(self, FtpListingResponse, &FtpListingResponse_data_type, ptr);
|
|
404
|
+
return ptr->handle;
|
|
405
|
+
}
|
data/ext/network/ftp.h
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#ifndef SFML_RB_NETWORK_FTP_H
|
|
2
|
+
#define SFML_RB_NETWORK_FTP_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_Ftp(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
VALUE Get_Klass_Ftp(void);
|
|
11
|
+
VALUE Get_Klass_FtpResponse(void);
|
|
12
|
+
VALUE Get_Klass_FtpDirectoryResponse(void);
|
|
13
|
+
VALUE Get_Klass_FtpListingResponse(void);
|
|
14
|
+
|
|
15
|
+
void *Get_Ftp_Struct(VALUE self);
|
|
16
|
+
void *Get_FtpResponse_Struct(VALUE self);
|
|
17
|
+
void *Get_FtpDirectoryResponse_Struct(VALUE self);
|
|
18
|
+
void *Get_FtpListingResponse_Struct(VALUE self);
|
|
19
|
+
|
|
20
|
+
#endif //SFML_RB_NETWORK_FTP_H
|
data/ext/network/http.c
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#include "network/http.h"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
|
|
6
|
+
#include "core/macros.h"
|
|
7
|
+
#include "network/network_enums.h"
|
|
8
|
+
#include "system/time.h"
|
|
9
|
+
|
|
10
|
+
typedef struct {
|
|
11
|
+
sfHttp *handle;
|
|
12
|
+
} Http;
|
|
13
|
+
|
|
14
|
+
typedef struct {
|
|
15
|
+
sfHttpRequest *handle;
|
|
16
|
+
} HttpRequest;
|
|
17
|
+
|
|
18
|
+
typedef struct {
|
|
19
|
+
sfHttpResponse *handle;
|
|
20
|
+
} HttpResponse;
|
|
21
|
+
|
|
22
|
+
static VALUE rb_cHttp;
|
|
23
|
+
static VALUE rb_cHttpRequest;
|
|
24
|
+
static VALUE rb_cHttpResponse;
|
|
25
|
+
|
|
26
|
+
static void Http_free(void *ptr) {
|
|
27
|
+
Http *http = ptr;
|
|
28
|
+
|
|
29
|
+
sfHttp_destroy(http->handle);
|
|
30
|
+
free(http);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static void HttpRequest_free(void *ptr) {
|
|
34
|
+
HttpRequest *request = ptr;
|
|
35
|
+
|
|
36
|
+
sfHttpRequest_destroy(request->handle);
|
|
37
|
+
free(request);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static void HttpResponse_free(void *ptr) {
|
|
41
|
+
HttpResponse *response = ptr;
|
|
42
|
+
|
|
43
|
+
sfHttpResponse_destroy(response->handle);
|
|
44
|
+
free(response);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static const rb_data_type_t Http_data_type = {
|
|
48
|
+
.wrap_struct_name = "SFML::Http",
|
|
49
|
+
.function = {.dmark = NULL, .dfree = Http_free, .dsize = NULL},
|
|
50
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static const rb_data_type_t HttpRequest_data_type = {
|
|
54
|
+
.wrap_struct_name = "SFML::HttpRequest",
|
|
55
|
+
.function = {.dmark = NULL, .dfree = HttpRequest_free, .dsize = NULL},
|
|
56
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
static const rb_data_type_t HttpResponse_data_type = {
|
|
60
|
+
.wrap_struct_name = "SFML::HttpResponse",
|
|
61
|
+
.function = {.dmark = NULL, .dfree = HttpResponse_free, .dsize = NULL},
|
|
62
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
static VALUE Http_wrap(VALUE klass, sfHttp *handle) {
|
|
66
|
+
Http *ptr;
|
|
67
|
+
|
|
68
|
+
if (handle == NULL) {
|
|
69
|
+
rb_raise(rb_eRuntimeError, "failed to create HTTP client");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
ptr = malloc(sizeof(Http));
|
|
73
|
+
ptr->handle = handle;
|
|
74
|
+
|
|
75
|
+
return TypedData_Wrap_Struct(klass, &Http_data_type, ptr);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static VALUE HttpRequest_wrap(VALUE klass, sfHttpRequest *handle) {
|
|
79
|
+
HttpRequest *ptr;
|
|
80
|
+
|
|
81
|
+
if (handle == NULL) {
|
|
82
|
+
rb_raise(rb_eRuntimeError, "failed to create HTTP request");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
ptr = malloc(sizeof(HttpRequest));
|
|
86
|
+
ptr->handle = handle;
|
|
87
|
+
|
|
88
|
+
return TypedData_Wrap_Struct(klass, &HttpRequest_data_type, ptr);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static VALUE HttpResponse_wrap(sfHttpResponse *handle) {
|
|
92
|
+
HttpResponse *ptr;
|
|
93
|
+
|
|
94
|
+
if (handle == NULL) {
|
|
95
|
+
rb_raise(rb_eRuntimeError, "HTTP request failed");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ptr = malloc(sizeof(HttpResponse));
|
|
99
|
+
ptr->handle = handle;
|
|
100
|
+
|
|
101
|
+
return TypedData_Wrap_Struct(rb_cHttpResponse, &HttpResponse_data_type, ptr);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static VALUE Http_new(VALUE klass) {
|
|
105
|
+
return Http_wrap(klass, sfHttp_create());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
static VALUE Http_set_host(VALUE self, VALUE rb_host, VALUE rb_port) {
|
|
109
|
+
sfHttp_setHost(Get_Http_Struct(self), StringValueCStr(rb_host), (unsigned short) NUM2INT(rb_port));
|
|
110
|
+
return self;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static VALUE Http_send_request(int argc, VALUE *argv, VALUE self) {
|
|
114
|
+
VALUE rb_request, rb_timeout;
|
|
115
|
+
sfTime timeout = sfTime_Zero;
|
|
116
|
+
|
|
117
|
+
rb_scan_args(argc, argv, "11", &rb_request, &rb_timeout);
|
|
118
|
+
|
|
119
|
+
if (!rb_obj_is_kind_of(rb_request, rb_cHttpRequest)) {
|
|
120
|
+
rb_raise(rb_eTypeError, "expected an SFML::HttpRequest");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!NIL_P(rb_timeout)) {
|
|
124
|
+
timeout = time_from_rb(rb_timeout);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return HttpResponse_wrap(
|
|
128
|
+
sfHttp_sendRequest(Get_Http_Struct(self), Get_HttpRequest_Struct(rb_request), timeout));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static VALUE HttpRequest_new(VALUE klass) {
|
|
132
|
+
return HttpRequest_wrap(klass, sfHttpRequest_create());
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static VALUE HttpRequest_set_field(VALUE self, VALUE rb_field, VALUE rb_value) {
|
|
136
|
+
sfHttpRequest_setField(Get_HttpRequest_Struct(self), StringValueCStr(rb_field),
|
|
137
|
+
StringValueCStr(rb_value));
|
|
138
|
+
return rb_value;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static VALUE HttpRequest_set_method(VALUE self, VALUE rb_method) {
|
|
142
|
+
sfHttpRequest_setMethod(Get_HttpRequest_Struct(self), http_method_from_rb(rb_method));
|
|
143
|
+
return rb_method;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static VALUE HttpRequest_set_uri(VALUE self, VALUE rb_uri) {
|
|
147
|
+
sfHttpRequest_setUri(Get_HttpRequest_Struct(self), StringValueCStr(rb_uri));
|
|
148
|
+
return rb_uri;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static VALUE HttpRequest_set_http_version(VALUE self, VALUE rb_major, VALUE rb_minor) {
|
|
152
|
+
sfHttpRequest_setHttpVersion(Get_HttpRequest_Struct(self), (unsigned int) NUM2INT(rb_major),
|
|
153
|
+
(unsigned int) NUM2INT(rb_minor));
|
|
154
|
+
|
|
155
|
+
return rb_ary_new_from_args(2, rb_major, rb_minor);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static VALUE HttpRequest_set_body(VALUE self, VALUE rb_body) {
|
|
159
|
+
sfHttpRequest_setBody(Get_HttpRequest_Struct(self), StringValueCStr(rb_body));
|
|
160
|
+
return rb_body;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static VALUE HttpResponse_field(VALUE self, VALUE rb_field) {
|
|
164
|
+
const char *field = sfHttpResponse_getField(Get_HttpResponse_Struct(self),
|
|
165
|
+
StringValueCStr(rb_field));
|
|
166
|
+
|
|
167
|
+
return field != NULL ? rb_str_new_cstr(field) : Qnil;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static VALUE HttpResponse_status(VALUE self) {
|
|
171
|
+
return INT2NUM(sfHttpResponse_getStatus(Get_HttpResponse_Struct(self)));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static VALUE HttpResponse_status_name(VALUE self) {
|
|
175
|
+
return ID2SYM(rb_intern(http_status_name(sfHttpResponse_getStatus(Get_HttpResponse_Struct(self)))));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static VALUE HttpResponse_major_version(VALUE self) {
|
|
179
|
+
return UINT2NUM(sfHttpResponse_getMajorVersion(Get_HttpResponse_Struct(self)));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static VALUE HttpResponse_minor_version(VALUE self) {
|
|
183
|
+
return UINT2NUM(sfHttpResponse_getMinorVersion(Get_HttpResponse_Struct(self)));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static VALUE HttpResponse_body(VALUE self) {
|
|
187
|
+
return rb_str_new_cstr(sfHttpResponse_getBody(Get_HttpResponse_Struct(self)));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
void Init_Http(VALUE rb_module) {
|
|
191
|
+
rb_cHttp = rb_define_class_under(rb_module, "Http", rb_cObject);
|
|
192
|
+
rb_cHttpRequest = rb_define_class_under(rb_module, "HttpRequest", rb_cObject);
|
|
193
|
+
rb_cHttpResponse = rb_define_class_under(rb_module, "HttpResponse", rb_cObject);
|
|
194
|
+
|
|
195
|
+
rb_define_singleton_method(rb_cHttp, "new", Http_new, 0);
|
|
196
|
+
rb_define_singleton_method(rb_cHttpRequest, "new", HttpRequest_new, 0);
|
|
197
|
+
|
|
198
|
+
rb_define_method(rb_cHttp, "set_host", Http_set_host, 2);
|
|
199
|
+
rb_define_method(rb_cHttp, "send_request", Http_send_request, -1);
|
|
200
|
+
|
|
201
|
+
rb_define_method(rb_cHttpRequest, "set_field", HttpRequest_set_field, 2);
|
|
202
|
+
rb_define_method(rb_cHttpRequest, "method=", HttpRequest_set_method, 1);
|
|
203
|
+
rb_define_method(rb_cHttpRequest, "uri=", HttpRequest_set_uri, 1);
|
|
204
|
+
rb_define_method(rb_cHttpRequest, "set_http_version", HttpRequest_set_http_version, 2);
|
|
205
|
+
rb_define_method(rb_cHttpRequest, "body=", HttpRequest_set_body, 1);
|
|
206
|
+
|
|
207
|
+
rb_define_method(rb_cHttpResponse, "field", HttpResponse_field, 1);
|
|
208
|
+
rb_define_method(rb_cHttpResponse, "status", HttpResponse_status, 0);
|
|
209
|
+
rb_define_method(rb_cHttpResponse, "status_name", HttpResponse_status_name, 0);
|
|
210
|
+
rb_define_method(rb_cHttpResponse, "major_version", HttpResponse_major_version, 0);
|
|
211
|
+
rb_define_method(rb_cHttpResponse, "minor_version", HttpResponse_minor_version, 0);
|
|
212
|
+
rb_define_method(rb_cHttpResponse, "body", HttpResponse_body, 0);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
VALUE Get_Klass_Http(void) {
|
|
216
|
+
return rb_cHttp;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
VALUE Get_Klass_HttpRequest(void) {
|
|
220
|
+
return rb_cHttpRequest;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
VALUE Get_Klass_HttpResponse(void) {
|
|
224
|
+
return rb_cHttpResponse;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
void *Get_Http_Struct(VALUE self) {
|
|
228
|
+
Http *ptr;
|
|
229
|
+
TypedData_Get_Struct(self, Http, &Http_data_type, ptr);
|
|
230
|
+
return ptr->handle;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
void *Get_HttpRequest_Struct(VALUE self) {
|
|
234
|
+
HttpRequest *ptr;
|
|
235
|
+
TypedData_Get_Struct(self, HttpRequest, &HttpRequest_data_type, ptr);
|
|
236
|
+
return ptr->handle;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
void *Get_HttpResponse_Struct(VALUE self) {
|
|
240
|
+
HttpResponse *ptr;
|
|
241
|
+
TypedData_Get_Struct(self, HttpResponse, &HttpResponse_data_type, ptr);
|
|
242
|
+
return ptr->handle;
|
|
243
|
+
}
|
data/ext/network/http.h
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#ifndef SFML_RB_NETWORK_HTTP_H
|
|
2
|
+
#define SFML_RB_NETWORK_HTTP_H
|
|
3
|
+
|
|
4
|
+
#include <ruby.h>
|
|
5
|
+
|
|
6
|
+
#include "core/sfml.h"
|
|
7
|
+
|
|
8
|
+
void Init_Http(VALUE rb_module);
|
|
9
|
+
|
|
10
|
+
VALUE Get_Klass_Http(void);
|
|
11
|
+
VALUE Get_Klass_HttpRequest(void);
|
|
12
|
+
VALUE Get_Klass_HttpResponse(void);
|
|
13
|
+
|
|
14
|
+
void *Get_Http_Struct(VALUE self);
|
|
15
|
+
void *Get_HttpRequest_Struct(VALUE self);
|
|
16
|
+
void *Get_HttpResponse_Struct(VALUE self);
|
|
17
|
+
|
|
18
|
+
#endif //SFML_RB_NETWORK_HTTP_H
|