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,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This script can be used to migrate from one jabber account to another
|
4
|
+
|
5
|
+
$:.unshift '../../../../../lib'
|
6
|
+
|
7
|
+
require 'optparse'
|
8
|
+
require 'xmpp4r'
|
9
|
+
include Jabber
|
10
|
+
|
11
|
+
jidfrom = JID.new('lucas@linux.ensimag.fr/JabberMigrate')
|
12
|
+
pwfrom = 'z'
|
13
|
+
jidto = JID.new('lucas@nussbaum.fr/JabberMigrate')
|
14
|
+
pwto = 'z'
|
15
|
+
|
16
|
+
BOTHOLD = "Hi, you are subscribed to my presence. I just changed my JID. The new one is #{jidto.strip}. You might want to update your roster. Thank you, and sorry for the inconvenience !"
|
17
|
+
BOTHNEW = "Hi, you are subscribed to the presence of my previous JID : #{jidfrom.strip}. I just changed my JID, and this is the new one. You might want to update your roster. Thank you, and sorry for the inconvenience !"
|
18
|
+
|
19
|
+
clfrom = Client.new(jidfrom)
|
20
|
+
clfrom.connect
|
21
|
+
clfrom.auth(pwfrom)
|
22
|
+
clto = Client.new(jidto)
|
23
|
+
clto.connect
|
24
|
+
clto.auth(pwto)
|
25
|
+
#clfrom.send(Presence.new)
|
26
|
+
#clto.send(Presence.new)
|
27
|
+
clfrom.send(Iq.new_rosterget)
|
28
|
+
exit = false
|
29
|
+
clfrom.add_iq_callback { |i|
|
30
|
+
if i.type == :result and i.queryns == 'jabber:iq:roster'
|
31
|
+
i.query.each_element do |e|
|
32
|
+
e.text = ''
|
33
|
+
jid = e.attribute('jid')
|
34
|
+
name = e.attribute('name')
|
35
|
+
subscription = e.attribute('subscription')
|
36
|
+
ask = e.attribute('ask')
|
37
|
+
jid &&= jid.value
|
38
|
+
next if jid =~ /@(icq|msn|aim|yahoo).blop.info/
|
39
|
+
# next if jid !~ /lucas@im.apinc.org/
|
40
|
+
puts "Processing #{e.to_s}"
|
41
|
+
# Jabber::debug = true
|
42
|
+
name &&= name.value
|
43
|
+
subscription &&= subscription.value
|
44
|
+
ask &&= ask.value
|
45
|
+
puts subscription
|
46
|
+
case subscription
|
47
|
+
when 'from'
|
48
|
+
# il veut me voir, je veux pas le voir.
|
49
|
+
# envoi unsubscribed
|
50
|
+
clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribed))
|
51
|
+
# envoi message d'info OLD & NEW
|
52
|
+
clfrom.send(Message.new(jid, BOTHOLD).set_type(:chat))
|
53
|
+
clto.send(Message.new(jid, BOTHNEW).set_type(:chat))
|
54
|
+
when 'to'
|
55
|
+
# je veux le voir, il veut pas me voir
|
56
|
+
# envoi unsubscribe
|
57
|
+
clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribe))
|
58
|
+
# envoi subscribe avec message
|
59
|
+
pres = Presence.new.set_to(jid).set_type(:subscribe)
|
60
|
+
pres.add(Element.new('status').add_text("Hi, I was previously subscribed to your presence with my JID #{jidfrom.strip}. Can I re-subscribe to your presence ? Thank you."))
|
61
|
+
clto.send(pres)
|
62
|
+
when 'both'
|
63
|
+
# envoi unsubscribed
|
64
|
+
clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribed))
|
65
|
+
# envoi unsubscribe
|
66
|
+
clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribe))
|
67
|
+
# update roster
|
68
|
+
iq = Iq.new_rosterset
|
69
|
+
e.delete_attribute('ask')
|
70
|
+
e.delete_attribute('subscription')
|
71
|
+
iq.query.add_element(e)
|
72
|
+
clto.send(iq)
|
73
|
+
# envoi message d'info OLD & NEW
|
74
|
+
clfrom.send(Message.new(jid, BOTHOLD).set_type(:chat))
|
75
|
+
pres = Presence.new.set_to(jid).set_type(:subscribe)
|
76
|
+
pres.add(Element.new('status').add_text("Hi, I was previously subscribed to your presence with my JID #{jidfrom.strip}. Can I re-subscribe to your presence ? Thank you."))
|
77
|
+
clto.send(pres)
|
78
|
+
clto.send(Message.new(jid, BOTHNEW).set_type(:chat))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
}
|
83
|
+
while not exit
|
84
|
+
clfrom.process
|
85
|
+
clto.process
|
86
|
+
end
|
87
|
+
clfrom.close
|
88
|
+
clto.close
|
@@ -0,0 +1,266 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift '../../../../../lib'
|
4
|
+
|
5
|
+
require 'xmpp4r'
|
6
|
+
require 'xmpp4r/iq/query/discoinfo'
|
7
|
+
require 'xmpp4r/iq/query/discoitems'
|
8
|
+
require 'xmpp4r/x/muc'
|
9
|
+
|
10
|
+
|
11
|
+
#Jabber::debug = true
|
12
|
+
|
13
|
+
class Room
|
14
|
+
class RoomException < Exception
|
15
|
+
attr_reader :error
|
16
|
+
def initialize(error, msg)
|
17
|
+
@error = Jabber::ErrorResponse.new(error, msg)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(stream, name)
|
22
|
+
@users = {} # nick => jid
|
23
|
+
@stream = stream
|
24
|
+
@name = name
|
25
|
+
end
|
26
|
+
|
27
|
+
def num_users
|
28
|
+
@users.size
|
29
|
+
end
|
30
|
+
|
31
|
+
def each_user(&block)
|
32
|
+
@users.each { |n,j| yield(n, j) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_message(msg)
|
36
|
+
origin = msg.from
|
37
|
+
msg.from = nil
|
38
|
+
@users.each { |nick,jid|
|
39
|
+
if jid == origin
|
40
|
+
msg.from = Jabber::JID.new(@name.node, @name.domain, nick)
|
41
|
+
end
|
42
|
+
}
|
43
|
+
unless msg.from.nil?
|
44
|
+
broadcast(msg)
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def handle_presence(pres)
|
51
|
+
reason = nil
|
52
|
+
|
53
|
+
# Check if nick already registered
|
54
|
+
@users.each { |nick,jid|
|
55
|
+
if pres.from != jid && pres.to.resource == nick
|
56
|
+
puts "#{pres.from} tried to use already active #{pres.to}"
|
57
|
+
raise RoomException.new('conflict', "Nick already used")
|
58
|
+
end
|
59
|
+
}
|
60
|
+
# New user?
|
61
|
+
unless @users.has_key?(pres.to.resource)
|
62
|
+
# Check nick length
|
63
|
+
if pres.to.resource.size < 1
|
64
|
+
puts "#{pres.from} tried to use empty nick"
|
65
|
+
raise RoomException.new('not-acceptable', "Nick must contain characters")
|
66
|
+
end
|
67
|
+
|
68
|
+
# Push user-list
|
69
|
+
userinfo = Jabber::Presence.import(pres)
|
70
|
+
userinfo.to = pres.from
|
71
|
+
userinfo.add(Jabber::XMUCUser.new).add(Jabber::XMUCUserItem.new(:none, :participant))
|
72
|
+
print "Sending all users for #{pres.to} to #{pres.from}:"
|
73
|
+
@users.each { |nick,jid|
|
74
|
+
userinfo.from = Jabber::JID.new(@name.node, @name.domain, nick)
|
75
|
+
print " #{nick} (#{jid})"
|
76
|
+
@stream.send(userinfo)
|
77
|
+
}
|
78
|
+
puts " Ok"
|
79
|
+
|
80
|
+
# Add the new user
|
81
|
+
puts "Adding #{pres.from} as #{pres.to}"
|
82
|
+
@users[pres.to.resource] = pres.from
|
83
|
+
|
84
|
+
send_message("#{pres.to.resource} joins #{@name.node}")
|
85
|
+
reason = "#{pres.to.resource} joins #{@name.node}"
|
86
|
+
end
|
87
|
+
|
88
|
+
# Remove dead rats
|
89
|
+
if pres.type == :error || pres.type == :unavailable
|
90
|
+
was_nick = nil
|
91
|
+
@users.delete_if { |nick,jid|
|
92
|
+
was_nick = nick
|
93
|
+
jid == pres.from
|
94
|
+
}
|
95
|
+
unless was_nick.nil?
|
96
|
+
send_message("#{was_nick} has left #{@name.node}")
|
97
|
+
reason = "#{was_nick} has left #{@name.node}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Advertise users presence to all
|
102
|
+
puts "Advertising user to all"
|
103
|
+
x = Jabber::XMUCUserItem.new(:none, :participant, pres.from)
|
104
|
+
x.reason = reason
|
105
|
+
pres.add(Jabber::XMUCUser.new).add(x)
|
106
|
+
pres.from = pres.to
|
107
|
+
broadcast(pres)
|
108
|
+
end
|
109
|
+
|
110
|
+
def send_message(body)
|
111
|
+
msg = Jabber::Message.new
|
112
|
+
msg.from = Jabber::JID.new(@name.node, @name.domain, "")
|
113
|
+
msg.type = :groupchat
|
114
|
+
msg.body = body
|
115
|
+
broadcast(msg)
|
116
|
+
end
|
117
|
+
|
118
|
+
def broadcast(stanza)
|
119
|
+
x = stanza.class::import(stanza)
|
120
|
+
@users.each { |nick,jid|
|
121
|
+
x.to = jid
|
122
|
+
@stream.send(x)
|
123
|
+
}
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class MUC
|
128
|
+
def initialize(jid, secret, addr, port=5347)
|
129
|
+
@rooms = {}
|
130
|
+
|
131
|
+
@component = Jabber::Component.new(jid, addr, port)
|
132
|
+
@component.connect
|
133
|
+
@component.auth(secret)
|
134
|
+
|
135
|
+
@component.add_iq_callback { |iq|
|
136
|
+
handle_iq(iq)
|
137
|
+
}
|
138
|
+
@component.add_presence_callback { |pres|
|
139
|
+
handle_presence(pres)
|
140
|
+
}
|
141
|
+
@component.add_message_callback { |msg|
|
142
|
+
handle_message(msg)
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
def handle_iq(iq)
|
147
|
+
puts "#{iq.from} #{iq.queryns} to #{iq.to}"
|
148
|
+
if iq.query.kind_of?(Jabber::IqQueryDiscoInfo)
|
149
|
+
handle_disco_info(iq)
|
150
|
+
true
|
151
|
+
elsif iq.query.kind_of?(Jabber::IqQueryDiscoItems)
|
152
|
+
handle_disco_items(iq)
|
153
|
+
true
|
154
|
+
else
|
155
|
+
false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def handle_presence(pres)
|
160
|
+
room = nil
|
161
|
+
@rooms.each { |name,r|
|
162
|
+
room = r if name == pres.to.strip
|
163
|
+
}
|
164
|
+
|
165
|
+
if room.nil? && pres.type.nil? && (pres.to.node.to_s != '')
|
166
|
+
room = Room.new(@component, pres.to.strip)
|
167
|
+
@rooms[pres.to.strip] = room
|
168
|
+
elsif room.nil? && pres.type != :error
|
169
|
+
pres.to, pres.from = pres.from, pres.to
|
170
|
+
pres.type = :error
|
171
|
+
pres.add(Jabber::ErrorResponse.new('item-not-found'))
|
172
|
+
@component.send(pres)
|
173
|
+
return(true)
|
174
|
+
end
|
175
|
+
|
176
|
+
begin
|
177
|
+
room.handle_presence(pres)
|
178
|
+
rescue Room::RoomException => e
|
179
|
+
pres.to, pres.from = pres.from, pres.to
|
180
|
+
pres.type = :error
|
181
|
+
pres.add(e.error)
|
182
|
+
@component.send(pres)
|
183
|
+
return(true)
|
184
|
+
end
|
185
|
+
return(false)
|
186
|
+
end
|
187
|
+
|
188
|
+
def handle_message(msg)
|
189
|
+
puts "Message from #{msg.from} to #{msg.to} (#{msg.type}): #{msg.body.inspect}"
|
190
|
+
return if msg.type == :error
|
191
|
+
|
192
|
+
room = @rooms[msg.to]
|
193
|
+
unless room.nil?
|
194
|
+
room.handle_message(msg)
|
195
|
+
else
|
196
|
+
msg.to, msg.from = msg.from, msg.to
|
197
|
+
msg.type = :error
|
198
|
+
msg.add(Jabber::ErrorResponse.new('item-not-found', 'The chatroom you are trying to reach is currently not available.'))
|
199
|
+
@component.send(msg)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def handle_disco_info(iq)
|
204
|
+
if (iq.type == :get)
|
205
|
+
iq.type = :result
|
206
|
+
iq.query = Jabber::IqQueryDiscoInfo.new
|
207
|
+
if iq.to.node == nil
|
208
|
+
iq.query.add(Jabber::DiscoIdentity.new('conference', 'Minimal Multi-User Chat', 'text'))
|
209
|
+
else
|
210
|
+
room = @rooms[iq.to]
|
211
|
+
if room.nil?
|
212
|
+
iq.type = :error
|
213
|
+
iq.add_element(Jabber::ErrorResponse.new('item-not-found'))
|
214
|
+
else
|
215
|
+
iq.query.add(Jabber::DiscoIdentity.new('conference', "#{iq.to.node} (#{room.num_users})", 'text'))
|
216
|
+
end
|
217
|
+
end
|
218
|
+
[Jabber::IqQueryDiscoInfo.new.namespace,
|
219
|
+
Jabber::IqQueryDiscoItems.new.namespace,
|
220
|
+
Jabber::XMUC.new.namespace,
|
221
|
+
Jabber::XMUCUser.new.namespace].each { |ns|
|
222
|
+
iq.query.add(Jabber::DiscoFeature.new(ns))
|
223
|
+
}
|
224
|
+
else
|
225
|
+
iq.type = :error
|
226
|
+
iq.add_element(Jabber::ErrorResponse.new('bad-request'))
|
227
|
+
end
|
228
|
+
iq.to, iq.from = iq.from, iq.to
|
229
|
+
@component.send(iq)
|
230
|
+
end
|
231
|
+
|
232
|
+
def handle_disco_items(iq)
|
233
|
+
if (iq.type == :get)
|
234
|
+
iq.type = :result
|
235
|
+
if iq.to.node == nil
|
236
|
+
@rooms.each { |name,room|
|
237
|
+
iq.query.add(Jabber::DiscoItem.new(Jabber::JID.new(name, @component.jid.domain), name))
|
238
|
+
}
|
239
|
+
elsif iq.to.resource == nil
|
240
|
+
room = @rooms[iq.to.strip]
|
241
|
+
unless room.nil?
|
242
|
+
room.each_user { |nick,jid|
|
243
|
+
iq.query.add(Jabber::DiscoItem.new(jid, nick))
|
244
|
+
}
|
245
|
+
else
|
246
|
+
iq.type = :error
|
247
|
+
iq.add_element(Jabber::ErrorResponse.new('item-not-found'))
|
248
|
+
end
|
249
|
+
end
|
250
|
+
else
|
251
|
+
iq.type = :error
|
252
|
+
iq.add_element(Jabber::ErrorResponse.new('bad-request'))
|
253
|
+
end
|
254
|
+
iq.to, iq.from = iq.from, iq.to
|
255
|
+
@component.send(iq)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
if ARGV.size != 3
|
260
|
+
puts "Syntax: ./minimuc.rb <JID> <Password> <Host>"
|
261
|
+
puts "Example: ./minimuc.rb conference.xmpp4r.mil minimuc localhost"
|
262
|
+
exit
|
263
|
+
end
|
264
|
+
|
265
|
+
muc = MUC.new(Jabber::JID.new(ARGV[0]), ARGV[1], ARGV[2])
|
266
|
+
Thread.stop
|
@@ -0,0 +1,235 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0"
|
3
|
+
xmlns="http://www.w3.org/1999/xhtml"
|
4
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
5
|
+
xmlns:j="jabber:client"
|
6
|
+
xmlns:p="http://jabber.org/protocol/pubsub"
|
7
|
+
xmlns:tune="http://jabber.org/protocol/tune"
|
8
|
+
xmlns:mood="http://jabber.org/protocol/mood"
|
9
|
+
xmlns:activity="http://jabber.org/protocol/activity"
|
10
|
+
xmlns:chatting="http://www.xmpp.org/extensions/xep-0194.html#ns"
|
11
|
+
xmlns:browsing="http://www.xmpp.org/extensions/xep-0195.html#ns"
|
12
|
+
xmlns:gaming="http://www.xmpp.org/extensions/xep-0196.html#ns"
|
13
|
+
xmlns:watching="http://www.xmpp.org/extensions/xep-0197.html#ns"
|
14
|
+
exclude-result-prefixes="xsl j p
|
15
|
+
tune mood activity chatting
|
16
|
+
browsing gaming watching">
|
17
|
+
|
18
|
+
<xsl:output method="xml"
|
19
|
+
version="1.0"
|
20
|
+
encoding="utf-8"
|
21
|
+
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
|
22
|
+
doctype-system="DTD/xhtml1-strict.dtd"
|
23
|
+
indent="yes"/>
|
24
|
+
|
25
|
+
<xsl:template match="/items">
|
26
|
+
<html>
|
27
|
+
<head>
|
28
|
+
<title>PEP aggregator</title>
|
29
|
+
<style type="text/css">
|
30
|
+
<![CDATA[
|
31
|
+
body { font-family: sans-serif; }
|
32
|
+
h1 { text-align: center; font-weight: bold; font-family: fantasy;
|
33
|
+
font-style: italic; }
|
34
|
+
h2 { margin-top: 2em; padding: 0.5em 8em; color: black; background:
|
35
|
+
#bfbfff; }
|
36
|
+
h2 a { color: black; font-decoration: none; }
|
37
|
+
p { margin: 0.5em 4em; }
|
38
|
+
p.footnote { margin-top: 16em; font-size: 90%; }
|
39
|
+
img.avatar { max-width: 10%; clear: left; float: left; padding: 4px; }
|
40
|
+
]]>
|
41
|
+
</style>
|
42
|
+
</head>
|
43
|
+
|
44
|
+
<body>
|
45
|
+
<h1>PEP aggregator</h1>
|
46
|
+
|
47
|
+
<xsl:apply-templates/>
|
48
|
+
|
49
|
+
<p class="footnote">
|
50
|
+
This aggregator consumes events by
|
51
|
+
the <a href="http://www.xmpp.org/">XMPP</a>
|
52
|
+
extension <a href="http://www.xmpp.org/extensions/xep-0163.html">Personal
|
53
|
+
Eventing via Pubsub</a>. If you want to participate you'll
|
54
|
+
need a PEP-enabled server
|
55
|
+
(<a href="http://www.ejabberd.im/">ejabberd</a>), client
|
56
|
+
(<a href="http://www.gajim.org/">Gajim</a>
|
57
|
+
or <a href="http://psi-im.org/">Psi</a>)
|
58
|
+
and <a href="xmpp:{@j:to}?subscribe"><xsl:value-of select="@j:to"/></a>
|
59
|
+
in your Jabber roster. The source code can
|
60
|
+
be <a href="http://svn.gna.org/viewcvs/xmpp4r/trunk/xmpp4r/data/doc/xmpp4r/examples/advanced/pep-aggregator/">viewed
|
61
|
+
online</a>.
|
62
|
+
</p>
|
63
|
+
</body>
|
64
|
+
</html>
|
65
|
+
</xsl:template>
|
66
|
+
|
67
|
+
<xsl:template match="p:item[@j:from]">
|
68
|
+
<xsl:if test="@j:has-avatar = 'true'">
|
69
|
+
<img class="avatar" src="/avatar/{@j:from}"/>
|
70
|
+
</xsl:if>
|
71
|
+
|
72
|
+
<h2>
|
73
|
+
<a href="xmpp:{@j:from}">
|
74
|
+
<xsl:value-of select="@j:from-name"/>
|
75
|
+
</a>
|
76
|
+
</h2>
|
77
|
+
|
78
|
+
<xsl:apply-templates/>
|
79
|
+
|
80
|
+
</xsl:template>
|
81
|
+
|
82
|
+
<xsl:template match="tune:tune[count(*) = 0]">
|
83
|
+
<p>Stopped listening</p>
|
84
|
+
</xsl:template>
|
85
|
+
|
86
|
+
<xsl:template match="tune:tune">
|
87
|
+
<p>
|
88
|
+
♫ Listening
|
89
|
+
<xsl:value-of select="tune:artist"/>
|
90
|
+
—
|
91
|
+
<xsl:value-of select="tune:source"/>
|
92
|
+
—
|
93
|
+
<xsl:value-of select="tune:title"/>
|
94
|
+
</p>
|
95
|
+
</xsl:template>
|
96
|
+
|
97
|
+
<xsl:template match="mood:mood">
|
98
|
+
<p>
|
99
|
+
☻ Feeling
|
100
|
+
<xsl:text> </xsl:text>
|
101
|
+
<xsl:value-of select="name(*[1])"/>
|
102
|
+
<xsl:if test="*[1]/*[1]">
|
103
|
+
<xsl:text> </xsl:text>
|
104
|
+
(<xsl:value-of select="name(*[1]/*[1])"/>)
|
105
|
+
</xsl:if>
|
106
|
+
<xsl:if test="mood:text">
|
107
|
+
<xsl:text> </xsl:text>
|
108
|
+
<i><xsl:value-of select="mood:text"/></i>
|
109
|
+
</xsl:if>
|
110
|
+
</p>
|
111
|
+
</xsl:template>
|
112
|
+
|
113
|
+
<xsl:template match="activity:activity">
|
114
|
+
<p>
|
115
|
+
↻ Doing
|
116
|
+
<xsl:text> </xsl:text>
|
117
|
+
<xsl:value-of select="name(*[1])"/>
|
118
|
+
<xsl:if test="*[1]/*[1]">
|
119
|
+
<xsl:text> </xsl:text>
|
120
|
+
(<xsl:value-of select="name(*[1]/*[1])"/>)
|
121
|
+
</xsl:if>
|
122
|
+
<xsl:if test="activity:text">
|
123
|
+
<xsl:text> </xsl:text>
|
124
|
+
<i><xsl:value-of select="activity:text"/></i>
|
125
|
+
</xsl:if>
|
126
|
+
</p>
|
127
|
+
</xsl:template>
|
128
|
+
|
129
|
+
<xsl:template match="chatting:room[count(*) = 0]">
|
130
|
+
<p>Stopped chatting</p>
|
131
|
+
</xsl:template>
|
132
|
+
|
133
|
+
<xsl:template match="chatting:room">
|
134
|
+
<p>
|
135
|
+
Chatting at
|
136
|
+
<a href="{chatting:uri}">
|
137
|
+
<xsl:choose>
|
138
|
+
<xsl:when test="chatting:name"><xsl:value-of select="chatting:name"/></xsl:when>
|
139
|
+
<xsl:otherwise><xsl:value-of select="chatting:uri"/></xsl:otherwise>
|
140
|
+
</xsl:choose>
|
141
|
+
</a>
|
142
|
+
<xsl:if test="chatting:topic">
|
143
|
+
<i><xsl:value-of select="chatting:topic"/></i>
|
144
|
+
</xsl:if>
|
145
|
+
</p>
|
146
|
+
</xsl:template>
|
147
|
+
|
148
|
+
<xsl:template match="browsing:page[count(*) = 0]">
|
149
|
+
<p>Stopped browsing</p>
|
150
|
+
</xsl:template>
|
151
|
+
|
152
|
+
<xsl:template match="browsing:page">
|
153
|
+
<p>
|
154
|
+
Browsing
|
155
|
+
<a href="{browsing:uri}">
|
156
|
+
<xsl:choose>
|
157
|
+
<xsl:when test="browsing:title"><xsl:value-of select="browsing:title"/></xsl:when>
|
158
|
+
<xsl:otherwise><xsl:value-of select="browsing:uri"/></xsl:otherwise>
|
159
|
+
</xsl:choose>
|
160
|
+
</a>
|
161
|
+
<xsl:if test="browsing:description">
|
162
|
+
<i><xsl:value-of select="browsing:description"/></i>
|
163
|
+
</xsl:if>
|
164
|
+
</p>
|
165
|
+
</xsl:template>
|
166
|
+
|
167
|
+
<xsl:template match="gaming:game[count(*) = 0]">
|
168
|
+
<p>Stopped gaming</p>
|
169
|
+
</xsl:template>
|
170
|
+
|
171
|
+
<xsl:template match="gaming:game">
|
172
|
+
<p>
|
173
|
+
|
174
|
+
Playing
|
175
|
+
<xsl:choose>
|
176
|
+
<xsl:when test="gaming:uri">
|
177
|
+
<a href="{gaming:uri}">
|
178
|
+
<xsl:value-of select="gaming:name"/>
|
179
|
+
</a>
|
180
|
+
</xsl:when>
|
181
|
+
<xsl:otherwise>
|
182
|
+
<xsl:value-of select="gaming:name"/>
|
183
|
+
</xsl:otherwise>
|
184
|
+
</xsl:choose>
|
185
|
+
|
186
|
+
<xsl:if test="gaming:character_name">
|
187
|
+
as
|
188
|
+
<xsl:choose>
|
189
|
+
<xsl:when test="gaming:character_profile">
|
190
|
+
<a href="{gaming:character_profile}">
|
191
|
+
<xsl:value-of select="gaming:character_name"/>
|
192
|
+
</a>
|
193
|
+
</xsl:when>
|
194
|
+
<xsl:otherwise>
|
195
|
+
<xsl:value-of select="gaming:character_name"/>
|
196
|
+
</xsl:otherwise>
|
197
|
+
</xsl:choose>
|
198
|
+
</xsl:if>
|
199
|
+
|
200
|
+
<xsl:if test="gaming:server_address">
|
201
|
+
on
|
202
|
+
<a href="{gaming:server_address}">
|
203
|
+
<xsl:choose>
|
204
|
+
<xsl:when test="gaming:server_name"><xsl:value-of select="gaming:server_name"/></xsl:when>
|
205
|
+
<xsl:otherwise><xsl:value-of select="gaming:server_name"/></xsl:otherwise>
|
206
|
+
</xsl:choose>
|
207
|
+
</a>
|
208
|
+
</xsl:if>
|
209
|
+
|
210
|
+
</p>
|
211
|
+
</xsl:template>
|
212
|
+
|
213
|
+
<xsl:template match="watching:video[count(*) = 0]">
|
214
|
+
<p>Stopped watching a video</p>
|
215
|
+
</xsl:template>
|
216
|
+
|
217
|
+
<xsl:template match="watching:video">
|
218
|
+
<xsl:if test="watching:program_name">
|
219
|
+
<p>
|
220
|
+
✇ Watching
|
221
|
+
<xsl:choose>
|
222
|
+
<xsl:when test="watching:uri">
|
223
|
+
<a href="{watching:uri}">
|
224
|
+
<xsl:value-of select="watching:program_name"/>
|
225
|
+
</a>
|
226
|
+
</xsl:when>
|
227
|
+
<xsl:otherwise>
|
228
|
+
<xsl:value-of select="watching:program_name"/>
|
229
|
+
</xsl:otherwise>
|
230
|
+
</xsl:choose>
|
231
|
+
</p>
|
232
|
+
</xsl:if>
|
233
|
+
</xsl:template>
|
234
|
+
|
235
|
+
</xsl:stylesheet>
|