view plugins/feature-not-implemented.js @ 57:91f18fdc0e2c

Some clean up.
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 01 Feb 2012 16:48:48 +0100
parents ea276b47c555
children
line wrap: on
line source

'use strict';

/**
  Copyright (c) 2012, Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>

  Permission to use, copy, modify, and/or distribute this software for any
  purpose with or without fee is hereby granted, provided that the above
  copyright notice and this permission notice appear in all copies.

  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

Lightstring.plugins['feature-not-implemented'] = {
  namespaces: {
    xmpp_stanzas: 'urn:ietf:params:xml:ns:xmpp-stanzas'
  },
  handlers: {
    'iq': function callback(stanza) {
      var type = stanza.DOM.getAttributeNS(null, 'type');
      if (type !== 'get' && type !== 'set')
        return;

      var handlers = conn.handlers;
      var events = [handlers['iq']];

      var payload = stanza.DOM.firstChild;
      if (payload)
        events.push('iq/' + payload.namespaceURI + ':' + payload.localName);

      var only = events.every(function(handler) {
        for (var i in handler)
          if (callback !== handler[i])
            return false;
        return true;
      });

      if (only)
        conn.send("<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" +
                     " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" +
                     " type='error'>" +
                    "<error type='cancel'>" +
                      "<feature-not-implemented xmlns='" + Lightstring.NS.xmpp_stanzas + "'/>" +
                    "</error>" +
                  "</iq>");
    }
  }
};