ruby_home 0.1.23 → 0.2.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/.travis.yml +1 -0
- data/lib/ruby_home/hap/hap_request.rb +5 -2
- data/lib/ruby_home/hap/server.rb +43 -82
- data/lib/ruby_home/hap/server_handler.rb +74 -0
- data/lib/ruby_home/http/application.rb +8 -17
- data/lib/ruby_home/version.rb +1 -1
- data/lib/ruby_home.rb +10 -3
- data/rubyhome.gemspec +0 -1
- metadata +3 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb157eb26583418aa02ef31fe2b4ed2f8f40f8cb57e46f78e7603cdd531256b
|
4
|
+
data.tar.gz: 5ed756570a2e0f3992a0b4b53eb0521bc94d7c46f55e5318a80e6bf74da27304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8732ab9a3caa1e9d61a371bbed0495eb523d6e0b1e0c248f1f7f1fc7d6ab6848ccaa8a5105a78214ad4375bb15df57e84df00d664cf4ad554bbab89a53e375d
|
7
|
+
data.tar.gz: 3f0b97b56c9785b1664a5fa7885407a37ae75bce6924f1b8c7dbee6b72ab3037b8037f5872c38e7fad6ed5bd88fa34f73f955a70138774b6b1fe18bfe218956a
|
data/.travis.yml
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module RubyHome
|
2
2
|
module HAP
|
3
3
|
class HAPRequest < WEBrick::HTTPRequest
|
4
|
-
|
4
|
+
def initialize(config, session:)
|
5
|
+
@session = session
|
6
|
+
super(config)
|
7
|
+
end
|
5
8
|
|
6
9
|
def meta_vars
|
7
10
|
super.merge(
|
8
|
-
{ "REQUEST_SESSION" => session }
|
11
|
+
{ "REQUEST_SESSION" => @session }
|
9
12
|
)
|
10
13
|
end
|
11
14
|
end
|
data/lib/ruby_home/hap/server.rb
CHANGED
@@ -1,90 +1,51 @@
|
|
1
1
|
module RubyHome
|
2
2
|
module HAP
|
3
|
-
class Server
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
3
|
+
class Server < ::WEBrick::HTTPServer
|
4
|
+
def run(sock)
|
5
|
+
session = Session.new(sock)
|
6
|
+
|
7
|
+
while true
|
8
|
+
req = HAPRequest.new(@config, session: session)
|
9
|
+
res = HAPResponse.new(@config)
|
10
|
+
begin
|
11
|
+
while true
|
12
|
+
break if sock.to_io.wait_readable(0.5)
|
13
|
+
break if @status != :Running
|
14
|
+
end
|
15
|
+
raise ::WEBrick::HTTPStatus::EOFError if @status != :Running
|
16
|
+
raise ::WEBrick::HTTPStatus::EOFError if sock.eof?
|
17
|
+
|
18
|
+
req.parse(session.parse)
|
19
|
+
|
20
|
+
res.request_method = req.request_method
|
21
|
+
res.request_uri = req.request_uri
|
22
|
+
res.request_http_version = req.http_version
|
23
|
+
res.keep_alive = req.keep_alive?
|
24
|
+
|
25
|
+
service(req, res)
|
26
|
+
rescue ::WEBrick::HTTPStatus::EOFError, ::WEBrick::HTTPStatus::RequestTimeout => ex
|
27
|
+
res.set_error(ex)
|
28
|
+
rescue ::WEBrick::HTTPStatus::Error => ex
|
29
|
+
@logger.error(ex.message)
|
30
|
+
res.set_error(ex)
|
31
|
+
rescue ::WEBrick::HTTPStatus::Status => ex
|
32
|
+
res.status = ex.code
|
33
|
+
rescue StandardError => ex
|
34
|
+
@logger.error(ex)
|
35
|
+
res.set_error(ex, true)
|
36
|
+
ensure
|
37
|
+
if req.request_line
|
38
|
+
if req.keep_alive? && res.keep_alive?
|
39
|
+
req.fixup()
|
40
|
+
end
|
41
|
+
res.send_response(session)
|
42
|
+
access_log(@config, req, res)
|
43
|
+
end
|
25
44
|
end
|
45
|
+
break unless req.keep_alive?
|
46
|
+
break unless res.keep_alive?
|
26
47
|
end
|
27
48
|
end
|
28
|
-
|
29
|
-
def shutdown
|
30
|
-
@status = :shutdown
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
SESSIONS = {}
|
36
|
-
|
37
|
-
def accept
|
38
|
-
socket = @server.accept
|
39
|
-
monitor = @selector.register(socket, :r)
|
40
|
-
monitor.value = proc { read(socket) }
|
41
|
-
end
|
42
|
-
|
43
|
-
def upstream
|
44
|
-
@_upstream ||= HTTP::Application.run
|
45
|
-
end
|
46
|
-
|
47
|
-
def webrick_config
|
48
|
-
@_webrick_config ||= WEBrick::Config::HTTP
|
49
|
-
end
|
50
|
-
|
51
|
-
def read(socket)
|
52
|
-
return close(socket) if socket.eof?
|
53
|
-
|
54
|
-
request = HAPRequest.new(webrick_config)
|
55
|
-
response = HAPResponse.new(webrick_config)
|
56
|
-
|
57
|
-
session = SESSIONS[socket] ||= Session.new(socket)
|
58
|
-
request.session = session
|
59
|
-
|
60
|
-
request.parse(session.parse)
|
61
|
-
response.request_method = request.request_method
|
62
|
-
response.request_uri = request.request_uri
|
63
|
-
response.request_http_version = request.http_version
|
64
|
-
response.keep_alive = request.keep_alive?
|
65
|
-
|
66
|
-
upstream.service(request, response)
|
67
|
-
|
68
|
-
if request.request_line
|
69
|
-
if request.keep_alive? && response.keep_alive?
|
70
|
-
request.fixup()
|
71
|
-
end
|
72
|
-
response.send_response(session)
|
73
|
-
end
|
74
|
-
|
75
|
-
return close(socket) unless request.keep_alive?
|
76
|
-
return close(socket) unless response.keep_alive?
|
77
|
-
rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EHOSTUNREACH,
|
78
|
-
Errno::EINVAL, Errno::ENOPROTOOPT, Errno::EPROTO, Errno::ETIMEDOUT
|
79
|
-
close(socket)
|
80
|
-
rescue EOFError
|
81
|
-
close(socket)
|
82
|
-
end
|
83
|
-
|
84
|
-
def close(socket)
|
85
|
-
@selector.deregister(socket)
|
86
|
-
socket.close
|
87
|
-
end
|
88
49
|
end
|
89
50
|
end
|
90
51
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module RubyHome
|
2
|
+
module HAP
|
3
|
+
class RackHandler < ::Rack::Handler::WEBrick
|
4
|
+
def self.run(app, options={})
|
5
|
+
@server = Server.new(options)
|
6
|
+
@server.mount "/", RackHandler, app
|
7
|
+
yield @server if block_given?
|
8
|
+
@server
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ServerHandler
|
13
|
+
def initialize(configuration: )
|
14
|
+
@configuration = configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
server.start
|
19
|
+
end
|
20
|
+
|
21
|
+
def shutdown
|
22
|
+
server.shutdown
|
23
|
+
end
|
24
|
+
|
25
|
+
def server
|
26
|
+
@server ||= RackHandler.run(
|
27
|
+
HTTP::Application.rack_builder,
|
28
|
+
server_options
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def server_options
|
33
|
+
{
|
34
|
+
Port: port,
|
35
|
+
Host: bind_address,
|
36
|
+
ServerSoftware: 'RubyHome',
|
37
|
+
Logger: server_logger,
|
38
|
+
AccessLog: access_logger
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def server_logger
|
43
|
+
if ENV['DEBUG']
|
44
|
+
WEBrick::Log::new(STDOUT, WEBrick::BasicLog::DEBUG)
|
45
|
+
else
|
46
|
+
WEBrick::Log::new("/dev/null", WEBrick::BasicLog::WARN)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def access_logger
|
51
|
+
if ENV['DEBUG']
|
52
|
+
[
|
53
|
+
[ STDOUT, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
|
54
|
+
[ STDOUT, WEBrick::AccessLog::REFERER_LOG_FORMAT ]
|
55
|
+
]
|
56
|
+
else
|
57
|
+
[]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def bind_address
|
62
|
+
configuration.host
|
63
|
+
end
|
64
|
+
|
65
|
+
def port
|
66
|
+
configuration.port
|
67
|
+
end
|
68
|
+
|
69
|
+
attr_reader :configuration
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
@@ -3,23 +3,14 @@ Dir[File.dirname(__FILE__) + '/controllers/*.rb'].each { |file| require file }
|
|
3
3
|
module RubyHome
|
4
4
|
module HTTP
|
5
5
|
class Application
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
)
|
12
|
-
|
13
|
-
|
14
|
-
def rack_builder
|
15
|
-
::Rack::Builder.new do
|
16
|
-
map('/accessories') { run AccessoriesController }
|
17
|
-
map('/characteristics') { run CharacteristicsController }
|
18
|
-
map('/identify') { run IdentifyController }
|
19
|
-
map('/pair-setup') { run PairSetupsController }
|
20
|
-
map('/pair-verify') { run PairVerifiesController }
|
21
|
-
map('/pairings') { run PairingsController }
|
22
|
-
end
|
6
|
+
def self.rack_builder
|
7
|
+
::Rack::Builder.new do
|
8
|
+
map('/accessories') { run AccessoriesController }
|
9
|
+
map('/characteristics') { run CharacteristicsController }
|
10
|
+
map('/identify') { run IdentifyController }
|
11
|
+
map('/pair-setup') { run PairSetupsController }
|
12
|
+
map('/pair-verify') { run PairVerifiesController }
|
13
|
+
map('/pairings') { run PairingsController }
|
23
14
|
end
|
24
15
|
end
|
25
16
|
end
|
data/lib/ruby_home/version.rb
CHANGED
data/lib/ruby_home.rb
CHANGED
@@ -2,7 +2,6 @@ require 'bindata'
|
|
2
2
|
require 'dnssd'
|
3
3
|
require 'facets/hash/slice'
|
4
4
|
require 'hkdf'
|
5
|
-
require 'nio'
|
6
5
|
require 'oj'
|
7
6
|
require 'rack'
|
8
7
|
require 'rbnacl'
|
@@ -16,7 +15,15 @@ require 'wisper'
|
|
16
15
|
require 'yaml'
|
17
16
|
|
18
17
|
module RubyHome
|
19
|
-
|
18
|
+
[
|
19
|
+
'/ruby_home/hap/**/*.rb',
|
20
|
+
'/ruby_home/http/**/*.rb',
|
21
|
+
'/ruby_home/factories/**/*.rb',
|
22
|
+
'/ruby_home/dns/**/*.rb',
|
23
|
+
'/ruby_home/*.rb'
|
24
|
+
].each do |pattern|
|
25
|
+
Dir[File.dirname(__FILE__) + pattern].each { |file| require file }
|
26
|
+
end
|
20
27
|
|
21
28
|
class << self
|
22
29
|
def configuration
|
@@ -58,7 +65,7 @@ module RubyHome
|
|
58
65
|
end
|
59
66
|
|
60
67
|
def hap_server
|
61
|
-
@_hap_server ||= HAP::
|
68
|
+
@_hap_server ||= HAP::ServerHandler.new(configuration: configuration)
|
62
69
|
end
|
63
70
|
|
64
71
|
def greet
|
data/rubyhome.gemspec
CHANGED
@@ -30,7 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_dependency 'dnssd', '~> 3.0'
|
31
31
|
spec.add_dependency 'facets', '~> 3.1'
|
32
32
|
spec.add_dependency 'hkdf', '~> 0.3.0'
|
33
|
-
spec.add_dependency 'nio4r', '~> 2.3', '>= 2.3.1'
|
34
33
|
spec.add_dependency 'oj', '3.7.9'
|
35
34
|
spec.add_dependency 'rbnacl', '~> 6.0'
|
36
35
|
spec.add_dependency 'ruby_home-srp', '~> 1.3'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_home
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Entwistle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -72,26 +72,6 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 0.3.0
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: nio4r
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '2.3'
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: 2.3.1
|
85
|
-
type: :runtime
|
86
|
-
prerelease: false
|
87
|
-
version_requirements: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- - "~>"
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: '2.3'
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: 2.3.1
|
95
75
|
- !ruby/object:Gem::Dependency
|
96
76
|
name: oj
|
97
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -296,6 +276,7 @@ files:
|
|
296
276
|
- lib/ruby_home/hap/hap_request.rb
|
297
277
|
- lib/ruby_home/hap/hap_response.rb
|
298
278
|
- lib/ruby_home/hap/server.rb
|
279
|
+
- lib/ruby_home/hap/server_handler.rb
|
299
280
|
- lib/ruby_home/hap/session.rb
|
300
281
|
- lib/ruby_home/hap/values/base_value.rb
|
301
282
|
- lib/ruby_home/hap/values/bool_value.rb
|