Class: Jabber::StreamParser
- Inherits:
-
Nokogiri::XML::SAX::Document
- Object
- Nokogiri::XML::SAX::Document
- Jabber::StreamParser
- Defined in:
- lib/xmpp4r/streamparser.rb
Instance Attribute Summary collapse
-
#started ⇒ Object
readonly
status if the parser is started.
Instance Method Summary collapse
- #cdata_block(s) ⇒ Object
- #characters(s) ⇒ Object
- #end_document ⇒ Object
- #end_element(name) ⇒ Object
-
#initialize(listener) ⇒ StreamParser
constructor
Constructs a parser for the supplied stream (socket input).
- #start_element(name, attrs = []) ⇒ Object
Constructor Details
#initialize(listener) ⇒ StreamParser
Constructs a parser for the supplied stream (socket input)
- stream
- IO
-
Socket input stream
- listener
- Object.receive(XMPPStanza)
-
The listener (usually a Jabber::Protocol::Connection instance)
21 22 23 24 25 |
# File 'lib/xmpp4r/streamparser.rb', line 21 def initialize(listener) @listener = listener @current = nil @started = false end |
Instance Attribute Details
#started ⇒ Object (readonly)
status if the parser is started
13 14 15 |
# File 'lib/xmpp4r/streamparser.rb', line 13 def started @started end |
Instance Method Details
#cdata_block(s) ⇒ Object
57 58 59 |
# File 'lib/xmpp4r/streamparser.rb', line 57 def cdata_block(s) @current.add(REXML::CData.new(s)) if @current end |
#characters(s) ⇒ Object
53 54 55 |
# File 'lib/xmpp4r/streamparser.rb', line 53 def characters(s) @current.add(REXML::Text.new(s.to_s, @current.whitespace, nil, false)) if @current end |
#end_document ⇒ Object
61 62 63 |
# File 'lib/xmpp4r/streamparser.rb', line 61 def end_document raise Jabber::ServerDisconnected, "Server Disconnected!" end |
#end_element(name) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/xmpp4r/streamparser.rb', line 43 def end_element(name) if name == 'stream:stream' and @current.nil? @started = false @listener.parser_end else @listener.receive(@current) unless @current.parent @current = @current.parent end end |
#start_element(name, attrs = []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/xmpp4r/streamparser.rb', line 27 def start_element(name, attrs = []) e = REXML::Element.new(name) e.add_attributes attrs @current = @current.nil? ? e : @current.add_element(e) # Handling <stream:stream> not only when it is being # received as a top-level tag but also as a child of the # top-level element itself. This way, we handle stream # restarts (ie. after SASL authentication). if @current.name == 'stream' and @current.parent.nil? @started = true @listener.receive(@current) @current = nil end end |