faye-websocket 0.4.1 → 0.4.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.
Potentially problematic release.
This version of faye-websocket might be problematic. Click here for more details.
- data/CHANGELOG.txt +5 -0
- data/ext/faye_websocket_mask/FayeWebsocketMaskService.java +61 -0
- data/ext/faye_websocket_mask/faye_websocket_mask.c +1 -3
- data/lib/faye/eventsource.rb +1 -1
- data/lib/faye/websocket.rb +21 -1
- data/lib/faye/websocket/client.rb +1 -1
- data/lib/faye/websocket/hybi_parser.rb +2 -2
- data/lib/faye_websocket_mask.jar +0 -0
- data/spec/faye/websocket/client_spec.rb +5 -0
- data/spec/spec_helper.rb +9 -6
- metadata +117 -132
data/CHANGELOG.txt
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
package com.jcoglan.faye;
|
2
|
+
|
3
|
+
import java.lang.Long;
|
4
|
+
import java.io.IOException;
|
5
|
+
|
6
|
+
import org.jruby.Ruby;
|
7
|
+
import org.jruby.RubyArray;
|
8
|
+
import org.jruby.RubyClass;
|
9
|
+
import org.jruby.RubyFixnum;
|
10
|
+
import org.jruby.RubyModule;
|
11
|
+
import org.jruby.RubyObject;
|
12
|
+
import org.jruby.anno.JRubyMethod;
|
13
|
+
import org.jruby.runtime.ObjectAllocator;
|
14
|
+
import org.jruby.runtime.ThreadContext;
|
15
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
16
|
+
import org.jruby.runtime.load.BasicLibraryService;
|
17
|
+
|
18
|
+
public class FayeWebsocketMaskService implements BasicLibraryService {
|
19
|
+
private Ruby runtime;
|
20
|
+
|
21
|
+
public boolean basicLoad(Ruby runtime) throws IOException {
|
22
|
+
this.runtime = runtime;
|
23
|
+
RubyModule faye = runtime.defineModule("Faye");
|
24
|
+
|
25
|
+
RubyClass webSocketMask = faye.defineClassUnder("WebSocketMask", runtime.getObject(), new ObjectAllocator() {
|
26
|
+
public IRubyObject allocate(Ruby runtime, RubyClass rubyClass) {
|
27
|
+
return new WebsocketMask(runtime, rubyClass);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
|
31
|
+
webSocketMask.defineAnnotatedMethods(WebsocketMask.class);
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
|
35
|
+
public class WebsocketMask extends RubyObject {
|
36
|
+
public WebsocketMask(final Ruby runtime, RubyClass rubyClass) {
|
37
|
+
super(runtime, rubyClass);
|
38
|
+
}
|
39
|
+
|
40
|
+
@JRubyMethod
|
41
|
+
public IRubyObject mask(ThreadContext context, IRubyObject payload, IRubyObject mask) {
|
42
|
+
int n = ((RubyArray)payload).getLength(), i;
|
43
|
+
long p, m;
|
44
|
+
RubyArray unmasked = RubyArray.newArray(runtime, n);
|
45
|
+
|
46
|
+
long[] maskArray = {
|
47
|
+
(Long)((RubyArray)mask).get(0),
|
48
|
+
(Long)((RubyArray)mask).get(1),
|
49
|
+
(Long)((RubyArray)mask).get(2),
|
50
|
+
(Long)((RubyArray)mask).get(3)
|
51
|
+
};
|
52
|
+
|
53
|
+
for (i = 0; i < n; i++) {
|
54
|
+
p = (Long)((RubyArray)payload).get(i);
|
55
|
+
m = maskArray[i % 4];
|
56
|
+
unmasked.set(i, p ^ m);
|
57
|
+
}
|
58
|
+
return unmasked;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
|
3
3
|
VALUE Faye = Qnil;
|
4
|
-
VALUE FayeWebSocket = Qnil;
|
5
4
|
VALUE FayeWebSocketMask = Qnil;
|
6
5
|
|
7
6
|
void Init_faye_websocket_mask();
|
@@ -9,8 +8,7 @@ VALUE method_faye_websocket_mask(VALUE self, VALUE payload, VALUE mask);
|
|
9
8
|
|
10
9
|
void Init_faye_websocket_mask() {
|
11
10
|
Faye = rb_define_module("Faye");
|
12
|
-
|
13
|
-
FayeWebSocketMask = rb_define_module_under(FayeWebSocket, "Mask");
|
11
|
+
FayeWebSocketMask = rb_define_module_under(Faye, "WebSocketMask");
|
14
12
|
rb_define_singleton_method(FayeWebSocketMask, "mask", method_faye_websocket_mask, 2);
|
15
13
|
}
|
16
14
|
|
data/lib/faye/eventsource.rb
CHANGED
data/lib/faye/websocket.rb
CHANGED
@@ -23,6 +23,26 @@ module Faye
|
|
23
23
|
root = File.expand_path('../websocket', __FILE__)
|
24
24
|
require root + '/../../faye_websocket_mask'
|
25
25
|
|
26
|
+
def self.jruby?
|
27
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.rbx?
|
31
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
32
|
+
end
|
33
|
+
|
34
|
+
if jruby?
|
35
|
+
require 'jruby'
|
36
|
+
com.jcoglan.faye.FayeWebsocketMaskService.new.basicLoad(JRuby.runtime)
|
37
|
+
end
|
38
|
+
|
39
|
+
unless WebSocketMask.respond_to?(:mask)
|
40
|
+
def WebSocketMask.mask(payload, mask)
|
41
|
+
@instance ||= new
|
42
|
+
@instance.mask(payload, mask)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
26
46
|
unless String.instance_methods.include?(:force_encoding)
|
27
47
|
require root + '/utf8_match'
|
28
48
|
end
|
@@ -183,7 +203,7 @@ module Faye
|
|
183
203
|
|
184
204
|
def write(data)
|
185
205
|
return unless @stream_send
|
186
|
-
@stream_send.call(data)
|
206
|
+
@stream_send.call(data) rescue nil
|
187
207
|
end
|
188
208
|
end
|
189
209
|
end
|
@@ -170,7 +170,7 @@ module Faye
|
|
170
170
|
if @masking
|
171
171
|
mask = [rand(256), rand(256), rand(256), rand(256)]
|
172
172
|
frame[header...offset] = mask
|
173
|
-
buffer =
|
173
|
+
buffer = WebSocketMask.mask(buffer, mask)
|
174
174
|
end
|
175
175
|
|
176
176
|
frame.concat(buffer)
|
@@ -235,7 +235,7 @@ module Faye
|
|
235
235
|
end
|
236
236
|
|
237
237
|
def emit_frame
|
238
|
-
payload = @masked ?
|
238
|
+
payload = @masked ? WebSocketMask.mask(@payload, @mask) : @payload
|
239
239
|
|
240
240
|
case @opcode
|
241
241
|
when OPCODES[:continuation] then
|
Binary file
|
@@ -77,6 +77,7 @@ WebSocketSteps = EM::RSpec.async_steps do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe Faye::WebSocket::Client do
|
80
|
+
next if Faye::WebSocket.jruby?
|
80
81
|
include WebSocketSteps
|
81
82
|
|
82
83
|
let(:protocols) { ["foo", "echo"] }
|
@@ -152,6 +153,8 @@ describe Faye::WebSocket::Client do
|
|
152
153
|
end
|
153
154
|
|
154
155
|
describe "with a plain-text Rainbows server" do
|
156
|
+
next if Faye::WebSocket.rbx?
|
157
|
+
|
155
158
|
let(:socket_url) { plain_text_url }
|
156
159
|
let(:blocked_url) { secure_url }
|
157
160
|
|
@@ -162,6 +165,8 @@ describe Faye::WebSocket::Client do
|
|
162
165
|
end
|
163
166
|
|
164
167
|
describe "with a secure Thin server" do
|
168
|
+
next if Faye::WebSocket.rbx?
|
169
|
+
|
165
170
|
let(:socket_url) { secure_url }
|
166
171
|
let(:blocked_url) { plain_text_url }
|
167
172
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
unless RUBY_PLATFORM =~ /java/
|
5
|
+
require 'thin'
|
6
|
+
Thin::Logging.silent = true
|
7
|
+
require 'rainbows'
|
8
|
+
Unicorn::Configurator::DEFAULTS[:logger] = Logger.new(StringIO.new)
|
9
|
+
end
|
10
|
+
|
5
11
|
require File.expand_path('../../lib/faye/websocket', __FILE__)
|
6
12
|
require File.expand_path('../../vendor/em-rspec/lib/em-rspec', __FILE__)
|
7
13
|
require File.expand_path('../faye/websocket/draft75_parser_examples', __FILE__)
|
8
14
|
|
9
|
-
Thin::Logging.silent = true
|
10
|
-
Unicorn::Configurator::DEFAULTS[:logger] = Logger.new(StringIO.new)
|
11
|
-
|
12
15
|
module EncodingHelper
|
13
16
|
def encode(message)
|
14
17
|
message.respond_to?(:force_encoding) ?
|
@@ -31,7 +34,7 @@ class EchoServer
|
|
31
34
|
socket.onmessage = lambda do |event|
|
32
35
|
socket.send(event.data)
|
33
36
|
end
|
34
|
-
|
37
|
+
socket.rack_response
|
35
38
|
end
|
36
39
|
|
37
40
|
def listen(port, backend, ssl = false)
|
metadata
CHANGED
@@ -1,152 +1,137 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: faye-websocket
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.1
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.4.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- James Coglan
|
7
|
+
authors:
|
8
|
+
- James Coglan
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
name: rake-compiler
|
60
|
-
requirement: &18046420 !ruby/object:Gem::Requirement
|
61
|
-
none: false
|
62
|
-
requirements:
|
63
|
-
- - ! '>='
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '0'
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *18046420
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: thin
|
71
|
-
requirement: &18045300 !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ! '>='
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 1.2.0
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: *18045300
|
12
|
+
|
13
|
+
date: 2012-03-09 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.12.0
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rack
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake-compiler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.8.0
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
80
59
|
description:
|
81
60
|
email: jcoglan@gmail.com
|
82
61
|
executables: []
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
- ext/faye_websocket_mask/
|
92
|
-
-
|
93
|
-
-
|
94
|
-
- lib/faye/
|
95
|
-
- lib/faye/websocket
|
96
|
-
- lib/faye/
|
97
|
-
- lib/faye/
|
98
|
-
- lib/faye/
|
99
|
-
- lib/faye/
|
100
|
-
- lib/faye/websocket/
|
101
|
-
- lib/faye/websocket/api
|
102
|
-
- lib/faye/websocket/
|
103
|
-
- lib/faye/websocket.rb
|
104
|
-
- lib/faye/
|
105
|
-
- lib/faye/
|
106
|
-
- lib/faye/
|
107
|
-
- lib/faye/
|
108
|
-
- lib/faye/
|
109
|
-
-
|
110
|
-
-
|
111
|
-
-
|
112
|
-
- examples/
|
113
|
-
- examples/
|
114
|
-
- examples/
|
115
|
-
- examples/
|
116
|
-
- examples/
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
120
|
-
- spec/
|
121
|
-
- spec/
|
122
|
-
- spec/server.key
|
123
|
-
- spec/
|
124
|
-
- spec/
|
125
|
-
- spec/
|
62
|
+
|
63
|
+
extensions:
|
64
|
+
- ext/faye_websocket_mask/extconf.rb
|
65
|
+
extra_rdoc_files:
|
66
|
+
- README.rdoc
|
67
|
+
files:
|
68
|
+
- README.rdoc
|
69
|
+
- CHANGELOG.txt
|
70
|
+
- ext/faye_websocket_mask/faye_websocket_mask.c
|
71
|
+
- ext/faye_websocket_mask/FayeWebsocketMaskService.java
|
72
|
+
- ext/faye_websocket_mask/extconf.rb
|
73
|
+
- lib/faye/eventsource.rb
|
74
|
+
- lib/faye/websocket.rb
|
75
|
+
- lib/faye/adapters/goliath.rb
|
76
|
+
- lib/faye/adapters/rainbows.rb
|
77
|
+
- lib/faye/adapters/rainbows_client.rb
|
78
|
+
- lib/faye/adapters/thin.rb
|
79
|
+
- lib/faye/websocket/adapter.rb
|
80
|
+
- lib/faye/websocket/api.rb
|
81
|
+
- lib/faye/websocket/client.rb
|
82
|
+
- lib/faye/websocket/draft75_parser.rb
|
83
|
+
- lib/faye/websocket/draft76_parser.rb
|
84
|
+
- lib/faye/websocket/hybi_parser.rb
|
85
|
+
- lib/faye/websocket/utf8_match.rb
|
86
|
+
- lib/faye/websocket/api/event.rb
|
87
|
+
- lib/faye/websocket/api/event_target.rb
|
88
|
+
- lib/faye/websocket/hybi_parser/handshake.rb
|
89
|
+
- lib/faye/websocket/hybi_parser/stream_reader.rb
|
90
|
+
- lib/faye_websocket_mask.jar
|
91
|
+
- examples/app.rb
|
92
|
+
- examples/autobahn_client.rb
|
93
|
+
- examples/client.rb
|
94
|
+
- examples/config.ru
|
95
|
+
- examples/haproxy.conf
|
96
|
+
- examples/server.rb
|
97
|
+
- examples/sse.html
|
98
|
+
- examples/ws.html
|
99
|
+
- spec/rainbows.conf
|
100
|
+
- spec/server.crt
|
101
|
+
- spec/server.key
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/faye/websocket/client_spec.rb
|
104
|
+
- spec/faye/websocket/draft75_parser_examples.rb
|
105
|
+
- spec/faye/websocket/draft75_parser_spec.rb
|
106
|
+
- spec/faye/websocket/draft76_parser_spec.rb
|
107
|
+
- spec/faye/websocket/hybi_parser_spec.rb
|
126
108
|
homepage: http://github.com/faye/faye-websocket-ruby
|
127
109
|
licenses: []
|
110
|
+
|
128
111
|
post_install_message:
|
129
|
-
rdoc_options:
|
130
|
-
- --main
|
131
|
-
- README.rdoc
|
132
|
-
require_paths:
|
133
|
-
- lib
|
134
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
rdoc_options:
|
113
|
+
- --main
|
114
|
+
- README.rdoc
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
118
|
none: false
|
136
|
-
requirements:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: "0"
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
124
|
none: false
|
142
|
-
requirements:
|
143
|
-
|
144
|
-
|
145
|
-
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: "0"
|
146
129
|
requirements: []
|
130
|
+
|
147
131
|
rubyforge_project:
|
148
|
-
rubygems_version: 1.8.
|
132
|
+
rubygems_version: 1.8.15
|
149
133
|
signing_key:
|
150
134
|
specification_version: 3
|
151
135
|
summary: Standards-compliant WebSocket server and client
|
152
136
|
test_files: []
|
137
|
+
|