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,211 @@
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 Discovery
9
+ NS_DISCO_INFO = 'http://jabber.org/protocol/disco#info'
10
+
11
+ ##
12
+ # Class for handling Service Discovery queries,
13
+ # info
14
+ # (JEP 0030)
15
+ #
16
+ # This <query/> may contain multiple Identity and Feature
17
+ # elements, describing the type and the supported namespaces of
18
+ # the service.
19
+ class IqQueryDiscoInfo < IqQuery
20
+ name_xmlns 'query', NS_DISCO_INFO
21
+
22
+ ##
23
+ # Get the queried Service Discovery node or nil
24
+ #
25
+ # See IqQueryDiscoItems#node for a
26
+ # small explanation of this.
27
+ def node
28
+ attributes['node']
29
+ end
30
+
31
+ ##
32
+ # Set the queried Service Discovery node or nil
33
+ # val:: [String]
34
+ def node=(val)
35
+ attributes['node'] = val
36
+ end
37
+
38
+ ##
39
+ # Set the queried Service Discovery node or nil
40
+ # (chaining-friendly)
41
+ # val:: [String]
42
+ def set_node(val)
43
+ self.node = val
44
+ self
45
+ end
46
+
47
+ ##
48
+ # Get the first identity child
49
+ # result:: [Identity]
50
+ def identity
51
+ first_element('identity')
52
+ end
53
+
54
+ ##
55
+ # Get list of identities
56
+ # result:: [Array] of [Identity]
57
+ def identities
58
+ get_elements('identity')
59
+ end
60
+
61
+ ##
62
+ # Get list of features
63
+ # result:: [Array] of [String]
64
+ def features
65
+ res = []
66
+ each_element('feature') { |feature|
67
+ res.push(feature.var)
68
+ }
69
+ res
70
+ end
71
+ end
72
+
73
+
74
+ ##
75
+ # Service Discovery identity to add() to IqQueryDiscoInfo
76
+ #
77
+ # Please note that XEP 0030 requires both category and type to occur,
78
+ # for a reference see: http://www.xmpp.org/registrar/disco-categories.html
79
+ class Identity < XMPPElement
80
+ name_xmlns 'identity', NS_DISCO_INFO
81
+
82
+ ##
83
+ # Initialize a new Identity
84
+ # category:: [String] Initial category or nil
85
+ # iname:: [String] Initial identity name or nil
86
+ # type:: [String] Initial type or nil
87
+ def initialize(category=nil, iname=nil, type=nil)
88
+ super()
89
+ set_category(category)
90
+ set_iname(iname)
91
+ set_type(type)
92
+ end
93
+
94
+ ##
95
+ # Get the identity's category or nil
96
+ # result:: [String]
97
+ def category
98
+ attributes['category']
99
+ end
100
+
101
+ ##
102
+ # Set the identity's category
103
+ #
104
+ # Service Discovery categories should be somewhat
105
+ # standardized by some registry, so clients may
106
+ # represent specific categories by specific icons...
107
+ # (see http://www.jabber.org/registrar/disco-categories.html)
108
+ # val:: [String]
109
+ def category=(val)
110
+ attributes['category'] = val
111
+ end
112
+
113
+ ##
114
+ # Set the identity's category (chaining-friendly)
115
+ # val:: [String]
116
+ def set_category(val)
117
+ self.category = val
118
+ self
119
+ end
120
+
121
+ ##
122
+ # Get the identity's name or nil
123
+ #
124
+ # This has been renamed from <name/> to "iname" here
125
+ # to keep REXML::Element#name accessible
126
+ # result:: [String]
127
+ def iname
128
+ attributes['name']
129
+ end
130
+
131
+ ##
132
+ # Set the identity's name
133
+ # val:: [String]
134
+ def iname=(val)
135
+ attributes['name'] = val
136
+ end
137
+
138
+ ##
139
+ # Set the identity's name (chaining-friendly)
140
+ # val:: [String]
141
+ def set_iname(val)
142
+ self.iname = val
143
+ self
144
+ end
145
+
146
+ ##
147
+ # Get the identity's type or nil
148
+ # result:: [String]
149
+ def type
150
+ attributes['type']
151
+ end
152
+
153
+ ##
154
+ # Set the identity's type
155
+ # (see http://www.jabber.org/registrar/disco-categories.html)
156
+ # val:: [String]
157
+ def type=(val)
158
+ attributes['type'] = val
159
+ end
160
+
161
+ ##
162
+ # Set the identity's type (chaining-friendly)
163
+ # val:: [String]
164
+ def set_type(val)
165
+ self.type = val
166
+ self
167
+ end
168
+ end
169
+
170
+ ##
171
+ # Service Discovery feature to add() to IqQueryDiscoInfo
172
+ #
173
+ # Please note that JEP 0030 requires var to be set,
174
+ # for a reference see: http://www.xmpp.org/registrar/disco-features.html
175
+ class Feature < XMPPElement
176
+ name_xmlns 'feature', NS_DISCO_INFO
177
+
178
+ ##
179
+ # Create a new <feature/> element
180
+ # var:: [String] New var
181
+ def initialize(var=nil)
182
+ super()
183
+ set_var(var)
184
+ end
185
+
186
+ ##
187
+ # Get the feature's var or nil
188
+ # result:: [String]
189
+ def var
190
+ attributes['var']
191
+ end
192
+
193
+ ##
194
+ # Set the feature's var
195
+ #
196
+ # This is a namespace the identity supports.
197
+ # val:: [String]
198
+ def var=(val)
199
+ attributes['var'] = val
200
+ end
201
+
202
+ ##
203
+ # Set the feature's var (chaining-friendly)
204
+ # val:: [String]
205
+ def set_var(val)
206
+ self.var = val
207
+ self
208
+ end
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,147 @@
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 Discovery
9
+ NS_DISCO_ITEMS = 'http://jabber.org/protocol/disco#items'
10
+
11
+ ##
12
+ # Class for handling Service Discovery queries,
13
+ # items
14
+ # (JEP 0030)
15
+ #
16
+ # This <query/> may contain multiple Item elements,
17
+ # describing multiple services to be browsed by Jabber clients.
18
+ # These may then get further information about these items by
19
+ # querying IqQueryDiscoInfo and further sub-items by querying
20
+ # IqQueryDiscoItems.
21
+ class IqQueryDiscoItems < IqQuery
22
+ name_xmlns 'query', NS_DISCO_ITEMS
23
+
24
+ ##
25
+ # Get the queried Service Discovery node or nil
26
+ #
27
+ # A Service Discovery node is _not_ a JID node,
28
+ # this may be a bit confusing. It's just to make
29
+ # Service Discovery browsing a bit more structured.
30
+ def node
31
+ attributes['node']
32
+ end
33
+
34
+ ##
35
+ # Set the queried Service Discovery node or nil
36
+ def node=(val)
37
+ attributes['node'] = val
38
+ end
39
+
40
+ ##
41
+ # Set the queried Service Discovery node or nil
42
+ # (chaining-friendly)
43
+ def set_node(val)
44
+ self.node = val
45
+ self
46
+ end
47
+
48
+ ##
49
+ # Get all item children
50
+ # result:: Array of [Discovery::Item]
51
+ def items
52
+ get_elements('item')
53
+ end
54
+ end
55
+
56
+
57
+ ##
58
+ # Service Discovery item to add() to IqQueryDiscoItems
59
+ #
60
+ # Please note that JEP 0030 requires the jid to occur
61
+ class Item < XMPPElement
62
+ name_xmlns 'item', NS_DISCO_ITEMS
63
+
64
+ ##
65
+ # Initialize a new Service Discovery <item/>
66
+ # to be added to IqQueryDiscoItems
67
+ # jid:: [JID]
68
+ # iname:: [String] Item name
69
+ # node:: [String] Service Discovery node (_not_ JID#node)
70
+ def initialize(jid=nil, iname=nil, node=nil)
71
+ super()
72
+ set_jid(jid)
73
+ set_iname(iname)
74
+ set_node(node)
75
+ end
76
+
77
+ ##
78
+ # Get the item's jid or nil
79
+ # result:: [String]
80
+ def jid
81
+ JID.new(attributes['jid'])
82
+ end
83
+
84
+ ##
85
+ # Set the item's jid
86
+ # val:: [JID]
87
+ def jid=(val)
88
+ attributes['jid'] = val.to_s
89
+ end
90
+
91
+ ##
92
+ # Set the item's jid (chaining-friendly)
93
+ # val:: [JID]
94
+ def set_jid(val)
95
+ self.jid = val
96
+ self
97
+ end
98
+
99
+ ##
100
+ # Get the item's name or nil
101
+ #
102
+ # This has been renamed from <name/> to "iname" here
103
+ # to keep REXML::Element#name accessible
104
+ # result:: [String]
105
+ def iname
106
+ attributes['name']
107
+ end
108
+
109
+ ##
110
+ # Set the item's name
111
+ # val:: [String]
112
+ def iname=(val)
113
+ attributes['name'] = val
114
+ end
115
+
116
+ ##
117
+ # Set the item's name (chaining-friendly)
118
+ # val:: [String]
119
+ def set_iname(val)
120
+ self.iname = val
121
+ self
122
+ end
123
+
124
+ ##
125
+ # Get the item's Service Discovery node or nil
126
+ # result:: [String]
127
+ def node
128
+ attributes['node']
129
+ end
130
+
131
+ ##
132
+ # Set the item's Service Discovery node
133
+ # val:: [String]
134
+ def node=(val)
135
+ attributes['node'] = val
136
+ end
137
+
138
+ ##
139
+ # Set the item's Service Discovery node (chaining-friendly)
140
+ # val:: [String]
141
+ def set_node(val)
142
+ self.node = val
143
+ self
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,8 @@
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/discovery/iq/discoinfo'
6
+ require 'xmpp4r/discovery/iq/discoitems'
7
+ require 'xmpp4r/discovery/helper/helper'
8
+ require 'xmpp4r/discovery/helper/responder'
@@ -0,0 +1,283 @@
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
+ module Jabber
6
+
7
+ # CUSTOM ERROR CLASSES
8
+
9
+ # All of our custom errors are superclassed by JabberError < StandardError
10
+ class JabberError < StandardError; end
11
+
12
+ # A client-side only argument error
13
+ class ArgumentError < JabberError; end
14
+
15
+ ##
16
+ # An error returned from the server
17
+ #
18
+ # e.g. This exception can be raised by helpers when they
19
+ # receive a server reply with <tt>type='error'</tt>
20
+ #
21
+ # The ServerError carries a Jabber::ErrorResponse element
22
+ #
23
+ class ServerError < JabberError #:nodoc:
24
+
25
+ ##
26
+ # The error element which caused this exception
27
+ attr_reader :error
28
+
29
+ ##
30
+ # Initialize a ServerError by passing an ErrorResponse instance
31
+ # error:: [Error]
32
+ def initialize(error)
33
+ @error = error
34
+ end
35
+
36
+ ##
37
+ # Sample output:
38
+ # 'subscription-required: Please subscribe first'
39
+ def to_s
40
+ "#{@error.error}: #{@error.text}"
41
+ end
42
+ end
43
+
44
+ class ClientAuthenticationFailure < JabberError; end
45
+
46
+ class ComponentAuthenticationFailure < JabberError; end
47
+
48
+ # TODO : Give this a better name
49
+ class NoNameXmlnsRegistered < JabberError
50
+ def initialize(klass)
51
+ super "Class #{klass} has not set name and xmlns"
52
+ end
53
+ end
54
+
55
+ # TODO : Give this a better name
56
+ class SOCKS5Error < JabberError; end
57
+
58
+ class InvalidChatState < JabberError; end
59
+
60
+ ##
61
+ # A class used to build/parse <error/> elements.
62
+ # Look at XEP-0086 for explanation:
63
+ # http://www.xmpp.org/extensions/xep-0086.html
64
+ #
65
+ # FIXME : XEP-0086 is officially deprecated. What effect does that have on this class? Any?
66
+ #
67
+ class ErrorResponse < XMPPElement
68
+ name_xmlns 'error'
69
+
70
+ ##
71
+ # errorcondition:: [nil] or [String] of the following:
72
+ # * "bad-request"
73
+ # * "conflict"
74
+ # * "feature-not-implemented"
75
+ # * "forbidden"
76
+ # * "gone"
77
+ # * "internal-server-error"
78
+ # * "item-not-found"
79
+ # * "jid-malformed"
80
+ # * "not-acceptable"
81
+ # * "not-allowed"
82
+ # * "not-authorized"
83
+ # * "payment-required"
84
+ # * "recipient-unavailable"
85
+ # * "redirect"
86
+ # * "registration-required"
87
+ # * "remote-server-not-found"
88
+ # * "remote-server-timeout"
89
+ # * "resource-constraint"
90
+ # * "service-unavailable"
91
+ # * "subscription-required"
92
+ # * "undefined-condition"
93
+ # * "unexpected-request"
94
+ # Will raise an [Exception] if not [nil] and none of the above
95
+ #
96
+ # Also sets type and code to appropriate values according to errorcondition
97
+ #
98
+ # text: [nil] or [String] ErrorResponse text
99
+ def initialize(errorcondition=nil, text=nil)
100
+ if errorcondition.nil?
101
+ super()
102
+ set_text(text) unless text.nil?
103
+ else
104
+ errortype = nil
105
+ errorcode = nil
106
+ @@Errors.each { |cond,type,code|
107
+ if errorcondition == cond
108
+ errortype = type
109
+ errorcode = code
110
+ end
111
+ }
112
+
113
+ if errortype.nil? || errorcode.nil?
114
+ raise ArgumentError, "Unknown error condition when initializing ErrorReponse"
115
+ end
116
+
117
+ super()
118
+ set_error(errorcondition)
119
+ set_type(errortype)
120
+ set_code(errorcode)
121
+ set_text(text) unless text.nil?
122
+ end
123
+ end
124
+
125
+ ##
126
+ # Get the 'Legacy error code' or nil
127
+ # result:: [Integer] Error code
128
+ def code
129
+ if attributes['code']
130
+ attributes['code'].to_i
131
+ else
132
+ nil
133
+ end
134
+ end
135
+
136
+ ##
137
+ # Set the 'Legacy error code' or nil
138
+ # i:: [Integer] Error code
139
+ def code=(i)
140
+ if i.nil?
141
+ attributes['code'] = nil
142
+ else
143
+ attributes['code'] = i.to_s
144
+ end
145
+ end
146
+
147
+ ##
148
+ # Set the 'Legacy error code' (chaining-friendly)
149
+ def set_code(i)
150
+ self.code = i
151
+ self
152
+ end
153
+
154
+ ##
155
+ # Get the 'XMPP error condition'
156
+ #
157
+ # This can be anything that possess the specific namespace,
158
+ # checks don't apply here
159
+ def error
160
+ name = nil
161
+ each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
162
+ name
163
+ end
164
+
165
+ ##
166
+ # Set the 'XMPP error condition'
167
+ #
168
+ # One previous element with that namespace will be deleted before
169
+ #
170
+ # s:: [String] Name of the element to be added,
171
+ # namespace will be added automatically, checks don't apply here
172
+ def error=(s)
173
+ xe = nil
174
+ each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
175
+ unless xe.nil?
176
+ delete_element(xe)
177
+ end
178
+
179
+ add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
180
+ end
181
+
182
+ ##
183
+ # Set the 'XMPP error condition' (chaining-friendly)
184
+ def set_error(s)
185
+ self.error = s
186
+ self
187
+ end
188
+
189
+ ##
190
+ # Get the errors <text/> element text
191
+ # result:: [String] or nil
192
+ def text
193
+ first_element_text('text') || super
194
+ end
195
+
196
+ ##
197
+ # Set the errors <text/> element text
198
+ # (Previous <text/> elements will be deleted first)
199
+ # s:: [String] <text/> content or [nil] if no <text/> element
200
+ def text=(s)
201
+ delete_elements('text')
202
+
203
+ unless s.nil?
204
+ e = add_element('text')
205
+ e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
206
+ e.text = s
207
+ end
208
+ end
209
+
210
+ ##
211
+ # Set the errors <text/> element text (chaining-friendly)
212
+ def set_text(s)
213
+ self.text = s
214
+ self
215
+ end
216
+
217
+ ##
218
+ # Get the type of error
219
+ # (meaning how to proceed)
220
+ # result:: [Symbol] or [nil] as following:
221
+ # * :auth
222
+ # * :cancel
223
+ # * :continue
224
+ # * :modify
225
+ # * :wait
226
+ def type
227
+ case attributes['type']
228
+ when 'auth' then :auth
229
+ when 'cancel' then :cancel
230
+ when 'continue' then :continue
231
+ when 'modify' then :modify
232
+ when 'wait' then :wait
233
+ else nil
234
+ end
235
+ end
236
+
237
+ ##
238
+ # Set the type of error (see ErrorResponse#type)
239
+ def type=(t)
240
+ case t
241
+ when :auth then attributes['type'] = 'auth'
242
+ when :cancel then attributes['type'] = 'cancel'
243
+ when :continue then attributes['type'] = 'continue'
244
+ when :modify then attributes['type'] = 'modify'
245
+ when :wait then attributes['type'] = 'wait'
246
+ else attributes['type'] = nil
247
+ end
248
+ end
249
+
250
+ ##
251
+ # Set the type of error (chaining-friendly)
252
+ def set_type(t)
253
+ self.type = t
254
+ self
255
+ end
256
+
257
+ ##
258
+ # Possible XMPP error conditions, types and codes (XEP-0086)
259
+ @@Errors = [['bad-request', :modify, 400],
260
+ ['conflict', :cancel, 409],
261
+ ['feature-not-implemented', :cancel, 501],
262
+ ['forbidden', :auth, 403],
263
+ ['gone', :modify, 302],
264
+ ['internal-server-error', :wait, 500],
265
+ ['item-not-found', :cancel, 404],
266
+ ['jid-malformed', :modify, 400],
267
+ ['not-acceptable', :modify, 406],
268
+ ['not-allowed', :cancel, 405],
269
+ ['not-authorized', :auth, 401],
270
+ ['payment-required', :auth, 402],
271
+ ['recipient-unavailable', :wait, 404],
272
+ ['redirect', :modify, 302],
273
+ ['registration-required', :auth, 407],
274
+ ['remote-server-not-found', :cancel, 404],
275
+ ['remote-server-timeout', :wait, 504],
276
+ ['resource-constraint', :wait, 500],
277
+ ['service-unavailable', :cancel, 503],
278
+ ['subscription-required', :auth, 407],
279
+ ['undefined-condition', nil, 500],
280
+ ['unexpected-request', :wait, 400]]
281
+ end
282
+
283
+ end
@@ -0,0 +1,28 @@
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/dataforms/x/data'
7
+
8
+ module Jabber
9
+ module FeatureNegotiation
10
+ ##
11
+ # Feature negotiation,
12
+ # can appear as direct child to Iq
13
+ # or as child of IqSi
14
+ class IqFeature < XMPPElement
15
+ name_xmlns 'feature', 'http://jabber.org/protocol/feature-neg'
16
+
17
+ ##
18
+ # First <x/> child with xmlns='jabber:x:data'
19
+ def x
20
+ res = nil
21
+ each_element('x') { |e|
22
+ res = e if e.namespace == 'jabber:x:data'
23
+ }
24
+ res
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
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/feature_negotiation/iq/feature.rb'