xmpp4r 0.3
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/COPYING +340 -0
- data/ChangeLog +28 -0
- data/LICENSE +59 -0
- data/README +20 -0
- data/Rakefile +103 -0
- data/UPDATING +40 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/README +57 -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 +425 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +344 -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 +89 -0
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
- data/data/doc/xmpp4r/examples/advanced/recvfile.rb +83 -0
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +130 -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 +90 -0
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +134 -0
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +9 -0
- data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/client.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
- data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +32 -0
- data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +32 -0
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +67 -0
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +39 -0
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +83 -0
- data/data/doc/xmpp4r/examples/basic/register.rb +25 -0
- data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
- data/data/doc/xmpp4r/examples/basic/roster.rb +42 -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 +172 -0
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
- data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +18 -0
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +192 -0
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +82 -0
- data/lib/callbacks.rb +122 -0
- data/lib/xmpp4r/authenticationfailure.rb +13 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +315 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +256 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +30 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +46 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +151 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +85 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +178 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +56 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +61 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +177 -0
- data/lib/xmpp4r/bytestreams/iq/si.rb +221 -0
- data/lib/xmpp4r/bytestreams.rb +11 -0
- data/lib/xmpp4r/client.rb +249 -0
- data/lib/xmpp4r/component.rb +103 -0
- data/lib/xmpp4r/connection.rb +166 -0
- data/lib/xmpp4r/dataforms/x/data.rb +248 -0
- data/lib/xmpp4r/dataforms.rb +1 -0
- data/lib/xmpp4r/debuglog.rb +34 -0
- data/lib/xmpp4r/delay/x/delay.rb +100 -0
- data/lib/xmpp4r/delay.rb +1 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +225 -0
- data/lib/xmpp4r/discovery/iq/discoitems.rb +162 -0
- data/lib/xmpp4r/discovery.rb +2 -0
- data/lib/xmpp4r/error.rb +230 -0
- data/lib/xmpp4r/errorexception.rb +32 -0
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +42 -0
- data/lib/xmpp4r/feature_negotiation.rb +1 -0
- data/lib/xmpp4r/idgenerator.rb +37 -0
- data/lib/xmpp4r/iq.rb +229 -0
- data/lib/xmpp4r/jid.rb +167 -0
- data/lib/xmpp4r/message.rb +171 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +107 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +382 -0
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +222 -0
- data/lib/xmpp4r/muc/x/muc.rb +98 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +58 -0
- data/lib/xmpp4r/muc/x/mucuseritem.rb +148 -0
- data/lib/xmpp4r/muc.rb +6 -0
- data/lib/xmpp4r/presence.rb +255 -0
- data/lib/xmpp4r/query.rb +43 -0
- data/lib/xmpp4r/rexmladdons.rb +826 -0
- data/lib/xmpp4r/roster/helper/roster.rb +514 -0
- data/lib/xmpp4r/roster/iq/roster.rb +244 -0
- data/lib/xmpp4r/roster/x/roster.rb +155 -0
- data/lib/xmpp4r/roster.rb +4 -0
- data/lib/xmpp4r/sasl.rb +167 -0
- data/lib/xmpp4r/stream.rb +543 -0
- data/lib/xmpp4r/streamparser.rb +77 -0
- data/lib/xmpp4r/vcard/helper/vcard.rb +86 -0
- data/lib/xmpp4r/vcard/iq/vcard.rb +102 -0
- data/lib/xmpp4r/vcard.rb +3 -0
- data/lib/xmpp4r/version/helper/responder.rb +71 -0
- data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
- data/lib/xmpp4r/version/iq/version.rb +118 -0
- data/lib/xmpp4r/version.rb +3 -0
- data/lib/xmpp4r/x.rb +43 -0
- data/lib/xmpp4r/xmlstanza.rb +174 -0
- data/lib/xmpp4r/xmpp4r.rb +16 -0
- data/lib/xmpp4r.rb +122 -0
- data/setup.rb +1360 -0
- data/test/bytestreams/tc_ibb.rb +186 -0
- data/test/bytestreams/tc_socks5bytestreams.rb +57 -0
- data/test/delay/tc_xdelay.rb +51 -0
- data/test/lib/clienttester.rb +110 -0
- data/test/muc/tc_muc_mucclient.rb +569 -0
- data/test/muc/tc_muc_simplemucclient.rb +72 -0
- data/test/roster/.tc_helper.rb.swp +0 -0
- data/test/roster/tc_helper.rb +389 -0
- data/test/roster/tc_iqqueryroster.rb +140 -0
- data/test/roster/tc_xroster.rb +70 -0
- data/test/tc_callbacks.rb +128 -0
- data/test/tc_class_names.rb +129 -0
- data/test/tc_client.rb +30 -0
- data/test/tc_error.rb +103 -0
- data/test/tc_idgenerator.rb +30 -0
- data/test/tc_iq.rb +109 -0
- data/test/tc_iqquery.rb +31 -0
- data/test/tc_jid.rb +202 -0
- data/test/tc_message.rb +114 -0
- data/test/tc_presence.rb +148 -0
- data/test/tc_stream.rb +182 -0
- data/test/tc_streamError.rb +87 -0
- data/test/tc_streamSend.rb +59 -0
- data/test/tc_streamThreaded.rb +168 -0
- data/test/tc_xmlstanza.rb +76 -0
- data/test/ts_xmpp4r.rb +34 -0
- data/test/vcard/tc_iqvcard.rb +52 -0
- data/test/version/tc_helper.rb +46 -0
- data/test/version/tc_iqqueryversion.rb +96 -0
- data/tools/doctoweb.bash +30 -0
- data/tools/gen_requires.bash +10 -0
- metadata +232 -0
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
module Jabber
|
|
6
|
+
module MUC
|
|
7
|
+
class XMUCUserInvite < REXML::Element
|
|
8
|
+
def initialize(to=nil, reason=nil)
|
|
9
|
+
super('invite')
|
|
10
|
+
set_to(to)
|
|
11
|
+
set_reason(reason)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to
|
|
15
|
+
attributes['to'].nil? ? nil : JID::new(attributes['to'])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to=(j)
|
|
19
|
+
attributes['to'] = j.nil? ? nil : j.to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def set_to(j)
|
|
23
|
+
self.to = j
|
|
24
|
+
self
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def from
|
|
28
|
+
attributes['from'].nil? ? nil : JID::new(attributes['from'])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def from=(j)
|
|
32
|
+
attributes['from'] = (j.nil? ? nil : j.to_s)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def set_from(j)
|
|
36
|
+
self.from = j
|
|
37
|
+
self
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def reason
|
|
41
|
+
first_element_text('reason')
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reason=(s)
|
|
45
|
+
if s
|
|
46
|
+
replace_element_text('reason', s)
|
|
47
|
+
else
|
|
48
|
+
delete_elements('reason')
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def set_reason(s)
|
|
53
|
+
self.reason = s
|
|
54
|
+
self
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
module Jabber
|
|
6
|
+
module MUC
|
|
7
|
+
class XMUCUserItem < REXML::Element
|
|
8
|
+
def initialize(affiliation=nil, role=nil, jid=nil)
|
|
9
|
+
super('item')
|
|
10
|
+
set_affiliation(affiliation)
|
|
11
|
+
set_role(role)
|
|
12
|
+
set_jid(jid)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def affiliation
|
|
16
|
+
case attributes['affiliation']
|
|
17
|
+
when 'admin' then :admin
|
|
18
|
+
when 'member' then :member
|
|
19
|
+
when 'none' then :none
|
|
20
|
+
when 'outcast' then :outcast
|
|
21
|
+
when 'owner' then :owner
|
|
22
|
+
else nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def affiliation=(v)
|
|
27
|
+
case v
|
|
28
|
+
when :admin then attributes['affiliation'] = 'admin'
|
|
29
|
+
when :member then attributes['affiliation'] = 'member'
|
|
30
|
+
when :none then attributes['affiliation'] = 'none'
|
|
31
|
+
when :outcast then attributes['affiliation'] = 'outcast'
|
|
32
|
+
when :owner then attributes['affiliation'] = 'owner'
|
|
33
|
+
else attributes['affiliation'] = nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def set_affiliation(v)
|
|
38
|
+
self.affiliation = v
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def jid
|
|
43
|
+
attributes['jid'].nil? ? nil : JID::new(attributes['jid'])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def jid=(j)
|
|
47
|
+
attributes['jid'] = j.nil? ? nil : j.to_s
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def set_jid(j)
|
|
51
|
+
self.jid = j
|
|
52
|
+
self
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def nick
|
|
56
|
+
attributes['nick']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def nick=(n)
|
|
60
|
+
attributes['nick'] = n
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set_nick(n)
|
|
64
|
+
self.nick = n
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def role
|
|
69
|
+
case attributes['role']
|
|
70
|
+
when 'moderator' then :moderator
|
|
71
|
+
when 'none' then :none
|
|
72
|
+
when 'participant' then :participant
|
|
73
|
+
when 'visitor' then :visitor
|
|
74
|
+
else nil
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def role=(r)
|
|
79
|
+
case r
|
|
80
|
+
when :moderator then attributes['role'] = 'moderator'
|
|
81
|
+
when :none then attributes['role'] = 'none'
|
|
82
|
+
when :participant then attributes['role'] = 'participant'
|
|
83
|
+
when :visitor then attributes['role'] = 'visitor'
|
|
84
|
+
else attributes['role'] = nil
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def set_role(r)
|
|
89
|
+
self.role = r
|
|
90
|
+
self
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def reason
|
|
94
|
+
text = nil
|
|
95
|
+
each_element('reason') { |xe| text = xe.text }
|
|
96
|
+
text
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def reason=(s)
|
|
100
|
+
delete_elements('reasion')
|
|
101
|
+
add_element('reason').text = s
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def set_reason(s)
|
|
105
|
+
self.reason = s
|
|
106
|
+
self
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def continue
|
|
110
|
+
c = nil
|
|
111
|
+
each_element('continue') { |xe| c = xe }
|
|
112
|
+
c.nil?
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def continue=(c)
|
|
116
|
+
delete_elements('continue')
|
|
117
|
+
add_element('continue') if c
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def set_continue(c)
|
|
121
|
+
self.continue = c
|
|
122
|
+
self
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def actors
|
|
126
|
+
a = []
|
|
127
|
+
each_element('actor') { |xe|
|
|
128
|
+
a.push(JID::new(xe.attributes['jid']))
|
|
129
|
+
}
|
|
130
|
+
a
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def actors=(a)
|
|
134
|
+
delete_elements('actor')
|
|
135
|
+
a.each { |jid|
|
|
136
|
+
e = add_element('actor')
|
|
137
|
+
e.attributes['jid'] = jid.to_s
|
|
138
|
+
}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def set_actors(a)
|
|
142
|
+
self.actors = a
|
|
143
|
+
self
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
data/lib/xmpp4r/muc.rb
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
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/xmlstanza'
|
|
6
|
+
require 'xmpp4r/x'
|
|
7
|
+
|
|
8
|
+
module Jabber
|
|
9
|
+
##
|
|
10
|
+
# The presence class is used to construct presence messages to
|
|
11
|
+
# send to the Jabber service.
|
|
12
|
+
class Presence < XMLStanza
|
|
13
|
+
include Comparable
|
|
14
|
+
|
|
15
|
+
##
|
|
16
|
+
# Create presence stanza
|
|
17
|
+
# show:: [String] Initial Availability Status
|
|
18
|
+
# status:: [String] Initial status message
|
|
19
|
+
# priority:: [Fixnum] Initial priority value
|
|
20
|
+
def initialize(show=nil, status=nil, priority=nil)
|
|
21
|
+
super("presence")
|
|
22
|
+
set_show(show) if show
|
|
23
|
+
set_status(status) if status
|
|
24
|
+
set_priority(priority) if priority
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Add an element to the presence stanza
|
|
29
|
+
# * <x/> elements are converted to [X]
|
|
30
|
+
# element:: [REXML::Element] to add
|
|
31
|
+
def typed_add(element)
|
|
32
|
+
if element.kind_of?(REXML::Element) && (element.name == 'x')
|
|
33
|
+
super(X::import(element))
|
|
34
|
+
else
|
|
35
|
+
super(element)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Create a new presence from a stanza
|
|
41
|
+
# result:: [Presence] Imported XMLStanza
|
|
42
|
+
def Presence.import(xmlstanza)
|
|
43
|
+
Presence::new.import(xmlstanza)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
##
|
|
47
|
+
# Get type of presence
|
|
48
|
+
#
|
|
49
|
+
# result:: [Symbol] or [Nil] Possible values are:
|
|
50
|
+
# * :error
|
|
51
|
+
# * :probe (Servers send this to request presence information)
|
|
52
|
+
# * :subscribe (Subscription request)
|
|
53
|
+
# * :subscribed (Subscription approval)
|
|
54
|
+
# * :unavailable (User has gone offline)
|
|
55
|
+
# * :unsubscribe (Unsubscription request)
|
|
56
|
+
# * :unsubscribed (Unsubscription approval)
|
|
57
|
+
# * [nil] (available)
|
|
58
|
+
# See RFC3921 - 2.2.1. for explanation.
|
|
59
|
+
def type
|
|
60
|
+
case super
|
|
61
|
+
when 'error' then :error
|
|
62
|
+
when 'probe' then :probe
|
|
63
|
+
when 'subscribe' then :subscribe
|
|
64
|
+
when 'subscribed' then :subscribed
|
|
65
|
+
when 'unavailable' then :unavailable
|
|
66
|
+
when 'unsubscribe' then :unsubscribe
|
|
67
|
+
when 'unsubscribed' then :unsubscribed
|
|
68
|
+
else nil
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# Set type of presence
|
|
74
|
+
# val:: [Symbol] See type for possible subscription types
|
|
75
|
+
def type=(val)
|
|
76
|
+
case val
|
|
77
|
+
when :error then super('error')
|
|
78
|
+
when :probe then super('probe')
|
|
79
|
+
when :subscribe then super('subscribe')
|
|
80
|
+
when :subscribed then super('subscribed')
|
|
81
|
+
when :unavailable then super('unavailable')
|
|
82
|
+
when :unsubscribe then super('unsubscribe')
|
|
83
|
+
when :unsubscribed then super('unsubscribed')
|
|
84
|
+
else super(nil)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
##
|
|
89
|
+
# Set type of presence (chaining-friendly)
|
|
90
|
+
# val:: [Symbol] See type for possible subscription types
|
|
91
|
+
def set_type(val)
|
|
92
|
+
self.type = val
|
|
93
|
+
self
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
##
|
|
97
|
+
# Get the first <x/> element of this stanza
|
|
98
|
+
# result:: [REXML::Element] or nil
|
|
99
|
+
def x
|
|
100
|
+
xe = nil
|
|
101
|
+
each_element('x') { |e| xe = e }
|
|
102
|
+
xe
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
##
|
|
106
|
+
# Get Availability Status (RFC3921 - 5.2)
|
|
107
|
+
# result:: [Symbol] or [Nil] Valid values according to RFC3921:
|
|
108
|
+
# * nil (Available, no <show/> element)
|
|
109
|
+
# * :away
|
|
110
|
+
# * :chat (Free for chat)
|
|
111
|
+
# * :dnd (Do not disturb)
|
|
112
|
+
# * :xa (Extended away)
|
|
113
|
+
def show
|
|
114
|
+
e = first_element('show')
|
|
115
|
+
text = e ? e.text : nil
|
|
116
|
+
case text
|
|
117
|
+
when 'away' then :away
|
|
118
|
+
when 'chat' then :chat
|
|
119
|
+
when 'dnd' then :dnd
|
|
120
|
+
when 'xa' then :xa
|
|
121
|
+
else nil
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
##
|
|
126
|
+
# Set Availability Status
|
|
127
|
+
# val:: [Symbol] or [Nil] See show for explanation
|
|
128
|
+
def show=(val)
|
|
129
|
+
xe = first_element('show')
|
|
130
|
+
if xe.nil?
|
|
131
|
+
xe = add_element('show')
|
|
132
|
+
end
|
|
133
|
+
case val
|
|
134
|
+
when :away then text = 'away'
|
|
135
|
+
when :chat then text = 'chat'
|
|
136
|
+
when :dnd then text = 'dnd'
|
|
137
|
+
when :xa then text = 'xa'
|
|
138
|
+
when nil then text = nil
|
|
139
|
+
else raise "Invalid value for show."
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
if text.nil?
|
|
143
|
+
delete_element(xe)
|
|
144
|
+
else
|
|
145
|
+
xe.text = text
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
##
|
|
150
|
+
# Set Availability Status (chaining-friendly)
|
|
151
|
+
# val:: [Symbol] or [Nil] See show for explanation
|
|
152
|
+
def set_show(val)
|
|
153
|
+
self.show = val
|
|
154
|
+
self
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
##
|
|
158
|
+
# Get status message
|
|
159
|
+
# result:: [String] or nil
|
|
160
|
+
def status
|
|
161
|
+
first_element_text('status')
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
##
|
|
165
|
+
# Set status message
|
|
166
|
+
# val:: [String] or nil
|
|
167
|
+
def status=(val)
|
|
168
|
+
if val.nil?
|
|
169
|
+
delete_element('status')
|
|
170
|
+
else
|
|
171
|
+
replace_element_text('status', val)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
##
|
|
176
|
+
# Set status message (chaining-friendly)
|
|
177
|
+
# val:: [String] or nil
|
|
178
|
+
def set_status(val)
|
|
179
|
+
self.status = val
|
|
180
|
+
self
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
##
|
|
184
|
+
# Get presence priority, or nil if absent
|
|
185
|
+
# result:: [Integer]
|
|
186
|
+
def priority
|
|
187
|
+
e = first_element_text('priority')
|
|
188
|
+
if e
|
|
189
|
+
return e.to_i
|
|
190
|
+
else
|
|
191
|
+
return nil
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
##
|
|
196
|
+
# Set presence priority
|
|
197
|
+
# val:: [Integer] Priority value between -128 and +127
|
|
198
|
+
#
|
|
199
|
+
# *Warning:* negative values make you receive no subscription requests etc.
|
|
200
|
+
# (RFC3921 - 2.2.2.3.)
|
|
201
|
+
def priority=(val)
|
|
202
|
+
if val.nil?
|
|
203
|
+
delete_element('priority')
|
|
204
|
+
else
|
|
205
|
+
replace_element_text('priority', val)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
##
|
|
210
|
+
# Set presence priority (chaining-friendly)
|
|
211
|
+
# val:: [Integer] Priority value between -128 and +127
|
|
212
|
+
def set_priority(val)
|
|
213
|
+
self.priority = val
|
|
214
|
+
self
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
##
|
|
218
|
+
# Compare two presences using priority
|
|
219
|
+
# (with cmp_interest as fall-back).
|
|
220
|
+
def <=>(o)
|
|
221
|
+
if priority.to_i == o.priority.to_i
|
|
222
|
+
cmp_interest(o)
|
|
223
|
+
else
|
|
224
|
+
priority.to_i <=> o.priority.to_i
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
##
|
|
229
|
+
# Compare two presences. The most suitable to talk with is the
|
|
230
|
+
# biggest.
|
|
231
|
+
PRESENCE_STATUS = { :chat => 4,
|
|
232
|
+
nil => 3,
|
|
233
|
+
:dnd => 2,
|
|
234
|
+
:away => 1,
|
|
235
|
+
:xa => 0,
|
|
236
|
+
:unavailable => -1,
|
|
237
|
+
:error => -2 }
|
|
238
|
+
def cmp_interest(o)
|
|
239
|
+
if type.nil?
|
|
240
|
+
if o.type.nil?
|
|
241
|
+
# both available.
|
|
242
|
+
PRESENCE_STATUS[show] <=> PRESENCE_STATUS[o.show]
|
|
243
|
+
else
|
|
244
|
+
return -1
|
|
245
|
+
end
|
|
246
|
+
elsif o.type.nil?
|
|
247
|
+
return 1
|
|
248
|
+
else
|
|
249
|
+
# both are non-nil. We consider this is equal.
|
|
250
|
+
return 0
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
end
|
|
255
|
+
end
|
data/lib/xmpp4r/query.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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/iq'
|
|
6
|
+
|
|
7
|
+
module Jabber
|
|
8
|
+
##
|
|
9
|
+
# A class used to build/parse IQ Query requests/responses
|
|
10
|
+
#
|
|
11
|
+
class IqQuery < REXML::Element
|
|
12
|
+
@@namespace_classes = {}
|
|
13
|
+
|
|
14
|
+
##
|
|
15
|
+
# Initialize a <query/> element
|
|
16
|
+
#
|
|
17
|
+
# Does nothing more than setting the element's name to 'query'
|
|
18
|
+
def initialize
|
|
19
|
+
super("query")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Create a new [IqQuery] from iq.query
|
|
24
|
+
# element:: [REXML::Element] to import, will be automatically converted if namespace appropriate
|
|
25
|
+
def IqQuery.import(element)
|
|
26
|
+
if @@namespace_classes.has_key?(element.namespace)
|
|
27
|
+
@@namespace_classes[element.namespace]::new.import(element)
|
|
28
|
+
else
|
|
29
|
+
IqQuery::new.import(element)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# Add a class by namespace for automatic IqQuery conversion (see IqQuery.import)
|
|
35
|
+
# ns:: [String] Namespace (e.g. 'jabber:iq:roster')
|
|
36
|
+
# queryclass:: [IqQuery] Query class derived from IqQuery
|
|
37
|
+
def IqQuery.add_namespaceclass(ns, queryclass)
|
|
38
|
+
@@namespace_classes[ns] = queryclass
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Iq.add_elementclass('query', IqQuery)
|
|
43
|
+
end
|