omf_common 6.0.0.pre.2 → 6.0.0.pre.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
|
|
1
|
+
module Blather
|
2
|
+
class Stream
|
3
|
+
# @private
|
4
|
+
class Features
|
5
|
+
def next!
|
6
|
+
@idx = @idx ? @idx+1 : 0
|
7
|
+
if stanza = @features.children[@idx]
|
8
|
+
if stanza.namespaces['xmlns'] && (klass = self.class.from_namespace(stanza.namespaces['xmlns']))
|
9
|
+
@feature = klass.new(
|
10
|
+
@stream,
|
11
|
+
proc {
|
12
|
+
if (klass == Blather::Stream::Register && @features && !@features.children.find { |v| v.element_name == "mechanisms" }.nil?)
|
13
|
+
stanza = @features.children.find { |v| v.element_name == "mechanisms" }
|
14
|
+
@idx = @features.children.index(stanza)
|
15
|
+
klass = self.class.from_namespace(stanza.namespaces['xmlns'])
|
16
|
+
@feature = klass.new @stream, proc { next! }, @fail
|
17
|
+
@feature.receive_data stanza
|
18
|
+
else
|
19
|
+
next!
|
20
|
+
end
|
21
|
+
},
|
22
|
+
(klass == Blather::Stream::SASL && @features && !@features.children.find { |v| v.element_name == "register" }.nil?) ? proc { next! } : @fail
|
23
|
+
)
|
24
|
+
@feature.receive_data stanza
|
25
|
+
else
|
26
|
+
next!
|
27
|
+
end
|
28
|
+
else
|
29
|
+
succeed!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end #Stream
|
34
|
+
end #Blather
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Blather
|
2
|
+
class Stream
|
3
|
+
class Register < Features
|
4
|
+
REGISTER_NS = "http://jabber.org/features/iq-register".freeze
|
5
|
+
|
6
|
+
register REGISTER_NS
|
7
|
+
|
8
|
+
def initialize(stream, succeed, fail)
|
9
|
+
super
|
10
|
+
@jid = @stream.jid
|
11
|
+
@pass = @stream.password
|
12
|
+
end
|
13
|
+
|
14
|
+
def receive_data(stanza)
|
15
|
+
error_node = stanza.xpath('//error').first
|
16
|
+
|
17
|
+
if error_node
|
18
|
+
fail!(error_node)
|
19
|
+
elsif stanza['type'] == 'result' && (stanza.content.empty? || !stanza.children.find { |v| v.element_name == "query" }.nil?)
|
20
|
+
succeed!
|
21
|
+
else
|
22
|
+
@stream.send register_node
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def register_node
|
27
|
+
node = Blather::Stanza::Iq::Query.new(:set)
|
28
|
+
query_node = node.xpath('//query').first
|
29
|
+
query_node['xmlns'] = 'jabber:iq:register'
|
30
|
+
username_node = Nokogiri::XML::Node.new('username', node)
|
31
|
+
username_node.content = @jid.node
|
32
|
+
password_node = Nokogiri::XML::Node.new('password', node)
|
33
|
+
password_node.content = @pass
|
34
|
+
query_node.add_child(username_node)
|
35
|
+
query_node.add_child(password_node)
|
36
|
+
node
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'blather/client/dsl'
|
2
2
|
require 'omf_common/core_ext/blather/dsl'
|
3
3
|
require 'omf_common/core_ext/blather/dsl/pubsub'
|
4
|
-
require 'omf_common/core_ext/blather/
|
4
|
+
require 'omf_common/core_ext/blather/stream/features'
|
5
|
+
require 'omf_common/core_ext/blather/stream/features/register'
|
5
6
|
|
6
7
|
module OmfCommon
|
7
8
|
module DSL
|
data/lib/omf_common/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omf_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0.0.pre.
|
4
|
+
version: 6.0.0.pre.3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -91,7 +91,8 @@ files:
|
|
91
91
|
- lib/omf_common/command.rb
|
92
92
|
- lib/omf_common/core_ext/blather/dsl.rb
|
93
93
|
- lib/omf_common/core_ext/blather/dsl/pubsub.rb
|
94
|
-
- lib/omf_common/core_ext/blather/
|
94
|
+
- lib/omf_common/core_ext/blather/stream/features.rb
|
95
|
+
- lib/omf_common/core_ext/blather/stream/features/register.rb
|
95
96
|
- lib/omf_common/core_ext/string.rb
|
96
97
|
- lib/omf_common/dsl/xmpp_blather.rb
|
97
98
|
- lib/omf_common/message.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'blather/stanza/iq'
|
2
|
-
|
3
|
-
module Blather
|
4
|
-
class Stanza
|
5
|
-
class Registration < Iq
|
6
|
-
def self.new(username, password)
|
7
|
-
node = super :set
|
8
|
-
Nokogiri::XML::Builder.with(node) do |xml|
|
9
|
-
xml.query('xmlns' => 'jabber:iq:register') do
|
10
|
-
xml.username username
|
11
|
-
xml.password password
|
12
|
-
end
|
13
|
-
end
|
14
|
-
node
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|