lightmelody

changeset 705:1ecb42cf6a09 objectify

Parser
author Mayank Singh <mayanks43@gmail.com>
date Wed, 02 Jan 2013 06:48:34 +0530
parents 41266f8b4fc8
children 01620bdc3d7b
files src/Connection.gs src/Parser.gs
diffstat 2 files changed, 75 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/src/Connection.gs	Mon Dec 31 19:01:36 2012 -0500
     1.2 +++ b/src/Connection.gs	Wed Jan 02 06:48:34 2013 +0530
     1.3 @@ -89,7 +89,7 @@
     1.4      init
     1.5          self.port = 5222 // default in case a SRV record can't be found
     1.6          self.state = State.CLOSED
     1.7 -        self.queue = new MessageQueue(self._queue_cb)
     1.8 +        self.queue = new MessageQueue(self._message_queue_cb)
     1.9  
    1.10          // Used to ensure unique IQ IDs
    1.11          self._last_id = 0
    1.12 @@ -131,7 +131,7 @@
    1.13      //////////////////////////////////////////////////////////////////////////
    1.14      // Callbacks
    1.15  
    1.16 -    def inline _queue_cb(queue : MessageQueue)
    1.17 +    def inline _message_queue_cb(queue : MessageQueue)
    1.18          result : HandlerResult
    1.19          //handler : MessageHandler
    1.20          m : Message = queue.pop_nth(0)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/Parser.gs	Wed Jan 02 06:48:34 2013 +0530
     2.3 @@ -0,0 +1,73 @@
     2.4 +/*
     2.5 + *  LightMelody - Lightweight XMPP/Jingle Client Library
     2.6 + *  Copyright (C) 2012,2013 Copyleft Games Group
     2.7 + *
     2.8 + *  This program is free software; you can redistribute it and/or modify
     2.9 + *  it under the terms of the GNU Affero General Public License as published
    2.10 + *  by the Free Software Foundation, either version 3 of the License, or
    2.11 + *  (at your option) any later version.
    2.12 + *
    2.13 + *  This program is distributed in the hope that it will be useful,
    2.14 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.16 + *  GNU Affero General Public License for more details.
    2.17 + *
    2.18 + *  You should have received a copy of the GNU Affero General Public License
    2.19 + *  along with this program; if not, see http://www.gnu.org/licenses
    2.20 + *
    2.21 + */
    2.22 +
    2.23 +[indent=4]
    2.24 +
    2.25 +namespace Lm
    2.26 +    delegate ParserMessageFunction (parser : Lm.Parser, message : Lm.Message)
    2.27 +    
    2.28 +class Lm.Parser
    2.29 +    _function : Lm.ParserMessageFunction?
    2.30 +    
    2.31 +    _cur_root : Lm.MessageNode
    2.32 +    _cur_node : Lm.MessageNode
    2.33 +        
    2.34 +    _m_parser : MarkupParser
    2.35 +    _context : MarkupParseContext
    2.36 +    
    2.37 +    init
    2.38 +    
    2.39 +        _m_parser.start_element = self._start_node_cb
    2.40 +        _m_parser.end_element = self._end_node_cb
    2.41 +        _m_parser.text = self._text_cb
    2.42 +        _m_parser.error = self._error_cb
    2.43 +
    2.44 +        _context = new MarkupParseContext (_m_parser, 0, self, null)
    2.45 +
    2.46 +        _cur_root = null
    2.47 +        _cur_node = null
    2.48 +    
    2.49 +    
    2.50 +    def _start_node_cb (context : MarkupParseContext,
    2.51 +                        node_name : string,
    2.52 +                        attribute_names : array of string,
    2.53 +                        attribute_values : array of string)
    2.54 +        if (self._cur_root == null)
    2.55 +            /* New toplevel element */
    2.56 +            self._cur_root = new MessageNode(node_name)
    2.57 +            self._cur_node = _cur_root;
    2.58 +        else
    2.59 +            parent_node : MessageNode
    2.60 +        
    2.61 +            parent_node = self._cur_node
    2.62 +            
    2.63 +            self._cur_node = new MessageNode(node_name)
    2.64 +            parent_node.add_child (parent_node,self._cur_node)
    2.65 +
    2.66 +            var i = 0
    2.67 +            while attribute_names[i] != null
    2.68 +                self._cur_node.set_attributes (
    2.69 +                                        attribute_names[i],
    2.70 +                                        attribute_values[i], 
    2.71 +                                        null)
    2.72 +    
    2.73 +            if ("stream:stream" == node_name) 
    2.74 +                self._end_node_cb (context,
    2.75 +                            "stream:stream")
    2.76 +