bayserver-docker-fcgi 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +7 -0
  2. data/lib/baykit/bayserver/docker/fcgi/command/cmd_begin_request.rb +66 -0
  3. data/lib/baykit/bayserver/docker/fcgi/command/cmd_end_request.rb +66 -0
  4. data/lib/baykit/bayserver/docker/fcgi/command/cmd_params.rb +160 -0
  5. data/lib/baykit/bayserver/docker/fcgi/command/cmd_stderr.rb +31 -0
  6. data/lib/baykit/bayserver/docker/fcgi/command/cmd_stdin.rb +33 -0
  7. data/lib/baykit/bayserver/docker/fcgi/command/cmd_stdout.rb +31 -0
  8. data/lib/baykit/bayserver/docker/fcgi/command/in_out_command_base.rb +57 -0
  9. data/lib/baykit/bayserver/docker/fcgi/command/package.rb +6 -0
  10. data/lib/baykit/bayserver/docker/fcgi/fcg_command.rb +40 -0
  11. data/lib/baykit/bayserver/docker/fcgi/fcg_command_handler.rb +24 -0
  12. data/lib/baykit/bayserver/docker/fcgi/fcg_command_unpacker.rb +56 -0
  13. data/lib/baykit/bayserver/docker/fcgi/fcg_docker.rb +14 -0
  14. data/lib/baykit/bayserver/docker/fcgi/fcg_inbound_handler.rb +354 -0
  15. data/lib/baykit/bayserver/docker/fcgi/fcg_packet.rb +56 -0
  16. data/lib/baykit/bayserver/docker/fcgi/fcg_packet_factory.rb +17 -0
  17. data/lib/baykit/bayserver/docker/fcgi/fcg_packet_unpacker.rb +201 -0
  18. data/lib/baykit/bayserver/docker/fcgi/fcg_params.rb +46 -0
  19. data/lib/baykit/bayserver/docker/fcgi/fcg_port_docker.rb +52 -0
  20. data/lib/baykit/bayserver/docker/fcgi/fcg_protocol_handler.rb +54 -0
  21. data/lib/baykit/bayserver/docker/fcgi/fcg_type.rb +23 -0
  22. data/lib/baykit/bayserver/docker/fcgi/fcg_warp_docker.rb +81 -0
  23. data/lib/baykit/bayserver/docker/fcgi/fcg_warp_handler.rb +324 -0
  24. data/lib/baykit/bayserver/docker/fcgi/package.rb +12 -0
  25. metadata +79 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2de0757edf90f4c3fe022303174264eb4a8a1cdf78d963bbc8f846bdd0b095ad
4
+ data.tar.gz: 1d587131837ea5a05db127671f4896e96c0784a9b23eeba7a4d03216faa6e2b0
5
+ SHA512:
6
+ metadata.gz: 5e3daecd02c65f999f1c853858a7b21dbe8898ec9800e462f6faaecc0fc868b4304a2636882b9e8a75d116525bb50e01a6b99c1c3510bd7e0251e50bee505256
7
+ data.tar.gz: 61fca56ffe15d0b9cc3d623157a36ed88a48d3d0d8a084440f8bd581139bb5f5e4756fd8d0e0b4b60364c71e8c9d81dec8f8b4b5c554eb280864a7fe1356806f
@@ -0,0 +1,66 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_command'
2
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
3
+
4
+ #
5
+ # FCGI spec
6
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
7
+ #
8
+ # Begin request command format
9
+ # typedef struct {
10
+ # unsigned char roleB1;
11
+ # unsigned char roleB0;
12
+ # unsigned char flags;
13
+ # unsigned char reserved[5];
14
+ # } FCGI_BeginRequestBody;
15
+ #
16
+ module Baykit
17
+ module BayServer
18
+ module Docker
19
+ module Fcgi
20
+ module Command
21
+ class CmdBeginRequest < Baykit::BayServer::Docker::Fcgi::FcgCommand
22
+ include Baykit::BayServer::Docker::Fcgi
23
+
24
+ FCGI_KEEP_CONN = 1
25
+ FCGI_RESPONDER = 1
26
+ FCGI_AUTHORIZER = 2
27
+ FCGI_FILTER = 3
28
+
29
+ attr_accessor :role
30
+ attr_accessor :keep_conn
31
+
32
+ def initialize(req_id)
33
+ super(FcgType::BEGIN_REQUEST, req_id)
34
+ end
35
+
36
+ def unpack(pkt)
37
+ super
38
+
39
+ acc = pkt.new_data_accessor
40
+ @role = acc.get_short
41
+ flags = acc.get_byte
42
+ @keep_conn = (flags & FCGI_KEEP_CONN) != 0
43
+ end
44
+
45
+ def pack(pkt)
46
+ acc = pkt.new_data_accessor
47
+ acc.put_short(@role)
48
+ acc.put_byte(@keep_conn ? 1 : 0)
49
+ reserved = " " * 5
50
+ acc.put_bytes(reserved)
51
+
52
+ # must be called from last line
53
+ super
54
+ end
55
+
56
+ def handle(cmd_handler)
57
+ return cmd_handler.handle_begin_request(self)
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,66 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_command'
2
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
3
+
4
+ #
5
+ # FCGI spec
6
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
7
+ #
8
+ # Endrequest command format
9
+ # typedef struct {
10
+ # unsigned char appStatusB3;
11
+ # unsigned char appStatusB2;
12
+ # unsigned char appStatusB1;
13
+ # unsigned char appStatusB0;
14
+ # unsigned char protocolStatus;
15
+ # unsigned char reserved[3];
16
+ # } FCGI_EndRequestBody;
17
+ #
18
+ module Baykit
19
+ module BayServer
20
+ module Docker
21
+ module Fcgi
22
+ module Command
23
+ class CmdEndRequest < Baykit::BayServer::Docker::Fcgi::FcgCommand
24
+
25
+ FCGI_REQUEST_COMPLETE = 0
26
+ FCGI_CANT_MPX_CONN = 1
27
+ FCGI_OVERLOADED = 2
28
+ FCGI_UNKNOWN_ROLE = 3
29
+
30
+ attr :app_status
31
+ attr :protocol_status
32
+
33
+ def initialize(req_id)
34
+ super(FcgType::END_REQUEST, req_id)
35
+ @app_status = 0
36
+ @protocol_status = FCGI_REQUEST_COMPLETE
37
+ end
38
+
39
+ def unpack(pkt)
40
+ super
41
+ acc = pkt.new_data_accessor
42
+ @app_status = acc.get_int
43
+ @protocol_status = acc.get_byte
44
+ end
45
+
46
+ def pack(pkt)
47
+ acc = pkt.new_data_accessor
48
+ acc.put_int(@app_status)
49
+ acc.put_byte(@protocol_status)
50
+ reserved = " " * 3
51
+ acc.put_bytes(reserved)
52
+
53
+ # must be called from last line
54
+ super
55
+ end
56
+
57
+ def handle(cmd_handler)
58
+ return cmd_handler.handle_end_request(self)
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,160 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_command'
2
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
3
+ require 'baykit/bayserver/util/string_util'
4
+
5
+ #
6
+ # FCGI spec
7
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
8
+ #
9
+ #
10
+ # Params command format (Name-Value list)
11
+ #
12
+ # typedef struct {
13
+ # unsigned char nameLengthB0; // nameLengthB0 >> 7 == 0
14
+ # unsigned char valueLengthB0; // valueLengthB0 >> 7 == 0
15
+ # unsigned char nameData[nameLength];
16
+ # unsigned char valueData[valueLength];
17
+ # } FCGI_NameValuePair11;
18
+ #
19
+ # typedef struct {
20
+ # unsigned char nameLengthB0; // nameLengthB0 >> 7 == 0
21
+ # unsigned char valueLengthB3; // valueLengthB3 >> 7 == 1
22
+ # unsigned char valueLengthB2;
23
+ # unsigned char valueLengthB1;
24
+ # unsigned char valueLengthB0;
25
+ # unsigned char nameData[nameLength];
26
+ # unsigned char valueData[valueLength
27
+ # ((B3 & 0x7f) << 24) + (B2 << 16) + (B1 << 8) + B0];
28
+ # } FCGI_NameValuePair14;
29
+ #
30
+ # typedef struct {
31
+ # unsigned char nameLengthB3; // nameLengthB3 >> 7 == 1
32
+ # unsigned char nameLengthB2;
33
+ # unsigned char nameLengthB1;
34
+ # unsigned char nameLengthB0;
35
+ # unsigned char valueLengthB0; // valueLengthB0 >> 7 == 0
36
+ # unsigned char nameData[nameLength
37
+ # ((B3 & 0x7f) << 24) + (B2 << 16) + (B1 << 8) + B0];
38
+ # unsigned char valueData[valueLength];
39
+ # } FCGI_NameValuePair41;
40
+ #
41
+ # typedef struct {
42
+ # unsigned char nameLengthB3; // nameLengthB3 >> 7 == 1
43
+ # unsigned char nameLengthB2;
44
+ # unsigned char nameLengthB1;
45
+ # unsigned char nameLengthB0;
46
+ # unsigned char valueLengthB3; // valueLengthB3 >> 7 == 1
47
+ # unsigned char valueLengthB2;
48
+ # unsigned char valueLengthB1;
49
+ # unsigned char valueLengthB0;
50
+ # unsigned char nameData[nameLength
51
+ # ((B3 & 0x7f) << 24) + (B2 << 16) + (B1 << 8) + B0];
52
+ # unsigned char valueData[valueLength
53
+ # ((B3 & 0x7f) << 24) + (B2 << 16) + (B1 << 8) + B0];
54
+ # } FCGI_NameValuePair44;
55
+ #
56
+
57
+ module Baykit
58
+ module BayServer
59
+ module Docker
60
+ module Fcgi
61
+ module Command
62
+ class CmdParams < Baykit::BayServer::Docker::Fcgi::FcgCommand
63
+ include Baykit::BayServer::Util
64
+
65
+ attr :params
66
+
67
+ def initialize(req_id)
68
+ super(FcgType::PARAMS, req_id)
69
+ @params = []
70
+ end
71
+
72
+ def unpack(pkt)
73
+ super
74
+ acc = pkt.new_data_accessor
75
+ while acc.pos < pkt.data_len
76
+ name_len = read_length(acc)
77
+ value_len = read_length(acc)
78
+
79
+ name = StringUtil.alloc(name_len)
80
+ acc.get_bytes(name, 0, name_len)
81
+
82
+ value = StringUtil.alloc(value_len)
83
+ acc.get_bytes(value, 0, value_len)
84
+
85
+ BayLog.trace("Params: %s=%s", name, value)
86
+ add_param(name, value)
87
+ end
88
+ end
89
+
90
+ def pack(pkt)
91
+ acc = pkt.new_data_accessor
92
+ @params.each do |nv|
93
+ name = nv[0]
94
+ value = nv[1]
95
+ name_len = name.length
96
+ value_len = value.length
97
+
98
+ write_length(name_len, acc)
99
+ write_length(value_len, acc)
100
+
101
+ acc.put_string(name)
102
+ acc.put_string(value)
103
+ end
104
+
105
+ # must be called from last line
106
+ super
107
+ end
108
+
109
+ def handle(cmd_handler)
110
+ return cmd_handler.handle_params(self)
111
+ end
112
+
113
+
114
+ def read_length(acc)
115
+ len = acc.get_byte
116
+ if len >> 7 == 0
117
+ return len
118
+ else
119
+ len2 = acc.get_byte
120
+ len3 = acc.get_byte
121
+ len4 = acc.get_byte
122
+ return ((len & 0x7f) << 24) | (len2 << 16) | (len3 << 8) | len4
123
+ end
124
+ end
125
+
126
+ def write_length(len, acc)
127
+ if len >> 7 == 0
128
+ acc.put_byte(len)
129
+ else
130
+ len1 = (len >> 24 & 0xFF) | 0x80
131
+ len2 = len >> 16 & 0xFF
132
+ len3 = len >> 8 & 0xFF
133
+ len4 = len & 0xFF
134
+ buf = StringUtil.alloc(4)
135
+ buf << len1 << len2 << len3 << len4
136
+ acc.put_bytes(buf)
137
+ end
138
+ end
139
+
140
+ def add_param(name, value)
141
+ if name == nil
142
+ raise RuntimeError.new("nil argument")
143
+ end
144
+
145
+ if value == nil
146
+ value = ""
147
+ end
148
+
149
+ @params.append([name, value])
150
+ end
151
+
152
+ def to_s()
153
+ "FcgCmdParams#{@params}"
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,31 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
2
+
3
+ #
4
+ # FCGI spec
5
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
6
+ #
7
+ # StdErr command format
8
+ # raw data
9
+ #
10
+
11
+ module Baykit
12
+ module BayServer
13
+ module Docker
14
+ module Fcgi
15
+ module Command
16
+ class CmdStdErr < InOutCommandBase
17
+
18
+ def initialize(req_id)
19
+ super(FcgType::STDERR, req_id)
20
+ end
21
+
22
+ def handle(cmd_handler)
23
+ return cmd_handler.handle_stderr(self)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
2
+ require 'baykit/bayserver/docker/fcgi/command/in_out_command_base'
3
+
4
+
5
+ #
6
+ # FCGI spec
7
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
8
+ #
9
+ # StdIn command format
10
+ # raw data
11
+ #
12
+ module Baykit
13
+ module BayServer
14
+ module Docker
15
+ module Fcgi
16
+ module Command
17
+ class CmdStdIn < Baykit::BayServer::Docker::Fcgi::Command::InOutCommandBase
18
+
19
+ def initialize(req_id, data=nil, start=0, len=0)
20
+ super(FcgType::STDIN, req_id, data, start, len)
21
+ end
22
+
23
+ def handle(cmd_handler)
24
+ return cmd_handler.handle_stdin(self)
25
+ end
26
+
27
+
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
2
+
3
+ #
4
+ # FCGI spec
5
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
6
+ #
7
+ # StdOut command format
8
+ # raw data
9
+ #
10
+
11
+ module Baykit
12
+ module BayServer
13
+ module Docker
14
+ module Fcgi
15
+ module Command
16
+ class CmdStdOut < InOutCommandBase
17
+
18
+ def initialize(req_id, data = nil, start = nil, len = nil)
19
+ super(FcgType::STDOUT, req_id, data, start, len)
20
+ end
21
+
22
+ def handle(cmd_handler)
23
+ return cmd_handler.handle_stdout(self)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,57 @@
1
+ require 'baykit/bayserver/docker/fcgi/fcg_command'
2
+ require 'baykit/bayserver/docker/fcgi/fcg_type'
3
+ require 'baykit/bayserver/docker/fcgi/fcg_packet'
4
+
5
+ #
6
+ # FCGI spec
7
+ # http://www.mit.edu/~yandros/doc/specs/fcgi-spec.html
8
+ #
9
+ # StdIn/StdOut/StdErr command format
10
+ # raw data
11
+ #
12
+ module Baykit
13
+ module BayServer
14
+ module Docker
15
+ module Fcgi
16
+ module Command
17
+ class InOutCommandBase < Baykit::BayServer::Docker::Fcgi::FcgCommand
18
+
19
+ MAX_DATA_LEN = FcgPacket::MAXLEN - FcgPacket::PREAMBLE_SIZE
20
+
21
+ #
22
+ # This class refers external byte array, so this IS NOT mutable
23
+ #
24
+ attr :start
25
+ attr :length
26
+ attr :data
27
+
28
+ def initialize(type, req_id, data=nil, start=0, len=0)
29
+ super(type, req_id)
30
+ @data = data
31
+ @start = start
32
+ @length = len
33
+ end
34
+
35
+ def unpack(pkt)
36
+ super
37
+ @start = pkt.header_len
38
+ @length = pkt.data_len
39
+ @data = pkt.buf
40
+ end
41
+
42
+ def pack(pkt)
43
+ if @data != nil && @length > 0
44
+ acc = pkt.new_data_accessor()
45
+ acc.put_bytes(@data, @start, @length)
46
+ end
47
+
48
+ # must be called from last line
49
+ super
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ require 'baykit/bayserver/docker/fcgi/command/cmd_begin_request'
2
+ require 'baykit/bayserver/docker/fcgi/command/cmd_end_request'
3
+ require 'baykit/bayserver/docker/fcgi/command/cmd_params'
4
+ require 'baykit/bayserver/docker/fcgi/command/cmd_stdin'
5
+ require 'baykit/bayserver/docker/fcgi/command/cmd_stdout'
6
+ require 'baykit/bayserver/docker/fcgi/command/cmd_stderr'
@@ -0,0 +1,40 @@
1
+ module Baykit
2
+ module BayServer
3
+ module Docker
4
+ module Fcgi
5
+ class FcgCommand < Baykit::BayServer::Protocol::Command
6
+
7
+ attr :req_id
8
+
9
+ def initialize(type, req_id)
10
+ super(type)
11
+ @req_id = req_id
12
+ end
13
+
14
+ def unpack(pkt)
15
+ @req_id = pkt.req_id
16
+ end
17
+
18
+ #
19
+ # Super class method must be called from last line of override method
20
+ # since header cannot be packed before data is constructed
21
+ #
22
+ def pack(pkt)
23
+ pkt.req_id = @req_id
24
+ pack_header(pkt)
25
+ end
26
+
27
+ def pack_header(pkt)
28
+ acc = pkt.new_header_accessor()
29
+ acc.put_byte(pkt.version)
30
+ acc.put_byte(pkt.type)
31
+ acc.put_short(pkt.req_id)
32
+ acc.put_short(pkt.data_len)
33
+ acc.put_byte(0) # paddinglen
34
+ acc.put_byte(0) # reserved
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ module Baykit
2
+ module BayServer
3
+ module Docker
4
+ module Fcgi
5
+ module FcgCommandHandler
6
+ include Baykit::BayServer::Protocol::CommandHandler # implements
7
+
8
+ #
9
+ # abstract methods
10
+ #
11
+ # public abstract NextSocketAction handleBeginRequest(CmdBeginRequest cmd) throws IOException;
12
+ # public abstract NextSocketAction handleEndRequest(CmdEndRequest cmd) throws IOException;
13
+ # public abstract NextSocketAction handleParams(CmdParams cmd) throws IOException;
14
+ # public abstract NextSocketAction handleStdErr(CmdStdErr cmd) throws IOException;
15
+ # public abstract NextSocketAction handleStdIn(CmdStdIn cmd) throws IOException;
16
+ # public abstract NextSocketAction handleStdOut(CmdStdOut cmd) throws IOException;
17
+ #
18
+
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,56 @@
1
+ require 'baykit/bayserver/protocol/command_unpacker'
2
+ require 'baykit/bayserver/docker/fcgi/command/package'
3
+
4
+ module Baykit
5
+ module BayServer
6
+ module Docker
7
+ module Fcgi
8
+ class FcgCommandUnPacker < Baykit::BayServer::Protocol::CommandUnPacker
9
+
10
+ include Baykit::BayServer::Docker::Fcgi::Command
11
+
12
+ attr :handler
13
+
14
+ def initialize(handler)
15
+ @handler = handler
16
+ reset()
17
+ end
18
+
19
+ def reset()
20
+
21
+ end
22
+
23
+ def packet_received(pkt)
24
+
25
+ case(pkt.type)
26
+ when FcgType::BEGIN_REQUEST
27
+ cmd = CmdBeginRequest.new(pkt.req_id)
28
+
29
+ when FcgType::END_REQUEST
30
+ cmd = CmdEndRequest.new(pkt.req_id)
31
+
32
+ when FcgType::PARAMS
33
+ cmd = CmdParams.new(pkt.req_id)
34
+
35
+ when FcgType::STDIN
36
+ cmd = CmdStdIn.new(pkt.req_id)
37
+
38
+ when FcgType::STDOUT
39
+ cmd = CmdStdOut.new(pkt.req_id)
40
+
41
+ when FcgType::STDERR
42
+ cmd = CmdStdErr.new(pkt.req_id)
43
+
44
+ else
45
+ raise RuntimeError.new("IllegalState")
46
+
47
+ end
48
+ cmd.unpack(pkt)
49
+ cmd.handle(handler)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -0,0 +1,14 @@
1
+ module Baykit
2
+ module BayServer
3
+ module Docker
4
+ module Fcgi
5
+ module FcgDocker
6
+ include Baykit::BayServer::Docker::Docker # implements
7
+
8
+ PROTO_NAME = "fcgi"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+