julien51-babylon 0.0.14 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -16
- data/Rakefile +1 -3
- data/lib/babylon.rb +37 -6
- data/lib/babylon/base/controller.rb +32 -24
- data/lib/babylon/base/stanza.rb +2 -4
- data/lib/babylon/base/view.rb +19 -19
- data/lib/babylon/client_connection.rb +93 -80
- data/lib/babylon/component_connection.rb +13 -9
- data/lib/babylon/generator.rb +1 -1
- data/lib/babylon/router.rb +48 -86
- data/lib/babylon/router/dsl.rb +0 -6
- data/lib/babylon/runner.rb +56 -34
- data/lib/babylon/xmpp_connection.rb +56 -46
- data/lib/babylon/xmpp_parser.rb +50 -53
- data/templates/babylon/config/boot.rb +1 -1
- data/templates/babylon/config/config.yaml +1 -3
- data/templates/babylon/config/routes.rb +1 -1
- data/templates/babylon/log/test.log +52 -0
- data/templates/babylon/script/component +36 -20
- metadata +2 -2
data/lib/babylon/xmpp_parser.rb
CHANGED
@@ -4,12 +4,13 @@ module Babylon
|
|
4
4
|
# This is the XML SAX Parser that accepts "pushed" content
|
5
5
|
class XmppParser < Nokogiri::XML::SAX::Document
|
6
6
|
|
7
|
-
attr_accessor :elem, :doc, :parser
|
7
|
+
attr_accessor :elem, :doc, :parser
|
8
8
|
|
9
9
|
##
|
10
10
|
# Initialize the parser and adds the callback that will be called upon stanza completion
|
11
|
-
def initialize(
|
11
|
+
def initialize(callback)
|
12
12
|
@callback = callback
|
13
|
+
@buffer = ""
|
13
14
|
super()
|
14
15
|
reset
|
15
16
|
end
|
@@ -17,9 +18,8 @@ module Babylon
|
|
17
18
|
##
|
18
19
|
# Resets the Pushed SAX Parser.
|
19
20
|
def reset
|
20
|
-
@parser
|
21
|
-
|
22
|
-
@elem = nil
|
21
|
+
@parser = Nokogiri::XML::SAX::PushParser.new(self, "UTF-8")
|
22
|
+
@elem = @doc = nil
|
23
23
|
end
|
24
24
|
|
25
25
|
##
|
@@ -28,79 +28,76 @@ module Babylon
|
|
28
28
|
@parser << data
|
29
29
|
end
|
30
30
|
|
31
|
-
##
|
32
|
-
# Called when the document contains a CData block
|
33
|
-
def cdata_block(string)
|
34
|
-
@elem.add_child(Nokogiri::XML::CDATA.new(@doc, string))
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
# Called when the document received in the stream is started
|
39
|
-
def start_document
|
40
|
-
@doc = Nokogiri::XML::Document.new
|
41
|
-
end
|
42
|
-
|
43
31
|
##
|
44
32
|
# Adds characters to the current element (being parsed)
|
45
33
|
def characters(string)
|
46
|
-
@
|
34
|
+
@buffer ||= ""
|
35
|
+
@buffer += string
|
47
36
|
end
|
48
|
-
|
37
|
+
|
49
38
|
##
|
50
|
-
# Instantiate a new current Element, adds the corresponding attributes and namespaces
|
39
|
+
# Instantiate a new current Element, adds the corresponding attributes and namespaces.
|
51
40
|
# The new element is eventually added to a parent element (if present).
|
52
|
-
# If
|
41
|
+
# If no element is being parsed, then, we create a new document, to which we add this new element as root. (we create one document per stanza to avoid memory problems)
|
53
42
|
def start_element(qname, attributes = [])
|
54
|
-
|
55
|
-
|
43
|
+
clear_characters_buffer
|
44
|
+
@doc ||= Nokogiri::XML::Document.new
|
45
|
+
@elem ||= @doc # If we have no current element, then, we take the doc
|
46
|
+
@elem = @elem.add_child(Nokogiri::XML::Element.new(qname, @doc))
|
47
|
+
add_namespaces_and_attributes_to_current_node(attributes)
|
56
48
|
|
57
|
-
if
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
49
|
+
if @elem.name == "stream:stream"
|
50
|
+
# We activate the callback since this element will never end.
|
51
|
+
@callback.call(@elem)
|
52
|
+
@doc = @elem = nil # Let's prepare for the next stanza
|
53
|
+
# And then, we start a new Sax Push Parser
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Clears the characters buffer
|
59
|
+
def clear_characters_buffer
|
60
|
+
if @buffer && @elem
|
61
|
+
@buffer.strip!
|
62
|
+
@elem.add_child(Nokogiri::XML::Text.new(Babylon.decode_xml(@buffer), @doc)) unless @buffer.empty?
|
63
|
+
@buffer = nil # empty the buffer
|
68
64
|
end
|
69
65
|
end
|
70
66
|
|
71
67
|
##
|
72
68
|
# Terminates the current element and calls the callback
|
73
69
|
def end_element(name)
|
70
|
+
clear_characters_buffer
|
74
71
|
if @elem
|
75
|
-
if @elem == @
|
72
|
+
if @elem.parent == @doc
|
73
|
+
# If we're actually finishing the stanza (a stanza is always a document's root)
|
76
74
|
@callback.call(@elem)
|
77
|
-
#
|
78
|
-
@elem
|
79
|
-
# And the current elem is the next sibling or the root
|
80
|
-
@elem = @top = nil
|
75
|
+
# We delete the current element and the doc (1 doc per stanza policy)
|
76
|
+
@elem = @doc = nil
|
81
77
|
else
|
82
78
|
@elem = @elem.parent
|
83
|
-
end
|
84
|
-
else
|
79
|
+
end
|
80
|
+
else
|
85
81
|
# Not sure what to do since it seems we're not processing any element at this time, so how can one end?
|
86
|
-
end
|
87
|
-
end
|
82
|
+
end
|
83
|
+
end
|
88
84
|
|
89
85
|
private
|
90
86
|
|
91
87
|
##
|
92
88
|
# Adds namespaces and attributes. Nokogiri passes them as a array of [name, value, name, value]...
|
93
|
-
def
|
89
|
+
def add_namespaces_and_attributes_to_current_node(attrs)
|
94
90
|
(attrs.size / 2).times do |i|
|
95
91
|
name, value = attrs[2 * i], attrs[2 * i + 1]
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
92
|
+
# TODO : FIX namespaces :they give a lot of problems with XPath
|
93
|
+
# if name == "xmlns"
|
94
|
+
# @elem.add_namespace(nil, value)
|
95
|
+
# elsif name =~ /\Axmlns:/
|
96
|
+
# @elem.add_namespace(name.gsub("xmlns:", ""), value)
|
97
|
+
# else
|
98
|
+
@elem.set_attribute name, Babylon.decode_xml(value)
|
99
|
+
# end
|
101
100
|
end
|
102
101
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
102
|
+
end
|
103
|
+
end
|
@@ -12,5 +12,5 @@ require File.dirname(__FILE__) + "/dependencies"
|
|
12
12
|
# Start the App
|
13
13
|
Babylon::Runner::run(ARGV[0] || "development") do
|
14
14
|
# Run the initializers, too. This is done here since some initializers might need EventMachine to be started.
|
15
|
-
Dir.glob('initializers/*.rb').each { |f| require f }
|
15
|
+
Dir.glob('config/initializers/*.rb').each { |f| require f }
|
16
16
|
end
|
@@ -7,10 +7,8 @@
|
|
7
7
|
# application_type: client | component (by default it is component and we strongly discourage any client application in production)
|
8
8
|
|
9
9
|
development:
|
10
|
-
jid:
|
10
|
+
jid: user@server.com
|
11
11
|
password: password
|
12
|
-
host: localhost
|
13
|
-
port: 5278
|
14
12
|
application_type: client
|
15
13
|
|
16
14
|
test:
|
@@ -0,0 +1,52 @@
|
|
1
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
2
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
3
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
4
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
5
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
6
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
7
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
8
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
9
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
10
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
11
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
12
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
13
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
14
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
15
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
16
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
17
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
18
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
19
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
20
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
21
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
22
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
23
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
24
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
25
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
26
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
27
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
28
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
29
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
30
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
31
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
32
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
33
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
34
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
35
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
36
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
37
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
38
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
39
|
+
ERROR BABYLON: Observer can only be Babylon::Base::Controller
|
40
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
41
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
42
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
43
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
44
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
45
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
46
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
47
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
48
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
49
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
50
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
51
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
52
|
+
ERROR BABYLON: CONNECTION ERROR : RuntimeError => RuntimeError
|
@@ -1,31 +1,47 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require 'rubygems'
|
4
3
|
require 'daemons'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
# default options
|
7
|
+
OPTIONS = {
|
8
|
+
:command => "run",
|
9
|
+
:environment => "development",
|
10
|
+
:name => "#{Dir.pwd.split("/").last}",
|
11
|
+
}
|
12
|
+
|
13
|
+
ARGV.options do |o|
|
14
|
+
script_name = File.basename($0)
|
15
|
+
|
16
|
+
o.set_summary_indent(' ')
|
17
|
+
o.banner = "Usage: script/#{script_name} [OPTIONS]"
|
18
|
+
o.define_head "Runs the Babylon Application."
|
19
|
+
o.separator ""
|
20
|
+
o.separator "Arguments :"
|
21
|
+
|
22
|
+
o.on("-c", "--command=[run|start|stop|restart]", String,
|
23
|
+
"The command you'd like to execute",
|
24
|
+
"Default: #{OPTIONS[:command]}") { |OPTIONS[:command]| }
|
25
|
+
o.on("-e", "--environment=env", String,
|
26
|
+
"The environment to run the application (you should have defined the argument into config/config.yaml)",
|
27
|
+
"Default: #{OPTIONS[:environment]}") { |OPTIONS[:environment]| }
|
28
|
+
o.on("-n", "--name=app_name", String,
|
29
|
+
"Name of your application. The pid_file will be name after this.",
|
30
|
+
"Default: #{OPTIONS[:name]}") { |OPTIONS[:name]| }
|
31
|
+
|
32
|
+
o.separator ""
|
5
33
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
env = ARGV[0] || "development"
|
11
|
-
case env
|
12
|
-
when "development"
|
13
|
-
command = "run"
|
14
|
-
when "production"
|
15
|
-
command = "start"
|
16
|
-
else
|
17
|
-
# By default, we run in "on-top" mode
|
18
|
-
command = "run"
|
19
|
-
end
|
34
|
+
o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
|
35
|
+
|
36
|
+
o.parse!
|
20
37
|
end
|
21
38
|
|
39
|
+
|
22
40
|
options = {
|
23
|
-
:ARGV => [command, '--',
|
24
|
-
:app_name =>
|
41
|
+
:ARGV => [OPTIONS[:command], '--', OPTIONS[:environment]],
|
42
|
+
:app_name => OPTIONS[:name],
|
25
43
|
:dir => "../tmp/pids/",
|
26
|
-
:multiple =>
|
44
|
+
:multiple => false,
|
27
45
|
:backtrace => true
|
28
46
|
}
|
29
|
-
|
30
47
|
Daemons.run(File.dirname(__FILE__) + '/../config/boot.rb', options)
|
31
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: julien51-babylon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- julien Genestoux
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-07 00:00:00 -07:00
|
13
13
|
default_executable: babylon
|
14
14
|
dependencies: []
|
15
15
|
|