Example #1
0
    def streamhandler(self, attrs):
        """Handles a stream start"""

        if attrs == {}:
            # </stream:stream> received
            self.connection.stop_connection()
        else:
            # check if we are responsible for this stream
            self.hostname = attrs.getValue("to")
            if self.hostname not in config.getlist("listeners", "domains"):
                raise HostUnknownError

            # Stream restart
            stream = ET.Element("stream:stream")
            stream.set("xmlns", attrs.getValue("xmlns"))
            stream.set("from", self.hostname)
            stream.set("id", uuid.uuid4().hex)
            stream.set("xml:lang", "en")
            stream.set("xmlns:stream", "http://etherx.jabber.org/streams")

            # only include version in response if client sent its max supported
            # version (RFC6120 Section 4.7.5)
            try:
                if attrs.getValue("version") != "1.0":
                    raise UnsupportedVersionError
                stream.set("version", "1.0")
            except KeyError:
                pass

            try:
                from_jid = JID(attrs.getValue("from"))
                stream.set("to", unicode(from_jid))
            except ValueError:
                raise InvalidFromError
            except KeyError:
                pass

            start_stream = """<?xml version="1.0"?>""" + ET.tostring(stream)
            # Element has subitems but are added later to the stream,
            # so don't mark it a single element
            self.send_string(start_stream.replace("/>", ">"))

            # Make a list of supported features
            features = ET.Element("stream:features")
            if not self.authenticated:
                self.add_auth_options(features)
            else:
                self.add_server_features(features)

            self.send_element(features)
Example #2
0
 def __init__(self, request, error_type, error_name):
     XMPPProtocolError.__init__(self, request.tag, "")
     try:
         if request.get("id") is not None:
             self.element.set("id", request.get("id"))
         self.element.set("to", request.get("from"))
         self.element.set("from", config.getlist('listeners', 'domains')[0])
     except KeyError:
         pass
     self.error = ET.Element("error")
     self.error.set("type", error_type)
     self.message = ET.Element(error_name)
     self.message.set("xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas")
     self.error.append(self.message)
     self.element.append(self.error)
Example #3
0
def fire_up():
    import pyfire.storage
    import pyfire.contact
    pyfire.storage.Base.metadata.create_all(pyfire.storage.engine)

    # create a forwader/router for internal communication
    fwd = zmq_forwarder.ZMQForwarder(config.get('ipc', 'forwarder'))
    thread.start_new_thread(fwd.start, ())

    # create a stamza processor for local domains
    stanza_proc = stanza_processor.StanzaProcessor(config.getlist('listeners', 'domains'))
    thread.start_new_thread(stanza_proc.start, ())

    # start listener for incomming Connections
    start_client_listener()
Example #4
0
 def __init__(self, request, error_type, error_name):
     XMPPProtocolError.__init__(self,
                             request.tag,
                             ""
                         )
     try:
         if request.get("id") is not None:
             self.element.set("id", request.get("id"))
         self.element.set("to", request.get("from"))
         self.element.set("from", config.getlist('listeners', 'domains')[0])
     except KeyError:
         pass
     self.error = ET.Element("error")
     self.error.set("type", error_type)
     self.message = ET.Element(error_name)
     self.message.set("xmlns", "urn:ietf:params:xml:ns:xmpp-stanzas")
     self.error.append(self.message)
     self.element.append(self.error)