ln-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. data/CHANGELOG +91 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +59 -0
  4. data/README.rdoc +113 -0
  5. data/README_ruby19.txt +43 -0
  6. data/Rakefile +252 -0
  7. data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
  8. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
  9. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
  10. data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
  11. data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
  12. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
  13. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
  15. data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
  16. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
  17. data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
  18. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  19. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  20. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  21. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +84 -0
  22. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
  23. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  24. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  25. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  26. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  27. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  28. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
  29. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
  30. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
  31. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  32. data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
  33. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  34. data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
  35. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  36. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
  37. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
  38. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
  39. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
  40. data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
  41. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  42. data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
  43. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  44. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  45. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
  46. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
  47. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  48. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  49. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  50. data/lib/xmpp4r.rb +116 -0
  51. data/lib/xmpp4r/base64.rb +32 -0
  52. data/lib/xmpp4r/bytestreams.rb +15 -0
  53. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +319 -0
  54. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
  55. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
  56. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
  57. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +152 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
  60. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
  61. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +79 -0
  62. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
  63. data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
  64. data/lib/xmpp4r/callbacks.rb +133 -0
  65. data/lib/xmpp4r/caps.rb +1 -0
  66. data/lib/xmpp4r/caps/c.rb +67 -0
  67. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  68. data/lib/xmpp4r/caps/helper/helper.rb +84 -0
  69. data/lib/xmpp4r/client.rb +344 -0
  70. data/lib/xmpp4r/command/helper/responder.rb +53 -0
  71. data/lib/xmpp4r/command/iq/command.rb +154 -0
  72. data/lib/xmpp4r/component.rb +103 -0
  73. data/lib/xmpp4r/connection.rb +223 -0
  74. data/lib/xmpp4r/dataforms.rb +5 -0
  75. data/lib/xmpp4r/dataforms/x/data.rb +297 -0
  76. data/lib/xmpp4r/debuglog.rb +63 -0
  77. data/lib/xmpp4r/delay.rb +5 -0
  78. data/lib/xmpp4r/delay/x/delay.rb +99 -0
  79. data/lib/xmpp4r/discovery.rb +8 -0
  80. data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
  81. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  82. data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
  83. data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
  84. data/lib/xmpp4r/errors.rb +284 -0
  85. data/lib/xmpp4r/feature_negotiation.rb +5 -0
  86. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
  87. data/lib/xmpp4r/framework/base.rb +55 -0
  88. data/lib/xmpp4r/framework/bot.rb +148 -0
  89. data/lib/xmpp4r/httpbinding.rb +5 -0
  90. data/lib/xmpp4r/httpbinding/client.rb +275 -0
  91. data/lib/xmpp4r/idgenerator.rb +37 -0
  92. data/lib/xmpp4r/iq.rb +221 -0
  93. data/lib/xmpp4r/jid.rb +167 -0
  94. data/lib/xmpp4r/last.rb +2 -0
  95. data/lib/xmpp4r/last/helper/helper.rb +37 -0
  96. data/lib/xmpp4r/last/iq/last.rb +67 -0
  97. data/lib/xmpp4r/location.rb +2 -0
  98. data/lib/xmpp4r/location/helper/helper.rb +56 -0
  99. data/lib/xmpp4r/location/location.rb +179 -0
  100. data/lib/xmpp4r/message.rb +180 -0
  101. data/lib/xmpp4r/muc.rb +14 -0
  102. data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
  103. data/lib/xmpp4r/muc/helper/mucclient.rb +462 -0
  104. data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
  105. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  106. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  107. data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
  108. data/lib/xmpp4r/muc/item.rb +143 -0
  109. data/lib/xmpp4r/muc/x/muc.rb +70 -0
  110. data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
  111. data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
  112. data/lib/xmpp4r/presence.rb +232 -0
  113. data/lib/xmpp4r/pubsub.rb +8 -0
  114. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  115. data/lib/xmpp4r/pubsub/children/event.rb +49 -0
  116. data/lib/xmpp4r/pubsub/children/item.rb +35 -0
  117. data/lib/xmpp4r/pubsub/children/items.rb +53 -0
  118. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  119. data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
  120. data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
  121. data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
  122. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  123. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
  124. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
  125. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
  126. data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
  127. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +456 -0
  128. data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  129. data/lib/xmpp4r/query.rb +15 -0
  130. data/lib/xmpp4r/reliable.rb +168 -0
  131. data/lib/xmpp4r/rexmladdons.rb +157 -0
  132. data/lib/xmpp4r/roster.rb +7 -0
  133. data/lib/xmpp4r/roster/helper/roster.rb +522 -0
  134. data/lib/xmpp4r/roster/iq/roster.rb +215 -0
  135. data/lib/xmpp4r/roster/x/roster.rb +138 -0
  136. data/lib/xmpp4r/rpc.rb +2 -0
  137. data/lib/xmpp4r/rpc/helper/client.rb +123 -0
  138. data/lib/xmpp4r/rpc/helper/server.rb +74 -0
  139. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
  140. data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
  141. data/lib/xmpp4r/sasl.rb +248 -0
  142. data/lib/xmpp4r/semaphore.rb +38 -0
  143. data/lib/xmpp4r/stream.rb +599 -0
  144. data/lib/xmpp4r/streamparser.rb +85 -0
  145. data/lib/xmpp4r/test/listener_mocker.rb +118 -0
  146. data/lib/xmpp4r/tune.rb +2 -0
  147. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  148. data/lib/xmpp4r/tune/tune.rb +113 -0
  149. data/lib/xmpp4r/vcard.rb +6 -0
  150. data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
  151. data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
  152. data/lib/xmpp4r/version.rb +7 -0
  153. data/lib/xmpp4r/version/helper/responder.rb +72 -0
  154. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  155. data/lib/xmpp4r/version/iq/version.rb +105 -0
  156. data/lib/xmpp4r/x.rb +37 -0
  157. data/lib/xmpp4r/xhtml.rb +1 -0
  158. data/lib/xmpp4r/xhtml/html.rb +115 -0
  159. data/lib/xmpp4r/xmpp4r.rb +20 -0
  160. data/lib/xmpp4r/xmppelement.rb +168 -0
  161. data/lib/xmpp4r/xmppstanza.rb +162 -0
  162. data/setup.rb +1586 -0
  163. data/test/bytestreams/tc_ibb.rb +188 -0
  164. data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
  165. data/test/caps/tc_helper.rb +158 -0
  166. data/test/dataforms/tc_data.rb +81 -0
  167. data/test/delay/tc_xdelay.rb +51 -0
  168. data/test/discovery/tc_responder.rb +91 -0
  169. data/test/last/tc_helper.rb +75 -0
  170. data/test/lib/assert_equal_xml.rb +14 -0
  171. data/test/lib/clienttester.rb +149 -0
  172. data/test/muc/tc_muc_mucclient.rb +834 -0
  173. data/test/muc/tc_muc_simplemucclient.rb +114 -0
  174. data/test/muc/tc_mucowner.rb +50 -0
  175. data/test/pubsub/tc_helper.rb +785 -0
  176. data/test/pubsub/tc_nodeconfig.rb +61 -0
  177. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  178. data/test/reliable/tc_disconnect_cleanup.rb +334 -0
  179. data/test/reliable/tc_disconnect_exception.rb +37 -0
  180. data/test/reliable/tc_listener_mocked_test.rb +68 -0
  181. data/test/reliable/tc_reliable_connection.rb +31 -0
  182. data/test/roster/tc_helper.rb +524 -0
  183. data/test/roster/tc_iqqueryroster.rb +173 -0
  184. data/test/roster/tc_xroster.rb +73 -0
  185. data/test/rpc/tc_helper.rb +96 -0
  186. data/test/tc_callbacks.rb +129 -0
  187. data/test/tc_class_names.rb +146 -0
  188. data/test/tc_client.rb +30 -0
  189. data/test/tc_errors.rb +146 -0
  190. data/test/tc_idgenerator.rb +30 -0
  191. data/test/tc_iq.rb +113 -0
  192. data/test/tc_iqquery.rb +31 -0
  193. data/test/tc_jid.rb +204 -0
  194. data/test/tc_message.rb +131 -0
  195. data/test/tc_presence.rb +150 -0
  196. data/test/tc_rexml.rb +139 -0
  197. data/test/tc_stream.rb +167 -0
  198. data/test/tc_streamComponent.rb +95 -0
  199. data/test/tc_streamError.rb +129 -0
  200. data/test/tc_streamSend.rb +59 -0
  201. data/test/tc_streamparser.rb +125 -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 +238 -0
  215. metadata +280 -0
@@ -0,0 +1,109 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/iq'
6
+ require 'xmpp4r/base64'
7
+
8
+ module Jabber
9
+ module Vcard
10
+ ##
11
+ # vCard container for User Information
12
+ # (can be specified by users themselves, mostly kept on servers)
13
+ # (JEP 0054)
14
+ class IqVcard < XMPPElement
15
+ name_xmlns 'vCard', 'vcard-temp'
16
+ force_xmlns true
17
+
18
+ ##
19
+ # Initialize a <vCard/> element
20
+ # fields:: [Hash] Initialize with keys as XPath element names and values for element texts
21
+ def initialize(fields=nil)
22
+ super()
23
+
24
+ unless fields.nil?
25
+ fields.each { |name,value|
26
+ self[name] = value
27
+ }
28
+ end
29
+ end
30
+
31
+ ##
32
+ # Get an elements/fields text
33
+ #
34
+ # vCards have too much possible children, so ask for them here
35
+ # and extract the result with iqvcard.element('...').text
36
+ # name:: [String] XPath
37
+ def [](name)
38
+ text = nil
39
+ each_element(name) { |child| text = child.text }
40
+ text
41
+ end
42
+
43
+ ##
44
+ # Set an elements/fields text
45
+ # name:: [String] XPath
46
+ # text:: [String] Value
47
+ def []=(name, text)
48
+ xe = self
49
+ name.split(/\//).each do |elementname|
50
+ # Does the children already exist?
51
+ newxe = nil
52
+ xe.each_element(elementname) { |child| newxe = child }
53
+
54
+ if newxe.nil?
55
+ # Create a new
56
+ xe = xe.add_element(elementname)
57
+ else
58
+ # Or take existing
59
+ xe = newxe
60
+ end
61
+ end
62
+ xe.text = text
63
+ end
64
+
65
+ ##
66
+ # Get vCard field names
67
+ #
68
+ # Example:
69
+ # ["NICKNAME", "BDAY", "ORG/ORGUNIT", "PHOTO/TYPE", "PHOTO/BINVAL"]
70
+ #
71
+ # result:: [Array] of [String]
72
+ def fields
73
+ element_names(self).uniq
74
+ end
75
+
76
+ ##
77
+ # Get the PHOTO/BINVAL (Avatar picture) field decoded from Base64
78
+ # result:: [String] or [nil]
79
+ def photo_binval
80
+ if (binval = self['PHOTO/BINVAL'])
81
+ Base64::decode64(binval)
82
+ else
83
+ nil
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ ##
90
+ # Recursive helper function,
91
+ # returns all element names in an array, concatenated
92
+ # to their parent's name with a slash
93
+ def element_names(xe, prefix='') # :nodoc:
94
+ res = []
95
+ xe.each_element { |child|
96
+ if child.kind_of?(REXML::Element)
97
+ children = element_names(child, "#{prefix}#{child.name}/")
98
+ if children == []
99
+ res.push("#{prefix}#{child.name}")
100
+ else
101
+ res += children
102
+ end
103
+ end
104
+ }
105
+ res
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,7 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/version/helper/responder.rb'
6
+ require 'xmpp4r/version/helper/simpleresponder.rb'
7
+ require 'xmpp4r/version/iq/version.rb'
@@ -0,0 +1,72 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/callbacks'
6
+ require 'xmpp4r/version/iq/version'
7
+
8
+ module Jabber
9
+ module Version
10
+ ##
11
+ # A class to answer version requests using IqQueryVersion
12
+ #
13
+ # If you don't need the flexibility of dynamic responses with
14
+ # the callback you can register with add_version_callback,
15
+ # take a look at SimpleResponder
16
+ class Responder
17
+ ##
18
+ # Initialize a new version responder
19
+ #
20
+ # Registers it's callback (prio = 180, ref = self)
21
+ # stream:: [Stream] Where to register callback handlers
22
+ def initialize(stream)
23
+ @stream = stream
24
+ @versioncbs = CallbackList.new
25
+
26
+ stream.add_iq_callback(180, self) { |iq|
27
+ iq_callback(iq)
28
+ }
29
+ end
30
+
31
+ ##
32
+ # Add a callback for Iq stanzas with IqQueryVersion
33
+ #
34
+ # First argument passed to block is the Iq stanza,
35
+ # second argument is a block, which can be called with
36
+ # software name, version and os
37
+ #
38
+ # Example:
39
+ # my_version_helper.add_version_callback { |iq,block|
40
+ # block.call('Cool client', '6.0', 'Cool OS')
41
+ # }
42
+ def add_version_callback(priority = 0, ref = nil, &block)
43
+ @versioncbs.add(priority, ref, block)
44
+ end
45
+
46
+ ##
47
+ # <iq/> callback handler to answer Software Version queries
48
+ # (registered by constructor and used internally only)
49
+ #
50
+ # Used internally
51
+ def iq_callback(iq)
52
+ if iq.type == :get
53
+ if iq.query.kind_of?(IqQueryVersion)
54
+ replyblock = lambda { |name,version,os|
55
+ answer = iq.answer
56
+ answer.type = :result
57
+ answer.query.set_iname(name).set_version(version).set_os(os)
58
+
59
+ @stream.send(answer)
60
+ true
61
+ }
62
+ @versioncbs.process(iq, replyblock)
63
+ else
64
+ false
65
+ end
66
+ else
67
+ false
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,44 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/iq'
6
+ require 'xmpp4r/version/helper/responder'
7
+
8
+ module Jabber
9
+ module Version
10
+ ##
11
+ # A class to answer version requests using IqQueryVersion
12
+ #
13
+ # This is simplification as one doesn't need dynamic
14
+ # version answering normally.
15
+ #
16
+ # Example usage:
17
+ # Jabber::Version::SimpleResponder.new(my_client, "My cool XMPP4R script", "1.0", "Younicks")
18
+ class SimpleResponder < Responder
19
+ attr_accessor :name
20
+ attr_accessor :version
21
+ attr_accessor :os
22
+
23
+ ##
24
+ # Initialize a new version responder
25
+ #
26
+ # Registers it's callback (prio = 180, ref = self)
27
+ # stream:: [Stream] Where to register callback handlers
28
+ # name:: [String] Software name for answers
29
+ # version:: [String] Software versio for answers
30
+ # os:: [String] Optional operating system name for answers
31
+ def initialize(stream, name, version, os=nil)
32
+ super stream
33
+
34
+ @name = name
35
+ @version = version
36
+ @os = os
37
+
38
+ add_version_callback(180, self) { |iq,block|
39
+ block.call(@name, @version, @os)
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,105 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/query'
6
+
7
+ module Jabber
8
+ module Version
9
+ ##
10
+ # Class for handling queries for 'Software Version'
11
+ # (JEP 0092)
12
+ #
13
+ # Notice that according to JEP 0092 only the <os/> element can be omitted,
14
+ # <name/> (iname) and <version/> must be present
15
+ class IqQueryVersion < IqQuery
16
+ name_xmlns 'query', 'jabber:iq:version'
17
+
18
+ ##
19
+ # Create a new <query xmlns='jabber:iq:version'/> element
20
+ def initialize(iname=nil, version=nil, os=nil)
21
+ super()
22
+ set_iname(iname) if iname
23
+ set_version(version) if version
24
+ set_os(os) if os
25
+ end
26
+
27
+ ##
28
+ # Get the name of the software
29
+ #
30
+ # This has been renamed to 'iname' here to keep
31
+ # REXML::Element#name accessible
32
+ def iname
33
+ first_element_text('name')
34
+ end
35
+
36
+ ##
37
+ # Set the name of the software
38
+ #
39
+ # The element won't be deleted if text is nil as
40
+ # it must occur in a version query, but its text will
41
+ # be empty.
42
+ def iname=(text)
43
+ replace_element_text('name', text.nil? ? '' : text)
44
+ end
45
+
46
+ ##
47
+ # Set the name of the software (chaining-friendly)
48
+ # result:: [String] or nil
49
+ def set_iname(text)
50
+ self.iname = text
51
+ self
52
+ end
53
+
54
+ ##
55
+ # Get the version of the software
56
+ # result:: [String] or nil
57
+ def version
58
+ first_element_text('version')
59
+ end
60
+
61
+ ##
62
+ # Set the version of the software
63
+ #
64
+ # The element won't be deleted if text is nil as
65
+ # it must occur in a version query
66
+ def version=(text)
67
+ replace_element_text('version', text.nil? ? '' : text)
68
+ end
69
+
70
+ ##
71
+ # Set the version of the software (chaining-friendly)
72
+ # text:: [String]
73
+ def set_version(text)
74
+ self.version = text
75
+ self
76
+ end
77
+
78
+ ##
79
+ # Get the operating system or nil
80
+ # (os is not mandatory for Version Query)
81
+ def os
82
+ first_element_text('os')
83
+ end
84
+
85
+ ##
86
+ # Set the os of the software
87
+ # text:: [String] or nil
88
+ def os=(text)
89
+ if text
90
+ replace_element_text('os', text)
91
+ else
92
+ delete_elements('os')
93
+ end
94
+ end
95
+
96
+ ##
97
+ # Set the os of the software (chaining-friendly)
98
+ # text:: [String] or nil
99
+ def set_os(text)
100
+ self.os = text
101
+ self
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,37 @@
1
+ # =XMPP4R - XMPP Library for Ruby
2
+ # License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
3
+ # Website::http://home.gna.org/xmpp4r/
4
+
5
+ require 'xmpp4r/xmppelement'
6
+
7
+ module Jabber
8
+ ##
9
+ # A class used to build/parse <x/> elements
10
+ #
11
+ # These elements may occur as "attachments"
12
+ # in [Message] and [Presence] stanzas
13
+ class X < XMPPElement
14
+ name_xmlns 'x'
15
+ force_xmlns true
16
+ end
17
+
18
+ module XParent
19
+ ##
20
+ # Get the first <x/> element in this stanza, or nil if none found.
21
+ # wanted_xmlns:: [String] Optional, find the first <x/> element having this xmlns,
22
+ # wanted_xmlns can also be a derivate of XMPPElement from which the namespace will be taken
23
+ # result:: [REXML::Element] or nil
24
+ def x(wanted_xmlns=nil)
25
+ if wanted_xmlns.kind_of? Class and wanted_xmlns.ancestors.include? XMPPElement
26
+ wanted_xmlns = wanted_xmlns.new.namespace
27
+ end
28
+
29
+ each_element('x') { |x|
30
+ if wanted_xmlns.nil? or wanted_xmlns == x.namespace
31
+ return x
32
+ end
33
+ }
34
+ nil
35
+ end
36
+ end
37
+ end
@@ -0,0 +1 @@
1
+ require 'xmpp4r/xhtml/html'
@@ -0,0 +1,115 @@
1
+ require 'xmpp4r/xmppelement'
2
+
3
+ module Jabber
4
+ module XHTML
5
+ NS_XHTML_IM = 'http://jabber.org/protocol/xhtml-im'
6
+ NS_XHTML = 'http://www.w3.org/1999/xhtml'
7
+
8
+ ##
9
+ # XHTML-IM (XEP-0071) container
10
+ #
11
+ # The important methods are:
12
+ # * HTML#contents=
13
+ # * HTML#to_text
14
+ class HTML < XMPPElement
15
+ name_xmlns 'html', NS_XHTML_IM
16
+ force_xmlns true
17
+
18
+ ##
19
+ # Initialize element with HTML contents (see HTML#contents=)
20
+ def initialize(contents=[])
21
+ super()
22
+ self.contents = contents
23
+ end
24
+
25
+ ##
26
+ # Get first XHTML::Body child
27
+ def body
28
+ first_element('body') || add(Body.new)
29
+ end
30
+
31
+ ##
32
+ # Replace first XHTML::Body child
33
+ def body=(body)
34
+ delete_elements('body')
35
+ add(body)
36
+ end
37
+
38
+ ##
39
+ # Replace first XHTML::Body child (chainable)
40
+ def set_body(body)
41
+ self.body = body
42
+ self
43
+ end
44
+
45
+ ##
46
+ # Set contents of this HTML document. The "contents" parameter can be:
47
+ # * An Array of REXML::Element and Strings which will replace the current children of the body
48
+ # * A single REXML::Element which will replace all other children of the body
49
+ # * An instance of XHTML::Body which will replace the current body
50
+ # * A String comprising an HTML fragment. This will be parsed, which could raise an Exception.
51
+ # We must never send invalid XML over an XMPP stream. If you intend to put variable data in
52
+ # your HTML, use something like Rails' Builder::XmlMarkup or Ramaze::Gestalt
53
+ def contents=(contents)
54
+ if contents.kind_of? String
55
+ self.body = REXML::Document.new("<body xmlns='#{NS_XHTML}'>#{contents}</body>").root
56
+ elsif contents.kind_of? Body
57
+ self.body = contents
58
+ elsif contents.kind_of? Array
59
+ self.body = Body.new
60
+ contents.each do |element|
61
+ if element.kind_of? String
62
+ body.add_text(element)
63
+ else
64
+ body.add(element)
65
+ end
66
+ end
67
+ else
68
+ self.body = Body.new
69
+ body.add(contents)
70
+ end
71
+ end
72
+
73
+ ##
74
+ # HTML#contents= chainable
75
+ def set_contents(contents)
76
+ self.contents = contents
77
+ self
78
+ end
79
+
80
+ ##
81
+ # Convert contents of this XHTML container to plain text
82
+ # for easy usage with an additional fall-back <body/> in message stanzas
83
+ #
84
+ # The resulting string is recursively composed of the text nodes of
85
+ # all children.
86
+ # This works because of the design criteria of HTML/XHTML:
87
+ # readable content is not being put into attributes but as text children.
88
+ #
89
+ # If you require clickable links and proper information representation
90
+ # then compose the text yourself!
91
+ def to_text
92
+ text_getter = nil # Create binding so that the following lambda can work recursively
93
+
94
+ text_getter = lambda do |element|
95
+ if element.kind_of? REXML::Text
96
+ element.value
97
+ elsif element.kind_of? REXML::Element
98
+ element.children.collect { |child|
99
+ text_getter.call(child)
100
+ }.join
101
+ end
102
+ end
103
+
104
+ text_getter.call(self) # Finally, execute and return results
105
+ end
106
+ end
107
+
108
+ ##
109
+ # HTML Body element, must be the only child of XHTML::HTML
110
+ class Body < XMPPElement
111
+ name_xmlns 'body', NS_XHTML
112
+ force_xmlns true
113
+ end
114
+ end
115
+ end