faye-websocket 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faye-websocket might be problematic. Click here for more details.

@@ -1,3 +1,8 @@
1
+ === 0.4.2 / 2012-03-09
2
+
3
+ * Port masking-function C extension to Java for JRuby
4
+
5
+
1
6
  === 0.4.1 / 2012-02-26
2
7
 
3
8
  * Treat anything other than an Array as a string when calling send()
@@ -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
- FayeWebSocket = rb_define_class_under(Faye, "WebSocket", rb_cObject);
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
 
@@ -116,7 +116,7 @@ module Faye
116
116
 
117
117
  def write(data)
118
118
  return unless @stream_send
119
- @stream_send.call(data)
119
+ @stream_send.call(data) rescue nil
120
120
  end
121
121
  end
122
122
  end
@@ -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
@@ -75,7 +75,7 @@ module Faye
75
75
  end
76
76
 
77
77
  def write(data)
78
- send_data(data)
78
+ send_data(data) rescue nil
79
79
  end
80
80
  end
81
81
  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 = Mask.mask(buffer, mask)
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 ? Mask.mask(@payload, @mask) : @payload
238
+ payload = @masked ? WebSocketMask.mask(@payload, @mask) : @payload
239
239
 
240
240
  case @opcode
241
241
  when OPCODES[:continuation] then
@@ -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
 
@@ -1,14 +1,17 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'thin'
4
- require 'rainbows'
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
- [-1, {}, []]
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
- date: 2012-02-26 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: eventmachine
16
- requirement: &20554820 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: 0.12.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *20554820
25
- - !ruby/object:Gem::Dependency
26
- name: rack
27
- requirement: &18050960 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *18050960
36
- - !ruby/object:Gem::Dependency
37
- name: rainbows
38
- requirement: &18049600 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: 1.0.0
44
- type: :development
45
- prerelease: false
46
- version_requirements: *18049600
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: &18047720 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 2.8.0
55
- type: :development
56
- prerelease: false
57
- version_requirements: *18047720
58
- - !ruby/object:Gem::Dependency
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
- extensions:
84
- - ext/faye_websocket_mask/extconf.rb
85
- extra_rdoc_files:
86
- - README.rdoc
87
- files:
88
- - README.rdoc
89
- - CHANGELOG.txt
90
- - ext/faye_websocket_mask/faye_websocket_mask.c
91
- - ext/faye_websocket_mask/extconf.rb
92
- - lib/faye/websocket/draft75_parser.rb
93
- - lib/faye/websocket/client.rb
94
- - lib/faye/websocket/hybi_parser.rb
95
- - lib/faye/websocket/draft76_parser.rb
96
- - lib/faye/websocket/utf8_match.rb
97
- - lib/faye/websocket/api.rb
98
- - lib/faye/websocket/hybi_parser/handshake.rb
99
- - lib/faye/websocket/hybi_parser/stream_reader.rb
100
- - lib/faye/websocket/api/event_target.rb
101
- - lib/faye/websocket/api/event.rb
102
- - lib/faye/websocket/adapter.rb
103
- - lib/faye/websocket.rb
104
- - lib/faye/eventsource.rb
105
- - lib/faye/adapters/thin.rb
106
- - lib/faye/adapters/rainbows.rb
107
- - lib/faye/adapters/goliath.rb
108
- - lib/faye/adapters/rainbows_client.rb
109
- - examples/app.rb
110
- - examples/client.rb
111
- - examples/haproxy.conf
112
- - examples/sse.html
113
- - examples/config.ru
114
- - examples/server.rb
115
- - examples/ws.html
116
- - examples/autobahn_client.rb
117
- - spec/faye/websocket/draft75_parser_spec.rb
118
- - spec/faye/websocket/client_spec.rb
119
- - spec/faye/websocket/draft75_parser_examples.rb
120
- - spec/faye/websocket/draft76_parser_spec.rb
121
- - spec/faye/websocket/hybi_parser_spec.rb
122
- - spec/server.key
123
- - spec/server.crt
124
- - spec/rainbows.conf
125
- - spec/spec_helper.rb
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
- - !ruby/object:Gem::Version
139
- version: '0'
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
- - !ruby/object:Gem::Version
145
- version: '0'
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: "0"
146
129
  requirements: []
130
+
147
131
  rubyforge_project:
148
- rubygems_version: 1.8.10
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
+