gmcmillan-xmpp4r 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +91 -0
- data/COPYING +340 -0
- data/LICENSE +59 -0
- data/README.rdoc +122 -0
- data/README_ruby19.txt +43 -0
- data/Rakefile +258 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
- data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
- data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
- data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
- data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
- data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
- data/data/doc/xmpp4r/examples/advanced/recvfile.rb +85 -0
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
- data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
- data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
- data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
- data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
- data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
- data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
- data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
- data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
- data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
- data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
- data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
- data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
- data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
- data/lib/xmpp4r.rb +118 -0
- data/lib/xmpp4r/base64.rb +32 -0
- data/lib/xmpp4r/bytestreams.rb +15 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +321 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +153 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +82 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
- data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
- data/lib/xmpp4r/callbacks.rb +133 -0
- data/lib/xmpp4r/caps.rb +1 -0
- data/lib/xmpp4r/caps/c.rb +67 -0
- data/lib/xmpp4r/caps/helper/generator.rb +160 -0
- data/lib/xmpp4r/caps/helper/helper.rb +84 -0
- data/lib/xmpp4r/client.rb +345 -0
- data/lib/xmpp4r/command/helper/responder.rb +53 -0
- data/lib/xmpp4r/command/iq/command.rb +154 -0
- data/lib/xmpp4r/component.rb +103 -0
- data/lib/xmpp4r/connection.rb +231 -0
- data/lib/xmpp4r/dataforms.rb +5 -0
- data/lib/xmpp4r/dataforms/x/data.rb +297 -0
- data/lib/xmpp4r/debuglog.rb +63 -0
- data/lib/xmpp4r/delay.rb +5 -0
- data/lib/xmpp4r/delay/x/delay.rb +99 -0
- data/lib/xmpp4r/discovery.rb +8 -0
- data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
- data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
- data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
- data/lib/xmpp4r/entity_time.rb +6 -0
- data/lib/xmpp4r/entity_time/iq.rb +45 -0
- data/lib/xmpp4r/entity_time/responder.rb +57 -0
- data/lib/xmpp4r/errors.rb +284 -0
- data/lib/xmpp4r/feature_negotiation.rb +5 -0
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
- data/lib/xmpp4r/framework/base.rb +55 -0
- data/lib/xmpp4r/framework/bot.rb +148 -0
- data/lib/xmpp4r/httpbinding.rb +5 -0
- data/lib/xmpp4r/httpbinding/client.rb +275 -0
- data/lib/xmpp4r/idgenerator.rb +37 -0
- data/lib/xmpp4r/iq.rb +221 -0
- data/lib/xmpp4r/jid.rb +167 -0
- data/lib/xmpp4r/last.rb +2 -0
- data/lib/xmpp4r/last/helper/helper.rb +37 -0
- data/lib/xmpp4r/last/iq/last.rb +67 -0
- data/lib/xmpp4r/location.rb +2 -0
- data/lib/xmpp4r/location/helper/helper.rb +56 -0
- data/lib/xmpp4r/location/location.rb +179 -0
- data/lib/xmpp4r/message.rb +226 -0
- data/lib/xmpp4r/muc.rb +14 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +469 -0
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
- data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
- data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
- data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
- data/lib/xmpp4r/muc/item.rb +143 -0
- data/lib/xmpp4r/muc/x/muc.rb +70 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
- data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
- data/lib/xmpp4r/presence.rb +232 -0
- data/lib/xmpp4r/pubsub.rb +8 -0
- data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
- data/lib/xmpp4r/pubsub/children/event.rb +49 -0
- data/lib/xmpp4r/pubsub/children/item.rb +35 -0
- data/lib/xmpp4r/pubsub/children/items.rb +53 -0
- data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
- data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
- data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
- data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
- data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
- data/lib/xmpp4r/pubsub/children/unsubscribe.rb +63 -0
- data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
- data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
- data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
- data/lib/xmpp4r/pubsub/helper/servicehelper.rb +490 -0
- data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
- data/lib/xmpp4r/query.rb +15 -0
- data/lib/xmpp4r/reliable.rb +168 -0
- data/lib/xmpp4r/rexmladdons.rb +197 -0
- data/lib/xmpp4r/roster.rb +7 -0
- data/lib/xmpp4r/roster/helper/roster.rb +532 -0
- data/lib/xmpp4r/roster/iq/roster.rb +215 -0
- data/lib/xmpp4r/roster/x/roster.rb +138 -0
- data/lib/xmpp4r/rpc.rb +2 -0
- data/lib/xmpp4r/rpc/helper/client.rb +123 -0
- data/lib/xmpp4r/rpc/helper/server.rb +74 -0
- data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
- data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
- data/lib/xmpp4r/sasl.rb +259 -0
- data/lib/xmpp4r/semaphore.rb +38 -0
- data/lib/xmpp4r/stream.rb +611 -0
- data/lib/xmpp4r/streamparser.rb +66 -0
- data/lib/xmpp4r/test/listener_mocker.rb +118 -0
- data/lib/xmpp4r/tune.rb +2 -0
- data/lib/xmpp4r/tune/helper/helper.rb +58 -0
- data/lib/xmpp4r/tune/tune.rb +113 -0
- data/lib/xmpp4r/vcard.rb +6 -0
- data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
- data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
- data/lib/xmpp4r/version.rb +7 -0
- data/lib/xmpp4r/version/helper/responder.rb +72 -0
- data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
- data/lib/xmpp4r/version/iq/version.rb +105 -0
- data/lib/xmpp4r/x.rb +37 -0
- data/lib/xmpp4r/xhtml.rb +1 -0
- data/lib/xmpp4r/xhtml/html.rb +115 -0
- data/lib/xmpp4r/xmpp4r.rb +20 -0
- data/lib/xmpp4r/xmppelement.rb +168 -0
- data/lib/xmpp4r/xmppstanza.rb +162 -0
- data/setup.rb +1586 -0
- data/test/bytestreams/tc_ibb.rb +188 -0
- data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
- data/test/caps/tc_helper.rb +158 -0
- data/test/dataforms/tc_data.rb +81 -0
- data/test/delay/tc_xdelay.rb +51 -0
- data/test/discovery/tc_responder.rb +91 -0
- data/test/entity_time/tc_responder.rb +65 -0
- data/test/last/tc_helper.rb +75 -0
- data/test/lib/assert_equal_xml.rb +14 -0
- data/test/lib/clienttester.rb +149 -0
- data/test/muc/tc_muc_mucclient.rb +834 -0
- data/test/muc/tc_muc_simplemucclient.rb +114 -0
- data/test/muc/tc_mucowner.rb +50 -0
- data/test/pubsub/tc_helper.rb +785 -0
- data/test/pubsub/tc_nodeconfig.rb +61 -0
- data/test/pubsub/tc_subscriptionconfig.rb +41 -0
- data/test/roster/tc_helper.rb +523 -0
- data/test/roster/tc_iqqueryroster.rb +173 -0
- data/test/roster/tc_xroster.rb +73 -0
- data/test/rpc/tc_helper.rb +96 -0
- data/test/tc_callbacks.rb +129 -0
- data/test/tc_class_names.rb +146 -0
- data/test/tc_client.rb +30 -0
- data/test/tc_errors.rb +146 -0
- data/test/tc_idgenerator.rb +30 -0
- data/test/tc_iq.rb +113 -0
- data/test/tc_iqquery.rb +31 -0
- data/test/tc_jid.rb +204 -0
- data/test/tc_presence.rb +150 -0
- data/test/tc_rexml.rb +139 -0
- data/test/tc_stream.rb +193 -0
- data/test/tc_streamComponent.rb +105 -0
- data/test/tc_streamError.rb +129 -0
- data/test/tc_streamSend.rb +59 -0
- data/test/tc_streamparser.rb +137 -0
- data/test/tc_xmppstanza.rb +135 -0
- data/test/ts_xmpp4r.rb +44 -0
- data/test/tune/tc_helper_recv.rb +82 -0
- data/test/tune/tc_helper_send.rb +74 -0
- data/test/tune/tc_tune.rb +79 -0
- data/test/vcard/tc_helper.rb +49 -0
- data/test/vcard/tc_iqvcard.rb +62 -0
- data/test/version/tc_helper.rb +60 -0
- data/test/version/tc_iqqueryversion.rb +97 -0
- data/test/xhtml/tc_html.rb +41 -0
- data/tools/gen_requires.bash +31 -0
- data/tools/xmpp4r-gemspec-test.rb +11 -0
- data/xmpp4r.gemspec +249 -0
- metadata +299 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
# =XMPP4R - XMPP Library for Ruby
|
2
|
+
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
|
3
|
+
# Website::http://home.gna.org/xmpp4r/
|
4
|
+
|
5
|
+
require 'xmpp4r/query'
|
6
|
+
|
7
|
+
module Jabber
|
8
|
+
module Roster
|
9
|
+
##
|
10
|
+
# Class for handling roster updates
|
11
|
+
#
|
12
|
+
# You must do 'client.send(Iq.new_rosterget)' or else you will
|
13
|
+
# have nothing to put in receive_iq()
|
14
|
+
#
|
15
|
+
# You must require 'xmpp4r/rosterquery' to use this class
|
16
|
+
# as its functionality is not needed for a working XMPP implementation.
|
17
|
+
# This will make [IqQuery] convert all Queries with namespace 'jabber:iq:roster'
|
18
|
+
# to [IqQueryRoster]
|
19
|
+
#
|
20
|
+
# This <query/> contains multiple <item/> children. See RosterItem.
|
21
|
+
class IqQueryRoster < IqQuery
|
22
|
+
name_xmlns 'query', 'jabber:iq:roster'
|
23
|
+
|
24
|
+
##
|
25
|
+
# Iterate through all items
|
26
|
+
# &block:: Yield for every [RosterItem]
|
27
|
+
def each(&block)
|
28
|
+
each_element { |item|
|
29
|
+
# XPath won't work here as it's missing a prefix...
|
30
|
+
yield(item) if item.kind_of?(RosterItem)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Get roster item by JID
|
36
|
+
# jid:: [JID] or [Nil]
|
37
|
+
# result:: [RosterItem]
|
38
|
+
def [](jid)
|
39
|
+
each { |item|
|
40
|
+
return(item) if item.jid == jid
|
41
|
+
}
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Get all items
|
47
|
+
# result:: [Array] of [RosterItem]
|
48
|
+
def to_a
|
49
|
+
a = []
|
50
|
+
each { |item|
|
51
|
+
a.push(item)
|
52
|
+
}
|
53
|
+
a
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Update roster by <iq/> stanza
|
58
|
+
# (to be fed by an iq_callback)
|
59
|
+
# iq:: [Iq] Containing new roster
|
60
|
+
# filter:: [Boolean] If false import non-roster-like results too
|
61
|
+
def receive_iq(iq, filter=true)
|
62
|
+
if filter && (((iq.type != :set) && (iq.type != :result)) || (iq.queryns != 'jabber:iq:roster'))
|
63
|
+
return
|
64
|
+
end
|
65
|
+
|
66
|
+
import(iq.query)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Output for "p"
|
71
|
+
#
|
72
|
+
# JIDs of all contained [RosterItem] elements are joined with a comma
|
73
|
+
# result:: [String]
|
74
|
+
def inspect
|
75
|
+
jids = to_a.collect { |item| item.jid.inspect }
|
76
|
+
jids.join(', ')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Class containing the <item/> elements of the roster
|
82
|
+
#
|
83
|
+
# The 'name' attribute has been renamed to 'iname' here
|
84
|
+
# as 'name' is already used by REXML::Element for the
|
85
|
+
# element's name. It's still name='...' in XML.
|
86
|
+
class RosterItem < XMPPElement
|
87
|
+
name_xmlns 'item', 'jabber:iq:roster'
|
88
|
+
|
89
|
+
##
|
90
|
+
# Construct a new roster item
|
91
|
+
# jid:: [JID] Jabber ID
|
92
|
+
# iname:: [String] Name in the roster
|
93
|
+
# subscription:: [Symbol] Type of subscription (see RosterItem#subscription=)
|
94
|
+
# ask:: [Symbol] or [Nil] Can be :subscribe
|
95
|
+
def initialize(jid=nil, iname=nil, subscription=nil, ask=nil)
|
96
|
+
super()
|
97
|
+
self.jid = jid
|
98
|
+
self.iname = iname
|
99
|
+
self.subscription = subscription
|
100
|
+
self.ask = ask
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Get name of roster item
|
105
|
+
#
|
106
|
+
# names can be set by the roster's owner himself
|
107
|
+
# return:: [String]
|
108
|
+
def iname
|
109
|
+
attributes['name']
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Set name of roster item
|
114
|
+
# val:: [String] Name for this item
|
115
|
+
def iname=(val)
|
116
|
+
attributes['name'] = val
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Get JID of roster item
|
121
|
+
# Resource of the JID will _not_ be stripped
|
122
|
+
# return:: [JID]
|
123
|
+
def jid
|
124
|
+
(a = attributes['jid']) ? JID.new(a) : nil
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Set JID of roster item
|
129
|
+
# val:: [JID] or nil
|
130
|
+
def jid=(val)
|
131
|
+
attributes['jid'] = val.nil? ? nil : val.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
##
|
135
|
+
# Get subscription type of roster item
|
136
|
+
# result:: [Symbol] or [Nil] The following values are valid according to RFC3921:
|
137
|
+
# * :both
|
138
|
+
# * :from
|
139
|
+
# * :none
|
140
|
+
# * :remove
|
141
|
+
# * :to
|
142
|
+
def subscription
|
143
|
+
case attributes['subscription']
|
144
|
+
when 'both' then :both
|
145
|
+
when 'from' then :from
|
146
|
+
when 'none' then :none
|
147
|
+
when 'remove' then :remove
|
148
|
+
when 'to' then :to
|
149
|
+
else nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Set subscription type of roster item
|
155
|
+
# val:: [Symbol] or [Nil] See subscription for possible Symbols
|
156
|
+
def subscription=(val)
|
157
|
+
case val
|
158
|
+
when :both then attributes['subscription'] = 'both'
|
159
|
+
when :from then attributes['subscription'] = 'from'
|
160
|
+
when :none then attributes['subscription'] = 'none'
|
161
|
+
when :remove then attributes['subscription'] = 'remove'
|
162
|
+
when :to then attributes['subscription'] = 'to'
|
163
|
+
else attributes['subscription'] = nil
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
##
|
168
|
+
# Get if asking for subscription
|
169
|
+
# result:: [Symbol] nil or :subscribe
|
170
|
+
def ask
|
171
|
+
case attributes['ask']
|
172
|
+
when 'subscribe' then :subscribe
|
173
|
+
else nil
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
##
|
178
|
+
# Set if asking for subscription
|
179
|
+
# val:: [Symbol] nil or :subscribe
|
180
|
+
def ask=(val)
|
181
|
+
case val
|
182
|
+
when :subscribe then attributes['ask'] = 'subscribe'
|
183
|
+
else attributes['ask'] = nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
##
|
188
|
+
# Get groups the item belongs to
|
189
|
+
# result:: [Array] of [String] The groups
|
190
|
+
def groups
|
191
|
+
result = []
|
192
|
+
each_element('group') { |group|
|
193
|
+
result.push(group.text)
|
194
|
+
}
|
195
|
+
result.uniq
|
196
|
+
end
|
197
|
+
|
198
|
+
##
|
199
|
+
# Set groups the item belongs to,
|
200
|
+
# deletes old groups first.
|
201
|
+
#
|
202
|
+
# See JEP 0083 for nested groups
|
203
|
+
# ary:: [Array] New groups, duplicate values will be removed
|
204
|
+
def groups=(ary)
|
205
|
+
# Delete old group elements
|
206
|
+
delete_elements('group')
|
207
|
+
|
208
|
+
# Add new group elements
|
209
|
+
ary.uniq.each { |group|
|
210
|
+
add_element('group').text = group
|
211
|
+
}
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end #Module Roster
|
215
|
+
end #Module Jabber
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# =XMPP4R - XMPP Library for Ruby
|
2
|
+
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
|
3
|
+
# Website::http://home.gna.org/xmpp4r/
|
4
|
+
|
5
|
+
require 'xmpp4r/x'
|
6
|
+
require 'xmpp4r/jid'
|
7
|
+
|
8
|
+
module Jabber
|
9
|
+
module Roster
|
10
|
+
##
|
11
|
+
# Implementation of JEP-0144
|
12
|
+
# for <tt><x xmlns='http://jabber.org/protocol/rosterx'/></tt>
|
13
|
+
# attached to <tt><message/></tt> stanzas
|
14
|
+
#
|
15
|
+
# Should be backwards compatible to JEP-0093,
|
16
|
+
# as only action attribute of roster items are missing there.
|
17
|
+
# Pay attention to the namespace which is <tt>jabber:x:roster</tt>
|
18
|
+
# for JEP-0093!
|
19
|
+
class XRoster < X
|
20
|
+
name_xmlns 'x', 'jabber:x:roster'
|
21
|
+
end #Class XRoster
|
22
|
+
|
23
|
+
class RosterX < XRoster
|
24
|
+
name_xmlns 'x', 'http://jabber.org/protocol/rosterx'
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Class containing an <item/> element
|
29
|
+
#
|
30
|
+
# The 'name' attribute has been renamed to 'iname' here
|
31
|
+
# as 'name' is already used by REXML::Element for the
|
32
|
+
# element's name. It's still name='...' in XML.
|
33
|
+
#
|
34
|
+
# This is all a bit analoguous to Jabber::RosterItem, used by
|
35
|
+
# Jabber::IqQueryRoster. But this class lacks the subscription and
|
36
|
+
# ask attributes.
|
37
|
+
class XRosterItem < XMPPElement
|
38
|
+
name_xmlns 'item', 'jabber:x:roster'
|
39
|
+
|
40
|
+
##
|
41
|
+
# Construct a new roster item
|
42
|
+
# jid:: [JID] Jabber ID
|
43
|
+
# iname:: [String] Name in the roster
|
44
|
+
def initialize(jid=nil, iname=nil)
|
45
|
+
super()
|
46
|
+
self.jid = jid
|
47
|
+
self.iname = iname
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Get name of roster item
|
52
|
+
#
|
53
|
+
# names can be set by the roster's owner himself
|
54
|
+
# return:: [String]
|
55
|
+
def iname
|
56
|
+
attributes['name']
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Set name of roster item
|
61
|
+
# val:: [String] Name for this item
|
62
|
+
def iname=(val)
|
63
|
+
attributes['name'] = val
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Get JID of roster item
|
68
|
+
# Resource of the JID will _not_ be stripped
|
69
|
+
# return:: [JID]
|
70
|
+
def jid
|
71
|
+
JID.new(attributes['jid'])
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Set JID of roster item
|
76
|
+
# val:: [JID] or nil
|
77
|
+
def jid=(val)
|
78
|
+
attributes['jid'] = val.nil? ? nil : val.to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Get action for this roster item
|
83
|
+
# * :add
|
84
|
+
# * :modify
|
85
|
+
# * :delete
|
86
|
+
# result:: [Symbol] (defaults to :add according to JEP-0144)
|
87
|
+
def action
|
88
|
+
case attributes['action']
|
89
|
+
when 'modify' then :modify
|
90
|
+
when 'delete' then :delete
|
91
|
+
else :add
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Set action for this roster item
|
97
|
+
# (see action)
|
98
|
+
def action=(a)
|
99
|
+
case a
|
100
|
+
when :modify then attributes['action'] = 'modify'
|
101
|
+
when :delete then attributes['action'] = 'delete'
|
102
|
+
else attributes['action'] = 'add'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Get groups the item belongs to
|
108
|
+
# result:: [Array] of [String] The groups
|
109
|
+
def groups
|
110
|
+
result = []
|
111
|
+
each_element('group') { |group|
|
112
|
+
result.push(group.text)
|
113
|
+
}
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Set groups the item belongs to,
|
119
|
+
# deletes old groups first.
|
120
|
+
#
|
121
|
+
# See JEP 0083 for nested groups
|
122
|
+
# ary:: [Array] New groups, duplicate values will be removed
|
123
|
+
def groups=(ary)
|
124
|
+
# Delete old group elements
|
125
|
+
delete_elements('group')
|
126
|
+
|
127
|
+
# Add new group elements
|
128
|
+
ary.uniq.each { |group|
|
129
|
+
add_element('group').text = group
|
130
|
+
}
|
131
|
+
end
|
132
|
+
end #Class XRosterItem
|
133
|
+
|
134
|
+
class RosterXItem < XRosterItem
|
135
|
+
name_xmlns 'item', 'http://jabber.org/protocol/rosterx'
|
136
|
+
end
|
137
|
+
end #Module Roster
|
138
|
+
end #Module Jabber
|
data/lib/xmpp4r/rpc.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'xmlrpc/server'
|
2
|
+
require 'xmlrpc/parser'
|
3
|
+
require 'xmlrpc/create'
|
4
|
+
require 'xmlrpc/config'
|
5
|
+
require 'xmlrpc/utils' # ParserWriterChooseMixin
|
6
|
+
|
7
|
+
require 'xmpp4r/dataforms/x/data'
|
8
|
+
require 'xmpp4r/rpc/iq/rpc'
|
9
|
+
require 'xmpp4r/rpc/helper/xmlrpcaddons'
|
10
|
+
|
11
|
+
module Jabber
|
12
|
+
module RPC
|
13
|
+
|
14
|
+
##
|
15
|
+
# XMLRPC Client
|
16
|
+
class Client
|
17
|
+
|
18
|
+
include XMLRPC::ParserWriterChooseMixin
|
19
|
+
include XMLRPC::ParseContentType
|
20
|
+
|
21
|
+
attr_accessor :my_jid
|
22
|
+
|
23
|
+
##
|
24
|
+
# xmppstream
|
25
|
+
# stream:: [Stream]
|
26
|
+
# jid where you want to send the rpc requests to
|
27
|
+
# jid:: [JID] rpcserver@jabberserver/ressource
|
28
|
+
def initialize(stream,jid)
|
29
|
+
@jid = JID.new(jid)
|
30
|
+
@my_jid = stream.jid
|
31
|
+
@stream = stream
|
32
|
+
@parser = nil
|
33
|
+
@create = XMLRPC::Create.new
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# automatically trys to find a method
|
38
|
+
# thanx to eric cestari :)
|
39
|
+
def method_missing(methodname, *args)
|
40
|
+
send("call", methodname,*args)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def call(method, *args)
|
45
|
+
ok, param = call2(method, *args)
|
46
|
+
if ok
|
47
|
+
param
|
48
|
+
else
|
49
|
+
raise param
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def call2(method, *args)
|
54
|
+
request = @create.methodCall(method, *args)
|
55
|
+
data = do_rpc(request)
|
56
|
+
parser().parseMethodResponse(data)
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# adds multi rpcalls to the query
|
61
|
+
# methods:: [Array]
|
62
|
+
def multicall(*methods)
|
63
|
+
ok, params = multicall2(*methods)
|
64
|
+
if ok
|
65
|
+
params
|
66
|
+
else
|
67
|
+
raise params
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# generate a multicall
|
73
|
+
# methods:: [Array]
|
74
|
+
def multicall2(*methods)
|
75
|
+
gen_multicall(methods)
|
76
|
+
end
|
77
|
+
|
78
|
+
def do_rpc(xmlrpc)
|
79
|
+
iq = Iq.new(:set, @jid)
|
80
|
+
iq.from = @my_jid
|
81
|
+
iq.id = IdGenerator::generate_id
|
82
|
+
rpcquery = iq.add(IqQueryRPC.new)
|
83
|
+
rpcquery.typed_add(xmlrpc)
|
84
|
+
|
85
|
+
result = nil
|
86
|
+
@stream.send_with_id(iq) do |iqreply|
|
87
|
+
if iqreply.query.kind_of?(IqQueryRPC)
|
88
|
+
result = iqreply.query.to_s
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
result
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def gen_multicall(methods=[])
|
98
|
+
ok, params = call2("system.multicall",
|
99
|
+
methods.collect { |m|
|
100
|
+
{
|
101
|
+
'methodName' => m[0],
|
102
|
+
'params' => m[1..-1]
|
103
|
+
}
|
104
|
+
}
|
105
|
+
)
|
106
|
+
|
107
|
+
if ok
|
108
|
+
params = params.collect{ |param|
|
109
|
+
if param.is_a? Array
|
110
|
+
param[0]
|
111
|
+
elsif param.is_a? Hash
|
112
|
+
XMLRPC::FaultException.new(param["faultCode"], param["faultString"])
|
113
|
+
else
|
114
|
+
raise "Wrong multicall return value"
|
115
|
+
end
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
return ok, params
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end # Helpers
|
123
|
+
end # Jabber
|