Beispiel #1
0
def getNicknameByJID(jid):
    global entitycache
    sh = shelve.open(entitycache)
    jid = utils.stripJID(jid)
    for nickname in sh:
        if jid in sh[nickname]['jids']:
            sh.close()
            return nickname
    sh.close()
    return False
Beispiel #2
0
    def run(self):
        logger.info("Starting up XMPP clients...")

        for each in self.clients:
            each[0].start()

        logger.info("All XMPP Clients fired.")
        logger.info("Feed watchdog.")
        self.feedDog()

        # begin looping
        while not self.sig_terminate.isSet():
            logger.debug("Enter a daemon running loop.")

            # Job now.
            now = time.time()

            # Job #1: Check if clients got messages for us.
            newmessages = []
            for each in self.clients:
                if each[0].isAlive():
                    newmessages += each[0].getMessage()
            if newmessages:
                logger.info("New message(s) retrived from clients. Will parse them.")
                for msg in newmessages:
                    #                    print msg
                    processor.handle(msg["message"], utils.stripJID(str(msg["jid"])))
                newmessages = []

            # Job #2: Check if there is anything to send.
            missions = utils.stack_get("outgoing")
            if missions:
                logger.info("New mission(s) accepted. Distributing them to clients.")
                for mission in missions:
                    for each in self.clients:
                        if not each[0].isAlive():
                            continue
                        each[1].append(mission)
            logger.info("Will try sending messages(if any).")
            for each in self.clients:
                if not each[1]:
                    continue
                if not each[0].isAlive():
                    logger.debug("[%s] is not alive. Will omit its job." % each[0].jid)
                    continue
                if not each[0].connect_status == 2:
                    logger.debug(
                        "[%s] is not connected(Status: %s). Will omit its job." % (each[0].jid, each[0].connect_status)
                    )
                    continue
                if each[0].xmpp.client_roster or True:  # XXX This hack enables forcing each account to send.
                    mission = each[1].pop(0)
                    possible_jids = entity.getJIDsByNickname(mission["receiver"])
                    if possible_jids == False:
                        continue
                    for jid in possible_jids:
                        if utils.stripJID(jid) == utils.stripJID(each[0].jid):
                            continue
                        if jid in each[0].xmpp.client_roster.keys() or True:  # The same with XXX
                            logger.debug("Set [%s] a new mission." % each[0].jid)
                            each[0].setMessage(jid, mission["message"])

            # Do WatchDog
            self.watchDog()
            # Now All Job Done
            time.sleep(0.1)

        logger.info("Exit the program.")
        for each in self.clients:
            each[0].terminate()
            each[0].join(10)
            if each[0].isAlive():
                try:
                    each[0].abort()
                except:
                    pass
Beispiel #3
0
if cachetime <= max(os.path.getmtime(entityconfig),
                    os.path.getmtime(entitypy)):
    print 'Generating entity cache.'

    sh = shelve.open(entitycache,writeback=True)
    sh.clear()

    cfg = ConfigParser.ConfigParser()
    cfg.read(entityconfig)
    
    for nickname in cfg.sections():
        sh[nickname] = {'special':{}, 'jids':[]}
        for x,y in cfg.items(nickname):
            x = x.strip().lower()
            if x.startswith('account'):
                sh[nickname]['jids'].append(utils.stripJID(y))
            elif x == 'allow_special':
                specials = [t.strip().lower() for t in y.split(',')]
                for special in specials:
                    if special.startswith('*'):
                        special = special[1:]
                        appendvalue = 0
                    else:
                        appendvalue = 1
                    if special in utils.SPECIALS:
                        sh[nickname]['special'][special] = appendvalue
    sh.close()

def getSpecialAuthsByNickname(nickname):
    global entitycache
    sh = shelve.open(entitycache)