compp 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/README.rdoc +66 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/example.rb +35 -0
- data/lib/compp.rb +22 -0
- data/lib/compp/connection.rb +23 -0
- data/lib/compp/default.rb +78 -0
- data/lib/compp/sprinkler.rb +43 -0
- data/spec/compp/connection_spec.rb +17 -0
- data/spec/compp/default_spec.rb +169 -0
- data/spec/compp/sprinkler_spec.rb +4 -0
- data/spec/compp_spec.rb +28 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +1 -0
- metadata +93 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= compp
|
2
|
+
|
3
|
+
Compp is Comet and XMPP. It will probably remind you of BOSH but is much simpler. It's an easy way to turn any any incoming XMPP messages into a comet stream.
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
=== Install
|
8
|
+
|
9
|
+
sudo gem install compp
|
10
|
+
|
11
|
+
=== Start
|
12
|
+
|
13
|
+
This will start a the server with a default behavior of putting any message stanza received down to the Comet connection
|
14
|
+
|
15
|
+
Compp.start(Compp::Default, {:host => '0.0.0.0', :port => 8000})
|
16
|
+
|
17
|
+
You can also customize more your server :
|
18
|
+
|
19
|
+
class MyCompp < Compp::Default
|
20
|
+
##
|
21
|
+
# This example just
|
22
|
+
def register_xmpp_handlers(connection)
|
23
|
+
connection.register_handler :message do |m|
|
24
|
+
status = m.xpath("//message/ps:event/sf:status", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first
|
25
|
+
if !status.nil?
|
26
|
+
feed = status["feed"]
|
27
|
+
http_code = status.xpath("./sf:http/@code", {"sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first
|
28
|
+
msg_status = status.xpath("./sf:http", {"sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first.text
|
29
|
+
orbitize("#{feed} => #{http_code} (#{msg_status})")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
# Starts the server
|
35
|
+
Compp.start(MyCompp, {:host => '0.0.0.0', :port => 8000})
|
36
|
+
|
37
|
+
Check out example.rb for more.
|
38
|
+
|
39
|
+
= Author
|
40
|
+
|
41
|
+
Julien (julien@superfeedr.com)
|
42
|
+
|
43
|
+
= License
|
44
|
+
|
45
|
+
Compp
|
46
|
+
|
47
|
+
Copyright (c) 2009 Superfeedr
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of this software and associated documentation files (the
|
51
|
+
"Software"), to deal in the Software without restriction, including
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
55
|
+
the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be
|
58
|
+
included in all copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
63
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
64
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
65
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
66
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "compp"
|
8
|
+
gem.summary = %Q{A Gem to make Comet-like HTTP connections from XMPP streams}
|
9
|
+
gem.description = %Q{A Gem to make Comet-like HTTP connections from XMPP streams}
|
10
|
+
gem.email = "julien.genestoux@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/julien51/compp"
|
12
|
+
gem.authors = ["julien"]
|
13
|
+
gem.add_dependency "eventmachine_httpserver", ">=0.2.0"
|
14
|
+
gem.add_dependency "blather", ">=0.4.7"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "compp #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/example.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "compp"
|
3
|
+
|
4
|
+
## Default
|
5
|
+
# Start the HTTP server with the right handler.
|
6
|
+
# A user connects and provides his jid:password
|
7
|
+
# By default, the 'message' stanzas send to 'jid' will be sent to the Comet connection
|
8
|
+
Compp.start(Compp::Default, {:host => '0.0.0.0', :port => 8000})
|
9
|
+
|
10
|
+
## Another Example : customization
|
11
|
+
# You can write classes that overide the default default behavior open XMPP events.
|
12
|
+
# We use Blather's syntax.
|
13
|
+
# This Example just show incoming XMPP notifications from Superfeedr (http://superfeedr.com)
|
14
|
+
class MyCompp < Compp::Default
|
15
|
+
##
|
16
|
+
# This example just
|
17
|
+
def register_xmpp_handlers(connection)
|
18
|
+
connection.register_handler :message do |m|
|
19
|
+
status = m.xpath("//message/ps:event/sf:status", {"ps" => "http://jabber.org/protocol/pubsub#event", "sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first
|
20
|
+
if !status.nil?
|
21
|
+
feed = status["feed"]
|
22
|
+
http_code = status.xpath("./sf:http/@code", {"sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first
|
23
|
+
msg_status = status.xpath("./sf:http", {"sf" => "http://superfeedr.com/xmpp-pubsub-ext"}).first.text
|
24
|
+
orbitize("#{feed} => #{http_code} (#{msg_status})")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
# Starts the server
|
30
|
+
Compp.start(MyCompp, {:host => '0.0.0.0', :port => 8000})
|
31
|
+
|
32
|
+
##
|
33
|
+
# A Sprinkler example
|
34
|
+
# The HTTP server connects just 1 client and broadcasts the messages to any HTTP comet connection
|
35
|
+
Compp.start(Compp::Sprinkler, {:host => '0.0.0.0', :port => 8000, :jid => "jid@server.tld", :password => "password"})
|
data/lib/compp.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'eventmachine'
|
5
|
+
require 'blather/client/client'
|
6
|
+
require 'evma_httpserver'
|
7
|
+
require 'base64'
|
8
|
+
require 'compp/connection'
|
9
|
+
require 'compp/default'
|
10
|
+
require 'compp/sprinkler'
|
11
|
+
|
12
|
+
module Compp
|
13
|
+
def self.start(klass, options = {})
|
14
|
+
EM.epoll
|
15
|
+
host = options[:host] || "0.0.0.0"
|
16
|
+
port = Integer(options[:port] || 8989)
|
17
|
+
EM.run {
|
18
|
+
EM.start_server(host, port, klass, options)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Compp
|
2
|
+
class Connection < EM::Connection
|
3
|
+
include EventMachine::HttpServer
|
4
|
+
|
5
|
+
##
|
6
|
+
# Initialize a new Compp:Connection
|
7
|
+
def initialize(opts = {})
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Sends obj.to_str on the comet connection!
|
12
|
+
def orbitize(obj)
|
13
|
+
send_data(obj.to_str + "\r\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# This is called upon new connection by an external client.
|
18
|
+
def process_http_request
|
19
|
+
# Does nothing, this should be overriden if you want more advanced behavior
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Compp
|
2
|
+
##
|
3
|
+
# This is the default Compp::Connection.
|
4
|
+
# For each GET request it receives, it extract the credentails from the headers, and connects an XMPP client.
|
5
|
+
# The user can define its own xmpp handlers by subclassing this class.
|
6
|
+
class Default < Compp::Connection
|
7
|
+
|
8
|
+
attr_accessor :http_headers
|
9
|
+
|
10
|
+
##
|
11
|
+
# Helping tool to extract jid and password from headers
|
12
|
+
def extract_jid_and_password_from_headers
|
13
|
+
jid, password = nil, nil
|
14
|
+
begin
|
15
|
+
headers = Hash[@http_headers.split("\000").map() {|h| h.split(": ")}]
|
16
|
+
if headers["Authorization"]
|
17
|
+
auth = headers["Authorization"].split(" ")
|
18
|
+
if auth[0] == "Basic"
|
19
|
+
jid, password = Base64.decode64(auth[1]).split(":")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
rescue
|
23
|
+
# Something was wring, w dont care
|
24
|
+
end
|
25
|
+
[jid, password]
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# This is the default behavior.
|
30
|
+
# When a user sends an HTTP request, the headers are parsed
|
31
|
+
# We connect an Blather Client using these headers
|
32
|
+
# Upon stanzas, we call on_stanza
|
33
|
+
def process_http_request
|
34
|
+
jid, password = extract_jid_and_password_from_headers()
|
35
|
+
if jid.nil?
|
36
|
+
send_401
|
37
|
+
else
|
38
|
+
client = Blather::Client.setup(jid, password)
|
39
|
+
client.register_handler(:ready) {
|
40
|
+
orbitize("HTTP/1.0 200 OK")
|
41
|
+
orbitize("Content-Type: text/xml")
|
42
|
+
orbitize("Connection: close\r\n")
|
43
|
+
orbitize( "<?xml version='1.0' encoding='utf-8' ?>")
|
44
|
+
}
|
45
|
+
register_xmpp_handlers(client) # This function should probably be overriden
|
46
|
+
client.connect
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Helping tool that sends a 401
|
52
|
+
def send_401
|
53
|
+
resp = EventMachine::DelegatedHttpResponse.new( self )
|
54
|
+
resp.status = 401
|
55
|
+
resp.content = "Please, authenticate with with jid:password\n\n"
|
56
|
+
resp.send_response
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Helping tool that sends a 403
|
61
|
+
def send_403
|
62
|
+
resp = EventMachine::DelegatedHttpResponse.new( self )
|
63
|
+
resp.status = 403
|
64
|
+
resp.content = "Couldn't authenticate XMPP user\n\n"
|
65
|
+
resp.send_response
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# This should be overiden!
|
70
|
+
# If, not, we assume the user just wants to puts the XML content of the message received to the HTTP connection
|
71
|
+
def register_xmpp_handlers(client)
|
72
|
+
client.register_handler(:message) do |m|
|
73
|
+
orbitize(m.to_xml)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Compp
|
2
|
+
##
|
3
|
+
# This is the default Compp::Connection.
|
4
|
+
# For each GET request it receives, it extract the credentails from the headers, and connects an XMPP client.
|
5
|
+
# The user can define its own xmpp handlers by subclassing this class.
|
6
|
+
class Sprinkler < Compp::Connection
|
7
|
+
|
8
|
+
@@xmpp_client = nil
|
9
|
+
@@channel = nil
|
10
|
+
|
11
|
+
##
|
12
|
+
# Initialize a new Compp:Connection
|
13
|
+
def initialize(opts = {})
|
14
|
+
if !@@xmpp_client
|
15
|
+
# Right, we need to connect the xmpp client now
|
16
|
+
@@xmpp_client = Blather::Client.setup(opts[:jid], opts[:password])
|
17
|
+
@@channel = EM::Channel.new
|
18
|
+
@@xmpp_client.register_handler(:message) do |m|
|
19
|
+
@@channel.push(m.to_xml)
|
20
|
+
end
|
21
|
+
@@xmpp_client.connect
|
22
|
+
end
|
23
|
+
@@channel.subscribe{ |msg|
|
24
|
+
orbitize(msg)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Called when a user send an HTTP request.
|
30
|
+
def process_http_request
|
31
|
+
orbitize("HTTP/1.0 200 OK")+
|
32
|
+
orbitize("Content-Type: text/xml")
|
33
|
+
orbitize("Connection: close\r\n")
|
34
|
+
orbitize( "<?xml version='1.0' encoding='utf-8' ?>")
|
35
|
+
end
|
36
|
+
|
37
|
+
##
|
38
|
+
# In this case, where we broadcast, this does nothing... and is never called anyway!
|
39
|
+
def register_xmpp_handlers(client)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe Compp::Connection do
|
4
|
+
it "should be a EventMachine::HttpServer" do
|
5
|
+
c = Compp::Connection.new("")
|
6
|
+
c.should be_a(Compp::Connection)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "orbitize" do
|
10
|
+
it "should send the data's to_s and add \r\n" do
|
11
|
+
c = Compp::Connection.new("")
|
12
|
+
data = "data"
|
13
|
+
c.should_receive(:send_data).with("#{data}\r\n")
|
14
|
+
c.orbitize(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe Compp::Default do
|
4
|
+
|
5
|
+
describe "send_401" do
|
6
|
+
before(:each) do
|
7
|
+
@c = Compp::Default.new({})
|
8
|
+
@mock_response = mock(EventMachine::DelegatedHttpResponse, :status= => true, :content= => true, :send_response => true)
|
9
|
+
EventMachine::DelegatedHttpResponse.stub!(:new).and_return(@mock_response)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create a new response" do
|
13
|
+
EventMachine::DelegatedHttpResponse.should_receive(:new).with(@c).and_return(@mock_response)
|
14
|
+
@c.send_401
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "response" do
|
18
|
+
it "should have a 401 status" do
|
19
|
+
@mock_response.should_receive(:status=).with(401)
|
20
|
+
@c.send_401
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have the right error message" do
|
24
|
+
@mock_response.should_receive(:content=).with("Please, authenticate with with jid:password\n\n")
|
25
|
+
@c.send_401
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
it "should send this response" do
|
30
|
+
@mock_response.should_receive(:send_response)
|
31
|
+
@c.send_401
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "send_403" do
|
36
|
+
before(:each) do
|
37
|
+
@c = Compp::Default.new({})
|
38
|
+
@mock_response = mock(EventMachine::DelegatedHttpResponse, :status= => true, :content= => true, :send_response => true)
|
39
|
+
EventMachine::DelegatedHttpResponse.stub!(:new).and_return(@mock_response)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should create a new response" do
|
43
|
+
EventMachine::DelegatedHttpResponse.should_receive(:new).with(@c).and_return(@mock_response)
|
44
|
+
@c.send_403
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "response" do
|
48
|
+
it "should have a 401 status" do
|
49
|
+
@mock_response.should_receive(:status=).with(403)
|
50
|
+
@c.send_403
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have the right error message" do
|
54
|
+
@mock_response.should_receive(:content=).with("Couldn't authenticate XMPP user\n\n")
|
55
|
+
@c.send_403
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
it "should send this response" do
|
60
|
+
@mock_response.should_receive(:send_response)
|
61
|
+
@c.send_403
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "register_xmpp_handlers" do
|
66
|
+
before(:each) do
|
67
|
+
@c = Compp::Default.new({})
|
68
|
+
@client = mock(Blather::Client)
|
69
|
+
@data = mock(Nokogiri::XML::Node, :to_xml => "cool")
|
70
|
+
@client.stub!(:register_handler).with(:message).and_yield(@data)
|
71
|
+
@c.stub(:orbitize)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should resgister a handler on message' do
|
75
|
+
@client.should_receive(:register_handler).with(:message).and_yield(@data)
|
76
|
+
@c.register_xmpp_handlers(@client)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should call to_xml on the data" do
|
80
|
+
@data.should_receive(:to_xml)
|
81
|
+
@c.register_xmpp_handlers(@client)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should orbitize any message received" do
|
85
|
+
@c.should_receive(:orbitize).with(@data.to_xml)
|
86
|
+
@c.register_xmpp_handlers(@client)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe "process_http_request" do
|
92
|
+
before(:each) do
|
93
|
+
@c = Compp::Default.new({})
|
94
|
+
@c.stub!(:extract_jid_and_password_from_headers)
|
95
|
+
@c.stub!(:send_401)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should extract the jid and password" do
|
99
|
+
@c.should_receive(:extract_jid_and_password_from_headers)
|
100
|
+
@c.process_http_request
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should call send_401 if no jid and password were extracted" do
|
104
|
+
@c.stub!(:extract_jid_and_password_from_headers)
|
105
|
+
@c.should_receive(:send_401)
|
106
|
+
@c.process_http_request
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when a jid password was exatcrted' do
|
110
|
+
|
111
|
+
before(:each) do
|
112
|
+
@jid = "julien@superfeedr.com"
|
113
|
+
@password = "password"
|
114
|
+
@mock_xmpp_client = mock(Blather::Client, :register_handler => true, :connect => true)
|
115
|
+
@c.stub!(:extract_jid_and_password_from_headers).and_return([@jid, @password])
|
116
|
+
Blather::Client.stub!(:setup).and_return(@mock_xmpp_client)
|
117
|
+
@mock_xmpp_client.stub!(:register_handler).with(:ready).and_yield()
|
118
|
+
@c.stub!(:orbitize)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should create a new xmpp client" do
|
122
|
+
Blather::Client.should_receive(:setup).with(@jid, @password).and_return(@mock_xmpp_client)
|
123
|
+
@c.process_http_request
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should register a handler on ready" do
|
127
|
+
@mock_xmpp_client.should_receive(:register_handler).with(:ready).and_yield()
|
128
|
+
@c.process_http_request
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should orbitize the http headers when ready" do
|
132
|
+
@c.should_receive(:orbitize).with("HTTP/1.0 200 OK")
|
133
|
+
@c.should_receive(:orbitize).with("Content-Type: text/xml")
|
134
|
+
@c.should_receive(:orbitize).with("Connection: close\r\n")
|
135
|
+
@c.should_receive(:orbitize).with("<?xml version='1.0' encoding='utf-8' ?>")
|
136
|
+
@c.process_http_request
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should call register_xmpp_handlers" do
|
140
|
+
@c.should_receive(:register_xmpp_handlers).with(@mock_xmpp_client)
|
141
|
+
@c.process_http_request
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should connect the client" do
|
145
|
+
@mock_xmpp_client.should_receive(:connect)
|
146
|
+
@c.process_http_request
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "extract_jid_and_password_from_headers" do
|
152
|
+
|
153
|
+
before(:each) do
|
154
|
+
@c = Compp::Default.new({})
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should extract the Auth headers" do
|
158
|
+
@c.http_headers = "Authorization: Basic anVsaWVuOnBhc3N3b3Jk\000User-Agent: curl/7.19.6 (i386-apple-darwin10.0.0) libcurl/7.19.6 zlib/1.2.3\000Host: 0.0.0.0:8000\000Accept: */*\000\000"
|
159
|
+
@c.extract_jid_and_password_from_headers.should == ["julien", "password"]
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return nil, nil if no Auth header was found" do
|
163
|
+
@c.http_headers = "User-Agent: curl/7.19.6 (i386-apple-darwin10.0.0) libcurl/7.19.6 zlib/1.2.3\000Host: 0.0.0.0:8000\000Accept: */*\000\000"
|
164
|
+
@c.extract_jid_and_password_from_headers.should == [nil, nil]
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
data/spec/compp_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe Compp do
|
4
|
+
describe "start" do
|
5
|
+
before(:each) do
|
6
|
+
EM.stub!(:epoll)
|
7
|
+
EM.stub!(:run).and_yield()
|
8
|
+
EM.stub!(:start_server)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should use epoll" do
|
12
|
+
EM.should_receive(:epoll)
|
13
|
+
Compp.start(Class.new)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should start EM" do
|
17
|
+
EM.should_receive(:run)
|
18
|
+
Compp.start(Class.new)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should start a server with the host, port, klass and options specified" do
|
22
|
+
options = {:port => 123, :host => "localhost"}
|
23
|
+
handler = Class.new
|
24
|
+
EM.should_receive(:start_server).with(options[:host], options[:port],handler , options)
|
25
|
+
Compp.start(handler, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/compp"
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- julien
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-14 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: eventmachine_httpserver
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: blather
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.7
|
34
|
+
version:
|
35
|
+
description: A Gem to make Comet-like HTTP connections from XMPP streams
|
36
|
+
email: julien.genestoux@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- .gitignore
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- VERSION
|
49
|
+
- example.rb
|
50
|
+
- lib/compp.rb
|
51
|
+
- lib/compp/connection.rb
|
52
|
+
- lib/compp/default.rb
|
53
|
+
- lib/compp/sprinkler.rb
|
54
|
+
- spec/compp/connection_spec.rb
|
55
|
+
- spec/compp/default_spec.rb
|
56
|
+
- spec/compp/sprinkler_spec.rb
|
57
|
+
- spec/compp_spec.rb
|
58
|
+
- spec/spec.opts
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/julien51/compp
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: A Gem to make Comet-like HTTP connections from XMPP streams
|
88
|
+
test_files:
|
89
|
+
- spec/compp/connection_spec.rb
|
90
|
+
- spec/compp/default_spec.rb
|
91
|
+
- spec/compp/sprinkler_spec.rb
|
92
|
+
- spec/compp_spec.rb
|
93
|
+
- spec/spec_helper.rb
|