tp-blather 0.8.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.
- data/.autotest +13 -0
- data/.gemtest +0 -0
- data/.gitignore +19 -0
- data/.rspec +3 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +249 -0
- data/Gemfile +4 -0
- data/Guardfile +5 -0
- data/LICENSE +22 -0
- data/README.md +413 -0
- data/Rakefile +20 -0
- data/TODO.md +2 -0
- data/blather.gemspec +51 -0
- data/examples/certs/README +20 -0
- data/examples/certs/ca-bundle.crt +3987 -0
- data/examples/echo.rb +19 -0
- data/examples/execute.rb +17 -0
- data/examples/ping_pong.rb +38 -0
- data/examples/print_hierarchy.rb +77 -0
- data/examples/rosterprint.rb +15 -0
- data/examples/stream_only.rb +28 -0
- data/examples/trusted_echo.rb +21 -0
- data/examples/xmpp4r/echo.rb +36 -0
- data/lib/blather.rb +112 -0
- data/lib/blather/cert_store.rb +53 -0
- data/lib/blather/client.rb +95 -0
- data/lib/blather/client/client.rb +345 -0
- data/lib/blather/client/dsl.rb +320 -0
- data/lib/blather/client/dsl/pubsub.rb +174 -0
- data/lib/blather/core_ext/eventmachine.rb +125 -0
- data/lib/blather/core_ext/ipaddr.rb +20 -0
- data/lib/blather/errors.rb +69 -0
- data/lib/blather/errors/sasl_error.rb +44 -0
- data/lib/blather/errors/stanza_error.rb +110 -0
- data/lib/blather/errors/stream_error.rb +84 -0
- data/lib/blather/file_transfer.rb +107 -0
- data/lib/blather/file_transfer/ibb.rb +68 -0
- data/lib/blather/file_transfer/s5b.rb +114 -0
- data/lib/blather/jid.rb +141 -0
- data/lib/blather/roster.rb +118 -0
- data/lib/blather/roster_item.rb +146 -0
- data/lib/blather/stanza.rb +167 -0
- data/lib/blather/stanza/disco.rb +32 -0
- data/lib/blather/stanza/disco/capabilities.rb +161 -0
- data/lib/blather/stanza/disco/disco_info.rb +205 -0
- data/lib/blather/stanza/disco/disco_items.rb +134 -0
- data/lib/blather/stanza/iq.rb +144 -0
- data/lib/blather/stanza/iq/command.rb +339 -0
- data/lib/blather/stanza/iq/ibb.rb +86 -0
- data/lib/blather/stanza/iq/ping.rb +50 -0
- data/lib/blather/stanza/iq/query.rb +53 -0
- data/lib/blather/stanza/iq/roster.rb +185 -0
- data/lib/blather/stanza/iq/s5b.rb +208 -0
- data/lib/blather/stanza/iq/si.rb +415 -0
- data/lib/blather/stanza/iq/vcard.rb +149 -0
- data/lib/blather/stanza/message.rb +428 -0
- data/lib/blather/stanza/message/muc_user.rb +119 -0
- data/lib/blather/stanza/muc/muc_user_base.rb +54 -0
- data/lib/blather/stanza/presence.rb +172 -0
- data/lib/blather/stanza/presence/c.rb +100 -0
- data/lib/blather/stanza/presence/muc.rb +35 -0
- data/lib/blather/stanza/presence/muc_user.rb +147 -0
- data/lib/blather/stanza/presence/status.rb +218 -0
- data/lib/blather/stanza/presence/subscription.rb +100 -0
- data/lib/blather/stanza/pubsub.rb +119 -0
- data/lib/blather/stanza/pubsub/affiliations.rb +79 -0
- data/lib/blather/stanza/pubsub/create.rb +65 -0
- data/lib/blather/stanza/pubsub/errors.rb +18 -0
- data/lib/blather/stanza/pubsub/event.rb +139 -0
- data/lib/blather/stanza/pubsub/items.rb +103 -0
- data/lib/blather/stanza/pubsub/publish.rb +103 -0
- data/lib/blather/stanza/pubsub/retract.rb +92 -0
- data/lib/blather/stanza/pubsub/subscribe.rb +68 -0
- data/lib/blather/stanza/pubsub/subscription.rb +135 -0
- data/lib/blather/stanza/pubsub/subscriptions.rb +83 -0
- data/lib/blather/stanza/pubsub/unsubscribe.rb +84 -0
- data/lib/blather/stanza/pubsub_owner.rb +51 -0
- data/lib/blather/stanza/pubsub_owner/delete.rb +52 -0
- data/lib/blather/stanza/pubsub_owner/purge.rb +52 -0
- data/lib/blather/stanza/x.rb +416 -0
- data/lib/blather/stream.rb +266 -0
- data/lib/blather/stream/client.rb +32 -0
- data/lib/blather/stream/component.rb +39 -0
- data/lib/blather/stream/features.rb +70 -0
- data/lib/blather/stream/features/register.rb +38 -0
- data/lib/blather/stream/features/resource.rb +63 -0
- data/lib/blather/stream/features/sasl.rb +190 -0
- data/lib/blather/stream/features/session.rb +45 -0
- data/lib/blather/stream/features/tls.rb +29 -0
- data/lib/blather/stream/parser.rb +102 -0
- data/lib/blather/version.rb +3 -0
- data/lib/blather/xmpp_node.rb +94 -0
- data/spec/blather/client/client_spec.rb +687 -0
- data/spec/blather/client/dsl/pubsub_spec.rb +492 -0
- data/spec/blather/client/dsl_spec.rb +266 -0
- data/spec/blather/errors/sasl_error_spec.rb +33 -0
- data/spec/blather/errors/stanza_error_spec.rb +129 -0
- data/spec/blather/errors/stream_error_spec.rb +108 -0
- data/spec/blather/errors_spec.rb +33 -0
- data/spec/blather/file_transfer_spec.rb +135 -0
- data/spec/blather/jid_spec.rb +87 -0
- data/spec/blather/roster_item_spec.rb +134 -0
- data/spec/blather/roster_spec.rb +107 -0
- data/spec/blather/stanza/discos/disco_info_spec.rb +247 -0
- data/spec/blather/stanza/discos/disco_items_spec.rb +154 -0
- data/spec/blather/stanza/iq/command_spec.rb +206 -0
- data/spec/blather/stanza/iq/ibb_spec.rb +124 -0
- data/spec/blather/stanza/iq/ping_spec.rb +45 -0
- data/spec/blather/stanza/iq/query_spec.rb +64 -0
- data/spec/blather/stanza/iq/roster_spec.rb +139 -0
- data/spec/blather/stanza/iq/s5b_spec.rb +57 -0
- data/spec/blather/stanza/iq/si_spec.rb +98 -0
- data/spec/blather/stanza/iq/vcard_spec.rb +93 -0
- data/spec/blather/stanza/iq_spec.rb +61 -0
- data/spec/blather/stanza/message/muc_user_spec.rb +152 -0
- data/spec/blather/stanza/message_spec.rb +282 -0
- data/spec/blather/stanza/presence/c_spec.rb +56 -0
- data/spec/blather/stanza/presence/muc_spec.rb +37 -0
- data/spec/blather/stanza/presence/muc_user_spec.rb +83 -0
- data/spec/blather/stanza/presence/status_spec.rb +144 -0
- data/spec/blather/stanza/presence/subscription_spec.rb +102 -0
- data/spec/blather/stanza/presence_spec.rb +125 -0
- data/spec/blather/stanza/pubsub/affiliations_spec.rb +57 -0
- data/spec/blather/stanza/pubsub/create_spec.rb +56 -0
- data/spec/blather/stanza/pubsub/event_spec.rb +98 -0
- data/spec/blather/stanza/pubsub/items_spec.rb +79 -0
- data/spec/blather/stanza/pubsub/publish_spec.rb +83 -0
- data/spec/blather/stanza/pubsub/retract_spec.rb +75 -0
- data/spec/blather/stanza/pubsub/subscribe_spec.rb +61 -0
- data/spec/blather/stanza/pubsub/subscription_spec.rb +97 -0
- data/spec/blather/stanza/pubsub/subscriptions_spec.rb +59 -0
- data/spec/blather/stanza/pubsub/unsubscribe_spec.rb +74 -0
- data/spec/blather/stanza/pubsub_owner/delete_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner/purge_spec.rb +50 -0
- data/spec/blather/stanza/pubsub_owner_spec.rb +27 -0
- data/spec/blather/stanza/pubsub_spec.rb +68 -0
- data/spec/blather/stanza/x_spec.rb +231 -0
- data/spec/blather/stanza_spec.rb +134 -0
- data/spec/blather/stream/client_spec.rb +1090 -0
- data/spec/blather/stream/component_spec.rb +108 -0
- data/spec/blather/stream/parser_spec.rb +152 -0
- data/spec/blather/stream/ssl_spec.rb +32 -0
- data/spec/blather/xmpp_node_spec.rb +47 -0
- data/spec/blather_spec.rb +34 -0
- data/spec/fixtures/pubsub.rb +311 -0
- data/spec/spec_helper.rb +17 -0
- data/yard/templates/default/class/html/handlers.erb +18 -0
- data/yard/templates/default/class/setup.rb +10 -0
- data/yard/templates/default/class/text/handlers.erb +1 -0
- metadata +459 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module Blather
|
|
2
|
+
class Stanza
|
|
3
|
+
class Iq
|
|
4
|
+
# # In-Band Bytestreams Stanza
|
|
5
|
+
#
|
|
6
|
+
# [XEP-0047: In-Band Bytestreams](http://xmpp.org/extensions/xep-0047.html)
|
|
7
|
+
#
|
|
8
|
+
# @handler :ibb_open
|
|
9
|
+
# @handler :ibb_data
|
|
10
|
+
# @handler :ibb_close
|
|
11
|
+
class Ibb < Iq
|
|
12
|
+
# @private
|
|
13
|
+
NS_IBB = 'http://jabber.org/protocol/ibb'
|
|
14
|
+
|
|
15
|
+
# Overrides the parent method to remove open, close and data nodes
|
|
16
|
+
#
|
|
17
|
+
# @see Blather::Stanza#reply
|
|
18
|
+
def reply
|
|
19
|
+
reply = super
|
|
20
|
+
reply.remove_children :open
|
|
21
|
+
reply.remove_children :close
|
|
22
|
+
reply.remove_children :data
|
|
23
|
+
reply
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# An Open stanza to
|
|
27
|
+
class Open < Ibb
|
|
28
|
+
register :ibb_open, :open, NS_IBB
|
|
29
|
+
|
|
30
|
+
# Find open node
|
|
31
|
+
#
|
|
32
|
+
# @return [Nokogiri::XML::Element]
|
|
33
|
+
def open
|
|
34
|
+
find_first('ns:open', :ns => NS_IBB)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Get the sid of the file transfer
|
|
38
|
+
#
|
|
39
|
+
# @return [String]
|
|
40
|
+
def sid
|
|
41
|
+
open['sid']
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# A Data stanza
|
|
47
|
+
class Data < Ibb
|
|
48
|
+
register :ibb_data, :data, NS_IBB
|
|
49
|
+
|
|
50
|
+
# Find data node
|
|
51
|
+
#
|
|
52
|
+
# @return [Nokogiri::XML::Element]
|
|
53
|
+
def data
|
|
54
|
+
find_first('ns:data', :ns => NS_IBB)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Get the sid of the file transfer
|
|
58
|
+
#
|
|
59
|
+
# @return [String]
|
|
60
|
+
def sid
|
|
61
|
+
data['sid']
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# A Close stanza
|
|
66
|
+
class Close < Ibb
|
|
67
|
+
register :ibb_close, :close, NS_IBB
|
|
68
|
+
|
|
69
|
+
# Find close node
|
|
70
|
+
#
|
|
71
|
+
# @return [Nokogiri::XML::Element]
|
|
72
|
+
def close
|
|
73
|
+
find_first('ns:close', :ns => NS_IBB)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Get the sid of the file transfer
|
|
77
|
+
#
|
|
78
|
+
# @return [String]
|
|
79
|
+
def sid
|
|
80
|
+
close['sid']
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Blather
|
|
2
|
+
class Stanza
|
|
3
|
+
class Iq
|
|
4
|
+
|
|
5
|
+
# # Ping Stanza
|
|
6
|
+
#
|
|
7
|
+
# [XEP-0199: XMPP Ping](http://xmpp.org/extensions/xep-0199.html)
|
|
8
|
+
#
|
|
9
|
+
# This is a base class for any Ping based Iq stanzas.
|
|
10
|
+
#
|
|
11
|
+
# @handler :ping
|
|
12
|
+
class Ping < Iq
|
|
13
|
+
# @private
|
|
14
|
+
register :ping, :ping, 'urn:xmpp:ping'
|
|
15
|
+
|
|
16
|
+
# Overrides the parent method to ensure a ping node is created
|
|
17
|
+
#
|
|
18
|
+
# @see Blather::Stanza::Iq.new
|
|
19
|
+
def self.new(type = :get, to = nil, id = nil)
|
|
20
|
+
node = super
|
|
21
|
+
node.ping
|
|
22
|
+
node
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Overrides the parent method to ensure the current ping node is destroyed
|
|
26
|
+
#
|
|
27
|
+
# @see Blather::Stanza::Iq#inherit
|
|
28
|
+
def inherit(node)
|
|
29
|
+
ping.remove
|
|
30
|
+
super
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Ping node accessor
|
|
34
|
+
# If a ping node exists it will be returned.
|
|
35
|
+
# Otherwise a new node will be created and returned
|
|
36
|
+
#
|
|
37
|
+
# @return [Balather::XMPPNode]
|
|
38
|
+
def ping
|
|
39
|
+
p = find_first 'ns:ping', :ns => self.class.registered_ns
|
|
40
|
+
|
|
41
|
+
unless p
|
|
42
|
+
(self << (p = XMPPNode.new('ping', self.document)))
|
|
43
|
+
p.namespace = self.class.registered_ns
|
|
44
|
+
end
|
|
45
|
+
p
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Blather
|
|
2
|
+
class Stanza
|
|
3
|
+
class Iq
|
|
4
|
+
|
|
5
|
+
# # Query Stanza
|
|
6
|
+
#
|
|
7
|
+
# This is a base class for any query based Iq stanzas. It provides a base set
|
|
8
|
+
# of methods for working with query stanzas
|
|
9
|
+
#
|
|
10
|
+
# @handler :query
|
|
11
|
+
class Query < Iq
|
|
12
|
+
register :query, :query
|
|
13
|
+
|
|
14
|
+
# Overrides the parent method to ensure a query node is created
|
|
15
|
+
#
|
|
16
|
+
# @see Blather::Stanza::Iq.new
|
|
17
|
+
def self.new(type = nil)
|
|
18
|
+
node = super
|
|
19
|
+
node.query
|
|
20
|
+
node
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Overrides the parent method to ensure the current query node is destroyed
|
|
24
|
+
#
|
|
25
|
+
# @see Blather::Stanza::Iq#inherit
|
|
26
|
+
def inherit(node)
|
|
27
|
+
query.remove
|
|
28
|
+
super
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Query node accessor
|
|
32
|
+
# If a query node exists it will be returned.
|
|
33
|
+
# Otherwise a new node will be created and returned
|
|
34
|
+
#
|
|
35
|
+
# @return [Balather::XMPPNode]
|
|
36
|
+
def query
|
|
37
|
+
q = if self.class.registered_ns
|
|
38
|
+
find_first('query_ns:query', :query_ns => self.class.registered_ns)
|
|
39
|
+
else
|
|
40
|
+
find_first('query')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
unless q
|
|
44
|
+
(self << (q = XMPPNode.new('query', self.document)))
|
|
45
|
+
q.namespace = self.class.registered_ns
|
|
46
|
+
end
|
|
47
|
+
q
|
|
48
|
+
end
|
|
49
|
+
end #Query
|
|
50
|
+
|
|
51
|
+
end #Iq
|
|
52
|
+
end #Stanza
|
|
53
|
+
end
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
module Blather
|
|
2
|
+
class Stanza
|
|
3
|
+
class Iq
|
|
4
|
+
|
|
5
|
+
# # Roster Stanza
|
|
6
|
+
#
|
|
7
|
+
# [RFC 3921 Section 7 - Roster Management](http://xmpp.org/rfcs/rfc3921.html#roster)
|
|
8
|
+
#
|
|
9
|
+
# @handler :roster
|
|
10
|
+
class Roster < Query
|
|
11
|
+
register :roster, nil, 'jabber:iq:roster'
|
|
12
|
+
|
|
13
|
+
# Create a new roster stanza and (optionally) load it with an item
|
|
14
|
+
#
|
|
15
|
+
# @param [<Blather::Stanza::Iq::VALID_TYPES>] type the stanza type
|
|
16
|
+
# @param [Blather::XMPPNode] item a roster item
|
|
17
|
+
def self.new(type = nil, item = nil)
|
|
18
|
+
node = super type
|
|
19
|
+
node.query << item if item
|
|
20
|
+
node
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Inherit the XMPPNode to create a proper Roster object.
|
|
24
|
+
# Creates RosterItem objects out of each roster item as well.
|
|
25
|
+
#
|
|
26
|
+
# @param [Blather::XMPPNode] node a node to inherit
|
|
27
|
+
def inherit(node)
|
|
28
|
+
# remove the current set of nodes
|
|
29
|
+
remove_children :item
|
|
30
|
+
super
|
|
31
|
+
# transmogrify nodes into RosterItems
|
|
32
|
+
items.each { |i| query << RosterItem.new(i); i.remove }
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# The list of roster items
|
|
37
|
+
#
|
|
38
|
+
# @return [Array<Blather::Stanza::Iq::Roster::RosterItem>]
|
|
39
|
+
def items
|
|
40
|
+
query.find('//ns:item', :ns => self.class.registered_ns).map do |i|
|
|
41
|
+
RosterItem.new i
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# # RosterItem Fragment
|
|
46
|
+
#
|
|
47
|
+
# Individual roster items.
|
|
48
|
+
# This is a convenience class to attach methods to the node
|
|
49
|
+
class RosterItem < XMPPNode
|
|
50
|
+
|
|
51
|
+
register :item, Roster.registered_ns
|
|
52
|
+
|
|
53
|
+
# Create a new RosterItem
|
|
54
|
+
# @overload new(XML::Node)
|
|
55
|
+
# Create a RosterItem by inheriting a node
|
|
56
|
+
# @param [XML::Node] node an xml node to inherit
|
|
57
|
+
# @overload new(opts)
|
|
58
|
+
# Create a RosterItem through a hash of options
|
|
59
|
+
# @param [Hash] opts the options
|
|
60
|
+
# @option opts [Blather::JID, String, nil] :jid the JID of the item
|
|
61
|
+
# @option opts [String, nil] :name the alias to give the JID
|
|
62
|
+
# @option opts [Symbol, nil] :subscription the subscription status of
|
|
63
|
+
# the RosterItem must be one of
|
|
64
|
+
# Blather::RosterItem::VALID_SUBSCRIPTION_TYPES
|
|
65
|
+
# @option opts [:subscribe, nil] :ask the ask value of the RosterItem
|
|
66
|
+
# @option opts [Array<#to_s>] :groups the group names the RosterItem is a member of
|
|
67
|
+
# @overload new(jid = nil, name = nil, subscription = nil, ask = nil)
|
|
68
|
+
# @param [Blather::JID, String, nil] jid the JID of the item
|
|
69
|
+
# @param [String, nil] name the alias to give the JID
|
|
70
|
+
# @param [Symbol, nil] subscription the subscription status of the
|
|
71
|
+
# RosterItem must be one of
|
|
72
|
+
# Blather::RosterItem::VALID_SUBSCRIPTION_TYPES
|
|
73
|
+
# @param [:subscribe, nil] ask the ask value of the RosterItem
|
|
74
|
+
# @param [Array<#to_s>] groups the group names the RosterItem is a member of
|
|
75
|
+
def self.new(jid = nil, name = nil, subscription = nil, ask = nil, groups = nil)
|
|
76
|
+
new_node = super :item
|
|
77
|
+
|
|
78
|
+
case jid
|
|
79
|
+
when Nokogiri::XML::Node
|
|
80
|
+
new_node.inherit jid
|
|
81
|
+
when Hash
|
|
82
|
+
new_node.jid = jid[:jid]
|
|
83
|
+
new_node.name = jid[:name]
|
|
84
|
+
new_node.subscription = jid[:subscription]
|
|
85
|
+
new_node.ask = jid[:ask]
|
|
86
|
+
new_node.groups = jid[:groups]
|
|
87
|
+
else
|
|
88
|
+
new_node.jid = jid
|
|
89
|
+
new_node.name = name
|
|
90
|
+
new_node.subscription = subscription
|
|
91
|
+
new_node.ask = ask
|
|
92
|
+
new_node.groups = groups
|
|
93
|
+
end
|
|
94
|
+
new_node
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Get the JID attached to the item
|
|
98
|
+
#
|
|
99
|
+
# @return [Blather::JID, nil]
|
|
100
|
+
def jid
|
|
101
|
+
(j = self[:jid]) ? JID.new(j) : nil
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Set the JID of the item
|
|
105
|
+
#
|
|
106
|
+
# @param [Blather::JID, String, nil] jid the new JID
|
|
107
|
+
def jid=(jid)
|
|
108
|
+
write_attr :jid, (jid.nil?) ? nil : JID.new(jid).stripped
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Get the item name
|
|
112
|
+
#
|
|
113
|
+
# @return [String, nil]
|
|
114
|
+
def name
|
|
115
|
+
read_attr :name
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Set the item name
|
|
119
|
+
#
|
|
120
|
+
# @param [#to_s] name the name of the item
|
|
121
|
+
def name=(name)
|
|
122
|
+
write_attr :name, name
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Get the subscription value of the item
|
|
126
|
+
#
|
|
127
|
+
# @return [<:both, :from, :none, :remove, :to>]
|
|
128
|
+
def subscription
|
|
129
|
+
read_attr :subscription, :to_sym
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Set the subscription value of the item
|
|
133
|
+
#
|
|
134
|
+
# @param [<:both, :from, :none, :remove, :to>] subscription
|
|
135
|
+
def subscription=(subscription)
|
|
136
|
+
write_attr :subscription, subscription
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Get the ask value of the item
|
|
140
|
+
#
|
|
141
|
+
# @return [<:subscribe, nil>]
|
|
142
|
+
def ask
|
|
143
|
+
read_attr :ask, :to_sym
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Set the ask value of the item
|
|
147
|
+
#
|
|
148
|
+
# @param [<:subscribe, nil>] ask
|
|
149
|
+
def ask=(ask)
|
|
150
|
+
write_attr :ask, ask
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# The groups roster item belongs to
|
|
154
|
+
#
|
|
155
|
+
# @return [Array<String>]
|
|
156
|
+
def groups
|
|
157
|
+
find('child::*[local-name()="group"]').map { |g| g.content }
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Set the roster item's groups
|
|
161
|
+
#
|
|
162
|
+
# @param [Array<#to_s>] new_groups an array of group names
|
|
163
|
+
def groups=(new_groups)
|
|
164
|
+
remove_children :group
|
|
165
|
+
if new_groups
|
|
166
|
+
new_groups.uniq.each do |g|
|
|
167
|
+
self << (group = XMPPNode.new(:group, self.document))
|
|
168
|
+
group.content = g
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Convert the roster item to a proper stanza all wrapped up
|
|
174
|
+
# This facilitates new subscriptions
|
|
175
|
+
#
|
|
176
|
+
# @return [Blather::Stanza::Iq::Roster]
|
|
177
|
+
def to_stanza
|
|
178
|
+
Roster.new(:set, self)
|
|
179
|
+
end
|
|
180
|
+
end #RosterItem
|
|
181
|
+
end #Roster
|
|
182
|
+
|
|
183
|
+
end #Iq
|
|
184
|
+
end #Stanza
|
|
185
|
+
end
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
module Blather
|
|
2
|
+
class Stanza
|
|
3
|
+
class Iq
|
|
4
|
+
# # SOCKS5 Bytestreams Stanza
|
|
5
|
+
#
|
|
6
|
+
# [XEP-0065: SOCKS5 Bytestreams](http://xmpp.org/extensions/xep-0065.html)
|
|
7
|
+
#
|
|
8
|
+
# @handler :s5b_open
|
|
9
|
+
class S5b < Query
|
|
10
|
+
# @private
|
|
11
|
+
NS_S5B = 'http://jabber.org/protocol/bytestreams'
|
|
12
|
+
|
|
13
|
+
register :s5b_open, :query, NS_S5B
|
|
14
|
+
|
|
15
|
+
# Overrides the parent method to remove query node
|
|
16
|
+
#
|
|
17
|
+
# @see Blather::Stanza#reply
|
|
18
|
+
def reply
|
|
19
|
+
reply = super
|
|
20
|
+
reply.remove_children :query
|
|
21
|
+
reply
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Get the sid of the file transfer
|
|
25
|
+
#
|
|
26
|
+
# @return [String]
|
|
27
|
+
def sid
|
|
28
|
+
query['sid']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Get the used streamhost
|
|
32
|
+
#
|
|
33
|
+
# @return [S5b::StreamHostUsed]
|
|
34
|
+
def streamhost_used
|
|
35
|
+
StreamHostUsed.new query.find_first('.//ns:streamhost-used', :ns => self.class.registered_ns)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Set the used streamhost
|
|
39
|
+
#
|
|
40
|
+
# @param [Blather::JID, String, nil] jid the jid of the used streamhost
|
|
41
|
+
def streamhost_used=(jid)
|
|
42
|
+
query.find('.//ns:streamhost-used', :ns => self.class.registered_ns).remove
|
|
43
|
+
|
|
44
|
+
if jid
|
|
45
|
+
query << StreamHostUsed.new(jid)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Get the streamhosts
|
|
50
|
+
#
|
|
51
|
+
# @return [Array<S5b::StreamHost>]
|
|
52
|
+
def streamhosts
|
|
53
|
+
query.find('.//ns:streamhost', :ns => self.class.registered_ns).map do |s|
|
|
54
|
+
StreamHost.new s
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Set the streamhosts
|
|
59
|
+
#
|
|
60
|
+
# @param streamhosts the array of streamhosts, passed directly to StreamHost.new
|
|
61
|
+
def streamhosts=(streamhosts)
|
|
62
|
+
query.find('.//ns:streamhost', :ns => self.class.registered_ns).remove
|
|
63
|
+
if streamhosts
|
|
64
|
+
[streamhosts].flatten.each { |s| self.query << StreamHost.new(s) }
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# StreamHost Stanza
|
|
69
|
+
class StreamHost < XMPPNode
|
|
70
|
+
register 'streamhost', NS_S5B
|
|
71
|
+
|
|
72
|
+
# Create a new S5b::StreamHost
|
|
73
|
+
#
|
|
74
|
+
# @overload new(node)
|
|
75
|
+
# Create a new StreamHost by inheriting an existing node
|
|
76
|
+
# @param [XML::Node] node an XML::Node to inherit from
|
|
77
|
+
# @overload new(opts)
|
|
78
|
+
# Create a new StreamHost through a hash of options
|
|
79
|
+
# @param [Hash] opts a hash options
|
|
80
|
+
# @option opts [Blather::JID, String] :jid the JID of the StreamHost
|
|
81
|
+
# @option opts [#to_s] :host the host the StreamHost
|
|
82
|
+
# @option opts [#to_s] :port the post of the StreamHost
|
|
83
|
+
# @overload new(jid, host = nil, port = nil)
|
|
84
|
+
# Create a new StreamHost
|
|
85
|
+
# @param [Blather::JID, String] jid the JID of the StreamHost
|
|
86
|
+
# @param [#to_s] host the host the StreamHost
|
|
87
|
+
# @param [#to_s] port the post of the StreamHost
|
|
88
|
+
def self.new(jid, host = nil, port = nil)
|
|
89
|
+
new_node = super 'streamhost'
|
|
90
|
+
|
|
91
|
+
case jid
|
|
92
|
+
when Nokogiri::XML::Node
|
|
93
|
+
new_node.inherit jid
|
|
94
|
+
when Hash
|
|
95
|
+
new_node.jid = jid[:jid]
|
|
96
|
+
new_node.host = jid[:host]
|
|
97
|
+
new_node.port = jid[:port]
|
|
98
|
+
else
|
|
99
|
+
new_node.jid = jid
|
|
100
|
+
new_node.host = host
|
|
101
|
+
new_node.port = port
|
|
102
|
+
end
|
|
103
|
+
new_node
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Get the jid of the streamhost
|
|
107
|
+
#
|
|
108
|
+
# @return [Blather::JID, nil]
|
|
109
|
+
def jid
|
|
110
|
+
if j = read_attr(:jid)
|
|
111
|
+
JID.new(j)
|
|
112
|
+
else
|
|
113
|
+
nil
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Set the jid of the streamhost
|
|
118
|
+
#
|
|
119
|
+
# @param [Blather::JID, String, nil]
|
|
120
|
+
def jid=(j)
|
|
121
|
+
write_attr :jid, (j ? j.to_s : nil)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Get the host address of the streamhost
|
|
125
|
+
#
|
|
126
|
+
# @return [String, nil]
|
|
127
|
+
def host
|
|
128
|
+
read_attr :host
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Set the host address of the streamhost
|
|
132
|
+
#
|
|
133
|
+
# @param [String, nil]
|
|
134
|
+
def host=(h)
|
|
135
|
+
write_attr :host, h
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Get the port of the streamhost
|
|
139
|
+
#
|
|
140
|
+
# @return [Fixnum, nil]
|
|
141
|
+
def port
|
|
142
|
+
if p = read_attr(:port)
|
|
143
|
+
p.to_i
|
|
144
|
+
else
|
|
145
|
+
nil
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Set the port of the streamhost
|
|
150
|
+
#
|
|
151
|
+
# @param [String, Fixnum, nil]
|
|
152
|
+
def port=(p)
|
|
153
|
+
write_attr :port, p
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Stream host used stanza
|
|
158
|
+
class StreamHostUsed < XMPPNode
|
|
159
|
+
register 'streamhost-used', NS_S5B
|
|
160
|
+
|
|
161
|
+
# Create a new S5b::StreamHostUsed
|
|
162
|
+
#
|
|
163
|
+
# @overload new(node)
|
|
164
|
+
# Create a new StreamHostUsed by inheriting an existing node
|
|
165
|
+
# @param [XML::Node] node an XML::Node to inherit from
|
|
166
|
+
# @overload new(opts)
|
|
167
|
+
# Create a new StreamHostUsed through a hash of options
|
|
168
|
+
# @param [Hash] opts a hash options
|
|
169
|
+
# @option opts [Blather::JID, String] :jid the JID of the StreamHostUsed
|
|
170
|
+
# @overload new(jid)
|
|
171
|
+
# Create a new StreamHostUsed
|
|
172
|
+
# @param [Blather::JID, String] jid the JID of the StreamHostUsed
|
|
173
|
+
def self.new(jid)
|
|
174
|
+
new_node = super 'streamhost-used'
|
|
175
|
+
|
|
176
|
+
case jid
|
|
177
|
+
when Nokogiri::XML::Node
|
|
178
|
+
new_node.inherit jid
|
|
179
|
+
when Hash
|
|
180
|
+
new_node.jid = jid[:jid]
|
|
181
|
+
else
|
|
182
|
+
new_node.jid = jid
|
|
183
|
+
end
|
|
184
|
+
new_node
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Get the jid of the used streamhost
|
|
188
|
+
#
|
|
189
|
+
# @return [Blather::JID, nil]
|
|
190
|
+
def jid
|
|
191
|
+
if j = read_attr(:jid)
|
|
192
|
+
JID.new(j)
|
|
193
|
+
else
|
|
194
|
+
nil
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# Set the jid of the used streamhost
|
|
199
|
+
#
|
|
200
|
+
# @param [Blather::JID, String, nil]
|
|
201
|
+
def jid=(j)
|
|
202
|
+
write_attr :jid, (j ? j.to_s : nil)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|