예제 #1
0
파일: queues.py 프로젝트: Kiesco08/pjabberd
def pickupResults():
    """Picks up any available results on the result queue and calls
    runMessages() to continue processing the queue.
    """
    while 1:
        try:
            connId, out = resultQ.get_nowait()
            for server in activeServers:
                if connId in server.conns:
                    conn = server.conns[connId][1]
                    # FIXME: this should be prevented. test socket for writability
                    try:
                        conn.send(prepareDataForSending(out))
                    except socket.error, e:
                        logging.warning("[pickupResults] Socket error: %s", e)
                    break
            else:
                # message left on the queue for a connection that's no longer
                # there, so we log it and move on
                logging.debug(
                    "[pickupResults] Connection id %s has no corresponding"
                    + " Connection object. Dropping result from queue.",
                    connId,
                )
            resultQ.task_done()
            del _runningMessages[connId]
예제 #2
0
    def handle(self, tree, msg, lastRetVal=None):
        # TODO: continue with features, auth, etc.
        # for now, just assume it's localhost

        # forward any queued messages for this connection
        out = prepareDataForSending(msg.conn.outQueue)
        return chainOutput(lastRetVal, out)
예제 #3
0
파일: stream.py 프로젝트: Kiesco08/pjabberd
    def handle(self, tree, msg, lastRetVal=None):
        # TODO: continue with features, auth, etc.
        # for now, just assume it's localhost

        # forward any queued messages for this connection
        out = prepareDataForSending(msg.conn.outQueue)
        return chainOutput(lastRetVal, out)
예제 #4
0
        def act():
            d = msg.conn.data
            if 'new-s2s-conn' not in d or \
                'hostname' not in d['new-s2s-conn'] or \
                'ip' not in d['new-s2s-conn']:
                logging.warning(
                    "[%s] Invoked without necessary data in connection",
                    self.__class__)
                return

            local = False
            if d['new-s2s-conn'].get('local'):
                local = True

            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((d['new-s2s-conn']['ip'],
                          d['new-s2s-conn'].setdefault('port', 5269)))

            serv = msg.conn.server.launcher.getS2SServer()
            if not serv:
                logging.warning("[%s] Can't find an S2SServer in launcher",
                                self.__class__)
                return

            if local:
                conn = serv.createLocalOutConnection(sock)
                # if we're connecting to ourselves, we don't need the <stream>.
                # instead just send out the outQueue
                data = d['new-s2s-conn'].get('queue')
                if data is not None:
                    conn.send(prepareDataForSending(data))
            else:
                sOutConn = serv.createRemoteOutConnection(sock)

                # copy over any queued messages to send once fully connected
                sOutConn.outQueue.extend(d['new-s2s-conn'].setdefault(
                    'queue', []))

                # register the connection with the S2S server
                serverConns = serv.s2sConns.setdefault(
                    d['new-s2s-conn']['hostname'], [None, None])
                serverConns[1] = sOutConn

                # send the initial stream
                # commenting this out for now as it causes expat problems
                sOutConn.send("<?xml version='1.0' ?>")
                sOutConn.send("<stream:stream xmlns='jabber:server' " +\
                              "xmlns:stream='http://etherx.jabber.org/streams' " +\
                              "to='%s' " % d['new-s2s-conn']['hostname'] + \
                              "version='1.0'>")
예제 #5
0
파일: stream.py 프로젝트: Kiesco08/pjabberd
        def act():
            d = msg.conn.data
            if "new-s2s-conn" not in d or "hostname" not in d["new-s2s-conn"] or "ip" not in d["new-s2s-conn"]:
                logging.warning("[%s] Invoked without necessary data in connection", self.__class__)
                return

            local = False
            if d["new-s2s-conn"].get("local"):
                local = True

            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((d["new-s2s-conn"]["ip"], d["new-s2s-conn"].setdefault("port", 5269)))

            serv = msg.conn.server.launcher.getS2SServer()
            if not serv:
                logging.warning("[%s] Can't find an S2SServer in launcher", self.__class__)
                return

            if local:
                conn = serv.createLocalOutConnection(sock)
                # if we're connecting to ourselves, we don't need the <stream>.
                # instead just send out the outQueue
                data = d["new-s2s-conn"].get("queue")
                if data is not None:
                    conn.send(prepareDataForSending(data))
            else:
                sOutConn = serv.createRemoteOutConnection(sock)

                # copy over any queued messages to send once fully connected
                sOutConn.outQueue.extend(d["new-s2s-conn"].setdefault("queue", []))

                # register the connection with the S2S server
                serverConns = serv.s2sConns.setdefault(d["new-s2s-conn"]["hostname"], [None, None])
                serverConns[1] = sOutConn

                # send the initial stream
                # commenting this out for now as it causes expat problems
                sOutConn.send("<?xml version='1.0' ?>")
                sOutConn.send(
                    "<stream:stream xmlns='jabber:server' "
                    + "xmlns:stream='http://etherx.jabber.org/streams' "
                    + "to='%s' " % d["new-s2s-conn"]["hostname"]
                    + "version='1.0'>"
                )
예제 #6
0
def pickupResults():
    """Picks up any available results on the result queue and calls
    runMessages() to continue processing the queue.
    """
    while 1:
        try:
            connId, out = resultQ.get_nowait()
            for server in activeServers:
                if connId in server.conns:
                    conn = server.conns[connId][1]
                    # FIXME: this should be prevented. test socket for writability
                    try:
                        conn.send(prepareDataForSending(out))
                    except socket.error, e:
                        logging.warning("[pickupResults] Socket error: %s", e)
                    break
            else:
                # message left on the queue for a connection that's no longer
                # there, so we log it and move on
                logging.debug("[pickupResults] Connection id %s has no corresponding" +\
                                " Connection object. Dropping result from queue.", connId)
            resultQ.task_done()
            del _runningMessages[connId]
예제 #7
0
            def f(i):
                if not conns[i][0]: return False
                return conns[i][0] == jid
        else:
            # locate all active resources of this JID
            def f(i):
                jidConn = conns[i]
                if not jidConn[0]: return False
                return jidConn[0].node == jid.node and jidConn[
                    0].domain == jid.domain

        activeJids = filter(f, conns)
        for con in activeJids:
            if callable(preprocessFunc):
                conns[con][1].send(
                    prepareDataForSending(preprocessFunc(data, conns[con][1])))
            else:
                conns[con][1].send(prepareDataForSending(data))


class ServerRouteHandler(Handler):
    """Handles routing of data to a client on this server.
    This handlers requires lastRetVal[-1] to contain the routing data. See
    ClientRouteHandler.__doc__.
    """
    def handle(self, tree, msg, lastRetVal=None):
        if not isinstance(lastRetVal[-1], dict):
            logging.warning("[%s] Passed in incorrect routing structure",
                            self.__class__)
            return
예제 #8
0
파일: route.py 프로젝트: Kiesco08/pjabberd
                if not conns[i][0]:
                    return False
                return conns[i][0] == jid

        else:
            # locate all active resources of this JID
            def f(i):
                jidConn = conns[i]
                if not jidConn[0]:
                    return False
                return jidConn[0].node == jid.node and jidConn[0].domain == jid.domain

        activeJids = filter(f, conns)
        for con in activeJids:
            if callable(preprocessFunc):
                conns[con][1].send(prepareDataForSending(preprocessFunc(data, conns[con][1])))
            else:
                conns[con][1].send(prepareDataForSending(data))


class ServerRouteHandler(Handler):
    """Handles routing of data to a client on this server.
    This handlers requires lastRetVal[-1] to contain the routing data. See
    ClientRouteHandler.__doc__.
    """

    def handle(self, tree, msg, lastRetVal=None):
        if not isinstance(lastRetVal[-1], dict):
            logging.warning("[%s] Passed in incorrect routing structure", self.__class__)
            return