xmpp4r 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/{ChangeLog → CHANGELOG} +33 -0
  2. data/LICENSE +9 -9
  3. data/README.rdoc +110 -0
  4. data/README_ruby19.txt +43 -0
  5. data/Rakefile +235 -74
  6. data/data/doc/xmpp4r/examples/advanced/adventure/README +0 -1
  7. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +1 -1
  8. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +12 -12
  9. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +10 -11
  10. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +11 -11
  11. data/data/doc/xmpp4r/examples/advanced/getonline.rb +7 -7
  12. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +3 -3
  13. data/data/doc/xmpp4r/examples/advanced/migrate.rb +21 -22
  14. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +22 -22
  15. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  16. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  17. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +0 -1
  18. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +2 -3
  19. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +3 -3
  20. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +10 -10
  21. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +2 -2
  22. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +12 -12
  23. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +2 -3
  24. data/data/doc/xmpp4r/examples/basic/change_password.rb +3 -3
  25. data/data/doc/xmpp4r/examples/basic/client.rb +5 -3
  26. data/data/doc/xmpp4r/examples/basic/component.rb +1 -1
  27. data/data/doc/xmpp4r/examples/basic/{echo_threaded.rb → echo.rb} +8 -7
  28. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +5 -5
  29. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +11 -11
  30. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +0 -1
  31. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +3 -1
  32. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +0 -1
  33. data/data/doc/xmpp4r/examples/basic/register.rb +21 -4
  34. data/data/doc/xmpp4r/examples/basic/roster.rb +7 -5
  35. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +0 -0
  36. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +2 -2
  37. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +6 -7
  38. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +3 -4
  39. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  40. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  41. data/data/doc/xmpp4r/examples/basic/versionbot.rb +1 -1
  42. data/lib/xmpp4r.rb +4 -4
  43. data/lib/xmpp4r/base64.rb +32 -0
  44. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +10 -11
  45. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +6 -8
  46. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +3 -6
  47. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +0 -1
  48. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +8 -11
  49. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +4 -7
  50. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +7 -3
  51. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +10 -5
  52. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +14 -4
  53. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb.orig +62 -0
  54. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +0 -1
  55. data/lib/xmpp4r/callbacks.rb +5 -5
  56. data/lib/xmpp4r/caps.rb +1 -0
  57. data/lib/xmpp4r/caps/c.rb +53 -0
  58. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  59. data/lib/xmpp4r/caps/helper/helper.rb +87 -0
  60. data/lib/xmpp4r/client.rb +111 -40
  61. data/lib/xmpp4r/command/iq/command.rb +1 -1
  62. data/lib/xmpp4r/component.rb +8 -8
  63. data/lib/xmpp4r/connection.rb +25 -9
  64. data/lib/xmpp4r/dataforms/x/data.rb +17 -5
  65. data/lib/xmpp4r/debuglog.rb +13 -5
  66. data/lib/xmpp4r/delay/x/delay.rb +1 -1
  67. data/lib/xmpp4r/discovery.rb +3 -2
  68. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  69. data/lib/xmpp4r/discovery/iq/discoinfo.rb +11 -12
  70. data/lib/xmpp4r/discovery/iq/discoitems.rb +12 -4
  71. data/lib/xmpp4r/{error.rb → errors.rb} +66 -10
  72. data/lib/xmpp4r/framework/base.rb +55 -0
  73. data/lib/xmpp4r/framework/bot.rb +148 -0
  74. data/lib/xmpp4r/httpbinding/client.rb +1 -1
  75. data/lib/xmpp4r/idgenerator.rb +1 -1
  76. data/lib/xmpp4r/iq.rb +34 -23
  77. data/lib/xmpp4r/jid.rb +2 -2
  78. data/lib/xmpp4r/message.rb +1 -1
  79. data/lib/xmpp4r/muc.rb +2 -0
  80. data/lib/xmpp4r/muc/helper/mucbrowser.rb +4 -19
  81. data/lib/xmpp4r/muc/helper/mucclient.rb +54 -23
  82. data/lib/xmpp4r/muc/helper/simplemucclient.rb +107 -1
  83. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  84. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  85. data/lib/xmpp4r/muc/iq/mucowner.rb +5 -1
  86. data/lib/xmpp4r/muc/item.rb +143 -0
  87. data/lib/xmpp4r/muc/x/mucuserinvite.rb +2 -2
  88. data/lib/xmpp4r/muc/x/mucuseritem.rb +3 -117
  89. data/lib/xmpp4r/presence.rb +2 -1
  90. data/lib/xmpp4r/pubsub.rb +7 -0
  91. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  92. data/lib/xmpp4r/pubsub/{stanzas → children}/event.rb +13 -13
  93. data/lib/xmpp4r/pubsub/{stanzas → children}/item.rb +9 -1
  94. data/lib/xmpp4r/pubsub/{stanzas → children}/items.rb +10 -1
  95. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  96. data/lib/xmpp4r/pubsub/children/publish.rb +24 -0
  97. data/lib/xmpp4r/pubsub/{stanzas → children}/subscription.rb +16 -12
  98. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  99. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
  100. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +49 -93
  101. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +39 -36
  102. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +253 -162
  103. data/lib/xmpp4r/pubsub/iq/pubsub.rb +1 -1
  104. data/lib/xmpp4r/rexmladdons.rb +56 -28
  105. data/lib/xmpp4r/roster.rb +0 -1
  106. data/lib/xmpp4r/roster/helper/roster.rb +26 -15
  107. data/lib/xmpp4r/roster/iq/roster.rb +19 -19
  108. data/lib/xmpp4r/roster/x/roster.rb +10 -10
  109. data/lib/xmpp4r/rpc/helper/client.rb +17 -8
  110. data/lib/xmpp4r/rpc/helper/server.rb +1 -2
  111. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +14 -4
  112. data/lib/xmpp4r/rpc/iq/rpc.rb +0 -1
  113. data/lib/xmpp4r/sasl.rb +27 -6
  114. data/lib/xmpp4r/stream.rb +39 -44
  115. data/lib/xmpp4r/streamparser.rb +4 -4
  116. data/lib/xmpp4r/tune.rb +2 -0
  117. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  118. data/lib/xmpp4r/tune/tune.rb +113 -0
  119. data/lib/xmpp4r/vcard.rb +0 -1
  120. data/lib/xmpp4r/vcard/helper/vcard.rb +1 -3
  121. data/lib/xmpp4r/vcard/iq/vcard.rb +14 -0
  122. data/lib/xmpp4r/version/iq/version.rb +0 -1
  123. data/lib/xmpp4r/x.rb +1 -1
  124. data/lib/xmpp4r/xhtml.rb +1 -0
  125. data/lib/xmpp4r/xhtml/html.rb +115 -0
  126. data/lib/xmpp4r/xmpp4r.rb +7 -5
  127. data/lib/xmpp4r/xmppelement.rb +21 -5
  128. data/lib/xmpp4r/xmppstanza.rb +6 -6
  129. data/setup.rb +4 -4
  130. data/test/bytestreams/tc_ibb.rb +2 -2
  131. data/test/bytestreams/tc_socks5bytestreams.rb +12 -2
  132. data/test/caps/tc_helper.rb +156 -0
  133. data/test/dataforms/tc_data.rb +0 -0
  134. data/test/delay/tc_xdelay.rb +2 -2
  135. data/test/discovery/tc_responder.rb +91 -0
  136. data/test/lib/assert_equal_xml.rb +14 -0
  137. data/test/lib/clienttester.rb +31 -24
  138. data/test/muc/tc_muc_mucclient.rb +249 -13
  139. data/test/muc/tc_muc_simplemucclient.rb +41 -2
  140. data/test/muc/tc_mucowner.rb +0 -0
  141. data/test/pubsub/tc_helper.rb +486 -51
  142. data/test/pubsub/tc_nodeconfig.rb +54 -0
  143. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  144. data/test/roster/tc_helper.rb +6 -7
  145. data/test/roster/tc_iqqueryroster.rb +16 -16
  146. data/test/roster/tc_xroster.rb +1 -1
  147. data/test/rpc/tc_helper.rb +15 -3
  148. data/test/tc_callbacks.rb +7 -7
  149. data/test/tc_class_names.rb +15 -6
  150. data/test/tc_client.rb +3 -3
  151. data/test/{tc_error.rb → tc_errors.rb} +54 -12
  152. data/test/tc_idgenerator.rb +0 -0
  153. data/test/tc_iq.rb +32 -29
  154. data/test/tc_iqquery.rb +2 -2
  155. data/test/tc_jid.rb +44 -42
  156. data/test/tc_message.rb +13 -12
  157. data/test/tc_presence.rb +25 -24
  158. data/test/tc_rexml.rb +81 -2
  159. data/test/tc_stream.rb +15 -13
  160. data/test/tc_streamComponent.rb +6 -5
  161. data/test/tc_streamError.rb +21 -15
  162. data/test/tc_streamSend.rb +9 -9
  163. data/test/tc_streamparser.rb +112 -0
  164. data/test/tc_xmppstanza.rb +19 -9
  165. data/test/ts_xmpp4r.rb +10 -1
  166. data/test/tune/tc_helper_recv.rb +84 -0
  167. data/test/tune/tc_helper_send.rb +74 -0
  168. data/test/tune/tc_tune.rb +79 -0
  169. data/test/vcard/tc_helper.rb +2 -2
  170. data/test/vcard/tc_iqvcard.rb +13 -3
  171. data/test/version/tc_helper.rb +2 -2
  172. data/test/version/tc_iqqueryversion.rb +10 -10
  173. data/test/xhtml/tc_html.rb +41 -0
  174. data/tools/gen_requires.bash +29 -8
  175. data/tools/xmpp4r-gemspec-test.rb +11 -0
  176. data/xmpp4r.gemspec +291 -0
  177. metadata +277 -218
  178. data/README +0 -28
  179. data/UPDATING +0 -40
  180. data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +0 -18
  181. data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +0 -192
  182. data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +0 -82
  183. data/lib/xmpp4r/authenticationfailure.rb +0 -13
  184. data/lib/xmpp4r/errorexception.rb +0 -32
  185. data/tools/doctoweb.bash +0 -30
@@ -54,4 +54,3 @@ RFC3920:
54
54
 
55
55
  Compliant server implementations MUST ensure in-order processing of
56
56
  XML stanzas between any two entities."
57
-
@@ -17,7 +17,7 @@ if ARGV.size != 3
17
17
  exit
18
18
  end
19
19
 
20
- muc = AdventureMUC::new(Jabber::JID::new(ARGV[0]), ARGV[1], ARGV[2])
20
+ muc = AdventureMUC.new(Jabber::JID.new(ARGV[0]), ARGV[1], ARGV[2])
21
21
  muc.add_world('tower.xml')
22
22
  muc.add_world('cube.xml')
23
23
  Thread.stop
@@ -3,8 +3,8 @@ require 'world'
3
3
  class AdventureMUC
4
4
  def initialize(jid, secret, addr, port=5347)
5
5
  @worlds = {}
6
-
7
- @component = Jabber::Component::new(jid)
6
+
7
+ @component = Jabber::Component.new(jid)
8
8
  @component.connect(addr, port)
9
9
  @component.auth(secret)
10
10
  @component.on_exception { |e,|
@@ -37,7 +37,7 @@ class AdventureMUC
37
37
  end
38
38
 
39
39
  def send(worldnode, worldresource, stanza)
40
- stanza.from = Jabber::JID::new(worldnode, @component.jid.domain, worldresource)
40
+ stanza.from = Jabber::JID.new(worldnode, @component.jid.domain, worldresource)
41
41
  @component.send(stanza)
42
42
  end
43
43
 
@@ -54,12 +54,12 @@ class AdventureMUC
54
54
  false
55
55
  end
56
56
  end
57
-
57
+
58
58
  def handle_disco_info(iq)
59
59
  if iq.type != :get
60
60
  answer = iq.answer
61
61
  answer.type = :error
62
- answer.add(Jabber::Error.new('bad-request'))
62
+ answer.add(Jabber::ErrorResponse.new('bad-request'))
63
63
  @component.send(answer) if iq.type != :error
64
64
  return
65
65
  end
@@ -73,7 +73,7 @@ class AdventureMUC
73
73
  world = @worlds[iq.to.node]
74
74
  if world.nil?
75
75
  answer.type = :error
76
- answer.query.add(Jabber::Error.new('item-not-found', 'The world you are trying to reach is currently unavailable.'))
76
+ answer.query.add(Jabber::ErrorResponse.new('item-not-found', 'The world you are trying to reach is currently unavailable.'))
77
77
  else
78
78
  answer.query.add(Jabber::Discovery::Identity.new('conference', world.iname, 'text'))
79
79
  answer.query.add(Jabber::Discovery::Feature.new(Jabber::Discovery::IqQueryDiscoInfo.new.namespace))
@@ -84,11 +84,11 @@ class AdventureMUC
84
84
  end
85
85
  @component.send(answer)
86
86
  end
87
-
87
+
88
88
  def handle_disco_items(iq)
89
89
  if iq.type != :get
90
90
  answer = iq.answer
91
- answer.add(Jabber::Error.new('bad-request'))
91
+ answer.add(Jabber::ErrorResponse.new('bad-request'))
92
92
  @component.send(answer)
93
93
  return
94
94
  end
@@ -96,7 +96,7 @@ class AdventureMUC
96
96
  answer.type = :result
97
97
  if iq.to.node == nil
98
98
  @worlds.each { |node,world|
99
- answer.query.add(Jabber::Discovery::Item.new(Jabber::JID::new(node, @component.jid.domain), world.iname))
99
+ answer.query.add(Jabber::Discovery::Item.new(Jabber::JID.new(node, @component.jid.domain), world.iname))
100
100
  }
101
101
  end
102
102
  @component.send(answer)
@@ -104,12 +104,12 @@ class AdventureMUC
104
104
 
105
105
  def handle_presence(pres)
106
106
  puts "presence: from #{pres.from} type #{pres.type} to #{pres.to}"
107
-
107
+
108
108
  world = @worlds[pres.to.node]
109
109
  if world.nil?
110
110
  answer = pres.answer
111
111
  answer.type = :error
112
- answer.add(Jabber::Error.new('item-not-found', 'The world you are trying to reach is currently unavailable.'))
112
+ answer.add(Jabber::ErrorResponse.new('item-not-found', 'The world you are trying to reach is currently unavailable.'))
113
113
  @component.send(answer)
114
114
  else
115
115
  world.handle_presence(pres)
@@ -125,7 +125,7 @@ class AdventureMUC
125
125
  if world.nil?
126
126
  answer = msg.answer
127
127
  answer.type = :error
128
- answer.add(Jabber::Error.new('item-not-found', 'The world you are trying to reach is currently unavailable.'))
128
+ answer.add(Jabber::ErrorResponse.new('item-not-found', 'The world you are trying to reach is currently unavailable.'))
129
129
  @component.send(answer)
130
130
  else
131
131
  world.handle_message(msg)
@@ -24,9 +24,9 @@ class World < REXML::Element
24
24
 
25
25
  def add(xmlelement)
26
26
  if xmlelement.kind_of?(REXML::Element) && (xmlelement.name == 'place')
27
- super(Place::new.import(xmlelement))
27
+ super(Place.new.import(xmlelement))
28
28
  elsif xmlelement.kind_of?(REXML::Element) && (xmlelement.name == 'thing') && !xmlelement.kind_of?(Player)
29
- super(Thing::new(self).import(xmlelement))
29
+ super(Thing.new(self).import(xmlelement))
30
30
  else
31
31
  super(xmlelement)
32
32
  end
@@ -135,7 +135,7 @@ class World < REXML::Element
135
135
  if thing.kind_of?(Player) && (pres.from == thing.jid) && (player != thing)
136
136
  answer = pres.answer(false)
137
137
  answer.type = :error
138
- answer.add(Jabber::Error.new('not-acceptable', 'Nickchange not allowed'))
138
+ answer.add(Jabber::ErrorResponse.new('not-acceptable', 'Nickchange not allowed'))
139
139
  send(thing.iname, answer)
140
140
  return(true)
141
141
  end
@@ -146,9 +146,9 @@ class World < REXML::Element
146
146
  answer = pres.answer
147
147
  answer.type = :error
148
148
  if (pres.to.resource.to_s.size > 1)
149
- answer.add(Jabber::Error::new('conflict', 'Nickname already used'))
149
+ answer.add(Jabber::ErrorResponse.new('conflict', 'Nickname already used'))
150
150
  else
151
- answer.add(Jabber::Error::new('not-acceptable', 'Please use a nickname'))
151
+ answer.add(Jabber::ErrorResponse.new('not-acceptable', 'Please use a nickname'))
152
152
  end
153
153
  send(nil, answer)
154
154
  return(true)
@@ -171,7 +171,7 @@ class World < REXML::Element
171
171
  send(player.iname, pres)
172
172
  }
173
173
  end
174
-
174
+
175
175
  # Remove the player instantly
176
176
  if pres.type == :error || pres.type == :unavailable
177
177
  move_thing(player, nil)
@@ -190,7 +190,7 @@ class World < REXML::Element
190
190
  if player.nil?
191
191
  answer = msg.answer
192
192
  answer.type = :error
193
- answer.add(Jabber::Error::new('forbidden'))
193
+ answer.add(Jabber::ErrorResponse.new('forbidden'))
194
194
  send(msg.to.resource, answer)
195
195
  return(true)
196
196
  end
@@ -336,7 +336,7 @@ class Thing < REXML::Element
336
336
  end
337
337
  }
338
338
  end
339
-
339
+
340
340
  def on_enter(thing, from)
341
341
  each_element('on-enter') { |c|
342
342
  command(thing, c, [from])
@@ -374,9 +374,9 @@ class Player < Thing
374
374
  attributes['name'] = iname
375
375
  attributes['jid'] = jid.to_s
376
376
  end
377
-
377
+
378
378
  def jid
379
- attributes['jid'].nil? ? nil : Jabber::JID::new(attributes['jid'])
379
+ attributes['jid'].nil? ? nil : Jabber::JID.new(attributes['jid'])
380
380
  end
381
381
 
382
382
  def see(place)
@@ -422,4 +422,3 @@ class Player < Thing
422
422
  end
423
423
  end
424
424
  end
425
-
@@ -198,7 +198,7 @@ class FileServe
198
198
  @socksserver = Jabber::Bytestreams::SOCKS5BytestreamsServer.new(conf['socks']['port'])
199
199
 
200
200
  conf['socks']['addresses'].each { |addr| @socksserver.add_address(addr) }
201
-
201
+
202
202
  @proxies = []
203
203
  conf['socks']['proxies'].collect { |jid|
204
204
  puts "Querying proxy #{jid}..."
@@ -207,8 +207,8 @@ class FileServe
207
207
  rescue
208
208
  puts "Error: #{$!}"
209
209
  end
210
- }
211
-
210
+ }
211
+
212
212
  Thread.new { presence }
213
213
  Thread.new { cleaner }
214
214
 
@@ -253,7 +253,7 @@ class FileServe
253
253
  }
254
254
 
255
255
  @ft.add_incoming_callback { |iq,file|
256
-
256
+
257
257
  say = lambda { |text|
258
258
  say(iq.from, text)
259
259
  }
@@ -261,23 +261,23 @@ class FileServe
261
261
  puts "Incoming file transfer from #{iq.from}: #{file.fname} (#{file.size / 1024} KB)"
262
262
  filename = file.fname.split(/\//).last
263
263
  filename.gsub!(/^\.+/, '')
264
-
264
+
265
265
  puts "Range: #{file.range != nil}"
266
266
  transfer = Upload.new(@ft, iq, "#{@directory}/#{filename}", file.size, file.range != nil, say)
267
267
  @uploads += 1
268
-
268
+
269
269
  @transfers_lock.synchronize {
270
270
  @transfers.push(transfer)
271
271
  }
272
-
272
+
273
273
  }
274
274
 
275
275
  roster = Jabber::Roster::Helper.new(@client)
276
-
276
+
277
277
  roster.add_subscription_request_callback { |item,presence|
278
278
  roster.accept_subscription(presence.from)
279
279
  }
280
-
280
+
281
281
  end
282
282
 
283
283
  def command(from, cmd, arg)
@@ -330,11 +330,11 @@ class FileServe
330
330
 
331
331
  def cleaner
332
332
  loop {
333
-
333
+
334
334
  @transfers_lock.synchronize {
335
335
  @transfers.delete_if { |t| t.done? }
336
336
  }
337
-
337
+
338
338
  sleep 1
339
339
  }
340
340
  end
@@ -7,14 +7,14 @@ require 'xmpp4r'
7
7
  include Jabber
8
8
 
9
9
  get = true
10
- jid = JID::new('lucastest@linux.ensimag.fr/rosterget')
10
+ jid = JID.new('lucastest@linux.ensimag.fr/rosterget')
11
11
  password = 'lucastest'
12
12
  domains = []
13
13
 
14
- OptionParser::new do |opts|
14
+ OptionParser.new do |opts|
15
15
  opts.banner = 'Usage: roster.rb -j jid -p password -d domain'
16
16
  opts.separator ''
17
- opts.on('-j', '--jid JID', 'sets the jid') { |j| jid = JID::new(j) }
17
+ opts.on('-j', '--jid JID', 'sets the jid') { |j| jid = JID.new(j) }
18
18
  opts.on('-p', '--password PASSWORD', 'sets the password') { |p| password = p }
19
19
  opts.on('-d', '--domain DOMAIN', 'sets the domain') { |d| domains << d }
20
20
  opts.on_tail('-h', '--help', 'Show this message') {
@@ -24,13 +24,13 @@ OptionParser::new do |opts|
24
24
  opts.parse!(ARGV)
25
25
  end
26
26
 
27
- cl = Client::new(jid, false)
27
+ cl = Client.new(jid)
28
28
  cl.connect
29
29
  cl.auth(password)
30
30
  exit = false
31
31
  nb = 0
32
32
  cl.add_iq_callback { |i|
33
- fjid = JID::new(i.from)
33
+ fjid = JID.new(i.from)
34
34
  if i.type == :result and fjid.resource == "admin"
35
35
  domain = fjid.domain
36
36
  items = nil
@@ -47,8 +47,8 @@ cl.add_iq_callback { |i|
47
47
  end
48
48
  }
49
49
  for d in domains do
50
- cl.send(Iq::new_browseget.set_to("#{d}/admin"))
51
- nb += 1
50
+ cl.send(Iq.new_browseget.set_to("#{d}/admin"))
51
+ nb += 1
52
52
  end
53
53
  while nb > 0
54
54
  cl.process(1)
@@ -57,7 +57,7 @@ class SetupWindow < Gtk::Window
57
57
  @entry_resource.show
58
58
  layout1.attach(@entry_resource, 1, 2, 3, 4)
59
59
 
60
-
60
+
61
61
  frame2 = Gtk::Frame.new('Multi-User Chat Settings')
62
62
  frame2.set_border_width(4)
63
63
  frame2.show
@@ -174,7 +174,7 @@ class ChatWindow < Gtk::Window
174
174
  roster_scroll.show
175
175
  roster_scroll.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
176
176
  layout_mid.pack2(roster_scroll, true, true)
177
-
177
+
178
178
  @roster = Gtk::ListStore.new(String)
179
179
  @roster.set_sort_column_id(0)
180
180
  roster_view = Gtk::TreeView.new(@roster)
@@ -196,7 +196,7 @@ class ChatWindow < Gtk::Window
196
196
 
197
197
  print_buffer "Welcome to the XMPP4R sample GTK2 Multi-User Chat client"
198
198
  print_buffer "Commands start with a slash, type \"/help\" for a list"
199
-
199
+
200
200
  @client = Jabber::Client.new(jid)
201
201
  Jabber::Version::SimpleResponder.new(@client, "XMPP4R example: GtkMUCClient", Jabber::XMPP4R_VERSION, IO.popen("uname -sr").readlines.to_s.strip)
202
202
  Thread.new {
@@ -2,29 +2,29 @@
2
2
 
3
3
  # This script can be used to migrate from one jabber account to another
4
4
 
5
- $:.unshift '../lib'
5
+ $:.unshift '../../../../../lib'
6
6
 
7
7
  require 'optparse'
8
8
  require 'xmpp4r'
9
9
  include Jabber
10
10
 
11
- jidfrom = JID::new('lucas@linux.ensimag.fr/JabberMigrate')
11
+ jidfrom = JID.new('lucas@linux.ensimag.fr/JabberMigrate')
12
12
  pwfrom = 'z'
13
- jidto = JID::new('lucas@nussbaum.fr/JabberMigrate')
13
+ jidto = JID.new('lucas@nussbaum.fr/JabberMigrate')
14
14
  pwto = 'z'
15
15
 
16
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
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
18
 
19
- clfrom = Client::new(jidfrom, false)
19
+ clfrom = Client.new(jidfrom)
20
20
  clfrom.connect
21
21
  clfrom.auth(pwfrom)
22
- clto = Client::new(jidto, false)
22
+ clto = Client.new(jidto)
23
23
  clto.connect
24
24
  clto.auth(pwto)
25
- #clfrom.send(Presence::new)
26
- #clto.send(Presence::new)
27
- clfrom.send(Iq::new_rosterget)
25
+ #clfrom.send(Presence.new)
26
+ #clto.send(Presence.new)
27
+ clfrom.send(Iq.new_rosterget)
28
28
  exit = false
29
29
  clfrom.add_iq_callback { |i|
30
30
  if i.type == :result and i.queryns == 'jabber:iq:roster'
@@ -47,35 +47,35 @@ clfrom.add_iq_callback { |i|
47
47
  when 'from'
48
48
  # il veut me voir, je veux pas le voir.
49
49
  # envoi unsubscribed
50
- clfrom.send(Presence::new.set_to(jid).set_type(:unsubscribed))
50
+ clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribed))
51
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))
52
+ clfrom.send(Message.new(jid, BOTHOLD).set_type(:chat))
53
+ clto.send(Message.new(jid, BOTHNEW).set_type(:chat))
54
54
  when 'to'
55
55
  # je veux le voir, il veut pas me voir
56
56
  # envoi unsubscribe
57
- clfrom.send(Presence::new.set_to(jid).set_type(:unsubscribe))
57
+ clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribe))
58
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."))
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
61
  clto.send(pres)
62
62
  when 'both'
63
63
  # envoi unsubscribed
64
- clfrom.send(Presence::new.set_to(jid).set_type(:unsubscribed))
64
+ clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribed))
65
65
  # envoi unsubscribe
66
- clfrom.send(Presence::new.set_to(jid).set_type(:unsubscribe))
66
+ clfrom.send(Presence.new.set_to(jid).set_type(:unsubscribe))
67
67
  # update roster
68
- iq = Iq::new_rosterset
68
+ iq = Iq.new_rosterset
69
69
  e.delete_attribute('ask')
70
70
  e.delete_attribute('subscription')
71
71
  iq.query.add_element(e)
72
72
  clto.send(iq)
73
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."))
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
77
  clto.send(pres)
78
- clto.send(Message::new(jid, BOTHNEW).set_type(:chat))
78
+ clto.send(Message.new(jid, BOTHNEW).set_type(:chat))
79
79
  end
80
80
  end
81
81
  end
@@ -86,4 +86,3 @@ while not exit
86
86
  end
87
87
  clfrom.close
88
88
  clto.close
89
-
@@ -14,10 +14,10 @@ class Room
14
14
  class RoomException < Exception
15
15
  attr_reader :error
16
16
  def initialize(error, msg)
17
- @error = Jabber::Error.new(error, msg)
17
+ @error = Jabber::ErrorResponse.new(error, msg)
18
18
  end
19
19
  end
20
-
20
+
21
21
  def initialize(stream, name)
22
22
  @users = {} # nick => jid
23
23
  @stream = stream
@@ -37,7 +37,7 @@ class Room
37
37
  msg.from = nil
38
38
  @users.each { |nick,jid|
39
39
  if jid == origin
40
- msg.from = Jabber::JID::new(@name.node, @name.domain, nick)
40
+ msg.from = Jabber::JID.new(@name.node, @name.domain, nick)
41
41
  end
42
42
  }
43
43
  unless msg.from.nil?
@@ -49,7 +49,7 @@ class Room
49
49
 
50
50
  def handle_presence(pres)
51
51
  reason = nil
52
-
52
+
53
53
  # Check if nick already registered
54
54
  @users.each { |nick,jid|
55
55
  if pres.from != jid && pres.to.resource == nick
@@ -71,12 +71,12 @@ class Room
71
71
  userinfo.add(Jabber::XMUCUser.new).add(Jabber::XMUCUserItem.new(:none, :participant))
72
72
  print "Sending all users for #{pres.to} to #{pres.from}:"
73
73
  @users.each { |nick,jid|
74
- userinfo.from = Jabber::JID::new(@name.node, @name.domain, nick)
74
+ userinfo.from = Jabber::JID.new(@name.node, @name.domain, nick)
75
75
  print " #{nick} (#{jid})"
76
76
  @stream.send(userinfo)
77
77
  }
78
78
  puts " Ok"
79
-
79
+
80
80
  # Add the new user
81
81
  puts "Adding #{pres.from} as #{pres.to}"
82
82
  @users[pres.to.resource] = pres.from
@@ -97,7 +97,7 @@ class Room
97
97
  reason = "#{was_nick} has left #{@name.node}"
98
98
  end
99
99
  end
100
-
100
+
101
101
  # Advertise users presence to all
102
102
  puts "Advertising user to all"
103
103
  x = Jabber::XMUCUserItem.new(:none, :participant, pres.from)
@@ -108,13 +108,13 @@ class Room
108
108
  end
109
109
 
110
110
  def send_message(body)
111
- msg = Jabber::Message::new
112
- msg.from = Jabber::JID::new(@name.node, @name.domain, "")
111
+ msg = Jabber::Message.new
112
+ msg.from = Jabber::JID.new(@name.node, @name.domain, "")
113
113
  msg.type = :groupchat
114
114
  msg.body = body
115
115
  broadcast(msg)
116
116
  end
117
-
117
+
118
118
  def broadcast(stanza)
119
119
  x = stanza.class::import(stanza)
120
120
  @users.each { |nick,jid|
@@ -127,8 +127,8 @@ end
127
127
  class MUC
128
128
  def initialize(jid, secret, addr, port=5347)
129
129
  @rooms = {}
130
-
131
- @component = Jabber::Component::new(jid, addr, port)
130
+
131
+ @component = Jabber::Component.new(jid, addr, port)
132
132
  @component.connect
133
133
  @component.auth(secret)
134
134
 
@@ -168,7 +168,7 @@ class MUC
168
168
  elsif room.nil? && pres.type != :error
169
169
  pres.to, pres.from = pres.from, pres.to
170
170
  pres.type = :error
171
- pres.add(Jabber::Error.new('item-not-found'))
171
+ pres.add(Jabber::ErrorResponse.new('item-not-found'))
172
172
  @component.send(pres)
173
173
  return(true)
174
174
  end
@@ -195,11 +195,11 @@ class MUC
195
195
  else
196
196
  msg.to, msg.from = msg.from, msg.to
197
197
  msg.type = :error
198
- msg.add(Jabber::Error.new('item-not-found', 'The chatroom you are trying to reach is currently not available.'))
198
+ msg.add(Jabber::ErrorResponse.new('item-not-found', 'The chatroom you are trying to reach is currently not available.'))
199
199
  @component.send(msg)
200
200
  end
201
201
  end
202
-
202
+
203
203
  def handle_disco_info(iq)
204
204
  if (iq.type == :get)
205
205
  iq.type = :result
@@ -210,7 +210,7 @@ class MUC
210
210
  room = @rooms[iq.to]
211
211
  if room.nil?
212
212
  iq.type = :error
213
- iq.add_element(Jabber::Error.new('item-not-found'))
213
+ iq.add_element(Jabber::ErrorResponse.new('item-not-found'))
214
214
  else
215
215
  iq.query.add(Jabber::DiscoIdentity.new('conference', "#{iq.to.node} (#{room.num_users})", 'text'))
216
216
  end
@@ -223,7 +223,7 @@ class MUC
223
223
  }
224
224
  else
225
225
  iq.type = :error
226
- iq.add_element(Jabber::Error.new('bad-request'))
226
+ iq.add_element(Jabber::ErrorResponse.new('bad-request'))
227
227
  end
228
228
  iq.to, iq.from = iq.from, iq.to
229
229
  @component.send(iq)
@@ -234,22 +234,22 @@ class MUC
234
234
  iq.type = :result
235
235
  if iq.to.node == nil
236
236
  @rooms.each { |name,room|
237
- iq.query.add(Jabber::DiscoItem::new(Jabber::JID::new(name, @component.jid.domain), name))
237
+ iq.query.add(Jabber::DiscoItem.new(Jabber::JID.new(name, @component.jid.domain), name))
238
238
  }
239
239
  elsif iq.to.resource == nil
240
240
  room = @rooms[iq.to.strip]
241
241
  unless room.nil?
242
242
  room.each_user { |nick,jid|
243
- iq.query.add(Jabber::DiscoItem::new(jid, nick))
243
+ iq.query.add(Jabber::DiscoItem.new(jid, nick))
244
244
  }
245
245
  else
246
246
  iq.type = :error
247
- iq.add_element(Jabber::Error.new('item-not-found'))
247
+ iq.add_element(Jabber::ErrorResponse.new('item-not-found'))
248
248
  end
249
249
  end
250
250
  else
251
251
  iq.type = :error
252
- iq.add_element(Jabber::Error.new('bad-request'))
252
+ iq.add_element(Jabber::ErrorResponse.new('bad-request'))
253
253
  end
254
254
  iq.to, iq.from = iq.from, iq.to
255
255
  @component.send(iq)
@@ -262,5 +262,5 @@ if ARGV.size != 3
262
262
  exit
263
263
  end
264
264
 
265
- muc = MUC::new(Jabber::JID::new(ARGV[0]), ARGV[1], ARGV[2])
265
+ muc = MUC.new(Jabber::JID.new(ARGV[0]), ARGV[1], ARGV[2])
266
266
  Thread.stop