mojodna-xmpp4r 0.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. data/CHANGELOG +83 -0
  2. data/COPYING +340 -0
  3. data/LICENSE +59 -0
  4. data/README.rdoc +133 -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/base64.rb +32 -0
  51. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +319 -0
  52. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
  53. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
  54. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +47 -0
  55. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +152 -0
  56. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
  57. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +73 -0
  60. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
  61. data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
  62. data/lib/xmpp4r/bytestreams.rb +15 -0
  63. data/lib/xmpp4r/callbacks.rb +133 -0
  64. data/lib/xmpp4r/caps/c.rb +67 -0
  65. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  66. data/lib/xmpp4r/caps/helper/helper.rb +87 -0
  67. data/lib/xmpp4r/caps.rb +1 -0
  68. data/lib/xmpp4r/client.rb +344 -0
  69. data/lib/xmpp4r/command/helper/responder.rb +53 -0
  70. data/lib/xmpp4r/command/iq/command.rb +154 -0
  71. data/lib/xmpp4r/component.rb +103 -0
  72. data/lib/xmpp4r/connection.rb +219 -0
  73. data/lib/xmpp4r/dataforms/x/data.rb +297 -0
  74. data/lib/xmpp4r/dataforms.rb +5 -0
  75. data/lib/xmpp4r/debuglog.rb +42 -0
  76. data/lib/xmpp4r/delay/x/delay.rb +99 -0
  77. data/lib/xmpp4r/delay.rb +5 -0
  78. data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
  79. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  80. data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
  81. data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
  82. data/lib/xmpp4r/discovery.rb +8 -0
  83. data/lib/xmpp4r/errors.rb +283 -0
  84. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
  85. data/lib/xmpp4r/feature_negotiation.rb +5 -0
  86. data/lib/xmpp4r/framework/base.rb +55 -0
  87. data/lib/xmpp4r/framework/bot.rb +148 -0
  88. data/lib/xmpp4r/httpbinding/client.rb +275 -0
  89. data/lib/xmpp4r/httpbinding.rb +5 -0
  90. data/lib/xmpp4r/idgenerator.rb +37 -0
  91. data/lib/xmpp4r/iq.rb +221 -0
  92. data/lib/xmpp4r/jid.rb +167 -0
  93. data/lib/xmpp4r/last/helper/helper.rb +37 -0
  94. data/lib/xmpp4r/last/iq/last.rb +67 -0
  95. data/lib/xmpp4r/last.rb +2 -0
  96. data/lib/xmpp4r/location/helper/helper.rb +56 -0
  97. data/lib/xmpp4r/location/location.rb +179 -0
  98. data/lib/xmpp4r/location.rb +2 -0
  99. data/lib/xmpp4r/message.rb +181 -0
  100. data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
  101. data/lib/xmpp4r/muc/helper/mucclient.rb +462 -0
  102. data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
  103. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  104. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  105. data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
  106. data/lib/xmpp4r/muc/item.rb +143 -0
  107. data/lib/xmpp4r/muc/x/muc.rb +70 -0
  108. data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
  109. data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
  110. data/lib/xmpp4r/muc.rb +14 -0
  111. data/lib/xmpp4r/presence.rb +232 -0
  112. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  113. data/lib/xmpp4r/pubsub/children/event.rb +49 -0
  114. data/lib/xmpp4r/pubsub/children/item.rb +35 -0
  115. data/lib/xmpp4r/pubsub/children/items.rb +53 -0
  116. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  117. data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
  118. data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
  119. data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
  120. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  121. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
  122. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +130 -0
  123. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
  124. data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +107 -0
  125. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +456 -0
  126. data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  127. data/lib/xmpp4r/pubsub.rb +8 -0
  128. data/lib/xmpp4r/query.rb +15 -0
  129. data/lib/xmpp4r/rexmladdons.rb +157 -0
  130. data/lib/xmpp4r/roster/helper/roster.rb +519 -0
  131. data/lib/xmpp4r/roster/iq/roster.rb +215 -0
  132. data/lib/xmpp4r/roster/x/roster.rb +138 -0
  133. data/lib/xmpp4r/roster.rb +7 -0
  134. data/lib/xmpp4r/rpc/helper/client.rb +123 -0
  135. data/lib/xmpp4r/rpc/helper/server.rb +74 -0
  136. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
  137. data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
  138. data/lib/xmpp4r/rpc.rb +2 -0
  139. data/lib/xmpp4r/sasl.rb +243 -0
  140. data/lib/xmpp4r/semaphore.rb +38 -0
  141. data/lib/xmpp4r/stream.rb +531 -0
  142. data/lib/xmpp4r/streamparser.rb +81 -0
  143. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  144. data/lib/xmpp4r/tune/tune.rb +113 -0
  145. data/lib/xmpp4r/tune.rb +2 -0
  146. data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
  147. data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
  148. data/lib/xmpp4r/vcard.rb +6 -0
  149. data/lib/xmpp4r/version/helper/responder.rb +72 -0
  150. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  151. data/lib/xmpp4r/version/iq/version.rb +105 -0
  152. data/lib/xmpp4r/version.rb +7 -0
  153. data/lib/xmpp4r/x.rb +37 -0
  154. data/lib/xmpp4r/xhtml/html.rb +115 -0
  155. data/lib/xmpp4r/xhtml.rb +1 -0
  156. data/lib/xmpp4r/xmpp4r.rb +18 -0
  157. data/lib/xmpp4r/xmppelement.rb +168 -0
  158. data/lib/xmpp4r/xmppstanza.rb +162 -0
  159. data/lib/xmpp4r.rb +116 -0
  160. data/setup.rb +1586 -0
  161. data/test/bytestreams/tc_ibb.rb +186 -0
  162. data/test/bytestreams/tc_socks5bytestreams.rb +113 -0
  163. data/test/caps/tc_helper.rb +156 -0
  164. data/test/dataforms/tc_data.rb +81 -0
  165. data/test/delay/tc_xdelay.rb +51 -0
  166. data/test/discovery/tc_responder.rb +91 -0
  167. data/test/lib/assert_equal_xml.rb +14 -0
  168. data/test/lib/clienttester.rb +120 -0
  169. data/test/muc/tc_muc_mucclient.rb +830 -0
  170. data/test/muc/tc_muc_simplemucclient.rb +114 -0
  171. data/test/muc/tc_mucowner.rb +50 -0
  172. data/test/pubsub/tc_helper.rb +722 -0
  173. data/test/pubsub/tc_nodeconfig.rb +54 -0
  174. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  175. data/test/roster/tc_helper.rb +514 -0
  176. data/test/roster/tc_iqqueryroster.rb +173 -0
  177. data/test/roster/tc_xroster.rb +73 -0
  178. data/test/rpc/tc_helper.rb +96 -0
  179. data/test/tc_callbacks.rb +129 -0
  180. data/test/tc_class_names.rb +146 -0
  181. data/test/tc_client.rb +30 -0
  182. data/test/tc_errors.rb +146 -0
  183. data/test/tc_idgenerator.rb +30 -0
  184. data/test/tc_iq.rb +113 -0
  185. data/test/tc_iqquery.rb +31 -0
  186. data/test/tc_jid.rb +204 -0
  187. data/test/tc_message.rb +132 -0
  188. data/test/tc_presence.rb +150 -0
  189. data/test/tc_rexml.rb +139 -0
  190. data/test/tc_stream.rb +229 -0
  191. data/test/tc_streamComponent.rb +95 -0
  192. data/test/tc_streamError.rb +131 -0
  193. data/test/tc_streamSend.rb +59 -0
  194. data/test/tc_streamparser.rb +120 -0
  195. data/test/tc_xmppstanza.rb +135 -0
  196. data/test/ts_xmpp4r.rb +53 -0
  197. data/test/tune/tc_helper_recv.rb +84 -0
  198. data/test/tune/tc_helper_send.rb +74 -0
  199. data/test/tune/tc_tune.rb +79 -0
  200. data/test/vcard/tc_helper.rb +49 -0
  201. data/test/vcard/tc_iqvcard.rb +62 -0
  202. data/test/version/tc_helper.rb +60 -0
  203. data/test/version/tc_iqqueryversion.rb +97 -0
  204. data/test/xhtml/tc_html.rb +41 -0
  205. data/tools/gen_requires.bash +31 -0
  206. data/tools/xmpp4r-gemspec-test.rb +11 -0
  207. data/xmpp4r.gemspec +304 -0
  208. metadata +346 -0
@@ -0,0 +1,18 @@
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
+ ##
6
+ # The Jabber module is the root namespace of the library.
7
+ module Jabber
8
+ # XMPP4R Version number. This is the ONLY place where the version number
9
+ # should be specified. This constant is used to determine the version of
10
+ # package tarballs and generated gems.
11
+ XMPP4R_VERSION = '0.4.0.2'
12
+ end
13
+
14
+ require 'xmpp4r/client'
15
+ require 'xmpp4r/component'
16
+ require 'xmpp4r/debuglog'
17
+ require 'xmpp4r/errors'
18
+
@@ -0,0 +1,168 @@
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/rexmladdons'
6
+
7
+ module Jabber
8
+
9
+ ##
10
+ # This class represents an XML element and provides functionality
11
+ # for automatic casting of XML element classes according to their
12
+ # element name and namespace.
13
+ #
14
+ # Deriving classes must met these criteria:
15
+ # * The element name and namespace must be specified by calling
16
+ # the name_xmlns class method
17
+ # * The class constructor must be callable with no mandatory parameter
18
+ class XMPPElement < REXML::Element
19
+ @@name_xmlns_classes = {}
20
+ @@force_xmlns = false
21
+
22
+ ##
23
+ # Specify XML element name and xmlns for a deriving class,
24
+ # this pair and the class will be added to a global pool
25
+ #
26
+ # If the namespace is nil the class is a "wildcard class"
27
+ # matching elements with any xmlns if no other class with
28
+ # that namespace was defined
29
+ def self.name_xmlns(name, xmlns=nil)
30
+ @@name_xmlns_classes[[name, xmlns]] = self
31
+ end
32
+
33
+ ##
34
+ # Set whether this element is always built with an xmlns attribute
35
+ def self.force_xmlns(force)
36
+ @@force_xmlns = force
37
+ end
38
+
39
+ ##
40
+ # Whether this element is always built with an xmlns attribute
41
+ def self.force_xmlns?
42
+ @@force_xmlns
43
+ end
44
+
45
+ ##
46
+ # Find the name and namespace for a given class.
47
+ # This class must have registered these two values
48
+ # by calling name_xmlns at definition time.
49
+ #
50
+ # Raises an exception if none was found
51
+ # klass:: [Class]
52
+ # result:: [String, String] name and namespace
53
+ def self.name_xmlns_for_class(klass)
54
+ klass.ancestors.each do |klass1|
55
+ @@name_xmlns_classes.each do |name_xmlns,k|
56
+ if klass1 == k
57
+ return name_xmlns
58
+ end
59
+ end
60
+ end
61
+
62
+ raise NoNameXmlnsRegistered.new(klass)
63
+ end
64
+
65
+ ##
66
+ # Find a class for given name and namespace
67
+ # name:: [String]
68
+ # xmlns:: [String]
69
+ # result:: A descendant of XMPPElement or REXML::Element
70
+ def self.class_for_name_xmlns(name, xmlns)
71
+ if @@name_xmlns_classes.has_key? [name, xmlns]
72
+ @@name_xmlns_classes[[name, xmlns]]
73
+ elsif @@name_xmlns_classes.has_key? [name, nil]
74
+ @@name_xmlns_classes[[name, nil]]
75
+ else
76
+ REXML::Element
77
+ end
78
+ end
79
+
80
+ ##
81
+ # Import another REXML::Element descendant to:
82
+ # * Either an element class that registered with
83
+ # name and xmlns before
84
+ # * Or if none was found to the class itself
85
+ # (you may call this class method on a deriving class)
86
+ def self.import(element)
87
+ klass = class_for_name_xmlns(element.name, element.namespace)
88
+ if klass != self and klass.ancestors.include?(self)
89
+ klass.new.import(element)
90
+ else
91
+ self.new.import(element)
92
+ end
93
+ end
94
+
95
+ ##
96
+ # Initialize this element, which will then be initialized
97
+ # with the name registered with name_xmlns.
98
+ def initialize(*arg)
99
+ if arg.empty?
100
+ name, xmlns = self.class::name_xmlns_for_class(self.class)
101
+ super(name)
102
+ if self.class::force_xmlns?
103
+ add_namespace(xmlns)
104
+ end
105
+ else
106
+ super
107
+ end
108
+ end
109
+
110
+ ##
111
+ # Add a child element which will be imported according to the
112
+ # child's name and xmlns
113
+ # element:: [REXML::Element] Child
114
+ # result:: [REXML::Element or descendant of XMPPElement] New child
115
+ def typed_add(element)
116
+ if element.kind_of? REXML::Element
117
+ element_ns = (element.namespace.to_s == '') ? namespace : element.namespace
118
+
119
+ klass = XMPPElement::class_for_name_xmlns(element.name, element_ns)
120
+ if klass != element.class
121
+ element = klass.import(element)
122
+ end
123
+ end
124
+
125
+ super(element)
126
+ end
127
+
128
+ def parent=(new_parent)
129
+ if parent and parent.namespace('') == namespace('') and attributes['xmlns'].nil?
130
+ add_namespace parent.namespace('')
131
+ end
132
+
133
+ super
134
+
135
+ if new_parent and new_parent.namespace('') == namespace('')
136
+ delete_namespace
137
+ end
138
+ end
139
+
140
+ def clone
141
+ cloned = self.class.new
142
+ cloned.add_attributes self.attributes.clone
143
+ cloned.context = @context
144
+ cloned
145
+ end
146
+
147
+ ##
148
+ # Generic XML attribute 'xml:lang'
149
+ # (REXML provides no shortcut)
150
+ def xml_lang
151
+ attributes['xml:lang']
152
+ end
153
+
154
+ ##
155
+ # Set XML language attribute
156
+ def xml_lang=(l)
157
+ attributes['xml:lang'] = l
158
+ end
159
+
160
+ ##
161
+ # Set XML language attribute (chainable)
162
+ def set_xml_lang(l)
163
+ self.xml_lang = l
164
+ self
165
+ end
166
+
167
+ end
168
+ end
@@ -0,0 +1,162 @@
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
+ require 'xmpp4r/errors'
7
+ require 'xmpp4r/jid'
8
+
9
+ module Jabber
10
+ ##
11
+ # root class of all Jabber XML elements
12
+ class XMPPStanza < XMPPElement
13
+ ##
14
+ # Compose a response by doing the following:
15
+ # * Create a new XMPPStanza of the same subclass
16
+ # with the same element-name
17
+ # * Import xmppstanza if import is true
18
+ # * Swap 'to' and 'from'
19
+ # * Copy 'id'
20
+ # * Does not take care about the type
21
+ #
22
+ # *Attention*: Be careful when answering to stanzas with
23
+ # <tt>type == :error</tt> - answering to an error may generate
24
+ # another error on the other side, which could be leading to a
25
+ # ping-pong effect quickly!
26
+ #
27
+ # xmppstanza:: [XMPPStanza] source
28
+ # import:: [true or false] Copy attributes and children of source
29
+ # result:: [XMPPStanza] answer stanza
30
+ def XMPPStanza.answer(xmppstanza, import=true)
31
+ x = xmppstanza.class.new
32
+ if import
33
+ x.import(xmppstanza)
34
+ end
35
+ x.from = xmppstanza.to
36
+ x.to = xmppstanza.from
37
+ x.id = xmppstanza.id
38
+ x
39
+ end
40
+
41
+ ##
42
+ # Return the first <tt><error/></tt> child
43
+ def error
44
+ first_element('error')
45
+ end
46
+
47
+ ##
48
+ # Compose a response of this XMPPStanza
49
+ # (see XMPPStanza.answer)
50
+ # result:: [XMPPStanza] New constructed stanza
51
+ def answer(import=true)
52
+ XMPPStanza.answer(self, import)
53
+ end
54
+
55
+ ##
56
+ # Makes some changes to the structure of an XML element to help
57
+ # it respect the specification. For example, in a message, we should
58
+ # have <subject/> < <body/> < { rest of tags }
59
+ def normalize
60
+ end
61
+
62
+ ##
63
+ # get the to attribute
64
+ #
65
+ # return:: [String] the element's to attribute
66
+ def to
67
+ (a = attribute('to')).nil? ? a : JID.new(a.value)
68
+ end
69
+
70
+ ##
71
+ # set the to attribute
72
+ #
73
+ # v:: [String] the value to set
74
+ def to= (v)
75
+ add_attribute('to', v ? v.to_s : nil)
76
+ end
77
+
78
+ ##
79
+ # set the to attribute (chaining-friendly)
80
+ #
81
+ # v:: [String] the value to set
82
+ def set_to(v)
83
+ self.to = v
84
+ self
85
+ end
86
+
87
+ ##
88
+ # get the from attribute
89
+ #
90
+ # return:: [String] the element's from attribute
91
+ def from
92
+ (a = attribute('from')).nil? ? a : JID.new(a.value)
93
+ end
94
+
95
+ ##
96
+ # set the from attribute
97
+ #
98
+ # v:: [String] the value from set
99
+ def from= (v)
100
+ add_attribute('from', v ? v.to_s : nil)
101
+ end
102
+
103
+ ##
104
+ # set the from attribute (chaining-friendly)
105
+ #
106
+ # v:: [String] the value from set
107
+ def set_from(v)
108
+ add_attribute('from', v ? v.to_s : nil)
109
+ self
110
+ end
111
+
112
+ ##
113
+ # get the id attribute
114
+ #
115
+ # return:: [String] the element's id attribute
116
+ def id
117
+ (a = attribute('id')).nil? ? a : a.value
118
+ end
119
+
120
+ ##
121
+ # set the id attribute
122
+ #
123
+ # v:: [String] the value id set
124
+ def id= (v)
125
+ add_attribute('id', v.to_s)
126
+ end
127
+
128
+ ##
129
+ # set the id attribute (chaining-friendly)
130
+ #
131
+ # v:: [String] the value id set
132
+ def set_id(v)
133
+ add_attribute('id', v.to_s)
134
+ self
135
+ end
136
+
137
+ ##
138
+ # get the type attribute
139
+ #
140
+ # return:: [String] the element's type attribute
141
+ def type
142
+ (a = attribute('type')).nil? ? a : a.value
143
+ end
144
+
145
+ ##
146
+ # set the type attribute
147
+ #
148
+ # v:: [String] the value type set
149
+ def type= (v)
150
+ add_attribute('type', v)
151
+ end
152
+
153
+ ##
154
+ # set the type attribute (chaining-friendly)
155
+ #
156
+ # v:: [String] the value type set
157
+ def set_type(v)
158
+ add_attribute('type', v)
159
+ self
160
+ end
161
+ end
162
+ end
data/lib/xmpp4r.rb ADDED
@@ -0,0 +1,116 @@
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
+ # ==Introduction
6
+ #
7
+ # XMPP4R is a XMPP/Jabber library for Ruby. It can be used to build scripts
8
+ # using Jabber, full-featured Jabber clients, and components. It is written
9
+ # with extensibility in mind.
10
+ #
11
+ # ==XML management
12
+ #
13
+ # All the XML parsing is REXML's, and XML stanzas like <message/> (class
14
+ # <tt>Jabber::Message</tt>) or <iq/> (class <tt>Jabber::Iq</tt>) are indirect
15
+ # derivatives from REXML's Element class. This provide a maximum flexibity:
16
+ # the user can access attributes and childs using either the XMPP4R's helpers
17
+ # or directly using REXML's methods.
18
+ #
19
+ # ===Automatic element casting
20
+ #
21
+ # Because there are special classes derived from REXML::Element to ease
22
+ # development on the protocol level, Elements must be cast to them. This is
23
+ # done via REXML::Element.import. This method is also used in import class
24
+ # methods of some Element classes.
25
+ #
26
+ # The first occurance of this feature is in Jabber::Stream::receive:
27
+ # * <tt><message/></tt> stanzas are cast to Jabber::Message class
28
+ # * <tt><presence/></tt> stanzas are cast to Jabber::Presence class
29
+ # * <tt><iq/></tt> stanzas are cast to Jabber::Iq class
30
+ #
31
+ # This is not only useful for stanzas but all other XML processing, too:
32
+ # * <tt><x/></tt> children elements of <tt><message/></tt> and <tt><presence/></tt> are converted to Jabber::X
33
+ # * <tt><error/></tt> children elements of all three stanzas are converted to Jabber::ErrorResponse
34
+ # * <tt><query/></tt> children elements of <tt><iq/></tt> are converted to Jabber::IqQuery
35
+ # * <tt><vCard/></tt> children elements of <tt><iq/></tt> are converted to Jabber::IqVcard
36
+ #
37
+ # The following conversion facilities are only executed if the respective
38
+ # library parts are loaded. See below for more details on Non-basic features.
39
+ # * Jabber::IqQuery elements are converted to Jabber::Roster::IqQueryRoster if their
40
+ # namespace is 'jabber:iq:roster'
41
+ # * Jabber::IqQuery elements are converted to Jabber::Version::IqQueryVersion if their
42
+ # namespace is 'jabber:iq:version'
43
+ # * Jabber::IqQuery elements are converted to Jabber::Discovery::IqQueryDiscoInfo if their
44
+ # namespace is 'http://jabber.org/protocol/disco#info'
45
+ # * Jabber::IqQuery elements are converted to Jabber::Discovery::IqQueryDiscoItems if their
46
+ # namespace is 'http://jabber.org/protocol/disco#items'
47
+ # * <tt><item/></tt> children elements of Jabber::Roster::IqQueryRoster are converted
48
+ # to Jabber::Roster::RosterItem
49
+ # * <tt><identity/></tt> children elements of Jabber::IqQueryDiscoInfo are converted
50
+ # to Jabber::Discovery::DiscoIdentity
51
+ # * <tt><feature/></tt> children elements of Jabber::IqQueryDiscoInfo are converted
52
+ # to Jabber::Discovery::DiscoFeature
53
+ # * <tt><item/></tt> children elements of Jabber::IqQueryDiscoItems are converted
54
+ # to Jabber::Discovery::DiscoItem
55
+ #
56
+ # To use this, don't check for:
57
+ # <tt>iq.queryns == 'http://jabber.org/protocol/disco#info'</tt>
58
+ #
59
+ # But instead check for the query's class:
60
+ # <tt>iq.query.kind_of?(Jabber::IqQueryDiscoInfo)</tt>
61
+ #
62
+ # ==Where to begin?
63
+ #
64
+ # Because it is built in an extensible way, it might be hard for newcomers to
65
+ # understand where to look at documentation for a specific method. For example,
66
+ # Client inherits from Connection, which itself inherits from Stream.
67
+ #
68
+ # A newcomer should have a look at the <tt>Jabber::Client</tt> and
69
+ # <tt>Jabber::Component</tt> classes, and their parent classes
70
+ # <tt>Jabber::Connection</tt> and <tt>Jabber::Stream</tt>. The best way to
71
+ # understand how to use them is probably to look at the examples in the
72
+ # <tt>examples/</tt> dir.
73
+ #
74
+ # ==Non-basic features
75
+ #
76
+ # <tt>require 'xmpp4r'</tt> only includes basic functionality for
77
+ # Connections, Authentication, Stream processing, Callbacks, Stanza handling
78
+ # and Debugging to keep the library's footprint small.
79
+ #
80
+ # There is code for features that aren't required by a *basic* client. These
81
+ # must be additionally included to use them.
82
+ #
83
+ # ===Protocol-level features
84
+ #
85
+ # You're highly advised to read the according RFCs and JEPs if you intend to
86
+ # use them. The benefit will be that you'll understand the protocols and be
87
+ # going to be more efficient when programming with them.
88
+ #
89
+ # * Jabber::Bytestreams, Jabber::FileTransfer: <tt>require 'xmpp4r/bytestreams'</tt>
90
+ # * Jabber::Dataforms: <tt>require 'xmpp4r/dataforms'</tt>
91
+ # * Jabber::Delay: <tt>require 'xmpp4r/delay'</tt>
92
+ # * Jabber::Discovery: <tt>require 'xmpp4r/discovery'</tt>
93
+ # * Jabber::FeatureNegotiation: <tt>require 'xmpp4r/feature_negotiation'</tt>
94
+ # * Jabber::MUC: <tt>require 'xmpp4r/muc'</tt>
95
+ # * Jabber::Roster: <tt>require 'xmpp4r/roster'</tt>
96
+ # * Jabber::Vcard: <tt>require 'xmpp4r/vcard'</tt>
97
+ # * Jabber::Version: <tt>require 'xmpp4r/version'</tt>
98
+ #
99
+ # ===Helpers
100
+ #
101
+ # Helpers are intended to give more simplistic interfaces to various tasks
102
+ # of Jabber clients at the cost of flexibility. But you won't need that
103
+ # level of flexibility in most cases.
104
+ #
105
+ # * Jabber::Roster::Helper: <tt>require 'xmpp4r/roster'</tt>
106
+ # * Jabber::MUC::MUCBrowser, Jabber::MUC::MUCClient, Jabber::MUC::SimpleMUCClient: <tt>require 'xmpp4r/muc'</tt>
107
+ # * Jabber::Version::SimpleResponder, Jabber::Version::Responder: <tt>require 'xmpp4r/version'</tt>
108
+ # * Jabber::Vcard::Helper: <tt>require 'xmpp4r/vcard'</tt>
109
+ # * Jabber::FileTransfer::Helper, Jabber::Bytestreams::SOCKS5BytestreamsServer: <tt>require 'xmpp4r/bytestreams'</tt>
110
+ #
111
+ # ==Debugging
112
+ #
113
+ # Dumping your Jabber stream can be enabled this way:
114
+ # Jabber::debug = true
115
+
116
+ require 'xmpp4r/xmpp4r'