xmpp4r 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/COPYING +340 -0
  2. data/ChangeLog +28 -0
  3. data/LICENSE +59 -0
  4. data/README +20 -0
  5. data/Rakefile +103 -0
  6. data/UPDATING +40 -0
  7. data/data/doc/xmpp4r/examples/advanced/adventure/README +57 -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 +425 -0
  13. data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
  14. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +344 -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 +89 -0
  18. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
  19. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +83 -0
  20. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +130 -0
  21. data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
  22. data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
  23. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
  24. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
  25. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
  26. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +90 -0
  27. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +134 -0
  28. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +9 -0
  29. data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
  30. data/data/doc/xmpp4r/examples/basic/client.rb +68 -0
  31. data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
  32. data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +32 -0
  33. data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +32 -0
  34. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
  35. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +67 -0
  36. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +39 -0
  37. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +83 -0
  38. data/data/doc/xmpp4r/examples/basic/register.rb +25 -0
  39. data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
  40. data/data/doc/xmpp4r/examples/basic/roster.rb +42 -0
  41. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
  42. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
  43. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +172 -0
  44. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +68 -0
  45. data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
  46. data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +18 -0
  47. data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +192 -0
  48. data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +82 -0
  49. data/lib/callbacks.rb +122 -0
  50. data/lib/xmpp4r/authenticationfailure.rb +13 -0
  51. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +315 -0
  52. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +256 -0
  53. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +30 -0
  54. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +46 -0
  55. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +151 -0
  56. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +85 -0
  57. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +178 -0
  58. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +56 -0
  59. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +61 -0
  60. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +177 -0
  61. data/lib/xmpp4r/bytestreams/iq/si.rb +221 -0
  62. data/lib/xmpp4r/bytestreams.rb +11 -0
  63. data/lib/xmpp4r/client.rb +249 -0
  64. data/lib/xmpp4r/component.rb +103 -0
  65. data/lib/xmpp4r/connection.rb +166 -0
  66. data/lib/xmpp4r/dataforms/x/data.rb +248 -0
  67. data/lib/xmpp4r/dataforms.rb +1 -0
  68. data/lib/xmpp4r/debuglog.rb +34 -0
  69. data/lib/xmpp4r/delay/x/delay.rb +100 -0
  70. data/lib/xmpp4r/delay.rb +1 -0
  71. data/lib/xmpp4r/discovery/iq/discoinfo.rb +225 -0
  72. data/lib/xmpp4r/discovery/iq/discoitems.rb +162 -0
  73. data/lib/xmpp4r/discovery.rb +2 -0
  74. data/lib/xmpp4r/error.rb +230 -0
  75. data/lib/xmpp4r/errorexception.rb +32 -0
  76. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +42 -0
  77. data/lib/xmpp4r/feature_negotiation.rb +1 -0
  78. data/lib/xmpp4r/idgenerator.rb +37 -0
  79. data/lib/xmpp4r/iq.rb +229 -0
  80. data/lib/xmpp4r/jid.rb +167 -0
  81. data/lib/xmpp4r/message.rb +171 -0
  82. data/lib/xmpp4r/muc/helper/mucbrowser.rb +107 -0
  83. data/lib/xmpp4r/muc/helper/mucclient.rb +382 -0
  84. data/lib/xmpp4r/muc/helper/simplemucclient.rb +222 -0
  85. data/lib/xmpp4r/muc/x/muc.rb +98 -0
  86. data/lib/xmpp4r/muc/x/mucuserinvite.rb +58 -0
  87. data/lib/xmpp4r/muc/x/mucuseritem.rb +148 -0
  88. data/lib/xmpp4r/muc.rb +6 -0
  89. data/lib/xmpp4r/presence.rb +255 -0
  90. data/lib/xmpp4r/query.rb +43 -0
  91. data/lib/xmpp4r/rexmladdons.rb +826 -0
  92. data/lib/xmpp4r/roster/helper/roster.rb +514 -0
  93. data/lib/xmpp4r/roster/iq/roster.rb +244 -0
  94. data/lib/xmpp4r/roster/x/roster.rb +155 -0
  95. data/lib/xmpp4r/roster.rb +4 -0
  96. data/lib/xmpp4r/sasl.rb +167 -0
  97. data/lib/xmpp4r/stream.rb +543 -0
  98. data/lib/xmpp4r/streamparser.rb +77 -0
  99. data/lib/xmpp4r/vcard/helper/vcard.rb +86 -0
  100. data/lib/xmpp4r/vcard/iq/vcard.rb +102 -0
  101. data/lib/xmpp4r/vcard.rb +3 -0
  102. data/lib/xmpp4r/version/helper/responder.rb +71 -0
  103. data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
  104. data/lib/xmpp4r/version/iq/version.rb +118 -0
  105. data/lib/xmpp4r/version.rb +3 -0
  106. data/lib/xmpp4r/x.rb +43 -0
  107. data/lib/xmpp4r/xmlstanza.rb +174 -0
  108. data/lib/xmpp4r/xmpp4r.rb +16 -0
  109. data/lib/xmpp4r.rb +122 -0
  110. data/setup.rb +1360 -0
  111. data/test/bytestreams/tc_ibb.rb +186 -0
  112. data/test/bytestreams/tc_socks5bytestreams.rb +57 -0
  113. data/test/delay/tc_xdelay.rb +51 -0
  114. data/test/lib/clienttester.rb +110 -0
  115. data/test/muc/tc_muc_mucclient.rb +569 -0
  116. data/test/muc/tc_muc_simplemucclient.rb +72 -0
  117. data/test/roster/.tc_helper.rb.swp +0 -0
  118. data/test/roster/tc_helper.rb +389 -0
  119. data/test/roster/tc_iqqueryroster.rb +140 -0
  120. data/test/roster/tc_xroster.rb +70 -0
  121. data/test/tc_callbacks.rb +128 -0
  122. data/test/tc_class_names.rb +129 -0
  123. data/test/tc_client.rb +30 -0
  124. data/test/tc_error.rb +103 -0
  125. data/test/tc_idgenerator.rb +30 -0
  126. data/test/tc_iq.rb +109 -0
  127. data/test/tc_iqquery.rb +31 -0
  128. data/test/tc_jid.rb +202 -0
  129. data/test/tc_message.rb +114 -0
  130. data/test/tc_presence.rb +148 -0
  131. data/test/tc_stream.rb +182 -0
  132. data/test/tc_streamError.rb +87 -0
  133. data/test/tc_streamSend.rb +59 -0
  134. data/test/tc_streamThreaded.rb +168 -0
  135. data/test/tc_xmlstanza.rb +76 -0
  136. data/test/ts_xmpp4r.rb +34 -0
  137. data/test/vcard/tc_iqvcard.rb +52 -0
  138. data/test/version/tc_helper.rb +46 -0
  139. data/test/version/tc_iqqueryversion.rb +96 -0
  140. data/tools/doctoweb.bash +30 -0
  141. data/tools/gen_requires.bash +10 -0
  142. metadata +232 -0
@@ -0,0 +1,225 @@
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
+ ##
10
+ # Class for handling Service Discovery queries,
11
+ # info
12
+ # (JEP 0030)
13
+ #
14
+ # This <query/> may contain multiple Identity and Feature
15
+ # elements, describing the type and the supported namespaces of
16
+ # the service.
17
+ class IqQueryDiscoInfo < IqQuery
18
+ ##
19
+ # Create a new query
20
+ # with namespace http://jabber.org/protocol/disco#info
21
+ def initialize
22
+ super
23
+ add_namespace('http://jabber.org/protocol/disco#info')
24
+ end
25
+
26
+ ##
27
+ # Add a children element
28
+ #
29
+ # Converts <identity/> elements to [Identity]
30
+ # and <feature/> elements to [Feature]
31
+ def typed_add(element)
32
+ if element.kind_of?(REXML::Element)
33
+
34
+ if element.name == 'identity'
35
+ super(Identity::new.import(element))
36
+ elsif element.name == 'feature'
37
+ super(Feature::new.import(element))
38
+ else
39
+ super(element)
40
+ end
41
+
42
+ else
43
+ super(element)
44
+ end
45
+ end
46
+
47
+ ##
48
+ # Get the queried Service Discovery node or nil
49
+ #
50
+ # See IqQueryDiscoItems#node for a
51
+ # small explanation of this.
52
+ def node
53
+ attributes['node']
54
+ end
55
+
56
+ ##
57
+ # Get the queried Service Discovery node or nil
58
+ # val:: [String]
59
+ def node=(val)
60
+ attributes['node'] = val
61
+ end
62
+
63
+ ##
64
+ # Get the queried Service Discovery node or nil
65
+ # (chaining-friendly)
66
+ # val:: [String]
67
+ def set_node(val)
68
+ self.node = val
69
+ self
70
+ end
71
+
72
+ ##
73
+ # Get the first identity child
74
+ # result:: [Identity]
75
+ def identity
76
+ first_element('identity')
77
+ end
78
+
79
+ ##
80
+ # Get list of features
81
+ # result:: [Array] of [String]
82
+ def features
83
+ res = []
84
+ each_element('feature') { |feature|
85
+ res.push(feature.var)
86
+ }
87
+ res
88
+ end
89
+ end
90
+
91
+ IqQuery.add_namespaceclass('http://jabber.org/protocol/disco#info', IqQueryDiscoInfo)
92
+
93
+ ##
94
+ # Service Discovery identity to add() to IqQueryDiscoInfo
95
+ #
96
+ # Please note that JEP 0030 requires both category and type to occur
97
+ class Identity < REXML::Element
98
+ ##
99
+ # Initialize a new Identity
100
+ # category:: [String] Initial category or nil
101
+ # iname:: [String] Initial identity name or nil
102
+ # type:: [String] Initial type or nil
103
+ def initialize(category=nil, iname=nil, type=nil)
104
+ super('identity')
105
+ set_category(category)
106
+ set_iname(iname)
107
+ set_type(type)
108
+ end
109
+
110
+ ##
111
+ # Get the identity's category or nil
112
+ # result:: [String]
113
+ def category
114
+ attributes['category']
115
+ end
116
+
117
+ ##
118
+ # Set the identity's category
119
+ #
120
+ # Service Discovery categories should be somewhat
121
+ # standardized by some registry, so clients may
122
+ # represent specific categories by specific icons...
123
+ # (see http://www.jabber.org/registrar/disco-categories.html)
124
+ # val:: [String]
125
+ def category=(val)
126
+ attributes['category'] = val
127
+ end
128
+
129
+ ##
130
+ # Set the identity's category (chaining-friendly)
131
+ # val:: [String]
132
+ def set_category(val)
133
+ self.category = val
134
+ self
135
+ end
136
+
137
+ ##
138
+ # Get the identity's name or nil
139
+ #
140
+ # This has been renamed from <name/> to "iname" here
141
+ # to keep REXML::Element#name accessible
142
+ # result:: [String]
143
+ def iname
144
+ attributes['name']
145
+ end
146
+
147
+ ##
148
+ # Set the identity's name
149
+ # val:: [String]
150
+ def iname=(val)
151
+ attributes['name'] = val
152
+ end
153
+
154
+ ##
155
+ # Set the identity's name (chaining-friendly)
156
+ # val:: [String]
157
+ def set_iname(val)
158
+ self.iname = val
159
+ self
160
+ end
161
+
162
+ ##
163
+ # Get the identity's type or nil
164
+ # result:: [String]
165
+ def type
166
+ attributes['type']
167
+ end
168
+
169
+ ##
170
+ # Set the identity's type
171
+ # (see http://www.jabber.org/registrar/disco-categories.html)
172
+ # val:: [String]
173
+ def type=(val)
174
+ attributes['type'] = val
175
+ end
176
+
177
+ ##
178
+ # Set the identity's type (chaining-friendly)
179
+ # val:: [String]
180
+ def set_type(val)
181
+ self.type = val
182
+ self
183
+ end
184
+ end
185
+
186
+ ##
187
+ # Service Discovery feature to add() to IqQueryDiscoInfo
188
+ #
189
+ # Please note that JEP 0030 requires var to be set
190
+ class Feature < REXML::Element
191
+ ##
192
+ # Create a new <feature/> element
193
+ # var:: [String] New var
194
+ def initialize(var=nil)
195
+ super('feature')
196
+ set_var(var)
197
+ end
198
+
199
+ ##
200
+ # Get the feature's var or nil
201
+ # result:: [String]
202
+ def var
203
+ attributes['var']
204
+ end
205
+
206
+ ##
207
+ # Set the feature's var
208
+ #
209
+ # This is a namespace the identity supports.
210
+ # val:: [String]
211
+ def var=(val)
212
+ attributes['var'] = val
213
+ end
214
+
215
+ ##
216
+ # Set the feature's var (chaining-friendly)
217
+ # val:: [String]
218
+ def set_var(val)
219
+ self.var = val
220
+ self
221
+ end
222
+ end
223
+ end
224
+ end
225
+
@@ -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/query'
6
+
7
+ module Jabber
8
+ module Discovery
9
+ ##
10
+ # Class for handling Service Discovery queries,
11
+ # items
12
+ # (JEP 0030)
13
+ #
14
+ # This <query/> may contain multiple Item elements,
15
+ # describing multiple services to be browsed by Jabber clients.
16
+ # These may then get further information about these items by
17
+ # querying IqQueryDiscoInfo and further sub-items by querying
18
+ # IqQueryDiscoItems.
19
+ class IqQueryDiscoItems < IqQuery
20
+ ##
21
+ # Create a new query
22
+ # with namespace http://jabber.org/protocol/disco#items
23
+ def initialize
24
+ super
25
+ add_namespace('http://jabber.org/protocol/disco#items')
26
+ end
27
+
28
+ ##
29
+ # Add a children element
30
+ #
31
+ # Converts <item/> elements to [Item]
32
+ def typed_add(element)
33
+ if element.kind_of?(REXML::Element)
34
+
35
+ if element.name == 'item'
36
+ super(Item::new.import(element))
37
+ else
38
+ super(element)
39
+ end
40
+
41
+ else
42
+ super(element)
43
+ end
44
+ end
45
+
46
+ ##
47
+ # Get the queried Service Discovery node or nil
48
+ #
49
+ # A Service Discovery node is _not_ a JID node,
50
+ # this may be a bit confusing. It's just to make
51
+ # Service Discovery browsing a bit more structured.
52
+ def node
53
+ attributes['node']
54
+ end
55
+
56
+ ##
57
+ # Get the queried Service Discovery node or nil
58
+ def node=(val)
59
+ attributes['node'] = val
60
+ end
61
+
62
+ ##
63
+ # Get the queried Service Discovery node or nil
64
+ # (chaining-friendly)
65
+ def set_node(val)
66
+ self.node = val
67
+ self
68
+ end
69
+ end
70
+
71
+ IqQuery.add_namespaceclass('http://jabber.org/protocol/disco#items', IqQueryDiscoItems)
72
+
73
+ ##
74
+ # Service Discovery item to add() to IqQueryDiscoItems
75
+ #
76
+ # Please note that JEP 0030 requires the jid to occur
77
+ class Item < REXML::Element
78
+ ##
79
+ # Initialize a new Service Discovery <item/>
80
+ # to be added to IqQueryDiscoItems
81
+ # jid:: [JID]
82
+ # iname:: [String] Item name
83
+ # node:: [String] Service Discovery node (_not_ JID#node)
84
+ def initialize(jid=nil, iname=nil, node=nil)
85
+ super('item')
86
+ set_jid(jid)
87
+ set_iname(iname)
88
+ set_node(node)
89
+ end
90
+
91
+ ##
92
+ # Get the item's jid or nil
93
+ # result:: [String]
94
+ def jid
95
+ JID::new(attributes['jid'])
96
+ end
97
+
98
+ ##
99
+ # Set the item's jid
100
+ # val:: [JID]
101
+ def jid=(val)
102
+ attributes['jid'] = val.to_s
103
+ end
104
+
105
+ ##
106
+ # Set the item's jid (chaining-friendly)
107
+ # val:: [JID]
108
+ def set_jid(val)
109
+ self.jid = val
110
+ self
111
+ end
112
+
113
+ ##
114
+ # Get the item's name or nil
115
+ #
116
+ # This has been renamed from <name/> to "iname" here
117
+ # to keep REXML::Element#name accessible
118
+ # result:: [String]
119
+ def iname
120
+ attributes['name']
121
+ end
122
+
123
+ ##
124
+ # Set the item's name
125
+ # val:: [String]
126
+ def iname=(val)
127
+ attributes['name'] = val
128
+ end
129
+
130
+ ##
131
+ # Set the item's name (chaining-friendly)
132
+ # val:: [String]
133
+ def set_iname(val)
134
+ self.iname = val
135
+ self
136
+ end
137
+
138
+ ##
139
+ # Get the item's Service Discovery node or nil
140
+ # result:: [String]
141
+ def node
142
+ attributes['node']
143
+ end
144
+
145
+ ##
146
+ # Set the item's Service Discovery node
147
+ # val:: [String]
148
+ def node=(val)
149
+ attributes['node'] = val
150
+ end
151
+
152
+ ##
153
+ # Set the item's Service Discovery node (chaining-friendly)
154
+ # val:: [String]
155
+ def set_node(val)
156
+ self.node = val
157
+ self
158
+ end
159
+ end
160
+ end
161
+ end
162
+
@@ -0,0 +1,2 @@
1
+ require 'xmpp4r/discovery/iq/discoinfo.rb'
2
+ require 'xmpp4r/discovery/iq/discoitems.rb'
@@ -0,0 +1,230 @@
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
+ # A class used to build/parse <error/> elements.
8
+ # Look at JEP 0086 for explanation.
9
+ class Error < REXML::Element
10
+ ##
11
+ # errorcondition:: [nil] or [String] of the following:
12
+ # * "bad-request"
13
+ # * "conflict"
14
+ # * "feature-not-implemented"
15
+ # * "forbidden"
16
+ # * "gone"
17
+ # * "internal-server-error"
18
+ # * "item-not-found"
19
+ # * "jid-malformed"
20
+ # * "not-acceptable"
21
+ # * "not-allowed"
22
+ # * "not-authorized"
23
+ # * "payment-required"
24
+ # * "recipient-unavailable"
25
+ # * "redirect"
26
+ # * "registration-required"
27
+ # * "remote-server-not-found"
28
+ # * "remote-server-timeout"
29
+ # * "resource-constraint"
30
+ # * "service-unavailable"
31
+ # * "subscription-required"
32
+ # * "undefined-condition"
33
+ # * "unexpected-request"
34
+ # Will raise an [Exception] if not [nil] and none of the above
35
+ #
36
+ # Does also set type and code to appropriate values according to errorcondition
37
+ #
38
+ # text: [nil] or [String] Error text
39
+ def initialize(errorcondition=nil, text=nil)
40
+ if errorcondition.nil?
41
+ super('error')
42
+ set_text(text) unless text.nil?
43
+ else
44
+ errortype = nil
45
+ errorcode = nil
46
+ @@Errors.each { |cond,type,code|
47
+ if errorcondition == cond
48
+ errortype = type
49
+ errorcode = code
50
+ end
51
+ }
52
+
53
+ if errortype.nil? || errorcode.nil?
54
+ raise("Unknown error condition when initializing Error")
55
+ end
56
+
57
+ super("error")
58
+ set_error(errorcondition)
59
+ set_type(errortype)
60
+ set_code(errorcode)
61
+ set_text(text) unless text.nil?
62
+ end
63
+ end
64
+
65
+ ##
66
+ # Create a new <error/> element and import from existing
67
+ # element:: [REXML::Element] to import
68
+ def Error.import(element)
69
+ Error::new.import(element)
70
+ end
71
+
72
+ ##
73
+ # Get the 'Legacy error code' or nil
74
+ # result:: [Integer] Error code
75
+ def code
76
+ if attributes['code']
77
+ attributes['code'].to_i
78
+ else
79
+ nil
80
+ end
81
+ end
82
+
83
+ ##
84
+ # Set the 'Legacy error code' or nil
85
+ # i:: [Integer] Error code
86
+ def code=(i)
87
+ if i.nil?
88
+ attributes['code'] = nil
89
+ else
90
+ attributes['code'] = i.to_s
91
+ end
92
+ end
93
+
94
+ ##
95
+ # Set the 'Legacy error code' (chaining-friendly)
96
+ def set_code(i)
97
+ self.code = i
98
+ self
99
+ end
100
+
101
+ ##
102
+ # Get the 'XMPP error condition'
103
+ #
104
+ # This can be anything that possess the specific namespace,
105
+ # checks don't apply here
106
+ def error
107
+ name = nil
108
+ each_element { |e| name = e.name if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
109
+ name
110
+ end
111
+
112
+ ##
113
+ # Set the 'XMPP error condition'
114
+ #
115
+ # One previous element with that namespace will be deleted before
116
+ #
117
+ # s:: [String] Name of the element to be added,
118
+ # namespace will be added automatically, checks don't apply here
119
+ def error=(s)
120
+ xe = nil
121
+ each_element { |e| xe = e if (e.namespace == 'urn:ietf:params:xml:ns:xmpp-stanzas') && (e.name != 'text') }
122
+ unless xe.nil?
123
+ delete_element(xe)
124
+ end
125
+
126
+ add_element(s).add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
127
+ end
128
+
129
+ ##
130
+ # Set the 'XMPP error condition' (chaining-friendly)
131
+ def set_error(s)
132
+ self.error = s
133
+ self
134
+ end
135
+
136
+ ##
137
+ # Get the errors <text/> element text
138
+ # result:: [String] or nil
139
+ def text
140
+ first_element_text('text') || super
141
+ end
142
+
143
+ ##
144
+ # Set the errors <text/> element text
145
+ # (Previous <text/> elements will be deleted first)
146
+ # s:: [String] <text/> content or [nil] if no <text/> element
147
+ def text=(s)
148
+ delete_elements('text')
149
+
150
+ unless s.nil?
151
+ e = add_element('text')
152
+ e.add_namespace('urn:ietf:params:xml:ns:xmpp-stanzas')
153
+ e.text = s
154
+ end
155
+ end
156
+
157
+ ##
158
+ # Set the errors <text/> element text (chaining-friendly)
159
+ def set_text(s)
160
+ self.text = s
161
+ self
162
+ end
163
+
164
+ ##
165
+ # Get the type of error
166
+ # (meaning how to proceed)
167
+ # result:: [Symbol] or [nil] as following:
168
+ # * :auth
169
+ # * :cancel
170
+ # * :continue
171
+ # * :modify
172
+ # * :wait
173
+ def type
174
+ case attributes['type']
175
+ when 'auth' then :auth
176
+ when 'cancel' then :cancel
177
+ when 'continue' then :continue
178
+ when 'modify' then :modify
179
+ when 'wait' then :wait
180
+ else nil
181
+ end
182
+ end
183
+
184
+ ##
185
+ # Set the type of error (see Error#type)
186
+ def type=(t)
187
+ case t
188
+ when :auth then attributes['type'] = 'auth'
189
+ when :cancel then attributes['type'] = 'cancel'
190
+ when :continue then attributes['type'] = 'continue'
191
+ when :modify then attributes['type'] = 'modify'
192
+ when :wait then attributes['type'] = 'wait'
193
+ else attributes['type'] = nil
194
+ end
195
+ end
196
+
197
+ ##
198
+ # Set the type of error (chaining-friendly)
199
+ def set_type(t)
200
+ self.type = t
201
+ self
202
+ end
203
+
204
+ ##
205
+ # Possible XMPP error conditions, types and codes
206
+ # (JEP 0086)
207
+ @@Errors = [['bad-request', :modify, 400],
208
+ ['conflict', :cancel, 409],
209
+ ['feature-not-implemented', :cancel, 501],
210
+ ['forbidden', :auth, 403],
211
+ ['gone', :modify, 302],
212
+ ['internal-server-error', :wait, 500],
213
+ ['item-not-found', :cancel, 404],
214
+ ['jid-malformed', :modify, 400],
215
+ ['not-acceptable', :modify, 406],
216
+ ['not-allowed', :cancel, 405],
217
+ ['not-authorized', :auth, 401],
218
+ ['payment-required', :auth, 402],
219
+ ['recipient-unavailable', :wait, 404],
220
+ ['redirect', :modify, 302],
221
+ ['registration-required', :auth, 407],
222
+ ['remote-server-not-found', :cancel, 404],
223
+ ['remote-server-timeout', :wait, 504],
224
+ ['resource-constraint', :wait, 500],
225
+ ['service-unavailable', :cancel, 503],
226
+ ['subscription-required', :auth, 407],
227
+ ['undefined-condition', nil, 500],
228
+ ['unexpected-request', :wait, 400]]
229
+ end
230
+ end
@@ -0,0 +1,32 @@
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
+ # This exception can be raised by Helpers when they
8
+ # receive answers with <tt>type='error'</tt>
9
+ #
10
+ # The ErrorException carries a Jabber::Error element
11
+ class ErrorException < RuntimeError
12
+ ##
13
+ # The error element which caused this exception
14
+ attr_reader :error
15
+
16
+ ##
17
+ # Initialize an ErrorException
18
+ # error:: [Error]
19
+ def initialize(error)
20
+ @error = error
21
+ end
22
+
23
+ ##
24
+ # Textual output
25
+ #
26
+ # Sample:
27
+ # subscription-required: Please subscribe first
28
+ def to_s
29
+ "#{@error.error}: #{@error.text}"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ require 'xmpp4r/iq'
2
+ require 'xmpp4r/dataforms/x/data'
3
+
4
+ module Jabber
5
+ module FeatureNegotiation
6
+ ##
7
+ # Feature negotiation,
8
+ # can appear as direct child to Iq
9
+ # or as child of IqSi
10
+ class IqFeature < REXML::Element
11
+ def initialize
12
+ super('feature')
13
+
14
+ add_namespace 'http://jabber.org/protocol/feature-neg'
15
+ end
16
+
17
+ def IqFeature.import(element)
18
+ IqFeature::new.import(element)
19
+ end
20
+
21
+ def typed_add(element)
22
+ if element.name == 'x' and element.namespace == 'jabber:x:data'
23
+ super Dataforms::XData.new.import(element)
24
+ else
25
+ super element
26
+ end
27
+ end
28
+
29
+ ##
30
+ # First <x/> child with xmlns='jabber:x:data'
31
+ def x
32
+ res = nil
33
+ each_element('x') { |e|
34
+ res = e if e.namespace == 'jabber:x:data'
35
+ }
36
+ res
37
+ end
38
+ end
39
+
40
+ Iq.add_elementclass('feature', IqFeature)
41
+ end
42
+ end
@@ -0,0 +1 @@
1
+ require 'xmpp4r/feature_negotiation/iq/feature.rb'