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,83 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
$:.unshift '../../../../../lib/'
|
|
3
|
+
require 'xmpp4r'
|
|
4
|
+
require 'xmpp4r/muc/helper/simplemucclient'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if ARGV.size != 3
|
|
8
|
+
puts "Usage: #{$0} <jid> <password> <room@conference/nick>"
|
|
9
|
+
exit
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Print a line formatted depending on time.nil?
|
|
13
|
+
def print_line(time, line)
|
|
14
|
+
if time.nil?
|
|
15
|
+
puts line
|
|
16
|
+
else
|
|
17
|
+
puts "#{time.strftime('%I:%M')} #{line}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
#Jabber::debug = true
|
|
23
|
+
cl = Jabber::Client.new(Jabber::JID.new(ARGV[0]))
|
|
24
|
+
cl.connect
|
|
25
|
+
cl.auth(ARGV[1])
|
|
26
|
+
|
|
27
|
+
# For waking up...
|
|
28
|
+
mainthread = Thread.current
|
|
29
|
+
|
|
30
|
+
# This is the SimpleMUCClient helper!
|
|
31
|
+
m = Jabber::MUC::SimpleMUCClient.new(cl)
|
|
32
|
+
|
|
33
|
+
# SimpleMUCClient callback-blocks
|
|
34
|
+
|
|
35
|
+
m.on_join { |time,nick|
|
|
36
|
+
print_line time, "#{nick} has joined!"
|
|
37
|
+
puts "Users: " + m.roster.keys.join(', ')
|
|
38
|
+
}
|
|
39
|
+
m.on_leave { |time,nick|
|
|
40
|
+
print_line time, "#{nick} has left!"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
m.on_message { |time,nick,text|
|
|
44
|
+
print_line time, "<#{nick}> #{text}"
|
|
45
|
+
|
|
46
|
+
# Avoid reacting on messaged delivered as room history
|
|
47
|
+
unless time
|
|
48
|
+
# Bot: invite astro@spaceboyz.net
|
|
49
|
+
if text.strip =~ /^(.+?): invite (.+)$/
|
|
50
|
+
jid = $2
|
|
51
|
+
if $1.downcase == m.jid.resource.downcase
|
|
52
|
+
m.invite(jid => "Inviting you on behalf of #{nick}")
|
|
53
|
+
m.say("Inviting #{jid}...")
|
|
54
|
+
end
|
|
55
|
+
# Bot: subject This is room is powered by XMPP4R
|
|
56
|
+
elsif text.strip =~ /^(.+?): subject (.+)$/
|
|
57
|
+
if $1.downcase == m.jid.resource.downcase
|
|
58
|
+
m.subject = $2
|
|
59
|
+
end
|
|
60
|
+
# Bot: exit please
|
|
61
|
+
elsif text.strip =~ /^(.+?): exit please$/
|
|
62
|
+
if $1.downcase == m.jid.resource.downcase
|
|
63
|
+
puts "exiting"
|
|
64
|
+
m.exit "Exiting on behalf of #{nick}"
|
|
65
|
+
mainthread.wakeup
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
}
|
|
70
|
+
m.on_room_message { |time,text|
|
|
71
|
+
print_line time, "- #{text}"
|
|
72
|
+
}
|
|
73
|
+
m.on_subject { |time,nick,subject|
|
|
74
|
+
print_line time, "*** (#{nick}) #{subject}"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
m.join(ARGV[2])
|
|
78
|
+
|
|
79
|
+
# Wait for being waken up by m.on_message
|
|
80
|
+
Thread.stop
|
|
81
|
+
|
|
82
|
+
cl.close
|
|
83
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift '../../../../../lib'
|
|
4
|
+
require 'xmpp4r'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Argument checking
|
|
8
|
+
if ARGV.size != 2
|
|
9
|
+
puts("Usage: #{$0} <desired jid> <password>")
|
|
10
|
+
exit
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# The usual procedure
|
|
15
|
+
cl = Jabber::Client.new(Jabber::JID.new(ARGV[0]))
|
|
16
|
+
puts "Connecting"
|
|
17
|
+
cl.connect
|
|
18
|
+
|
|
19
|
+
# Registration of the new user account
|
|
20
|
+
puts "Registering..."
|
|
21
|
+
cl.register(ARGV[1])
|
|
22
|
+
puts "Successful"
|
|
23
|
+
|
|
24
|
+
# Shutdown
|
|
25
|
+
cl.close
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift '../../../../../lib'
|
|
4
|
+
require 'xmpp4r'
|
|
5
|
+
include Jabber
|
|
6
|
+
|
|
7
|
+
if ARGV.size != 2
|
|
8
|
+
puts "Warning! This example UNREGISTERS user accounts!"
|
|
9
|
+
puts "Usage: #{$0} <jid> <password>"
|
|
10
|
+
exit
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
cl = Client.new(JID.new(ARGV[0]))
|
|
14
|
+
cl.connect
|
|
15
|
+
cl.auth(ARGV[1])
|
|
16
|
+
cl.remove_registration
|
|
17
|
+
|
|
18
|
+
cl.close
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
# This script can get all roster entries
|
|
4
|
+
|
|
5
|
+
require 'optparse'
|
|
6
|
+
require 'xmpp4r'
|
|
7
|
+
require 'xmpp4r/roster/iq/roster'
|
|
8
|
+
include Jabber
|
|
9
|
+
|
|
10
|
+
jid = JID::new('lucastest@linux.ensimag.fr/rosterget')
|
|
11
|
+
password = 'lucastest'
|
|
12
|
+
|
|
13
|
+
OptionParser::new do |opts|
|
|
14
|
+
opts.banner = 'Usage: roster.rb -t get -j jid -p password'
|
|
15
|
+
opts.separator ''
|
|
16
|
+
opts.on('-j', '--jid JID', 'sets the jid') { |j| jid = JID::new(j) }
|
|
17
|
+
opts.on('-p', '--password PASSWORD', 'sets the password') { |p| password = p }
|
|
18
|
+
opts.on_tail('-h', '--help', 'Show this message') {
|
|
19
|
+
puts opts
|
|
20
|
+
exit
|
|
21
|
+
}
|
|
22
|
+
opts.parse!(ARGV)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
cl = Client::new(jid, false)
|
|
26
|
+
cl.connect
|
|
27
|
+
cl.auth(password)
|
|
28
|
+
cl.send(Iq::new_rosterget)
|
|
29
|
+
exit = false
|
|
30
|
+
cl.add_iq_callback { |i|
|
|
31
|
+
if i.type == :result and i.query.kind_of?(Roster::IqQueryRoster)
|
|
32
|
+
i.query.each_element { |e|
|
|
33
|
+
e.text = ''
|
|
34
|
+
puts e.to_s
|
|
35
|
+
}
|
|
36
|
+
exit = true
|
|
37
|
+
end
|
|
38
|
+
}
|
|
39
|
+
while not exit
|
|
40
|
+
cl.process
|
|
41
|
+
end
|
|
42
|
+
cl.close
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift '../../../../../lib/'
|
|
4
|
+
|
|
5
|
+
require 'xmpp4r'
|
|
6
|
+
require 'xmpp4r/roster/helper/roster'
|
|
7
|
+
|
|
8
|
+
# Command line argument checking
|
|
9
|
+
|
|
10
|
+
if ARGV.size != 2
|
|
11
|
+
puts("Usage: ./rosterprint.rb <jid> <password>")
|
|
12
|
+
exit
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Building up the connection
|
|
16
|
+
|
|
17
|
+
#Jabber::debug = true
|
|
18
|
+
|
|
19
|
+
jid = Jabber::JID.new(ARGV[0])
|
|
20
|
+
|
|
21
|
+
cl = Jabber::Client.new(jid)
|
|
22
|
+
cl.connect
|
|
23
|
+
cl.auth(ARGV[1])
|
|
24
|
+
|
|
25
|
+
# The roster instance
|
|
26
|
+
roster = Jabber::Roster::Helper.new(cl)
|
|
27
|
+
|
|
28
|
+
mainthread = Thread.current
|
|
29
|
+
|
|
30
|
+
roster.add_query_callback { |iq|
|
|
31
|
+
mainthread.wakeup
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Thread.stop
|
|
35
|
+
|
|
36
|
+
roster.groups.each { |group|
|
|
37
|
+
if group.nil?
|
|
38
|
+
puts "*** Ungrouped ***"
|
|
39
|
+
else
|
|
40
|
+
puts "*** #{group} ***"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
roster.find_by_group(group).each { |item|
|
|
44
|
+
puts "- #{item.iname} (#{item.jid})"
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
print "\n"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
cl.close
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift '../../../../../lib'
|
|
4
|
+
|
|
5
|
+
require 'xmpp4r'
|
|
6
|
+
require 'xmpp4r/roster/iq/roster'
|
|
7
|
+
|
|
8
|
+
# Command line argument checking
|
|
9
|
+
|
|
10
|
+
if ARGV.size < 4
|
|
11
|
+
puts("Usage: ./rosterrename.rb <your jid> <password> <jid to rename> <new name> [<group1> ... <groupn>]")
|
|
12
|
+
exit
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Building up the connection
|
|
16
|
+
|
|
17
|
+
#Jabber::debug = true
|
|
18
|
+
|
|
19
|
+
jid = Jabber::JID.new(ARGV[0])
|
|
20
|
+
|
|
21
|
+
cl = Jabber::Client.new(jid, false)
|
|
22
|
+
cl.connect
|
|
23
|
+
cl.auth(ARGV[1])
|
|
24
|
+
|
|
25
|
+
# The iq stanza
|
|
26
|
+
iq = Jabber::Iq::new(:set)
|
|
27
|
+
# The new roster instance and item element
|
|
28
|
+
iq.add(Jabber::Roster::IqQueryRoster.new).add(Jabber::Roster::RosterItem.new(ARGV[2], ARGV[3])).groups = ARGV[4..ARGV.size]
|
|
29
|
+
|
|
30
|
+
# Sending the stanza
|
|
31
|
+
cl.send(iq)
|
|
32
|
+
|
|
33
|
+
# Don't look at the results:
|
|
34
|
+
cl.close
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# XMPP4R - XMPP Library for Ruby
|
|
4
|
+
# Copyright (C) 2005 Stephan Maka <stephan@spaceboyz.net>
|
|
5
|
+
# Released under Ruby's license (see the LICENSE file) or GPL, at your option
|
|
6
|
+
#
|
|
7
|
+
#
|
|
8
|
+
# Roster-Watch example
|
|
9
|
+
#
|
|
10
|
+
#
|
|
11
|
+
# Learn how a roster looks like
|
|
12
|
+
# how presences are received
|
|
13
|
+
# about subscription requests and answers
|
|
14
|
+
# what vCards contain
|
|
15
|
+
#
|
|
16
|
+
# It's recommended to insert 'p' commands in this script. :-)
|
|
17
|
+
#
|
|
18
|
+
# This script does:
|
|
19
|
+
#
|
|
20
|
+
# * Listing roster changes
|
|
21
|
+
#
|
|
22
|
+
# * Subscribe to roster items which have a subscription of "none" or "from"
|
|
23
|
+
# WARNING: Chances are that you don't want that :-)
|
|
24
|
+
#
|
|
25
|
+
# * Requesting vCards for unnamed items in your roster and renaming them
|
|
26
|
+
# to the <NICKNAME/> or <FN/> field in the vCard
|
|
27
|
+
#
|
|
28
|
+
# * Listing presence changes
|
|
29
|
+
#
|
|
30
|
+
# * Listing subscription and unsubscription requests and answers
|
|
31
|
+
|
|
32
|
+
$:.unshift '../../../../../lib/'
|
|
33
|
+
|
|
34
|
+
require 'xmpp4r'
|
|
35
|
+
require 'xmpp4r/roster/helper/roster'
|
|
36
|
+
require 'xmpp4r/vcard/helper/vcard'
|
|
37
|
+
|
|
38
|
+
# Command line argument checking
|
|
39
|
+
|
|
40
|
+
if ARGV.size != 2
|
|
41
|
+
puts("Usage: ./rosterwatch.rb <jid> <password>")
|
|
42
|
+
exit
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Building up the connection
|
|
46
|
+
|
|
47
|
+
#Jabber::debug = true
|
|
48
|
+
|
|
49
|
+
jid = Jabber::JID.new(ARGV[0])
|
|
50
|
+
|
|
51
|
+
cl = Jabber::Client.new(jid)
|
|
52
|
+
cl.connect
|
|
53
|
+
cl.auth(ARGV[1])
|
|
54
|
+
|
|
55
|
+
# The roster instance
|
|
56
|
+
roster = Jabber::Roster::Helper.new(cl)
|
|
57
|
+
|
|
58
|
+
# Callback to handle updated roster items
|
|
59
|
+
roster.add_update_callback { |olditem,item|
|
|
60
|
+
if [:from, :none].include?(item.subscription) && item.ask != :subscribe
|
|
61
|
+
puts("Subscribing to #{item.jid}")
|
|
62
|
+
item.subscribe
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Print the item
|
|
66
|
+
if olditem.nil?
|
|
67
|
+
# We didn't knew before:
|
|
68
|
+
puts("#{item.iname} (#{item.jid}, #{item.subscription}) #{item.groups.join(', ')}")
|
|
69
|
+
else
|
|
70
|
+
# Showing whats different:
|
|
71
|
+
puts("#{olditem.iname} (#{olditem.jid}, #{olditem.subscription}) #{olditem.groups.join(', ')} -> #{item.iname} (#{item.jid}, #{item.subscription}) #{item.groups.join(', ')}")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# If the item has no name associated...
|
|
75
|
+
unless item.iname
|
|
76
|
+
Thread.new do
|
|
77
|
+
puts("#{item.jid} has no nickname... getting vCard")
|
|
78
|
+
begin
|
|
79
|
+
# ...get a vCard
|
|
80
|
+
vcard = Jabber::Vcard::Helper.new(cl).get(item.jid.strip)
|
|
81
|
+
|
|
82
|
+
unless vcard.nil?
|
|
83
|
+
# Rename him to vCard's <NICKNAME/> field
|
|
84
|
+
if vcard['NICKNAME']
|
|
85
|
+
item.iname = vcard['NICKNAME']
|
|
86
|
+
puts("Renaming #{item.jid} to #{vcard['NICKNAME']}")
|
|
87
|
+
item.send
|
|
88
|
+
# Rename him to vCard's <FN/> field
|
|
89
|
+
elsif vcard['FN']
|
|
90
|
+
item.iname = vcard['FN']
|
|
91
|
+
puts("Renaming #{item.jid} to #{vcard['FN']}")
|
|
92
|
+
item.send
|
|
93
|
+
# We've got a lazy one
|
|
94
|
+
else
|
|
95
|
+
puts("#{item.jid} provided no details in vCard")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
rescue Exception => e
|
|
100
|
+
# This will be (mostly) thrown by Jabber::Vcard::Helper#get
|
|
101
|
+
puts("Error getting vCard for #{item.jid}: #{e.to_s}")
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# Presence updates:
|
|
108
|
+
roster.add_presence_callback { |item,oldpres,pres|
|
|
109
|
+
# Can't look for something that just does not exist...
|
|
110
|
+
if pres.nil?
|
|
111
|
+
# ...so create it:
|
|
112
|
+
pres = Jabber::Presence.new
|
|
113
|
+
end
|
|
114
|
+
if oldpres.nil?
|
|
115
|
+
# ...so create it:
|
|
116
|
+
oldpres = Jabber::Presence.new
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Print name and jid:
|
|
120
|
+
name = "#{pres.from}"
|
|
121
|
+
if item.iname
|
|
122
|
+
name = "#{item.iname} (#{pres.from})"
|
|
123
|
+
end
|
|
124
|
+
puts(name)
|
|
125
|
+
|
|
126
|
+
# Print type changes:
|
|
127
|
+
unless oldpres.type.nil? && pres.type.nil?
|
|
128
|
+
puts(" Type: #{oldpres.type.inspect} -> #{pres.type.inspect}")
|
|
129
|
+
end
|
|
130
|
+
# Print show changes:
|
|
131
|
+
unless oldpres.show.nil? && pres.show.nil?
|
|
132
|
+
puts(" Show: #{oldpres.show.to_s.inspect} -> #{pres.show.to_s.inspect}")
|
|
133
|
+
end
|
|
134
|
+
# Print status changes:
|
|
135
|
+
unless oldpres.status.nil? && pres.status.nil?
|
|
136
|
+
puts(" Status: #{oldpres.status.to_s.inspect} -> #{pres.status.to_s.inspect}")
|
|
137
|
+
end
|
|
138
|
+
# Print priority changes:
|
|
139
|
+
unless oldpres.priority.nil? && pres.priority.nil?
|
|
140
|
+
puts(" Priority: #{oldpres.priority.inspect} -> #{pres.priority.inspect}")
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Note: presences with type='error' will reflect our own show/status/priority
|
|
144
|
+
# as it is mostly just a reply from a server. This is *not* a bug.
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Subscription requests and responses:
|
|
148
|
+
subscription_callback = lambda { |item,pres|
|
|
149
|
+
name = pres.from
|
|
150
|
+
if item != nil && item.iname != nil
|
|
151
|
+
name = "#{item.iname} (#{pres.from})"
|
|
152
|
+
end
|
|
153
|
+
case pres.type
|
|
154
|
+
when :subscribe then puts("Subscription request from #{name}")
|
|
155
|
+
when :subscribed then puts("Subscribed to #{name}")
|
|
156
|
+
when :unsubscribe then puts("Unsubscription request from #{name}")
|
|
157
|
+
when :unsubscribed then puts("Unsubscribed from #{name}")
|
|
158
|
+
else raise "The Roster Helper is buggy!!! subscription callback with type=#{pres.type}"
|
|
159
|
+
end
|
|
160
|
+
}
|
|
161
|
+
roster.add_subscription_callback(0, nil, &subscription_callback)
|
|
162
|
+
roster.add_subscription_request_callback(0, nil, &subscription_callback)
|
|
163
|
+
|
|
164
|
+
# Send initial presence
|
|
165
|
+
# this is important for receiving presence of subscribed users
|
|
166
|
+
cl.send(Jabber::Presence.new.set_show(:dnd).set_status('Watching my roster change...'))
|
|
167
|
+
|
|
168
|
+
# Main loop:
|
|
169
|
+
Thread.stop
|
|
170
|
+
|
|
171
|
+
cl.close
|
|
172
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
# Demonstration of the Vcard helper class
|
|
4
|
+
#
|
|
5
|
+
# * Retrieves your own vCard
|
|
6
|
+
# * Modify fields given on the command line
|
|
7
|
+
# * Dumps the vCard
|
|
8
|
+
# * Send your vCard to the server
|
|
9
|
+
|
|
10
|
+
$:.unshift('../../../../../lib')
|
|
11
|
+
|
|
12
|
+
require 'xmpp4r'
|
|
13
|
+
require 'xmpp4r/vcard/helper/vcard'
|
|
14
|
+
include Jabber
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# settings
|
|
18
|
+
if ARGV.length < 2
|
|
19
|
+
puts "Usage:\t./send_vcard.rb <jid> <password> [<field1>=<value1> [... <fieldN>=<valueN>] ]"
|
|
20
|
+
puts "Example:\t./send_vcard.rb user@server/resource password NICKNAME=User \"FN=A user\""
|
|
21
|
+
exit 1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Do the client stuff...
|
|
25
|
+
myJID = JID::new(ARGV.shift)
|
|
26
|
+
myPassword = ARGV.shift
|
|
27
|
+
cl = Client::new(myJID)
|
|
28
|
+
cl.connect
|
|
29
|
+
cl.auth(myPassword)
|
|
30
|
+
|
|
31
|
+
# The Vcard helper
|
|
32
|
+
vcard_helper = Vcard::Helper.new(cl)
|
|
33
|
+
|
|
34
|
+
begin
|
|
35
|
+
puts "Retrieving vCard information for #{cl.jid.strip}"
|
|
36
|
+
vcard = vcard_helper.get
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# Inspect the command line for vCard fields to be changed
|
|
40
|
+
ARGV.each { |arg|
|
|
41
|
+
arg.scan(/^(.+?)=(.*)$/) { |field,text|
|
|
42
|
+
puts "field #{field}: #{vcard[field].inspect} => #{text.inspect}"
|
|
43
|
+
vcard[field] = text
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# Dump the vCard
|
|
48
|
+
vcard.fields.each { |field|
|
|
49
|
+
if field.split(/\//).pop == 'BINVAL'
|
|
50
|
+
puts "#{field}:\tBINVAL"
|
|
51
|
+
else
|
|
52
|
+
puts "#{field}:\t#{vcard[field].inspect}"
|
|
53
|
+
end
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
begin
|
|
57
|
+
puts "Sending vCard information for #{cl.jid.strip}"
|
|
58
|
+
vcard_helper.set(vcard)
|
|
59
|
+
rescue Exception => e
|
|
60
|
+
puts "Sorry, we stumbled upon the following when sending the vCard of #{cl.jid.strip}: #{e.to_s.inspect}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
rescue Exception => e
|
|
64
|
+
puts "Sorry, we stumbled upon the following when requesting the vCard of #{cl.jid.strip}: #{e.to_s.inspect}"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
cl.close
|
|
68
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift '../../../../../lib'
|
|
4
|
+
|
|
5
|
+
require 'xmpp4r'
|
|
6
|
+
require 'xmpp4r/version/iq/version'
|
|
7
|
+
require 'xmpp4r/version/helper/simpleresponder'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# A Hash containing all Version Query answers with their JIDs as keys:
|
|
11
|
+
versions = {}
|
|
12
|
+
|
|
13
|
+
# Command line argument checking
|
|
14
|
+
|
|
15
|
+
if ARGV.size != 2
|
|
16
|
+
puts("Usage: ./versionbot.rb <jid> <password>")
|
|
17
|
+
exit
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Building up the connection
|
|
21
|
+
|
|
22
|
+
#Jabber::debug = true
|
|
23
|
+
|
|
24
|
+
jid = Jabber::JID.new(ARGV[0])
|
|
25
|
+
|
|
26
|
+
cl = Jabber::Client.new(jid, false)
|
|
27
|
+
cl.connect
|
|
28
|
+
cl.auth(ARGV[1])
|
|
29
|
+
|
|
30
|
+
cl.on_exception { |*a|
|
|
31
|
+
p a[0].backtrace
|
|
32
|
+
exit!
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# I'm not sure about the portability of 'uname -sr' here ;-)
|
|
36
|
+
# but that's all needed to answer version queries:
|
|
37
|
+
Jabber::Version::SimpleResponder.new(cl, 'xmpp4r Versionbot example', Jabber::XMPP4R_VERSION, IO.popen('uname -sr').readlines.to_s.strip)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
cl.add_iq_callback { |iq|
|
|
41
|
+
# Filter for version query results
|
|
42
|
+
if (iq.type == :result) && iq.query.kind_of?(Jabber::Version::IqQueryVersion)
|
|
43
|
+
puts "Version query result from #{iq.from}"
|
|
44
|
+
# Keep track of results per JID
|
|
45
|
+
versions[iq.from] = iq.query
|
|
46
|
+
# Print details
|
|
47
|
+
puts " Name: #{iq.query.iname.inspect}"
|
|
48
|
+
puts " Version: #{iq.query.version.inspect}"
|
|
49
|
+
puts " OS: #{iq.query.os.inspect}"
|
|
50
|
+
end
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
cl.add_presence_callback { |pres|
|
|
54
|
+
# Already fingerprinted or offline?
|
|
55
|
+
unless versions.has_key?(pres.from) || (pres.type == :unavailable) || (pres.type == :error)
|
|
56
|
+
# Construct a new query
|
|
57
|
+
iq = Jabber::Iq.new(:get, pres.from)
|
|
58
|
+
# and ask for the version
|
|
59
|
+
iq.query = Jabber::Version::IqQueryVersion.new
|
|
60
|
+
puts "Asking #{iq.to} for his/her/its version"
|
|
61
|
+
versions[pres.from] = :asking
|
|
62
|
+
cl.send(iq)
|
|
63
|
+
end
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
# Send initial presence
|
|
67
|
+
cl.send(Jabber::Presence.new.set_show(:xa).set_status('I am the evil fingerprinting robot'))
|
|
68
|
+
|
|
69
|
+
# Main loop:
|
|
70
|
+
loop do
|
|
71
|
+
cl.process
|
|
72
|
+
sleep(1)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
cl.close
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
$:.unshift '../lib'
|
|
4
|
+
|
|
5
|
+
require 'xmpp4r'
|
|
6
|
+
include Jabber
|
|
7
|
+
|
|
8
|
+
c = Component::new('example.blop.info', 'linux.ensimag.fr', 2609)
|
|
9
|
+
c.connect
|
|
10
|
+
c.auth('BenEuh')
|
|
11
|
+
c.add_iq_callback { |i|
|
|
12
|
+
puts i.to_s
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
c.add_message_callback { |m|
|
|
16
|
+
puts m.to_s
|
|
17
|
+
}
|
|
18
|
+
Thread.stop
|