plamo 0.2.0 → 0.3.0
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/.github/FUNDING.yml +12 -0
- data/Gemfile.lock +1 -1
- data/ext/plamo/plamo.c +5 -0
- data/ext/plamo/plamo.h +5 -0
- data/ext/plamo/plamo_app.c +26 -25
- data/ext/plamo/plamo_byte_array.c +28 -14
- data/ext/plamo/plamo_byte_array.h +1 -0
- data/ext/plamo/plamo_form_data.c +67 -0
- data/ext/plamo/plamo_form_data.h +6 -0
- data/ext/plamo/plamo_form_data_field.c +70 -0
- data/ext/plamo/plamo_form_data_field.h +9 -0
- data/ext/plamo/plamo_form_data_field_array.c +88 -0
- data/ext/plamo/plamo_form_data_field_array.h +9 -0
- data/ext/plamo/plamo_form_data_file.c +69 -0
- data/ext/plamo/plamo_form_data_file.h +9 -0
- data/ext/plamo/plamo_form_urlencoded.c +62 -0
- data/ext/plamo/plamo_form_urlencoded.h +6 -0
- data/ext/plamo/plamo_http_header.c +32 -31
- data/ext/plamo/plamo_http_header.h +1 -0
- data/ext/plamo/plamo_http_query.c +26 -21
- data/ext/plamo/plamo_http_query.h +1 -0
- data/ext/plamo/plamo_middleware.c +19 -18
- data/ext/plamo/plamo_middleware.h +1 -0
- data/ext/plamo/plamo_request.c +44 -45
- data/ext/plamo/plamo_request.h +1 -0
- data/ext/plamo/plamo_response.c +33 -33
- data/ext/plamo/plamo_response.h +1 -0
- data/ext/plamo/plamo_string_array.c +46 -27
- data/ext/plamo/plamo_string_array.h +1 -0
- data/lib/plamo/version.rb +1 -1
- metadata +13 -3
- data/ext/plamo/wrapper.h +0 -8
data/ext/plamo/plamo_request.h
CHANGED
data/ext/plamo/plamo_response.c
CHANGED
@@ -1,55 +1,57 @@
|
|
1
1
|
#include "plamo.h"
|
2
|
-
#include "wrapper.h"
|
3
2
|
|
4
3
|
VALUE rb_cPlamoResponse;
|
5
4
|
|
6
|
-
static void deallocate(
|
7
|
-
plamo_response_destroy(
|
8
|
-
free(wrapper);
|
5
|
+
static void deallocate(void *plamo_response) {
|
6
|
+
plamo_response_destroy(plamo_response);
|
9
7
|
}
|
10
8
|
|
9
|
+
const rb_data_type_t rb_plamo_response_type = {
|
10
|
+
"Response",
|
11
|
+
{
|
12
|
+
NULL,
|
13
|
+
deallocate,
|
14
|
+
NULL,
|
15
|
+
},
|
16
|
+
NULL,
|
17
|
+
NULL,
|
18
|
+
0,
|
19
|
+
};
|
20
|
+
|
11
21
|
static VALUE allocate(VALUE klass) {
|
12
|
-
return
|
22
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_response_type, NULL);
|
13
23
|
}
|
14
24
|
|
15
25
|
static VALUE initialize(VALUE self) {
|
16
|
-
|
17
|
-
Data_Get_Struct(self, Wrapper, wrapper);
|
18
|
-
wrapper->inner = plamo_response_new();
|
26
|
+
DATA_PTR(self) = plamo_response_new();
|
19
27
|
return self;
|
20
28
|
}
|
21
29
|
|
22
30
|
static VALUE status_code(VALUE self) {
|
23
|
-
|
24
|
-
|
25
|
-
return UINT2NUM(
|
31
|
+
PlamoResponse *plamo_response;
|
32
|
+
TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
|
33
|
+
return UINT2NUM(plamo_response->status_code);
|
26
34
|
}
|
27
35
|
|
28
36
|
static VALUE set_status_code(VALUE self, VALUE code) {
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
PlamoResponse *plamo_response;
|
38
|
+
TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
|
39
|
+
plamo_response->status_code = FIX2UINT(code);
|
32
40
|
return code;
|
33
41
|
}
|
34
42
|
|
35
43
|
static VALUE header(VALUE self) {
|
36
|
-
|
37
|
-
|
38
|
-
VALUE rb_plamo_http_header =
|
39
|
-
Wrapper *plamo_http_header_wrapper;
|
40
|
-
Data_Get_Struct(rb_plamo_http_header, Wrapper, plamo_http_header_wrapper);
|
41
|
-
plamo_http_header_wrapper->inner = ((PlamoResponse*)wrapper->inner)->header;
|
44
|
+
PlamoResponse *plamo_response;
|
45
|
+
TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
|
46
|
+
VALUE rb_plamo_http_header = TypedData_Wrap_Struct(rb_cPlamoHttpHeader, &rb_plamo_http_header_type, plamo_response->header);
|
42
47
|
return rb_plamo_http_header;
|
43
48
|
}
|
44
49
|
|
45
50
|
static VALUE body(VALUE self) {
|
46
|
-
|
47
|
-
|
48
|
-
if (
|
49
|
-
VALUE rb_plamo_byte_array =
|
50
|
-
Wrapper *plamo_byte_array_wrapper;
|
51
|
-
Data_Get_Struct(rb_plamo_byte_array, Wrapper, plamo_byte_array_wrapper);
|
52
|
-
plamo_byte_array_wrapper->inner = ((PlamoResponse*)wrapper->inner)->body;
|
51
|
+
PlamoResponse *plamo_response;
|
52
|
+
TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
|
53
|
+
if (plamo_response->body != NULL) {
|
54
|
+
VALUE rb_plamo_byte_array = TypedData_Wrap_Struct(rb_cPlamoByteArray, &rb_plamo_byte_array_type, plamo_response->body);
|
53
55
|
return rb_plamo_byte_array;
|
54
56
|
} else {
|
55
57
|
return Qnil;
|
@@ -57,12 +59,11 @@ static VALUE body(VALUE self) {
|
|
57
59
|
}
|
58
60
|
|
59
61
|
static VALUE set_body(VALUE self, VALUE rb_body) {
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
PlamoResponse *plamo_response;
|
63
|
+
TypedData_Get_Struct(self, PlamoResponse, &rb_plamo_response_type, plamo_response);
|
63
64
|
if (strcmp("String", rb_class2name(rb_obj_class(rb_body))) == 0) {
|
64
65
|
struct RString *rstring = RSTRING(rb_body);
|
65
|
-
|
66
|
+
plamo_response->body = plamo_byte_array_new(RSTRING_PTR(rstring), RSTRING_LEN(rstring));
|
66
67
|
} else {
|
67
68
|
VALUE *array = RARRAY_PTR(rb_body);
|
68
69
|
size_t len = RARRAY_LEN(rb_body);
|
@@ -70,10 +71,9 @@ static VALUE set_body(VALUE self, VALUE rb_body) {
|
|
70
71
|
for (size_t i = 0; i < len; i++) {
|
71
72
|
buf[i] = NUM2CHR(array[i]);
|
72
73
|
}
|
73
|
-
|
74
|
+
plamo_response->body = plamo_byte_array_new(buf, len);
|
74
75
|
free(array);
|
75
76
|
}
|
76
|
-
|
77
77
|
return self;
|
78
78
|
}
|
79
79
|
|
data/ext/plamo/plamo_response.h
CHANGED
@@ -1,35 +1,53 @@
|
|
1
1
|
#include "plamo.h"
|
2
|
-
#include "wrapper.h"
|
3
2
|
|
4
3
|
VALUE rb_cPlamoStringArray;
|
5
4
|
|
6
|
-
static void deallocate(
|
7
|
-
plamo_string_array_destroy(
|
8
|
-
free(wrapper);
|
5
|
+
static void deallocate(void *plamo_string_array) {
|
6
|
+
plamo_string_array_destroy(plamo_string_array);
|
9
7
|
}
|
10
8
|
|
9
|
+
const rb_data_type_t rb_plamo_string_array_type = {
|
10
|
+
"StringArray",
|
11
|
+
{
|
12
|
+
NULL,
|
13
|
+
deallocate,
|
14
|
+
NULL,
|
15
|
+
},
|
16
|
+
NULL,
|
17
|
+
NULL,
|
18
|
+
0,
|
19
|
+
};
|
20
|
+
|
11
21
|
static VALUE allocate(VALUE klass) {
|
12
|
-
return
|
22
|
+
return TypedData_Wrap_Struct(klass, &rb_plamo_string_array_type, NULL);
|
13
23
|
}
|
14
24
|
|
15
25
|
static VALUE initialize(VALUE self) {
|
16
|
-
|
17
|
-
Data_Get_Struct(self, Wrapper, wrapper);
|
18
|
-
wrapper->inner = plamo_string_array_new();
|
26
|
+
DATA_PTR(self) = plamo_string_array_new();
|
19
27
|
return self;
|
20
28
|
}
|
21
29
|
|
30
|
+
static VALUE length(VALUE self) {
|
31
|
+
PlamoStringArray *plamo_string_array;
|
32
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
33
|
+
return SIZET2NUM(plamo_string_array_length(plamo_string_array));
|
34
|
+
}
|
35
|
+
|
22
36
|
static VALUE push(VALUE self, VALUE rb_string) {
|
23
|
-
|
24
|
-
|
25
|
-
|
37
|
+
PlamoStringArray *plamo_string_array;
|
38
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
39
|
+
if (OBJ_FROZEN(self)) {
|
40
|
+
rb_exc_raise(rb_eFrozenError);
|
41
|
+
return Qnil;
|
42
|
+
}
|
43
|
+
plamo_string_array_add(plamo_string_array, StringValueCStr(rb_string));
|
26
44
|
return Qnil;
|
27
45
|
}
|
28
46
|
|
29
47
|
static VALUE first(VALUE self) {
|
30
|
-
|
31
|
-
|
32
|
-
const char *str = plamo_string_array_get_first(
|
48
|
+
PlamoStringArray *plamo_string_array;
|
49
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
50
|
+
const char *str = plamo_string_array_get_first(plamo_string_array);
|
33
51
|
if (str != NULL) {
|
34
52
|
return rb_str_new2(str);
|
35
53
|
} else {
|
@@ -38,9 +56,9 @@ static VALUE first(VALUE self) {
|
|
38
56
|
}
|
39
57
|
|
40
58
|
static VALUE last(VALUE self) {
|
41
|
-
|
42
|
-
|
43
|
-
const char *str = plamo_string_array_get_last(
|
59
|
+
PlamoStringArray *plamo_string_array;
|
60
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
61
|
+
const char *str = plamo_string_array_get_last(plamo_string_array);
|
44
62
|
if (str != NULL) {
|
45
63
|
return rb_str_new2(str);
|
46
64
|
} else {
|
@@ -49,9 +67,9 @@ static VALUE last(VALUE self) {
|
|
49
67
|
}
|
50
68
|
|
51
69
|
static VALUE get_at(VALUE self, VALUE index) {
|
52
|
-
|
53
|
-
|
54
|
-
const char *str = plamo_string_array_get_at(
|
70
|
+
PlamoStringArray *plamo_string_array;
|
71
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
72
|
+
const char *str = plamo_string_array_get_at(plamo_string_array, FIX2ULONG(index));
|
55
73
|
if (str != NULL) {
|
56
74
|
return rb_str_new2(str);
|
57
75
|
} else {
|
@@ -64,16 +82,16 @@ static void execute_each(const char *str) {
|
|
64
82
|
}
|
65
83
|
|
66
84
|
static VALUE each(VALUE self) {
|
67
|
-
|
68
|
-
|
69
|
-
plamo_string_array_for_each(
|
85
|
+
PlamoStringArray *plamo_string_array;
|
86
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
87
|
+
plamo_string_array_for_each(plamo_string_array, execute_each);
|
70
88
|
return Qnil;
|
71
89
|
}
|
72
90
|
|
73
91
|
static VALUE delete_at(VALUE self, VALUE index) {
|
74
|
-
|
75
|
-
|
76
|
-
if (plamo_string_array_remove_at(
|
92
|
+
PlamoStringArray *plamo_string_array;
|
93
|
+
TypedData_Get_Struct(self, PlamoStringArray, &rb_plamo_string_array_type, plamo_string_array);
|
94
|
+
if (plamo_string_array_remove_at(plamo_string_array, FIX2ULONG(index))) {
|
77
95
|
return Qtrue;
|
78
96
|
} else {
|
79
97
|
return Qfalse;
|
@@ -84,6 +102,8 @@ void Init_plamo_string_array(void) {
|
|
84
102
|
rb_cPlamoStringArray = rb_define_class_under(rb_mPlamo, "StringArray", rb_cObject);
|
85
103
|
rb_define_alloc_func(rb_cPlamoStringArray, allocate);
|
86
104
|
rb_define_method(rb_cPlamoStringArray, "initialize", initialize, 0);
|
105
|
+
rb_define_method(rb_cPlamoStringArray, "length", length, 0);
|
106
|
+
rb_define_alias(rb_cPlamoStringArray, "size", "length");
|
87
107
|
rb_define_method(rb_cPlamoStringArray, "push", push, 1);
|
88
108
|
rb_define_method(rb_cPlamoStringArray, "first", first, 0);
|
89
109
|
rb_define_method(rb_cPlamoStringArray, "last", last, 0);
|
@@ -91,4 +111,3 @@ void Init_plamo_string_array(void) {
|
|
91
111
|
rb_define_method(rb_cPlamoStringArray, "each", each, 0);
|
92
112
|
rb_define_method(rb_cPlamoStringArray, "delete_at", delete_at, 1);
|
93
113
|
}
|
94
|
-
|
data/lib/plamo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plamo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shogo Otake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions:
|
|
60
60
|
- ext/plamo/extconf.rb
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- ".github/FUNDING.yml"
|
63
64
|
- ".gitignore"
|
64
65
|
- Gemfile
|
65
66
|
- Gemfile.lock
|
@@ -75,6 +76,16 @@ files:
|
|
75
76
|
- ext/plamo/plamo_app.h
|
76
77
|
- ext/plamo/plamo_byte_array.c
|
77
78
|
- ext/plamo/plamo_byte_array.h
|
79
|
+
- ext/plamo/plamo_form_data.c
|
80
|
+
- ext/plamo/plamo_form_data.h
|
81
|
+
- ext/plamo/plamo_form_data_field.c
|
82
|
+
- ext/plamo/plamo_form_data_field.h
|
83
|
+
- ext/plamo/plamo_form_data_field_array.c
|
84
|
+
- ext/plamo/plamo_form_data_field_array.h
|
85
|
+
- ext/plamo/plamo_form_data_file.c
|
86
|
+
- ext/plamo/plamo_form_data_file.h
|
87
|
+
- ext/plamo/plamo_form_urlencoded.c
|
88
|
+
- ext/plamo/plamo_form_urlencoded.h
|
78
89
|
- ext/plamo/plamo_http_header.c
|
79
90
|
- ext/plamo/plamo_http_header.h
|
80
91
|
- ext/plamo/plamo_http_query.c
|
@@ -87,7 +98,6 @@ files:
|
|
87
98
|
- ext/plamo/plamo_response.h
|
88
99
|
- ext/plamo/plamo_string_array.c
|
89
100
|
- ext/plamo/plamo_string_array.h
|
90
|
-
- ext/plamo/wrapper.h
|
91
101
|
- lib/plamo.rb
|
92
102
|
- lib/plamo/version.rb
|
93
103
|
- plamo.gemspec
|