jabber4r-revive 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +5 -4
  2. data/.rspec +3 -3
  3. data/.travis.yml +7 -7
  4. data/CHANGELOG +11 -1
  5. data/Gemfile +3 -3
  6. data/README.md +29 -29
  7. data/Rakefile +70 -70
  8. data/jabber4r-revive.gemspec +25 -25
  9. data/lib/jabber4r.rb +38 -33
  10. data/lib/jabber4r/bosh.rb +21 -0
  11. data/lib/jabber4r/bosh/authentication.rb +13 -0
  12. data/lib/jabber4r/bosh/authentication/non_sasl.rb +219 -0
  13. data/lib/jabber4r/bosh/authentication/sasl.rb +239 -0
  14. data/lib/jabber4r/bosh/session.rb +144 -0
  15. data/lib/jabber4r/connection.rb +259 -258
  16. data/lib/jabber4r/debugger.rb +60 -60
  17. data/lib/jabber4r/jid.rb +20 -19
  18. data/lib/jabber4r/protocol.rb +249 -257
  19. data/lib/jabber4r/protocol/authentication.rb +14 -0
  20. data/lib/jabber4r/protocol/authentication/non_sasl.rb +138 -0
  21. data/lib/jabber4r/protocol/authentication/sasl.rb +88 -0
  22. data/lib/jabber4r/protocol/iq.rb +259 -259
  23. data/lib/jabber4r/protocol/message.rb +245 -245
  24. data/lib/jabber4r/protocol/parsed_xml_element.rb +207 -207
  25. data/lib/jabber4r/protocol/presence.rb +160 -160
  26. data/lib/jabber4r/protocol/xml_element.rb +143 -143
  27. data/lib/jabber4r/rexml_1.8_patch.rb +15 -15
  28. data/lib/jabber4r/roster.rb +38 -38
  29. data/lib/jabber4r/session.rb +615 -615
  30. data/lib/jabber4r/version.rb +10 -3
  31. data/spec/lib/jabber4r/bosh/authentication/non_sasl_spec.rb +79 -0
  32. data/spec/lib/jabber4r/bosh/authentication/sasl_spec.rb +42 -0
  33. data/spec/lib/jabber4r/bosh/session_spec.rb +406 -0
  34. data/spec/lib/jabber4r/bosh_spec.rb +0 -0
  35. data/spec/lib/jabber4r/connection_spec.rb +174 -174
  36. data/spec/lib/jabber4r/debugger_spec.rb +35 -35
  37. data/spec/lib/jabber4r/jid_spec.rb +197 -197
  38. data/spec/lib/jabber4r/protocol/authentication/non_sasl_spec.rb +79 -0
  39. data/spec/lib/jabber4r/protocol/authentication/sasl_spec.rb +42 -0
  40. data/spec/spec_helper.rb +11 -11
  41. data/spec/support/mocks/tcp_socket_mock.rb +8 -8
  42. metadata +61 -45
  43. data/Gemfile.lock +0 -45
  44. data/lib/jabber4r/bosh_session.rb +0 -224
  45. data/spec/lib/jabber4r/bosh_session_spec.rb +0 -150
@@ -1,144 +1,144 @@
1
- # coding: utf-8
2
-
3
- # License: see LICENSE
4
- # Jabber4R - Jabber Instant Messaging Library for Ruby
5
- # Copyright (C) 2002 Rich Kilmer <rich@infoether.com>
6
-
7
- module Jabber::Protocol
8
- ##
9
- # Utility class to create valid XML strings
10
- #
11
- class XMLElement
12
-
13
- # The parent XMLElement
14
- attr_accessor :parent
15
-
16
- ##
17
- # Construct an XMLElement for the supplied tag and attributes
18
- #
19
- # tag:: [String] XML tag
20
- # attributes:: [Hash = {}] The attribute hash[attribute]=value
21
- def initialize(tag, attributes={})
22
- @tag = tag
23
- @elements = []
24
- @attributes = attributes
25
- @data = ""
26
- end
27
-
28
- ##
29
- # Adds an attribute to this element
30
- #
31
- # attrib:: [String] The attribute name
32
- # value:: [String] The attribute value
33
- # return:: [Jabber::Protocol::XMLElement] self for chaining
34
- #
35
- def add_attribute(attrib, value)
36
- @attributes[attrib]=value
37
- self
38
- end
39
-
40
- ##
41
- # Adds data to this element
42
- #
43
- # data:: [String] The data to add
44
- # return:: [Jabber::Protocol::XMLElement] self for chaining
45
- #
46
- def add_data(data)
47
- @data += data.to_s
48
- self
49
- end
50
-
51
- ##
52
- # Sets the namespace for this tag
53
- #
54
- # ns:: [String] The namespace
55
- # return:: [Jabber::Protocol::XMLElement] self for chaining
56
- #
57
- def set_namespace(ns)
58
- @tag+=":#{ns}"
59
- self
60
- end
61
-
62
- ##
63
- # Adds cdata to this element
64
- #
65
- # cdata:: [String] The cdata to add
66
- # return:: [Jabber::Protocol::XMLElement] self for chaining
67
- #
68
- def add_cdata(cdata)
69
- @data += "<![CDATA[#{cdata.to_s}]]>"
70
- self
71
- end
72
-
73
- ##
74
- # Returns the parent element
75
- #
76
- # return:: [Jabber::Protocol::XMLElement] The parent XMLElement
77
- #
78
- def to_parent
79
- @parent
80
- end
81
-
82
- ##
83
- # Adds a child to this element of the supplied tag
84
- #
85
- # tag:: [String] The element tag
86
- # attributes:: [Hash = {}] The attributes hash[attribute]=value
87
- # return:: [Jabber::Protocol::XMLElement] newly created child element
88
- #
89
- def add_child(tag, attributes={})
90
- child = XMLElement.new(tag, attributes)
91
- child.parent = self
92
- @elements << child
93
- return child
94
- end
95
-
96
- ##
97
- # Adds arbitrary XML data to this object
98
- #
99
- # xml:: [String] the xml to add
100
- #
101
- def add_xml(xml)
102
- @xml = xml
103
- end
104
-
105
- ##
106
- # Recursively builds the XML string by traversing this element's
107
- # children.
108
- #
109
- # format:: [Boolean] True to pretty-print (format) the output string
110
- # indent:: [Integer = 0] The indent level (recursively more)
111
- #
112
- def to_xml(format, indent=0)
113
- result = ""
114
- result += " "*indent if format
115
- result += "<#{@tag}"
116
- @attributes.each {|attrib, value| result += (' '+attrib.to_s+'="'+value.to_s+'"') }
117
- if @data=="" and @elements.size==0
118
- result +="/>"
119
- result +="\n" if format
120
- return result
121
- end
122
- result += ">"
123
- result += "\n" if format and @data==""
124
- result += @data if @data!=""
125
- @elements.each {|element| result+=element.to_xml(format, indent+4)}
126
- result += @xml if not @xml.nil?
127
- result += " "*indent if format and @data==""
128
- result+="</#{@tag}>"
129
- result+="\n" if format
130
- return result
131
- end
132
-
133
- ##
134
- # Climbs to the top of this elements parent tree and then returns
135
- # the to_xml XML string.
136
- #
137
- # return:: [String] The XML string of this element (from the topmost parent).
138
- #
139
- def to_s
140
- return @parent.to_s if @parent
141
- return to_xml(true)
142
- end
143
- end
1
+ # coding: utf-8
2
+
3
+ # License: see LICENSE
4
+ # Jabber4R - Jabber Instant Messaging Library for Ruby
5
+ # Copyright (C) 2002 Rich Kilmer <rich@infoether.com>
6
+
7
+ module Jabber::Protocol
8
+ ##
9
+ # Utility class to create valid XML strings
10
+ #
11
+ class XMLElement
12
+
13
+ # The parent XMLElement
14
+ attr_accessor :parent
15
+
16
+ ##
17
+ # Construct an XMLElement for the supplied tag and attributes
18
+ #
19
+ # tag:: [String] XML tag
20
+ # attributes:: [Hash = {}] The attribute hash[attribute]=value
21
+ def initialize(tag, attributes={})
22
+ @tag = tag
23
+ @elements = []
24
+ @attributes = attributes
25
+ @data = ""
26
+ end
27
+
28
+ ##
29
+ # Adds an attribute to this element
30
+ #
31
+ # attrib:: [String] The attribute name
32
+ # value:: [String] The attribute value
33
+ # return:: [Jabber::Protocol::XMLElement] self for chaining
34
+ #
35
+ def add_attribute(attrib, value)
36
+ @attributes[attrib]=value
37
+ self
38
+ end
39
+
40
+ ##
41
+ # Adds data to this element
42
+ #
43
+ # data:: [String] The data to add
44
+ # return:: [Jabber::Protocol::XMLElement] self for chaining
45
+ #
46
+ def add_data(data)
47
+ @data += data.to_s
48
+ self
49
+ end
50
+
51
+ ##
52
+ # Sets the namespace for this tag
53
+ #
54
+ # ns:: [String] The namespace
55
+ # return:: [Jabber::Protocol::XMLElement] self for chaining
56
+ #
57
+ def set_namespace(ns)
58
+ @tag+=":#{ns}"
59
+ self
60
+ end
61
+
62
+ ##
63
+ # Adds cdata to this element
64
+ #
65
+ # cdata:: [String] The cdata to add
66
+ # return:: [Jabber::Protocol::XMLElement] self for chaining
67
+ #
68
+ def add_cdata(cdata)
69
+ @data += "<![CDATA[#{cdata.to_s}]]>"
70
+ self
71
+ end
72
+
73
+ ##
74
+ # Returns the parent element
75
+ #
76
+ # return:: [Jabber::Protocol::XMLElement] The parent XMLElement
77
+ #
78
+ def to_parent
79
+ @parent
80
+ end
81
+
82
+ ##
83
+ # Adds a child to this element of the supplied tag
84
+ #
85
+ # tag:: [String] The element tag
86
+ # attributes:: [Hash = {}] The attributes hash[attribute]=value
87
+ # return:: [Jabber::Protocol::XMLElement] newly created child element
88
+ #
89
+ def add_child(tag, attributes={})
90
+ child = XMLElement.new(tag, attributes)
91
+ child.parent = self
92
+ @elements << child
93
+ return child
94
+ end
95
+
96
+ ##
97
+ # Adds arbitrary XML data to this object
98
+ #
99
+ # xml:: [String] the xml to add
100
+ #
101
+ def add_xml(xml)
102
+ @xml = xml
103
+ end
104
+
105
+ ##
106
+ # Recursively builds the XML string by traversing this element's
107
+ # children.
108
+ #
109
+ # format:: [Boolean] True to pretty-print (format) the output string
110
+ # indent:: [Integer = 0] The indent level (recursively more)
111
+ #
112
+ def to_xml(format, indent=0)
113
+ result = ""
114
+ result += " "*indent if format
115
+ result += "<#{@tag}"
116
+ @attributes.each {|attrib, value| result += (' '+attrib.to_s+'="'+value.to_s+'"') }
117
+ if @data=="" and @elements.size==0
118
+ result +="/>"
119
+ result +="\n" if format
120
+ return result
121
+ end
122
+ result += ">"
123
+ result += "\n" if format and @data==""
124
+ result += @data if @data!=""
125
+ @elements.each {|element| result+=element.to_xml(format, indent+4)}
126
+ result += @xml if not @xml.nil?
127
+ result += " "*indent if format and @data==""
128
+ result+="</#{@tag}>"
129
+ result+="\n" if format
130
+ return result
131
+ end
132
+
133
+ ##
134
+ # Climbs to the top of this elements parent tree and then returns
135
+ # the to_xml XML string.
136
+ #
137
+ # return:: [String] The XML string of this element (from the topmost parent).
138
+ #
139
+ def to_s
140
+ return @parent.to_s if @parent
141
+ return to_xml(true)
142
+ end
143
+ end
144
144
  end
@@ -1,16 +1,16 @@
1
- if RUBY_VERSION=="1.8.0"
2
- module REXML
3
- module Parsers
4
- class BaseParser
5
- # Returns true if there are more events. Synonymous with !empty?
6
- def has_next?
7
- return true if @closed # THIS WAS ADDED TO FIX PROBLEM
8
- @source.read if @source.buffer.size==0 and !@source.empty?
9
- (!@source.empty? and @source.buffer.strip.size>0) or @stack.size>0 or @closed
10
- end
11
- end
12
- end
13
- end
14
- else
15
- puts "WARNING: rexml_1.8_patch is needed on Ruby 1.8.0 and not by Ruby #{RUBY_VERSION}"
1
+ if RUBY_VERSION=="1.8.0"
2
+ module REXML
3
+ module Parsers
4
+ class BaseParser
5
+ # Returns true if there are more events. Synonymous with !empty?
6
+ def has_next?
7
+ return true if @closed # THIS WAS ADDED TO FIX PROBLEM
8
+ @source.read if @source.buffer.size==0 and !@source.empty?
9
+ (!@source.empty? and @source.buffer.strip.size>0) or @stack.size>0 or @closed
10
+ end
11
+ end
12
+ end
13
+ end
14
+ else
15
+ puts "WARNING: rexml_1.8_patch is needed on Ruby 1.8.0 and not by Ruby #{RUBY_VERSION}"
16
16
  end
@@ -1,7 +1,7 @@
1
1
  # License: see LICENSE.txt
2
2
  # Jabber4R - Jabber Instant Messaging Library for Ruby
3
3
  # Copyright (C) 2002 Rich Kilmer <rich@infoether.com>
4
- #
4
+ #
5
5
 
6
6
 
7
7
  module Jabber
@@ -9,17 +9,17 @@ module Jabber
9
9
  ##
10
10
  # The Roster class encapsulates the runtime roster of the session instance.
11
11
  # The Roster contains all subscriptions in a Jabber::Roster::RosterItem hash.
12
- #
12
+ #
13
13
  class Roster
14
14
  ITEM_ADDED=1
15
15
  ITEM_DELETED=2
16
16
  RESOURCE_ADDED=4
17
17
  RESOURCE_UPDATED=8
18
18
  RESOURCE_DELETED=16
19
-
19
+
20
20
  # The Jabber::Session instance
21
21
  attr_reader :session
22
-
22
+
23
23
  ##
24
24
  # Creates a Roster for the session
25
25
  #
@@ -30,7 +30,7 @@ module Jabber
30
30
  @map = {}
31
31
  @listeners = {}
32
32
  end
33
-
33
+
34
34
  ##
35
35
  # The RosterItem class embodies another Jabber user's status (from
36
36
  # the local user's perspective). RosterItems contain
@@ -40,19 +40,19 @@ module Jabber
40
40
  class RosterItem
41
41
  # The Jabber::Roster instance
42
42
  attr_reader :roster
43
-
43
+
44
44
  # The Jabber ID (Jabber::JID)
45
45
  attr_accessor :jid
46
-
46
+
47
47
  # The subscription type
48
48
  attr_accessor :subscription
49
-
49
+
50
50
  # The (nick)name of this account
51
51
  attr_accessor :name
52
-
52
+
53
53
  # The group name for this account
54
54
  attr_accessor :group
55
-
55
+
56
56
  ##
57
57
  # Constructs a RosterItem
58
58
  #
@@ -69,22 +69,22 @@ module Jabber
69
69
  @resources = {}
70
70
  @roster = roster
71
71
  end
72
-
72
+
73
73
  ##
74
74
  # The Resource class embodies a Resource endpoint in Jabber.
75
75
  # The resource endpoint it what maintains a status (not an account).
76
76
  #
77
77
  class Resource
78
-
78
+
79
79
  # The name of the resource
80
80
  attr_reader :name
81
-
81
+
82
82
  # How the resource should be shown
83
83
  attr_reader :show
84
-
84
+
85
85
  # The status message of the resource
86
86
  attr_reader :status
87
-
87
+
88
88
  ##
89
89
  # Constructs a new Resource instance
90
90
  #
@@ -99,7 +99,7 @@ module Jabber
99
99
  @show = show
100
100
  @status = status
101
101
  end
102
-
102
+
103
103
  ##
104
104
  # Updates the state of a resource and notifies listeners.
105
105
  #
@@ -111,7 +111,7 @@ module Jabber
111
111
  @status = status
112
112
  @item.roster.notify_listeners(RESOURCE_UPDATED, self)
113
113
  end
114
-
114
+
115
115
  ##
116
116
  # Dumps the Resource as a string
117
117
  #
@@ -121,7 +121,7 @@ module Jabber
121
121
  "RESOURCE:#{@name} SHOW:#{@show} STATUS:#{@status}"
122
122
  end
123
123
  end
124
-
124
+
125
125
  ##
126
126
  # Retrieves the VCard for this (RosterItem) account. This method
127
127
  # blocks until the the vcard is returned.
@@ -143,7 +143,7 @@ module Jabber
143
143
  Thread.stop
144
144
  return result
145
145
  end
146
-
146
+
147
147
  ##
148
148
  # Adds a new resource to the Roster item and notifies listeners
149
149
  #
@@ -158,7 +158,7 @@ module Jabber
158
158
  @roster.notify_listeners(RESOURCE_ADDED, resource)
159
159
  resource
160
160
  end
161
-
161
+
162
162
  ##
163
163
  # Deletes a resource from this roster item and notifies listeners
164
164
  #
@@ -170,7 +170,7 @@ module Jabber
170
170
  @roster.notify_listeners(RESOURCE_DELETED, resource) if resource
171
171
  resource
172
172
  end
173
-
173
+
174
174
  ##
175
175
  # Retrieves a resource object
176
176
  #
@@ -180,7 +180,7 @@ module Jabber
180
180
  def [](resourceName)
181
181
  return @resources[resourceName]
182
182
  end
183
-
183
+
184
184
  ##
185
185
  # Iterates over the list of available resources
186
186
  #
@@ -189,7 +189,7 @@ module Jabber
189
189
  def each_resource
190
190
  @resources.each_value {|resource| yield resource}
191
191
  end
192
-
192
+
193
193
  ##
194
194
  # Dumps the roster item
195
195
  #
@@ -198,7 +198,7 @@ module Jabber
198
198
  "ITEM:#{@jid.to_s} SUBSCRIPTION:#{@subscription} NAME:#{@name} GROUP:#{@group}"
199
199
  end
200
200
  end
201
-
201
+
202
202
  ##
203
203
  # Adds a listener to the roster to process roster changes
204
204
  #
@@ -210,7 +210,7 @@ module Jabber
210
210
  @listeners[id]=block if block
211
211
  return id
212
212
  end
213
-
213
+
214
214
  ##
215
215
  # Deletes a listener for processing roster messages
216
216
  #
@@ -219,7 +219,7 @@ module Jabber
219
219
  def delete_listener(id)
220
220
  @listeners.delete(id)
221
221
  end
222
-
222
+
223
223
  ##
224
224
  # Adds a subscription to be tracked in the Roster
225
225
  #
@@ -230,10 +230,10 @@ module Jabber
230
230
  #
231
231
  def add(jid, subscription, name, group=nil)
232
232
  if jid.kind_of? String
233
- jid = JID.new(jid)
233
+ jid = JID.new(jid)
234
234
  jid.strip!
235
235
  elsif jid.kind_of? JID
236
- jid = JID.new(jid.node+"@"+jid.host)
236
+ jid = JID.new(jid.node+"@"+jid.domain)
237
237
  else
238
238
  return
239
239
  end
@@ -245,7 +245,7 @@ module Jabber
245
245
  puts ex.backtrace.join("\n")
246
246
  end
247
247
  end
248
-
248
+
249
249
  ##
250
250
  # Returns a Jabber::Roster::RosterItem based on the JID
251
251
  #
@@ -254,16 +254,16 @@ module Jabber
254
254
  #
255
255
  def [](jid)
256
256
  if jid.kind_of? String
257
- jid = JID.new(jid)
257
+ jid = JID.new(jid)
258
258
  jid.strip!
259
259
  elsif jid.kind_of? JID
260
- jid = JID.new(jid.node+"@"+jid.host)
260
+ jid = JID.new(jid.node+"@"+jid.domain)
261
261
  else
262
262
  return
263
263
  end
264
264
  return @map[jid.to_s]
265
265
  end
266
-
266
+
267
267
  ##
268
268
  # Deletes a roster item based on the supplied Jabber ID
269
269
  #
@@ -274,7 +274,7 @@ module Jabber
274
274
  jid = JID.new(jid)
275
275
  jid.strip!
276
276
  elsif jid.kind_of? JID
277
- jid = JID.new(jid.node+"@"+jid.host)
277
+ jid = JID.new(jid.node+"@"+jid.domain)
278
278
  else
279
279
  return
280
280
  end
@@ -282,7 +282,7 @@ module Jabber
282
282
  notify_listeners(ITEM_DELETED, item) if item
283
283
  item
284
284
  end
285
-
285
+
286
286
  ##
287
287
  # Iterates over each RosterItem
288
288
  #
@@ -291,7 +291,7 @@ module Jabber
291
291
  def each_item
292
292
  @map.each_value {|item| yield item}
293
293
  end
294
-
294
+
295
295
  ##
296
296
  # Dumps the Roster state as a string
297
297
  #
@@ -308,15 +308,15 @@ module Jabber
308
308
 
309
309
  ##
310
310
  # Notifies listeners of a roster change event
311
- #
311
+ #
312
312
  # event:: [Integer] The roster event
313
313
  # object:: [RosterItem] The modified item
314
314
  #
315
315
  def notify_listeners(event, object)
316
316
  @listeners.each_value {|listener| listener.call(event, object)}
317
317
  end
318
-
318
+
319
319
  end
320
-
320
+
321
321
  end
322
322