gmcmillan-xmpp4r 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +91 -0
  3. data/COPYING +340 -0
  4. data/LICENSE +59 -0
  5. data/README.rdoc +122 -0
  6. data/README_ruby19.txt +43 -0
  7. data/Rakefile +258 -0
  8. data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
  9. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  10. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  11. data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  12. data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  13. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  15. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
  16. data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  17. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  18. data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
  19. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  20. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  21. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  22. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +85 -0
  23. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
  24. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  25. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  26. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  27. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  28. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  29. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
  30. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
  31. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
  32. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  33. data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
  34. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  35. data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
  36. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  37. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
  38. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
  39. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
  40. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
  41. data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
  42. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  43. data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
  44. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  45. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  46. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
  47. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
  48. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  49. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  50. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  51. data/lib/xmpp4r.rb +118 -0
  52. data/lib/xmpp4r/base64.rb +32 -0
  53. data/lib/xmpp4r/bytestreams.rb +15 -0
  54. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +321 -0
  55. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
  56. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
  57. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +153 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
  60. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
  61. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
  62. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +82 -0
  63. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
  64. data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
  65. data/lib/xmpp4r/callbacks.rb +133 -0
  66. data/lib/xmpp4r/caps.rb +1 -0
  67. data/lib/xmpp4r/caps/c.rb +67 -0
  68. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  69. data/lib/xmpp4r/caps/helper/helper.rb +84 -0
  70. data/lib/xmpp4r/client.rb +345 -0
  71. data/lib/xmpp4r/command/helper/responder.rb +53 -0
  72. data/lib/xmpp4r/command/iq/command.rb +154 -0
  73. data/lib/xmpp4r/component.rb +103 -0
  74. data/lib/xmpp4r/connection.rb +231 -0
  75. data/lib/xmpp4r/dataforms.rb +5 -0
  76. data/lib/xmpp4r/dataforms/x/data.rb +297 -0
  77. data/lib/xmpp4r/debuglog.rb +63 -0
  78. data/lib/xmpp4r/delay.rb +5 -0
  79. data/lib/xmpp4r/delay/x/delay.rb +99 -0
  80. data/lib/xmpp4r/discovery.rb +8 -0
  81. data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
  82. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  83. data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
  84. data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
  85. data/lib/xmpp4r/entity_time.rb +6 -0
  86. data/lib/xmpp4r/entity_time/iq.rb +45 -0
  87. data/lib/xmpp4r/entity_time/responder.rb +57 -0
  88. data/lib/xmpp4r/errors.rb +284 -0
  89. data/lib/xmpp4r/feature_negotiation.rb +5 -0
  90. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
  91. data/lib/xmpp4r/framework/base.rb +55 -0
  92. data/lib/xmpp4r/framework/bot.rb +148 -0
  93. data/lib/xmpp4r/httpbinding.rb +5 -0
  94. data/lib/xmpp4r/httpbinding/client.rb +275 -0
  95. data/lib/xmpp4r/idgenerator.rb +37 -0
  96. data/lib/xmpp4r/iq.rb +221 -0
  97. data/lib/xmpp4r/jid.rb +167 -0
  98. data/lib/xmpp4r/last.rb +2 -0
  99. data/lib/xmpp4r/last/helper/helper.rb +37 -0
  100. data/lib/xmpp4r/last/iq/last.rb +67 -0
  101. data/lib/xmpp4r/location.rb +2 -0
  102. data/lib/xmpp4r/location/helper/helper.rb +56 -0
  103. data/lib/xmpp4r/location/location.rb +179 -0
  104. data/lib/xmpp4r/message.rb +226 -0
  105. data/lib/xmpp4r/muc.rb +14 -0
  106. data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
  107. data/lib/xmpp4r/muc/helper/mucclient.rb +469 -0
  108. data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
  109. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  110. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  111. data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
  112. data/lib/xmpp4r/muc/item.rb +143 -0
  113. data/lib/xmpp4r/muc/x/muc.rb +70 -0
  114. data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
  115. data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
  116. data/lib/xmpp4r/presence.rb +232 -0
  117. data/lib/xmpp4r/pubsub.rb +8 -0
  118. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  119. data/lib/xmpp4r/pubsub/children/event.rb +49 -0
  120. data/lib/xmpp4r/pubsub/children/item.rb +35 -0
  121. data/lib/xmpp4r/pubsub/children/items.rb +53 -0
  122. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  123. data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
  124. data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
  125. data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
  126. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  127. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +63 -0
  128. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
  129. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
  130. data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
  131. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +490 -0
  132. data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  133. data/lib/xmpp4r/query.rb +15 -0
  134. data/lib/xmpp4r/reliable.rb +168 -0
  135. data/lib/xmpp4r/rexmladdons.rb +197 -0
  136. data/lib/xmpp4r/roster.rb +7 -0
  137. data/lib/xmpp4r/roster/helper/roster.rb +532 -0
  138. data/lib/xmpp4r/roster/iq/roster.rb +215 -0
  139. data/lib/xmpp4r/roster/x/roster.rb +138 -0
  140. data/lib/xmpp4r/rpc.rb +2 -0
  141. data/lib/xmpp4r/rpc/helper/client.rb +123 -0
  142. data/lib/xmpp4r/rpc/helper/server.rb +74 -0
  143. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
  144. data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
  145. data/lib/xmpp4r/sasl.rb +259 -0
  146. data/lib/xmpp4r/semaphore.rb +38 -0
  147. data/lib/xmpp4r/stream.rb +611 -0
  148. data/lib/xmpp4r/streamparser.rb +66 -0
  149. data/lib/xmpp4r/test/listener_mocker.rb +118 -0
  150. data/lib/xmpp4r/tune.rb +2 -0
  151. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  152. data/lib/xmpp4r/tune/tune.rb +113 -0
  153. data/lib/xmpp4r/vcard.rb +6 -0
  154. data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
  155. data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
  156. data/lib/xmpp4r/version.rb +7 -0
  157. data/lib/xmpp4r/version/helper/responder.rb +72 -0
  158. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  159. data/lib/xmpp4r/version/iq/version.rb +105 -0
  160. data/lib/xmpp4r/x.rb +37 -0
  161. data/lib/xmpp4r/xhtml.rb +1 -0
  162. data/lib/xmpp4r/xhtml/html.rb +115 -0
  163. data/lib/xmpp4r/xmpp4r.rb +20 -0
  164. data/lib/xmpp4r/xmppelement.rb +168 -0
  165. data/lib/xmpp4r/xmppstanza.rb +162 -0
  166. data/setup.rb +1586 -0
  167. data/test/bytestreams/tc_ibb.rb +188 -0
  168. data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
  169. data/test/caps/tc_helper.rb +158 -0
  170. data/test/dataforms/tc_data.rb +81 -0
  171. data/test/delay/tc_xdelay.rb +51 -0
  172. data/test/discovery/tc_responder.rb +91 -0
  173. data/test/entity_time/tc_responder.rb +65 -0
  174. data/test/last/tc_helper.rb +75 -0
  175. data/test/lib/assert_equal_xml.rb +14 -0
  176. data/test/lib/clienttester.rb +149 -0
  177. data/test/muc/tc_muc_mucclient.rb +834 -0
  178. data/test/muc/tc_muc_simplemucclient.rb +114 -0
  179. data/test/muc/tc_mucowner.rb +50 -0
  180. data/test/pubsub/tc_helper.rb +785 -0
  181. data/test/pubsub/tc_nodeconfig.rb +61 -0
  182. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  183. data/test/roster/tc_helper.rb +523 -0
  184. data/test/roster/tc_iqqueryroster.rb +173 -0
  185. data/test/roster/tc_xroster.rb +73 -0
  186. data/test/rpc/tc_helper.rb +96 -0
  187. data/test/tc_callbacks.rb +129 -0
  188. data/test/tc_class_names.rb +146 -0
  189. data/test/tc_client.rb +30 -0
  190. data/test/tc_errors.rb +146 -0
  191. data/test/tc_idgenerator.rb +30 -0
  192. data/test/tc_iq.rb +113 -0
  193. data/test/tc_iqquery.rb +31 -0
  194. data/test/tc_jid.rb +204 -0
  195. data/test/tc_presence.rb +150 -0
  196. data/test/tc_rexml.rb +139 -0
  197. data/test/tc_stream.rb +193 -0
  198. data/test/tc_streamComponent.rb +105 -0
  199. data/test/tc_streamError.rb +129 -0
  200. data/test/tc_streamSend.rb +59 -0
  201. data/test/tc_streamparser.rb +137 -0
  202. data/test/tc_xmppstanza.rb +135 -0
  203. data/test/ts_xmpp4r.rb +44 -0
  204. data/test/tune/tc_helper_recv.rb +82 -0
  205. data/test/tune/tc_helper_send.rb +74 -0
  206. data/test/tune/tc_tune.rb +79 -0
  207. data/test/vcard/tc_helper.rb +49 -0
  208. data/test/vcard/tc_iqvcard.rb +62 -0
  209. data/test/version/tc_helper.rb +60 -0
  210. data/test/version/tc_iqqueryversion.rb +97 -0
  211. data/test/xhtml/tc_html.rb +41 -0
  212. data/tools/gen_requires.bash +31 -0
  213. data/tools/xmpp4r-gemspec-test.rb +11 -0
  214. data/xmpp4r.gemspec +249 -0
  215. metadata +299 -0
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'xmpp4r/framework/bot'
4
+ require 'xmpp4r/pubsub'
5
+ require 'xmpp4r/vcard'
6
+ require 'ramaze'
7
+
8
+ if ARGV.size < 3
9
+ puts "Usage: #{$0} <HTTP port> <JID> <Password> [Status message]"
10
+ exit
11
+ end
12
+ HTTP_PORT = ARGV.shift.to_i
13
+ JID = ARGV.shift
14
+ PASSWORD = ARGV.shift
15
+ STATUS_MESSAGE = ARGV.shift
16
+
17
+ def xml_namespaces(filename, excludes=[])
18
+ namespaces_recursive = nil
19
+ namespaces_recursive = lambda { |element|
20
+ namespaces = element.namespaces
21
+ element.each_element { |child|
22
+ namespaces.merge!(namespaces_recursive.call(child))
23
+ }
24
+ namespaces
25
+ }
26
+
27
+ root = REXML::Document.new(File.new(filename)).root
28
+ all = namespaces_recursive.call(root)
29
+ res = {}
30
+ all.each { |prefix,uri|
31
+ res[prefix] = uri unless excludes.include? prefix
32
+ }
33
+ res
34
+ end
35
+
36
+ Jabber::debug = true
37
+
38
+ class VcardCache < Jabber::Vcard::Helper
39
+ attr_reader :vcards
40
+
41
+ def initialize(stream)
42
+ super
43
+ @vcards = {}
44
+ end
45
+
46
+ def get(jid)
47
+ unless @vcards[jid]
48
+ begin
49
+ @vcards[jid] = super
50
+ rescue Jabber::ServerError
51
+ @vcards[jid] = :error
52
+ end
53
+ end
54
+
55
+ @vcards[jid]
56
+ end
57
+
58
+ def get_until(jid, timeout=10)
59
+ begin
60
+ Timeout::timeout(timeout) {
61
+ get(jid)
62
+ }
63
+ rescue Timeout::Error
64
+ @vcards[jid] = :timeout
65
+ end
66
+
67
+ @vcards[jid]
68
+ end
69
+ end
70
+
71
+ MAX_ITEMS = 50
72
+ $jid_items = []
73
+
74
+ $bot = Jabber::Framework::Bot.new(JID, PASSWORD)
75
+ class << $bot
76
+ def accept_subscription_from?(jid)
77
+ roster.add(jid, nil, true)
78
+ true
79
+ end
80
+ end
81
+ $vcards = VcardCache.new($bot.stream)
82
+ xml_namespaces('index.xsl', %w(xmlns xsl pa j p)).each { |prefix,node|
83
+ $bot.add_pep_notification(node) do |from,item|
84
+ from.strip!
85
+ item.add_namespace(Jabber::PubSub::NS_PUBSUB)
86
+ item.attributes['node'] = node
87
+ is_duplicate = false
88
+ $jid_items.each { |jid1,item1|
89
+ if jid1.to_s == from.to_s and node == item1.attributes['node']
90
+ is_duplicate = (item.to_s == item1.to_s)
91
+ break
92
+ end
93
+ }
94
+ unless is_duplicate
95
+ $jid_items.unshift([from, item])
96
+ $jid_items = $jid_items[0..(MAX_ITEMS-1)]
97
+ end
98
+ end
99
+ }
100
+
101
+ $bot.set_presence(nil, STATUS_MESSAGE || "Busy aggregating PEP events...")
102
+
103
+ class WebController < Ramaze::Controller
104
+ map '/'
105
+ template_root __DIR__
106
+ engine :XSLT
107
+
108
+ def index
109
+ "<?xml version='1.0' encoding='UTF-8'?>" +
110
+ "<items xmlns:jabber='jabber:client' jabber:to='#{Jabber::JID.new(JID).strip}'>" +
111
+ $jid_items.collect do |jid,item_orig|
112
+ item = item_orig.deep_clone
113
+ item.attributes['jabber:from'] = jid.to_s
114
+ vcard = $vcards.get_until(jid)
115
+ if vcard.kind_of? Jabber::Vcard::IqVcard
116
+ item.attributes['jabber:from-name'] = vcard['NICKNAME'] || vcard['FN'] || jid.node
117
+ item.attributes['jabber:has-avatar'] = (vcard['PHOTO/TYPE'] and
118
+ vcard['PHOTO/BINVAL']) ? 'true' : 'false'
119
+ else
120
+ item.attributes['jabber:from-name'] = jid.node
121
+ item.attributes['jabber:has-avatar'] = 'false'
122
+ end
123
+ item
124
+ end.join +
125
+ "</items>"
126
+ end
127
+
128
+ def avatar(jid)
129
+ trait :engine => :None
130
+
131
+ vcard = $vcards.get_until(jid)
132
+ if vcard.kind_of? Jabber::Vcard::IqVcard
133
+ if vcard['PHOTO/TYPE'] and vcard.photo_binval
134
+ response['Content-Type'] = vcard['PHOTO/TYPE']
135
+ response.body = vcard.photo_binval
136
+ else
137
+ response['Status'] = 404
138
+ end
139
+ else
140
+ response['Status'] = 404
141
+ end
142
+
143
+ throw :respond
144
+ end
145
+ end
146
+
147
+ Ramaze::start(:port => HTTP_PORT)
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'xmpp4r'
4
+ require 'xmpp4r/bytestreams/helper/filetransfer'
5
+
6
+ Jabber::debug = true
7
+
8
+ if ARGV.size != 3
9
+ puts "Usage: #{$0} <jid> <password> <incoming-directory>"
10
+ exit
11
+ end
12
+
13
+
14
+ #Jabber::debug = true
15
+
16
+ cl = Jabber::Client.new(Jabber::JID.new(ARGV[0]))
17
+ puts "Connecting Jabber client..."
18
+ cl.connect
19
+ puts "Authenticating..."
20
+ cl.auth ARGV[1]
21
+
22
+ ft = Jabber::FileTransfer::Helper.new(cl)
23
+ ft.add_incoming_callback { |iq,file|
24
+ puts "Incoming file transfer from #{iq.from}: #{file.fname} (#{file.size / 1024} KB)"
25
+
26
+ filename = "#{ARGV[2]}/#{file.fname.split(/\//).last}"
27
+ offset = nil
28
+ if File::exist?(filename)
29
+ puts "#{filename} already exists"
30
+ if File::size(filename) < file.size and file.range
31
+ offset = File::size(filename)
32
+ puts "Peer supports <range/>, will retrieve #{file.fname} starting at #{offset}"
33
+ else
34
+ puts "#{file.fname} is already fully retrieved, declining file-transfer"
35
+ ft.decline(iq)
36
+ next
37
+ end
38
+ end
39
+
40
+ Thread.new {
41
+ begin
42
+ puts "Accepting #{file.fname}"
43
+ stream = ft.accept(iq, offset)
44
+ if stream.kind_of?(Jabber::Bytestreams::SOCKS5Bytestreams)
45
+ stream.connect_timeout = 5
46
+ stream.add_streamhost_callback { |streamhost,state,e|
47
+ case state
48
+ when :connecting
49
+ puts "Connecting to #{streamhost.jid} (#{streamhost.host}:#{streamhost.port})"
50
+ when :success
51
+ puts "Successfully using #{streamhost.jid} (#{streamhost.host}:#{streamhost.port})"
52
+ when :failure
53
+ puts "Error using #{streamhost.jid} (#{streamhost.host}:#{streamhost.port}): #{e}"
54
+ end
55
+ }
56
+ end
57
+
58
+ puts "Waiting for stream configuration"
59
+ if stream.accept
60
+ puts "Stream established"
61
+ outfile = File.new(filename, (offset ? 'ab' : 'wb'))
62
+ while buf = stream.read(65536)
63
+ outfile.write(buf)
64
+ print '.'
65
+ $stdout.flush
66
+ end
67
+ puts '!'
68
+ outfile.close
69
+ stream.close
70
+ else
71
+ puts "Stream failed"
72
+ end
73
+ rescue Exception => e
74
+ puts "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
75
+ end
76
+ }
77
+ }
78
+
79
+ cl.send(Jabber::Presence.new(:chat, 'Send me files!'))
80
+
81
+ puts "Waiting."
82
+
83
+ Thread.stop
84
+
85
+ cl.close
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env 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-Discovery example
9
+ #
10
+ # If you don't understand this code read JEP-0030 (Service Discovery) first:
11
+ # http://www.jabber.org/jeps/jep-0030.html
12
+ #
13
+ # This examples exposes your roster to Service Discovery and can be browsed
14
+ # by anyone. Please use with care if you want to keep your roster private!
15
+ #
16
+ # The Psi client has a very pretty Service Discovery dialog. But be sure
17
+ # to turn off "Auto-browse into objects" for big rosters.
18
+ #
19
+
20
+ $:.unshift '../../../../../lib'
21
+
22
+ require 'thread'
23
+
24
+ require 'xmpp4r'
25
+ require 'xmpp4r/helpers/roster'
26
+ require 'xmpp4r/iq/query/discoinfo'
27
+ require 'xmpp4r/iq/query/discoitems'
28
+
29
+ # Command line argument checking
30
+
31
+ if ARGV.size != 2
32
+ puts("Usage: ./rosterdiscovery.rb <jid> <password>")
33
+ exit
34
+ end
35
+
36
+ # Building up the connection
37
+
38
+ #Jabber::debug = true
39
+
40
+ jid = Jabber::JID.new(ARGV[0])
41
+
42
+ cl = Jabber::Client.new(jid)
43
+ cl.connect
44
+ cl.auth(ARGV[1])
45
+
46
+
47
+ # The roster instance
48
+ roster = Jabber::Helpers::Roster.new(cl)
49
+
50
+
51
+ cl.add_iq_callback { |iq|
52
+ if iq.query.kind_of?(Jabber::IqQueryDiscoInfo) || iq.query.kind_of?(Jabber::IqQueryDiscoItems)
53
+
54
+ # Prepare the <iq/> stanza for result
55
+ iq.from, iq.to = iq.to, iq.from
56
+ iq.type = :result
57
+
58
+
59
+ if iq.query.kind_of?(Jabber::IqQueryDiscoInfo)
60
+ # iq.to and iq.from are already switched here:
61
+ puts("#{iq.to} requests info of #{iq.from} node #{iq.query.node.inspect}")
62
+
63
+ if iq.query.node.nil?
64
+ iq.query.add(Jabber::DiscoIdentity.new('directory', 'Roster discovery', 'user'))
65
+ else
66
+ # Count contacts in group
67
+ in_group = 0
68
+ roster.items.each { |jid,item|
69
+ if item.groups.include?(iq.query.node)
70
+ in_group += 1
71
+ end
72
+ }
73
+
74
+ iq.query.add(Jabber::DiscoIdentity.new('directory', "#{iq.query.node} (#{in_group})", 'group'))
75
+ end
76
+
77
+ iq.query.add(Jabber::DiscoFeature.new(Jabber::IqQueryDiscoInfo.new.namespace))
78
+ iq.query.add(Jabber::DiscoFeature.new(Jabber::IqQueryDiscoItems.new.namespace))
79
+
80
+ elsif iq.query.kind_of?(Jabber::IqQueryDiscoItems)
81
+ # iq.to and iq.from are already switched here:
82
+ puts("#{iq.to} requests items of #{iq.from} node #{iq.query.node.inspect}")
83
+
84
+ if iq.query.node.nil?
85
+ # Make items from group names
86
+ groups = []
87
+
88
+ roster.items.each { |jid,item|
89
+ groups += item.groups
90
+ }
91
+
92
+ groups.uniq.each { |group|
93
+ iq.query.add(Jabber::DiscoItem.new(cl.jid, group, group))
94
+ }
95
+
96
+ # Collect all ungrouped roster items
97
+ roster.items.each { |jid,item|
98
+ if item.groups == []
99
+ iq.query.add(Jabber::DiscoItem.new(item.jid, item.iname.to_s == '' ? item.jid : item.iname))
100
+ end
101
+ }
102
+ else
103
+ # Add a discovery item for each roster item in that group
104
+ roster.items.each { |jid,item|
105
+ if item.groups.include?(iq.query.node)
106
+ iq.query.add(Jabber::DiscoItem.new(item.jid, item.iname.to_s == '' ? item.jid : item.iname))
107
+ end
108
+ }
109
+ end
110
+
111
+ end
112
+
113
+ cl.send(iq)
114
+
115
+ true
116
+ end
117
+ }
118
+
119
+ # Initial presence
120
+ cl.send(Jabber::Presence.new.set_status("Discover my roster at #{jid}"))
121
+
122
+ # Main loop:
123
+
124
+ loop do
125
+ cl.process
126
+ Thread.stop
127
+ end
128
+
129
+ cl.close
@@ -0,0 +1,10 @@
1
+ ---
2
+ jabber:
3
+ jid: user@server/resource
4
+ password: password
5
+ local:
6
+ port: 65010
7
+ addresses: [172.22.16.3]
8
+ proxies:
9
+ - proxy.jabber.org
10
+ - transfer.jabber.freenet.de
@@ -0,0 +1,72 @@
1
+ require 'xmpp4r'
2
+ require 'xmpp4r/bytestreams'
3
+ require 'yaml'
4
+
5
+ Jabber::debug = true
6
+
7
+ if ARGV.size != 3
8
+ puts "Usage: #{$0} <jid> <description> <file>"
9
+ exit
10
+ end
11
+
12
+ conf = YAML::load File.new('sendfile.conf')
13
+
14
+ cl = Jabber::Client.new(Jabber::JID.new(conf['jabber']['jid']))
15
+ puts "Connecting Jabber client..."
16
+ cl.connect
17
+ puts "Authenticating..."
18
+ cl.auth conf['jabber']['password']
19
+
20
+ puts "Starting local Bytestreams server"
21
+ bss = Jabber::Bytestreams::SOCKS5BytestreamsServer.new(conf['local']['port'])
22
+ conf['local']['addresses'].each { |address|
23
+ bss.add_address(address)
24
+ }
25
+ ft = Jabber::FileTransfer::Helper.new(cl)
26
+ #ft.allow_bytestreams = false
27
+ source = Jabber::FileTransfer::FileSource.new(ARGV[2])
28
+ puts "Offering #{source.filename} to #{ARGV[0]}"
29
+ stream = ft.offer(Jabber::JID.new(ARGV[0]), source, ARGV[1])
30
+
31
+ if stream
32
+ puts "Starting stream initialization (#{stream.class})"
33
+
34
+ if stream.kind_of? Jabber::Bytestreams::SOCKS5BytestreamsInitiator
35
+ stream.add_streamhost(bss)
36
+ (conf['proxies'] || []).each { |proxy|
37
+ puts "Querying proxy #{proxy}"
38
+ stream.add_streamhost proxy
39
+ }
40
+ puts "Offering streamhosts " + stream.streamhosts.collect { |sh| sh.jid }.join(' ')
41
+
42
+ stream.add_streamhost_callback { |streamhost,state,e|
43
+ case state
44
+ when :connecting
45
+ puts "Connecting to #{streamhost.jid} (#{streamhost.host}:#{streamhost.port})"
46
+ when :success
47
+ puts "Successfully using #{streamhost.jid} (#{streamhost.host}:#{streamhost.port})"
48
+ when :failure
49
+ puts "Error using #{streamhost.jid} (#{streamhost.host}:#{streamhost.port}): #{e}"
50
+ end
51
+ }
52
+ end
53
+
54
+ stream.open
55
+ if stream.kind_of? Jabber::Bytestreams::SOCKS5BytestreamsInitiator
56
+ puts "Using streamhost #{stream.streamhost_used.jid} (#{stream.streamhost_used.host}:#{stream.streamhost_used.port})"
57
+ end
58
+
59
+ while buf = source.read
60
+ print "."
61
+ $stdout.flush
62
+ stream.write buf
63
+ stream.flush
64
+ end
65
+ puts "!"
66
+ stream.close
67
+
68
+ else
69
+ puts "Peer declined"
70
+ end
71
+
72
+ cl.close
@@ -0,0 +1,51 @@
1
+ require 'thread'
2
+
3
+ class Shell
4
+
5
+ PROMPT = "_-=READY=-_"
6
+
7
+ def initialize(shell = "/bin/bash", delay = 1, &block)
8
+ @cb = block
9
+ @shell = shell
10
+ @delay = delay
11
+ @parent_to_child_read, @parent_to_child_write = IO.pipe
12
+ @child_to_parent_read, @child_to_parent_write = IO.pipe
13
+ @child_pid = fork do
14
+ @parent_to_child_write.close
15
+ @child_to_parent_read.close
16
+ $stdin.reopen(@parent_to_child_read)
17
+ $stdout.reopen(@child_to_parent_write)
18
+ $stderr.reopen(@child_to_parent_write)
19
+ exec("/bin/bash")
20
+ end
21
+ buffer = ""
22
+ semaphore = Mutex.new
23
+ Thread.new do
24
+ while true
25
+ c = @child_to_parent_read.read(1)
26
+ semaphore.synchronize { buffer += c }
27
+ end
28
+ end
29
+ Thread.new do
30
+ ch = ""
31
+ while true do
32
+ sleep @delay
33
+ semaphore.synchronize {
34
+ if buffer == ch and ch != ""
35
+ @cb.call buffer
36
+ buffer = ""
37
+ end
38
+ ch = buffer
39
+ }
40
+ end
41
+ end
42
+ end
43
+
44
+ def puts(str)
45
+ @parent_to_child_write.puts(str)
46
+ end
47
+
48
+ def kill
49
+ @child_pid.kill
50
+ end
51
+ end