예제 #1
0
    def connect_stream(self):
        try:  #protection against None stream
            self.hash = self.j.s5bserver.conn_id(self.sid, self.j.stream.me,
                                                 self.jid)
        except AttributeError:
            self.event("stream_connect_failed")
            return
        self.j.s5bserver.add_hash(self.hash)

        i = Iq(to_jid=self.jid, stanza_type='set')
        b = ByteStreams(sid=self.sid)
        if pref('jabber.use_direct_ft'):
            if not pref('jabber.use_faulty_localhost_ips'):
                [
                    b.add_host(self.j.stream.me, h[0], h[1])
                    for h in self.j.s5bserver.hosts
                ]
            else:
                [
                    b.add_host(self.j.stream.me, h[0].replace("192", "129"),
                               h[1]) for h in self.j.s5bserver.hosts
                ]
        if pref('jabber.use_proxy_ft'):
            b.hosts.extend(
                set(h for hosts in self.j.known_s5b_proxies.values()
                    for h in hosts))
            if pref('jabber.use_jabber_org_proxy', True):
                b.add_host("proxy.jabber.org", "208.245.212.98", 7777)
        b.as_xml(i.get_node())

        self.j.send_cb(i,
                       success=self.handle_ready,
                       error=self.handle_error,
                       timeout=self.timed_out)
예제 #2
0
파일: chat.py 프로젝트: mor1/karaka
    def probe(self, stanza):
        dbg("probe:\n%s" % (fmt_evt(stanza,)))
        StLock.acquire()
        try:
            to = stanza.get_to()
            if (to.node, to.domain) == (None, self.config.component):
                ## probe to us
                self.safe_send(Presence(from_jid=self.config.component, to_jid=get_from(stanza)))

            elif to.domain == self.config.component:
                frm = get_from(stanza)
                ujid = frm.bare()
                if ujid not in St['users']:
                    err("probe from unknown user!  ujid:%s" % (ujid.as_utf8(),))
                    return True

                djid = St['users'][ujid]
                if (djid not in St['dialback_online']
                    or (djid in St['dialback_online']
                        and St['dialback_online'][djid] == DIALBACK.pending
                        )):
                    return True
                
                iq = Iq(to_jid=djid, from_jid=self.config.component, stanza_type="set")
                command = iq.new_query("http://vipadia.com/skype", "command")
                add_child(command, "item", attrs={ "command": "probe",
                                                   "from": to.node,
                                                   })
                dbg("  probe:\n%s" % (fmt_evt(iq),))
                self.safe_send(iq)

            return True
        finally:
            StLock.release()
예제 #3
0
    def presence_error(self, p):
        dbg("presence_error:\n%s" % (fmt_evt(p), ))
        StLock.acquire()
        try:
            djid = get_from(p)
            if djid in St['dialbacks']:
                to = St['dialbacks'][djid]
                p.set_from(p.get_to())
                p.set_to(to)
                self.safe_send(p)

                if is_googletalk():
                    iq = Iq(to_jid=self.config.register,
                            from_jid=self.config.component,
                            stanza_type="set")
                    command = iq.new_query("http://vipadia.com/skype",
                                           "command")
                    add_child(command,
                              "item",
                              attrs={
                                  "command": "message",
                                  "message": Msgs.bad_credentials,
                                  "ujid": to.as_utf8(),
                              })
                    dbg("  iq:\n%s" % (fmt_evt(iq), ))
                    self.safe_send(iq)

            return True
        finally:
            StLock.release()
예제 #4
0
파일: chat.py 프로젝트: mor1/karaka
    def subscribed(self, stanza):
        dbg("subscribed:\n%s" % (fmt_evt(stanza),))
        StLock.acquire()
        try:
            to = stanza.get_to()
            if to.bare().as_utf8() == self.config.component:
                ## to master
                pass

            else: ## to user @ skype
                frm = get_from(stanza)
                if frm in St['dialbacks']:
                    ## ...from skype user
                    ujid = St['dialbacks'][frm]
                    self.safe_send(Stanza(stanza, to_jid=ujid, from_jid=stanza.get_to()))

                else: ## ...from a dialback: forward on to user
                    ujid = frm.bare()
                    if ujid not in St['users']: return True
                    djid = St['users'][ujid]

                    iq = Iq(to_jid=djid, from_jid=self.config.component, stanza_type="set")
                    command = iq.new_query("http://vipadia.com/skype", "command")
                    add_child(command, "item", attrs={ "from": "%s" % to.node,
                                                       "command": "subscribed",
                                                       })
                    dbg("  subscribed:\n%s" % (fmt_evt(iq),))
                    self.safe_send(iq)

            return True
        finally:
            StLock.release()
예제 #5
0
파일: chat.py 프로젝트: mor1/karaka
    def presence_error(self, p):
        dbg("presence_error:\n%s" % (fmt_evt(p),))
        StLock.acquire()
        try:
            djid = get_from(p)
            if djid in St['dialbacks']:
                to = St['dialbacks'][djid]
                p.set_from(p.get_to())
                p.set_to(to)
                self.safe_send(p)

                if is_googletalk():
                    iq = Iq(to_jid=self.config.register,
                            from_jid=self.config.component, stanza_type="set")
                    command = iq.new_query("http://vipadia.com/skype", "command")
                    add_child(command, "item", attrs={ "command": "message",
                                                       "message": Msgs.bad_credentials,
                                                       "ujid": to.as_utf8(),
                                                       })
                    dbg("  iq:\n%s" % (fmt_evt(iq),))
                    self.safe_send(iq)

            return True
        finally:
            StLock.release()
예제 #6
0
파일: bundle.py 프로젝트: mor1/karaka
def destroy_muc(gid):
    dbg("  destroy-muc: gid:%s" % (gid,))
    iq = Iq(to_jid=Muc, stanza_type="set")
    command = iq.new_query("http://vipadia.com/skype", "command")
    add_child(command, "item", attrs={ "command": "destroy-muc",
                                       "gid": gid,
                                       })
    Bundle.safe_send(Iq(iq))
예제 #7
0
def destroy_muc(gid):
    dbg("  destroy-muc: gid:%s" % (gid,))
    iq = Iq(to_jid=Muc, stanza_type="set")
    command = iq.new_query("http://vipadia.com/skype", "command")
    add_child(command, "item", attrs={ "command": "destroy-muc",
                                       "gid": gid,
                                       })
    Bundle.safe_send(Iq(iq))
예제 #8
0
파일: xmppfb.py 프로젝트: AlexUlrich/digsby
    def request_vcard(self, jid, callback=None):
        i = Iq(stanza_type='get');
        if jid: i.set_to(JID(jid).bare())

        _q = i.add_new_content('vcard-temp', 'vCard');
        #Facebook chat servers don't like the below two items
#        q.setProp('prodid', '-//HandGen//NONSGML vGen v1.0//EN')
#        q.setProp('version', '2.0');

        self.send_cb(i, callback=callback)
예제 #9
0
파일: core.py 프로젝트: Apkawa/nyasha
    def send_ping(self):
        client_jid = JID(settings.JABBER_BOT_SETTINGS['jid'])

        ping = Iq(to_jid=client_jid.domain, from_jid=client_jid, stanza_type='get')
        ping.new_query('urn:xmpp:ping', name='ping')

        self.get_stream().set_response_handlers(ping, res_handler=self.pong_handler,
                err_handler=lambda x: x, timeout_handler=self.pong_timeout_handler, timeout=120)
        self.get_stream().send(ping)
        self.last_ping_time = time.time()
예제 #10
0
파일: xmppfb.py 프로젝트: sgricci/digsby
    def request_vcard(self, jid, callback=None):
        i = Iq(stanza_type='get')
        if jid: i.set_to(JID(jid).bare())

        _q = i.add_new_content('vcard-temp', 'vCard')
        #Facebook chat servers don't like the below two items
        #        q.setProp('prodid', '-//HandGen//NONSGML vGen v1.0//EN')
        #        q.setProp('version', '2.0');

        self.send_cb(i, callback=callback)
예제 #11
0
    def _spawn(self, frm, user, secret):
        dbg("_spawn: frm:%s user:%s secret:%s" % (frm.as_utf8(), user, secret))

        ujid = frm.bare()

        ## don't spawn if one already exists for this user
        if ujid in St['users']: return

        self.regdb.log_start(ujid.as_utf8(), user)  # log it

        (slavejid, screen) = self.allocate_djid()
        if not slavejid: return "resource-constraint"

        djid = JID("%s@%s/%s:%s:%s" %
                   (self.config.dialback, self.config.domain, slavejid.node,
                    screen, hash(ujid)))

        dbg("  before avail: St['slots']:%s  St['dialback_slave']:%s" %
            (St['slots'], St['dialback_slave']))
        St['slots'][slavejid][screen] = djid
        St['dialback_slave'][djid] = (slavejid, screen)
        dbg("  after avail: St['slots']:%s  St['dialback_slave']:%s" %
            (St['slots'], St['dialback_slave']))

        St['dialbacks'][djid] = ujid
        St['users'][ujid] = djid
        if ujid not in St['userjids']: St['userjids'][ujid] = {}
        St['userjids'][ujid][frm] = None

        St['dialback_online'][djid] = DIALBACK.pending

        spawn = Iq(to_jid=slavejid,
                   from_jid=self.config.component,
                   stanza_type="set")
        query = spawn.new_query('http://vipadia.com/skype', "query")
        add_child(query,
                  "item",
                  attrs={
                      "skypeuser":
                      user,
                      "skypesecret":
                      secret,
                      "dialback":
                      djid.as_utf8(),
                      "secret":
                      self.config.dialback_secret,
                      "xmppujid":
                      ujid.as_utf8(),
                      "mode":
                      CLIENT_MODE,
                      "marketing-message":
                      self.regdb.get_marketing_message(frm.as_utf8()),
                  })
        dbg("  spawn:\n%s" % (fmt_evt(spawn), ))
        self.safe_send(spawn)
예제 #12
0
파일: slave.py 프로젝트: Ranushka/karaka
 def slave_online(self):
     slavejid = JID("%s@%s/slave" % (self.config.slave, self.config.domain))
     iq = Iq(to_jid=self.config.master, from_jid=slavejid, stanza_type="set")
     command = iq.new_query('http://vipadia.com/skype', "command")
     digest = generate_slave_digest(str(slavejid.as_utf8()),
                                    self.config.slave_secret)
     add_child(command, "item", attrs={ "command": "slave-online",
                                        "capacity": self.config.capacity,
                                        "base": self.config.base,
                                        "digest": digest
                                        })
     dbg("  iq:\n%s" % (fmt_evt(iq),))
     self.safe_send(iq)
예제 #13
0
파일: bundle.py 프로젝트: mor1/karaka
    def vipadia_command(self, iq):
        dbg("vipadia_command:\n%s" % (fmt_evt(iq),), 3)

        if not self.attached: return True

        to = iq.get_to()
        if to != self.jid:
            err("misdirected vipadia_command!\n%s" % (fmt_evt(iq),))
            return True

        frm = iq.get_from()
        if (frm.domain not in (Master, Muc)):
            err("command untrusted source!  jid:%s stanza:\n%s" % (self.jid, fmt_evt(iq)))
            return True
            
        items = iq.xpath_eval("v:command/v:item", { "v": "http://vipadia.com/skype", })
        for item in items:
            command = item.prop("command")
            if command == "subscribed":
                frm = item.prop("from")
                for user in self.skype.UsersWaitingAuthorization:
                    dbg("  frm:%s waiting:%s" % (frm, user.Handle,))
                    if user.Handle == frm: user.IsAuthorized = True ; break
            
            elif command == "subscribe":
                frm = item.prop("from")
                for friend in self.skype.Friends:
                    if friend.Handle == frm and friend.BuddyStatus == 3:
                        ## already a friend
                        iq = Iq(to_jid=Master, stanza_type="set")
                        command = iq.new_query("http://vipadia.com/skype", "command")
                        add_child(command, "item", attrs={ "command": "subscribed",
                                                           "from": friend.Handle,
                                                           })
                        self.safe_send(iq)
                        return True
                    
                skcmd = self.skype.Command(
                    "SET USER %s BUDDYSTATUS 2 Please authorize me" % (frm,))
                self.skype.SendCommand(skcmd)

            elif command == "probe":
                frm = item.prop("from")
                for friend in self.skype.Friends:
                    if friend.Handle != frm: continue
                    skype_OnOnlineStatus(friend, friend.OnlineStatus)
            
            else:
                err("unknown command!  command:%s\n%s" % (command, fmt_evt(iq),))
        
        return True
예제 #14
0
    def vipadia_command(self, iq):
        dbg("vipadia_command:\n%s" % (fmt_evt(iq),), 3)

        if not self.attached: return True

        to = iq.get_to()
        if to != self.jid:
            err("misdirected vipadia_command!\n%s" % (fmt_evt(iq),))
            return True

        frm = iq.get_from()
        if (frm.domain not in (Master, Muc)):
            err("command untrusted source!  jid:%s stanza:\n%s" % (self.jid, fmt_evt(iq)))
            return True
            
        items = iq.xpath_eval("v:command/v:item", { "v": "http://vipadia.com/skype", })
        for item in items:
            command = item.prop("command")
            if command == "subscribed":
                frm = item.prop("from")
                for user in self.skype.UsersWaitingAuthorization:
                    dbg("  frm:%s waiting:%s" % (frm, user.Handle,))
                    if user.Handle == frm: user.IsAuthorized = True ; break
            
            elif command == "subscribe":
                frm = item.prop("from")
                for friend in self.skype.Friends:
                    if friend.Handle == frm and friend.BuddyStatus == 3:
                        ## already a friend
                        iq = Iq(to_jid=Master, stanza_type="set")
                        command = iq.new_query("http://vipadia.com/skype", "command")
                        add_child(command, "item", attrs={ "command": "subscribed",
                                                           "from": friend.Handle,
                                                           })
                        self.safe_send(iq)
                        return True
                    
                skcmd = self.skype.Command(
                    "SET USER %s BUDDYSTATUS 2 Please authorize me" % (frm,))
                self.skype.SendCommand(skcmd)

            elif command == "probe":
                frm = item.prop("from")
                for friend in self.skype.Friends:
                    if friend.Handle != frm: continue
                    skype_OnOnlineStatus(friend, friend.OnlineStatus)
            
            else:
                err("unknown command!  command:%s\n%s" % (command, fmt_evt(iq),))
        
        return True
예제 #15
0
    def send_offer(self):
        self.state = self.states.WAITING_FOR_BUDDY

        i = Iq(to_jid=self.jid, stanza_type='set')

        #CAS: id generator for streams
        si = SI_FileTransfer(self.sid)
        si.file = File(self.filestor.name, self.filestor.size)
        si.feature = Feature(possible_streams=supported_streams)
        si.as_xml(i.get_node())

        self.j.send_cb(i, success = self.handle_response,
                          error   = self.handle_error,
                          timeout = self.timed_out)
예제 #16
0
 def handle_proxy_connect(self):
     log.info('handle_proxy_connect called')
     self.conn.set_terminator(0)
     #activate
     streamhost = self.streamhost
     sh_jid = streamhost.jid
     targ_jid = self.jid
     b = ByteStreams(None, self.sid)
     b.activate = targ_jid
     i = Iq(to_jid=sh_jid, stanza_type='set')
     b.as_xml(i.get_node())
     self.j.send_cb(i, success=self.handle_proxy_activate,
                       error=self.handle_proxy_failure2,
                       timeout=self.proxy_activate_timeout)
예제 #17
0
파일: bundle.py 프로젝트: mor1/karaka
def skype_OnAttachmentStatus(status):
    try:
        dbg("skype_OnAttachmentStatus: status:%s" % (status,), 3)

        if status == Skype4Py.apiAttachAvailable:
            try:
                status = Bundle.skype.Attach()

            except Exception, exc:
                log_stacktrace(exc)
                Bundle.running = False
                raise

        if status != Skype4Py.apiAttachSuccess:
            return

        dbg("  attached!")
        Bundle.attached = True
        
        time.sleep(1) ## skype needs some me-time before doing anything
        Bundle.safe_send(Presence(to_jid=Master))

        rosterq = Iq(to_jid=Master, stanza_type="set")

        x = rosterq.new_query('http://jabber.org/protocol/rosterx', "x")
        for user in Bundle.skype.Friends:
            handle, name = user.Handle, user.Handle
            jid = "%s@%s" % (handle, Master)

            add_child(x, "item", attrs={ "action": "add",
                                         "jid": jid,
                                         "name": name,
                                         "group": "Skype", })

        dbg("  roster:\n%s" % (fmt_evt(rosterq),), 3)
        Bundle.safe_send(rosterq)

        if is_googletalk():
            for friend in Bundle.skype.Friends:
                iq = Iq(to_jid=Master, stanza_type="set")
                command = iq.new_query("http://vipadia.com/skype", "command")
                add_child(command, "item", attrs={ "command": "out-subscribe",
                                                   "from": friend.Handle,
                                                   })
                Bundle.safe_send(iq)
            
        dbg("  waiting:%s" % (Bundle.skype.UsersWaitingAuthorization,))
        for user in Bundle.skype.UsersWaitingAuthorization:
            skype_OnUserAuthorizationRequestReceived(user)
예제 #18
0
def skype_OnUserAuthorizationRequestReceived(user):
    try:
        dbg("skype_OnUserAuthorizationRequestReceived: user:%s" % (user,), 2)

        iq = Iq(to_jid=Master, stanza_type="set")
        command = iq.new_query("http://vipadia.com/skype", "command")
        add_child(command, "item", attrs={ "from": "%s@%s" % (user.Handle, Master),
                                           "djid": Bundle.jid.as_utf8(),
                                           "command": "subscribe",
                                           })
        dbg("  subscribe:\n%s" % (fmt_evt(iq),))
        Bundle.safe_send(iq)

    except Exception, exc:
        log_stacktrace(exc)
예제 #19
0
파일: bundle.py 프로젝트: mor1/karaka
def skype_OnUserAuthorizationRequestReceived(user):
    try:
        dbg("skype_OnUserAuthorizationRequestReceived: user:%s" % (user,), 2)

        iq = Iq(to_jid=Master, stanza_type="set")
        command = iq.new_query("http://vipadia.com/skype", "command")
        add_child(command, "item", attrs={ "from": "%s@%s" % (user.Handle, Master),
                                           "djid": Bundle.jid.as_utf8(),
                                           "command": "subscribe",
                                           })
        dbg("  subscribe:\n%s" % (fmt_evt(iq),))
        Bundle.safe_send(iq)

    except Exception, exc:
        log_stacktrace(exc)
예제 #20
0
    def send_offer(self):
        self.state = self.states.WAITING_FOR_BUDDY

        i = Iq(to_jid=self.jid, stanza_type='set')

        #CAS: id generator for streams
        si = SI_FileTransfer(self.sid)
        si.file = File(self.filestor.name, self.filestor.size)
        si.feature = Feature(possible_streams=supported_streams)
        si.as_xml(i.get_node())

        self.j.send_cb(i,
                       success=self.handle_response,
                       error=self.handle_error,
                       timeout=self.timed_out)
예제 #21
0
 def handle_proxy_connect(self):
     log.info('handle_proxy_connect called')
     self.conn.set_terminator(0)
     #activate
     streamhost = self.streamhost
     sh_jid = streamhost.jid
     targ_jid = self.jid
     b = ByteStreams(None, self.sid)
     b.activate = targ_jid
     i = Iq(to_jid=sh_jid, stanza_type='set')
     b.as_xml(i.get_node())
     self.j.send_cb(i,
                    success=self.handle_proxy_activate,
                    error=self.handle_proxy_failure2,
                    timeout=self.proxy_activate_timeout)
예제 #22
0
 def incoming(self, stanza):
     """dispatch"""
     #CAS: error cases
     prof = stanza.xpath_eval('si:si/@profile', {'si': SI_NS})[0].content
     if prof not in self.handlers:
         self.respond_not_understood(stanza)
     else:
         self.handlers[prof](self, Iq(stanza.get_node()))
예제 #23
0
파일: slave.py 프로젝트: optixx/karaka
 def slave_online(self):
     slavejid = JID("%s@%s/slave" % (self.config.slave, self.config.domain))
     iq = Iq(to_jid=self.config.master,
             from_jid=slavejid,
             stanza_type="set")
     command = iq.new_query('http://vipadia.com/skype', "command")
     digest = generate_slave_digest(str(slavejid.as_utf8()),
                                    self.config.slave_secret)
     add_child(command,
               "item",
               attrs={
                   "command": "slave-online",
                   "capacity": self.config.capacity,
                   "base": self.config.base,
                   "digest": digest
               })
     dbg("  iq:\n%s" % (fmt_evt(iq), ))
     self.safe_send(iq)
예제 #24
0
파일: chat.py 프로젝트: mor1/karaka
    def _spawn(self, frm, user, secret):
        dbg("_spawn: frm:%s user:%s secret:%s" % (frm.as_utf8(), user, secret))

        ujid = frm.bare()
        
        ## don't spawn if one already exists for this user
        if ujid in St['users']: return
        
        self.regdb.log_start(ujid.as_utf8(), user) # log it

        (slavejid, screen) = self.allocate_djid()
        if not slavejid: return "resource-constraint"

        djid = JID("%s@%s/%s:%s:%s" % (
            self.config.dialback, self.config.domain, slavejid.node, screen, hash(ujid)))

        dbg("  before avail: St['slots']:%s  St['dialback_slave']:%s" % (
            St['slots'], St['dialback_slave']))
        St['slots'][slavejid][screen] = djid
        St['dialback_slave'][djid] = (slavejid, screen)
        dbg("  after avail: St['slots']:%s  St['dialback_slave']:%s" % (
            St['slots'], St['dialback_slave']))

        St['dialbacks'][djid] = ujid
        St['users'][ujid] = djid
        if ujid not in St['userjids']: St['userjids'][ujid] = {}
        St['userjids'][ujid][frm] = None

        St['dialback_online'][djid] = DIALBACK.pending

        spawn = Iq(to_jid=slavejid, from_jid=self.config.component, stanza_type="set")
        query = spawn.new_query('http://vipadia.com/skype', "query")
        add_child(query, "item",
                  attrs={ "skypeuser": user,
                          "skypesecret": secret,
                          "dialback": djid.as_utf8(),
                          "secret": self.config.dialback_secret,
                          "xmppujid": ujid.as_utf8(),
                          "mode": CLIENT_MODE,
                          "marketing-message": self.regdb.get_marketing_message(frm.as_utf8()),
                          })
        dbg("  spawn:\n%s" % (fmt_evt(spawn),))
        self.safe_send(spawn)
예제 #25
0
    def probe(self, stanza):
        dbg("probe:\n%s" % (fmt_evt(stanza, )))
        StLock.acquire()
        try:
            to = stanza.get_to()
            if (to.node, to.domain) == (None, self.config.component):
                ## probe to us
                self.safe_send(
                    Presence(from_jid=self.config.component,
                             to_jid=get_from(stanza)))

            elif to.domain == self.config.component:
                frm = get_from(stanza)
                ujid = frm.bare()
                if ujid not in St['users']:
                    err("probe from unknown user!  ujid:%s" %
                        (ujid.as_utf8(), ))
                    return True

                djid = St['users'][ujid]
                if (djid not in St['dialback_online'] or
                    (djid in St['dialback_online']
                     and St['dialback_online'][djid] == DIALBACK.pending)):
                    return True

                iq = Iq(to_jid=djid,
                        from_jid=self.config.component,
                        stanza_type="set")
                command = iq.new_query("http://vipadia.com/skype", "command")
                add_child(command,
                          "item",
                          attrs={
                              "command": "probe",
                              "from": to.node,
                          })
                dbg("  probe:\n%s" % (fmt_evt(iq), ))
                self.safe_send(iq)

            return True
        finally:
            StLock.release()
예제 #26
0
    def subscribed(self, stanza):
        dbg("subscribed:\n%s" % (fmt_evt(stanza), ))
        StLock.acquire()
        try:
            to = stanza.get_to()
            if to.bare().as_utf8() == self.config.component:
                ## to master
                pass

            else:  ## to user @ skype
                frm = get_from(stanza)
                if frm in St['dialbacks']:
                    ## ...from skype user
                    ujid = St['dialbacks'][frm]
                    self.safe_send(
                        Stanza(stanza, to_jid=ujid, from_jid=stanza.get_to()))

                else:  ## ...from a dialback: forward on to user
                    ujid = frm.bare()
                    if ujid not in St['users']: return True
                    djid = St['users'][ujid]

                    iq = Iq(to_jid=djid,
                            from_jid=self.config.component,
                            stanza_type="set")
                    command = iq.new_query("http://vipadia.com/skype",
                                           "command")
                    add_child(command,
                              "item",
                              attrs={
                                  "from": "%s" % to.node,
                                  "command": "subscribed",
                              })
                    dbg("  subscribed:\n%s" % (fmt_evt(iq), ))
                    self.safe_send(iq)

            return True
        finally:
            StLock.release()
예제 #27
0
    def lobby_update(self):
        # Only update if we're registered
        if not self.lobby_registered:
            return

        update_iq = Iq(stanza_type='set', to_jid=self.gamelist_jid)
        query_node = update_iq.new_query('garagegames:connect')
        query_node.newChild(None, 'command', 'lobby.update')
        args_node = query_node.newChild(None, 'args', None)
        args_node.newChild(None, 'state', self.state)
        canhost_node = args_node.newChild(None, 'canHost', 'true')
        canhost_node.setProp('type', 'boolean')

        if self.state in ['ready', 'playing']:
            args_node.newChild(None, 'matchID', '%s19884641' % self.bot_nick)
            args_node.newChild(None, 'game', 'Legions')
            args_node.newChild(None, 'gameLevelId', str(self.level_id))
            args_node.newChild(None, 'gameLevel', self.level)

            if self.game_handler.lt:
                game_mode = u'LT %s' % self.mode
            else:
                game_mode = self.mode

            args_node.newChild(None, 'gameMode', game_mode)
            args_node.newChild(None, 'jid', unicode(self.gamelist_jid))

        maxplayers_node = args_node.newChild(None, 'maxplayers', str(self.size_limit))
        maxplayers_node.setProp('type', 'number')
        args_node.newChild(None, 'partyJID', unicode(self.room_state.room_jid.bare()))
        args_node.newChild(None, 'private', yes_or_no(self.private))
        args_node.newChild(None, 'allowAnon', 'no')
        args_node.newChild(None, 'createdAt', self.lobby_started)
        # args_node.newChild(None, 'dedicatedServer', 'true')

        stream = self.room_state.manager.stream
        stream.send(update_iq)
예제 #28
0
    def connect_stream(self):
        try: #protection against None stream
            self.hash = self.j.s5bserver.conn_id(self.sid, self.j.stream.me, self.jid)
        except AttributeError:
            self.event("stream_connect_failed")
            return
        self.j.s5bserver.add_hash(self.hash)

        i = Iq(to_jid=self.jid, stanza_type='set')
        b = ByteStreams(sid = self.sid )
        if pref('jabber.use_direct_ft'):
            if not pref('jabber.use_faulty_localhost_ips'):
                [b.add_host(self.j.stream.me, h[0], h[1]) for h in self.j.s5bserver.hosts]
            else:
                [b.add_host(self.j.stream.me, h[0].replace("192", "129"),
                            h[1]) for h in self.j.s5bserver.hosts]
        if pref('jabber.use_proxy_ft'):
            b.hosts.extend(set(h for hosts in self.j.known_s5b_proxies.values() for h in hosts))
            if pref('jabber.use_jabber_org_proxy', True):
                b.add_host("proxy.jabber.org", "208.245.212.98", 7777)
        b.as_xml(i.get_node())


        self.j.send_cb(i, success=self.handle_ready, error=self.handle_error, timeout=self.timed_out)
예제 #29
0
파일: bundle.py 프로젝트: optixx/karaka
def skype_OnAttachmentStatus(status):
    try:
        dbg("skype_OnAttachmentStatus: status:%s" % (status, ), 3)

        if status == Skype4Py.apiAttachAvailable:
            try:
                status = Bundle.skype.Attach()

            except Exception, exc:
                log_stacktrace(exc)
                Bundle.running = False
                raise

        if status != Skype4Py.apiAttachSuccess:
            return

        dbg("  attached!")
        Bundle.attached = True

        time.sleep(1)  ## skype needs some me-time before doing anything
        Bundle.safe_send(Presence(to_jid=Master))

        rosterq = Iq(to_jid=Master, stanza_type="set")

        x = rosterq.new_query('http://jabber.org/protocol/rosterx', "x")
        for user in Bundle.skype.Friends:
            handle, name = user.Handle, user.Handle
            jid = "%s@%s" % (handle, Master)

            add_child(x,
                      "item",
                      attrs={
                          "action": "add",
                          "jid": jid,
                          "name": name,
                          "group": "Skype",
                      })

        dbg("  roster:\n%s" % (fmt_evt(rosterq), ), 3)
        Bundle.safe_send(rosterq)

        if is_googletalk():
            for friend in Bundle.skype.Friends:
                iq = Iq(to_jid=Master, stanza_type="set")
                command = iq.new_query("http://vipadia.com/skype", "command")
                add_child(command,
                          "item",
                          attrs={
                              "command": "out-subscribe",
                              "from": friend.Handle,
                          })
                Bundle.safe_send(iq)

        dbg("  waiting:%s" % (Bundle.skype.UsersWaitingAuthorization, ))
        for user in Bundle.skype.UsersWaitingAuthorization:
            skype_OnUserAuthorizationRequestReceived(user)
예제 #30
0
def register_keepalive():
    config = registerconfig.RegisterConfig()

    global Register
    Register = _Register(config)

    global RegDB
    RegDB = DatabaseAPI()

    keepalive = Iq(to_jid=config.domain, stanza_type="set")
    keptalive = 0

    while Register.running:
        try:
            if Register.connection == CONNECTION.idle:
                dbg("register connecting")
                Register.connect()
                Register.connection = CONNECTION.connecting

            elif Register.connection == CONNECTION.connecting:
                dbg("register connecting...")
                if Register.stream: Register.stream.loop_iter(1)

            elif Register.connection == CONNECTION.connected:
                dbg("looping register")
                if Register.stream: Register.stream.loop_iter(1)

                Register.idle()
                now = time.time()
                if now - keptalive > 60:
                    dbg("register keepalive! %s" % (fmt_evt(keepalive), ), 5)
                    Register.safe_send(keepalive)
                    keptalive = now

            elif Register.connection == CONNECTION.error:
                Register.connection = CONNECTION.idle

        except Exception, exc:
            log_stacktrace(exc)
            try:
                Register.disconnect()
            except Exception, exc:
                err("second chance!  failing")
                log_stacktrace(exc)

            Register.connection = CONNECTION.error
예제 #31
0
파일: master.py 프로젝트: smarchenah/karaka
def master_keepalive():
    config = masterconfig.MasterConfig()

    global Master
    Master = chat.Master(config)

    keepalive = Iq(to_jid=config.domain,
                   from_jid=config.component,
                   stanza_type="set")
    keptalive = 0

    while Master.running:
        try:
            if Master.connection == CONNECTION.idle:
                dbg("master connecting")
                Master.connect()
                Master.connection = CONNECTION.connecting

            elif Master.connection == CONNECTION.connecting:
                dbg("master connecting...")
                if Master.stream: Master.stream.loop_iter(1)

            elif Master.connection == CONNECTION.connected:
                dbg("looping master")
                if Master.stream: Master.stream.loop_iter(1)

                Master.idle()
                now = time.time()
                if now - keptalive > 60:
                    dbg("master keepalive! %s" % (fmt_evt(keepalive), ), 5)
                    Master.stream.send(keepalive)
                    keptalive = now

            elif Master.connection == CONNECTION.error:
                Master.connection = CONNECTION.idle

        except Exception, exc:
            log_stacktrace(exc)
            try:
                Master.disconnect()
            except Exception, exc:
                err("second chance!  failing")
                log_stacktrace(exc)

            Master.connection = CONNECTION.error
            time.sleep(1)
예제 #32
0
파일: slave.py 프로젝트: optixx/karaka
def slave_keepalive():
    name = sys.argv[1]
    config = slaveconfig.SlaveConfig(name)

    global Slave
    Slave = SkypeSlave(config)

    keepalive = Iq(to_jid=config.domain, stanza_type="set")
    keptalive = 0

    while Slave.running:
        try:
            if Slave.connection == CONNECTION.idle:
                dbg("slave connecting")
                Slave.connect()
                Slave.connection = CONNECTION.connecting

            elif Slave.connection == CONNECTION.connecting:
                dbg("slave connecting...")
                if Slave.stream: Slave.stream.loop_iter(1)

            elif Slave.connection == CONNECTION.connected:
                dbg("looping slave")
                if Slave.stream: Slave.stream.loop_iter(1)

                Slave.idle()
                now = time.time()
                if now - keptalive > 60:
                    dbg("slave keepalive! %s" % (fmt_evt(keepalive), ), 5)
                    Slave.safe_send(keepalive)
                    keptalive = now

            elif Slave.connection == CONNECTION.error:
                Slave.connection = CONNECTION.idle

        except Exception, exc:
            log_stacktrace(exc)
            try:
                Slave.disconnect()
            except Exception, exc:
                err("second chance!  failing")
                log_stacktrace(exc)

            Slave.connection = CONNECTION.error
예제 #33
0
파일: bundle.py 프로젝트: optixx/karaka
def skype_OnChatMembersChanged(chat, members):
    try:
        dbg(
            "skype_OnChatMembersChanged: chat:%s members:%s" % (
                chat,
                members,
            ), 4)
        if is_googletalk(): return True

        chatid = chat.Name
        handles = [m.Handle for m in members]
        dbg("  chatid:%s handles:%s" % (chatid, handles), 4)

        if Bundle.skypeuser not in handles:
            ## we've left!  tidy up
            gid = ChatIDs[chatid]
            del GIDs[gid], Nicks[gid]
            del ChatIDs[chatid]

            try:
                MembersLock.acquire()
                del Members[chatid]
            finally:
                MembersLock.release()

            if chatid in Msgs: del Msgs[chatid]
            destroy_muc(gid)
            return True

        if chatid not in Members and len(members) > 2:
            ## 1-1 chat has become multi-user chat!
            iq = Iq(to_jid=Muc, stanza_type="set")
            command = iq.new_query("http://vipadia.com/skype", "command")
            add_child(command,
                      "item",
                      attrs={
                          "command": "create-muc",
                          "chatid": chat.Name,
                          "jid": Bundle.xmppujid.as_utf8(),
                          "member": members[0].Handle,
                      })
            dbg("  create-muc:\n%s" % (fmt_evt(iq), ))

            try:
                MembersLock.acquire()
                Members[chatid] = {}
            finally:
                MembersLock.release()

            # set a handler for the reply
            Bundle.stream.set_response_handlers(iq, Bundle.muc_result,
                                                Bundle.muc_result)
            Bundle.safe_send(iq)

        empty_members = False
        try:
            MembersLock.acquire()
            empty_members = (chatid not in Members
                             or len(Members[chatid]) == 0)
        finally:
            MembersLock.release()
            if empty_members: return True

        ## on departure, we need to send unavailable to remove them from room
        try:
            MembersLock.acquire()
            chat_handles = Members[chatid].keys()
        finally:
            MembersLock.release()

        for handle in chat_handles:
            if handle not in handles:  ## ...member has left
                jid = "%s@%s/%s" % (ChatIDs[chatid], Muc, handle)
                Bundle.safe_send(
                    Presence(to_jid=jid, stanza_type="unavailable"))
                try:
                    MembersLock.acquire()
                    del Members[chatid][handle]
                finally:
                    MembersLock.release()

        ## on arrival, if there are *no* existing members, then the room is
        ## really "pending" and we don't send the presences yet (that will be
        ## handled when the groupchat sends us the room presence saying that the
        ## room is created).  if there *are* existing members, then this is
        ## simply someone joining an ongoing room and so we send available
        ## presence on their behalf.
        for handle in handles:
            if handle not in chat_handles:  ## ...member has joined
                jid = "%s@%s/%s" % (ChatIDs[chatid], Muc, handle)
                Bundle.safe_send(Presence(to_jid=jid))
                try:
                    MembersLock.acquire()
                    Members[chatid][handle] = None
                finally:
                    MembersLock.release()

    except Exception, exc:
        log_stacktrace(exc)
예제 #34
0
파일: chat.py 프로젝트: mor1/karaka
    def presence_available(self, stanza):
        dbg("presence_available:\n%s" % (fmt_evt(stanza),))
        StLock.acquire()
        try:
            global St

            frm = get_from(stanza) ## FFS.  GoogleTalk
            ujid = frm.bare()
            dbg("  frm:%s ujid:%s node:%s domain:%s resource:%s  config:%s,%s" % (
                frm.as_utf8(), ujid.as_utf8(), frm.node, frm.domain, frm.resource,
                self.config.dialback, self.config.domain))

            if (frm.node, frm.domain) == (self.config.dialback, self.config.domain):
                ## from bundle...
                djid = frm
                if djid not in St['dialbacks']:
                    self._send_suicide(djid) # tell bundle to suicide since it surprised us
                    return True

                to = stanza.get_to()
                if to.node: # ...for a skype jid ([email protected]) -- BUNDLE > USER
                    self.safe_send(Presence(stanza, to_jid=St['dialbacks'][frm], from_jid=to))

                else: # ...for us (master) -- bundle is online -- BUNDLE > MASTER
                    St['dialback_online'][djid] = DIALBACK.online
                    self.safe_send(Presence( # tell user that bundle online
                        stanza, to_jid=St['dialbacks'][djid], from_jid=self.config.component))
                    self.safe_send(Presence( # tell bundle that user online
                        stanza, to_jid=djid, from_jid=self.config.component))

            else: # from the user...
                dbg("  frm:%s St['users']:%s  Dbo:%s" % (
                    frm.as_utf8(), St['users'], St['dialback_online']))
                if (ujid in St['users'] and St['users'][ujid] in St['dialback_online']):
                    # ...which we knew about
                    dbg("  KNOWN JID")
                    djid = St['users'][ujid]
                    if St['dialback_online'][djid] == DIALBACK.online:
                        self.safe_send(Presence(
                            stanza, to_jid=djid, from_jid=self.config.component))
                    if ujid not in St['userjids']: St['userjids'][ujid] = {}
                    St['userjids'][ujid][frm] = None

                else: # ...but this is a new user -- spawn a bundle
                    if is_carrier(): return True

                    usersecret = self.regdb.get_credentials_crypt(ujid.as_utf8())
                    if not usersecret: return True
                    (user, secret) = usersecret

                    errstr = self._spawn(frm, user, secret)
                    if errstr:
                        err("spawn error! errstr:%s presence:\n%s" % (errstr, fmt_evt(stanza),))
                        ret = stanza.make_error_response(errstr)
                        ret.set_from(self.config.component)
                        self.safe_send(ret)

                        ## for the poor clients who haven't the foggiest about the
                        ## above error, send a message
                        if is_googletalk():
                            iq = Iq(to_jid=self.config.register, from_jid=self.config.component,
                                    stanza_type="set")
                            command = iq.new_query("http://vipadia.com/skype", "command")
                            add_child(command, "item", attrs={ "command": "message",
                                                               "message": Msgs.resource_constraint,
                                                               "ujid": ujid.as_utf8(),
                                                               })
                            dbg("  iq:\n%s" % (fmt_evt(iq),))
                            self.safe_send(iq)

            return True

        finally:
            StLock.release()
예제 #35
0
    def message(self, stanza):
        dbg(
            "message:\nfrm:%s to:%s" % (
                stanza.get_from().as_utf8(),
                stanza.get_to().as_utf8(),
            ), 3)
        global RegDB

        body = stanza.get_body()
        frm = stanza.get_from()
        user = stanza.get_from().bare().as_utf8()

        ujid = JID(user)
        dbg("  ++ujid:%s precedingmessage:%s" % (
            ujid.as_utf8(),
            PrecedingMessage,
        ))
        if ujid in PrecedingMessage: del PrecedingMessage[ujid]
        dbg("  --ujid:%s precedingmessage:%s" % (
            ujid.as_utf8(),
            PrecedingMessage,
        ))

        if body:
            cmd = body.split()
            if len(cmd) > 0:
                reply = ""
                if cmd[0].lower() == "register":
                    if len(cmd) != 3:
                        reply = "error, please use: register <skypeuser> <skypepassword>"

                    skypeuser = cmd[1]
                    skypepass = cmd[2]

                    RegDB.remove_credentials(user)
                    RegDB.set_credentials_plain(user, skypeuser, skypepass)

                    reply = "Registration successful for " + skypeuser
                    message = Message(to_jid=stanza.get_from(), body=reply)
                    self.safe_send(message)

                    sub = Iq(to_jid=self.config.master, stanza_type="set")
                    query = sub.new_query('http://vipadia.com/skype',
                                          "command")
                    add_child(query,
                              "item",
                              attrs={
                                  "command": "register-available",
                                  "jid": frm.as_utf8()
                              })
                    dbg("  sub:\n%s" % (fmt_evt(sub), ))
                    self.safe_send(sub)
                    reply = "Presence request sent"

                elif cmd[0].lower() == "register-carrier":
                    if len(cmd) != 3:
                        reply = "error, please use: register <skypeuser> <skypepassword>"

                    skypeuser = cmd[1]
                    ## KeyCzar
                    ##                     crypter = keyczar.Encrypter.Read(PUBLIC_KEYLOC)
                    skypesecret = cmd[2]
                    ## KeyCzar
                    ##                     skypesecret = crypter.Encrypt(str(skypesecret))

                    spawn = Iq(to_jid=self.config.master, stanza_type="set")
                    command = spawn.new_query("http://vipadia.com/skype",
                                              "command")
                    add_child(command,
                              "item",
                              attrs={
                                  "command": "spawn",
                                  "ujid": frm.as_utf8(),
                                  "skypeuser": skypeuser,
                                  "skypesecret": skypesecret,
                              })
                    self.safe_send(spawn)

                elif cmd[0].lower() == "unregister":
                    if len(cmd) == 1:
                        RegDB.remove_credentials(user)
                        reply = "Unregistration successful"

                else:
                    reply = "Skype Registration Commands:\r\n" + \
                    " register <skypeuser> <skypepass>\r\n" + \
                    " unregister"

                message = Message(to_jid=stanza.get_from(), body=reply)
                self.safe_send(message)

        return True
예제 #36
0
파일: register.py 프로젝트: mor1/karaka
    def message(self, stanza):
        dbg("message:\nfrm:%s to:%s" % (
            stanza.get_from().as_utf8(), stanza.get_to().as_utf8(),), 3)
        global RegDB
        
        body = stanza.get_body()
        frm = stanza.get_from()
        user = stanza.get_from().bare().as_utf8()

        ujid = JID(user)
        dbg("  ++ujid:%s precedingmessage:%s" % (ujid.as_utf8(), PrecedingMessage,))
        if ujid in PrecedingMessage: del PrecedingMessage[ujid]
        dbg("  --ujid:%s precedingmessage:%s" % (ujid.as_utf8(), PrecedingMessage,))
                                                               
        if body:         
            cmd = body.split()
            if len(cmd) > 0 :
                reply = ""
                if cmd[0].lower() == "register":
                    if len(cmd) != 3:
                        reply = "error, please use: register <skypeuser> <skypepassword>"

                    skypeuser = cmd[1]
                    skypepass = cmd[2]
                    
                    RegDB.remove_credentials(user)
                    RegDB.set_credentials_plain(user, skypeuser, skypepass)
                                                                     
                    reply = "Registration successful for " + skypeuser
                    message = Message(to_jid=stanza.get_from(), body=reply)
                    self.safe_send(message)

                    sub = Iq(to_jid=self.config.master, stanza_type="set")
                    query = sub.new_query('http://vipadia.com/skype', "command")
                    add_child(query, "item", attrs={ "command" : "register-available",
                                                     "jid": frm.as_utf8() })
                    dbg("  sub:\n%s" % (fmt_evt(sub),))
                    self.safe_send(sub)
                    reply = "Presence request sent"

                elif cmd[0].lower() == "register-carrier":
                    if len(cmd) != 3:
                        reply = "error, please use: register <skypeuser> <skypepassword>"
                        
                    skypeuser = cmd[1]
                    ## KeyCzar
##                     crypter = keyczar.Encrypter.Read(PUBLIC_KEYLOC)
                    skypesecret = cmd[2]
                    ## KeyCzar
##                     skypesecret = crypter.Encrypt(str(skypesecret))
                    
                    spawn = Iq(to_jid=self.config.master, stanza_type="set")
                    command = spawn.new_query("http://vipadia.com/skype", "command")
                    add_child(command, "item", attrs={ "command": "spawn",
                                                       "ujid": frm.as_utf8(),
                                                       "skypeuser": skypeuser,
                                                       "skypesecret": skypesecret,
                                                       })
                    self.safe_send(spawn)
                    
                elif cmd[0].lower() == "unregister":
                    if len(cmd) == 1:
                        RegDB.remove_credentials(user)
                        reply = "Unregistration successful"

                else:
                    reply = "Skype Registration Commands:\r\n" + \
                    " register <skypeuser> <skypepass>\r\n" + \
                    " unregister"
                
                message = Message(to_jid=stanza.get_from(), body=reply)
                self.safe_send(message)
        
        return True
예제 #37
0
파일: bundle.py 프로젝트: mor1/karaka
def skype_OnChatMembersChanged(chat, members):
    try:
        dbg("skype_OnChatMembersChanged: chat:%s members:%s" % (chat, members,), 4)
        if is_googletalk(): return True
        
        chatid = chat.Name
        handles = [ m.Handle for m in members ]
        dbg("  chatid:%s handles:%s" % (chatid, handles), 4)
        
        if Bundle.skypeuser not in handles:
            ## we've left!  tidy up
            gid = ChatIDs[chatid]
            del GIDs[gid], Nicks[gid]
            del ChatIDs[chatid]
            
            try:
                MembersLock.acquire()
                del Members[chatid]
            finally:
                MembersLock.release()
                                     
            if chatid in Msgs: del Msgs[chatid]
            destroy_muc(gid)
            return True

        if chatid not in Members and len(members) > 2:
            ## 1-1 chat has become multi-user chat!
            iq = Iq(to_jid=Muc, stanza_type="set")
            command = iq.new_query("http://vipadia.com/skype", "command")
            add_child(command, "item", attrs={ "command": "create-muc",
                                               "chatid": chat.Name,
                                               "jid": Bundle.xmppujid.as_utf8(),
                                               "member": members[0].Handle,
                                               })
            dbg("  create-muc:\n%s" % (fmt_evt(iq),))

            try:
                MembersLock.acquire()
                Members[chatid] = {}
            finally:
                MembersLock.release()

            # set a handler for the reply
            Bundle.stream.set_response_handlers(iq, Bundle.muc_result, Bundle.muc_result)
            Bundle.safe_send(iq)

        empty_members = False
        try:            
            MembersLock.acquire()
            empty_members = (chatid not in Members or len(Members[chatid]) == 0)
        finally:
            MembersLock.release()
            if empty_members: return True
            
        ## on departure, we need to send unavailable to remove them from room
        try:
            MembersLock.acquire()
            chat_handles = Members[chatid].keys()
        finally:
            MembersLock.release()
            
        for handle in chat_handles:
            if handle not in handles: ## ...member has left
                jid = "%s@%s/%s" % (ChatIDs[chatid], Muc, handle)
                Bundle.safe_send(Presence(to_jid=jid, stanza_type="unavailable"))
                try:
                    MembersLock.acquire()
                    del Members[chatid][handle]
                finally:
                    MembersLock.release()

        ## on arrival, if there are *no* existing members, then the room is
        ## really "pending" and we don't send the presences yet (that will be
        ## handled when the groupchat sends us the room presence saying that the
        ## room is created).  if there *are* existing members, then this is
        ## simply someone joining an ongoing room and so we send available
        ## presence on their behalf.
        for handle in handles:
            if handle not in chat_handles: ## ...member has joined
                jid = "%s@%s/%s" % (ChatIDs[chatid], Muc, handle)
                Bundle.safe_send(Presence(to_jid=jid))
                try:
                    MembersLock.acquire()
                    Members[chatid][handle] = None
                finally:
                    MembersLock.release()
           
    except Exception, exc:
        log_stacktrace(exc)
예제 #38
0
    def presence_available(self, stanza):
        dbg("presence_available:\n%s" % (fmt_evt(stanza), ))
        StLock.acquire()
        try:
            global St

            frm = get_from(stanza)  ## FFS.  GoogleTalk
            ujid = frm.bare()
            dbg("  frm:%s ujid:%s node:%s domain:%s resource:%s  config:%s,%s"
                % (frm.as_utf8(), ujid.as_utf8(), frm.node, frm.domain,
                   frm.resource, self.config.dialback, self.config.domain))

            if (frm.node, frm.domain) == (self.config.dialback,
                                          self.config.domain):
                ## from bundle...
                djid = frm
                if djid not in St['dialbacks']:
                    self._send_suicide(
                        djid)  # tell bundle to suicide since it surprised us
                    return True

                to = stanza.get_to()
                if to.node:  # ...for a skype jid ([email protected]) -- BUNDLE > USER
                    self.safe_send(
                        Presence(stanza,
                                 to_jid=St['dialbacks'][frm],
                                 from_jid=to))

                else:  # ...for us (master) -- bundle is online -- BUNDLE > MASTER
                    St['dialback_online'][djid] = DIALBACK.online
                    self.safe_send(
                        Presence(  # tell user that bundle online
                            stanza,
                            to_jid=St['dialbacks'][djid],
                            from_jid=self.config.component))
                    self.safe_send(
                        Presence(  # tell bundle that user online
                            stanza,
                            to_jid=djid,
                            from_jid=self.config.component))

            else:  # from the user...
                dbg("  frm:%s St['users']:%s  Dbo:%s" %
                    (frm.as_utf8(), St['users'], St['dialback_online']))
                if (ujid in St['users']
                        and St['users'][ujid] in St['dialback_online']):
                    # ...which we knew about
                    dbg("  KNOWN JID")
                    djid = St['users'][ujid]
                    if St['dialback_online'][djid] == DIALBACK.online:
                        self.safe_send(
                            Presence(stanza,
                                     to_jid=djid,
                                     from_jid=self.config.component))
                    if ujid not in St['userjids']: St['userjids'][ujid] = {}
                    St['userjids'][ujid][frm] = None

                else:  # ...but this is a new user -- spawn a bundle
                    if is_carrier(): return True

                    usersecret = self.regdb.get_credentials_crypt(
                        ujid.as_utf8())
                    if not usersecret: return True
                    (user, secret) = usersecret

                    errstr = self._spawn(frm, user, secret)
                    if errstr:
                        err("spawn error! errstr:%s presence:\n%s" % (
                            errstr,
                            fmt_evt(stanza),
                        ))
                        ret = stanza.make_error_response(errstr)
                        ret.set_from(self.config.component)
                        self.safe_send(ret)

                        ## for the poor clients who haven't the foggiest about the
                        ## above error, send a message
                        if is_googletalk():
                            iq = Iq(to_jid=self.config.register,
                                    from_jid=self.config.component,
                                    stanza_type="set")
                            command = iq.new_query("http://vipadia.com/skype",
                                                   "command")
                            add_child(command,
                                      "item",
                                      attrs={
                                          "command": "message",
                                          "message": Msgs.resource_constraint,
                                          "ujid": ujid.as_utf8(),
                                      })
                            dbg("  iq:\n%s" % (fmt_evt(iq), ))
                            self.safe_send(iq)

            return True

        finally:
            StLock.release()
예제 #39
0
파일: bundle.py 프로젝트: optixx/karaka
    jid, secret, skypeuser, skypesecret, xmppujid, \
         Mode, Master, Muc, Slave, Marketing_message = args

    jid = JID(jid)
    xmppujid = JID(xmppujid)

    logger = logging.getLogger()
    logger.addHandler(logging.FileHandler("/tmp/bundle-%s.log" % jid.resource))
    logger.setLevel(logging.DEBUG)  # change to DEBUG for higher verbosity

    try:
        log("bundle: jid:%s xmppujid:%s" % (jid.as_utf8(), xmppujid.as_utf8()))
        Bundle = SkypeBundle(jid, secret, skypeuser, skypesecret, xmppujid)

        attempts = 0
        keepalive = Iq(to_jid=Slave, stanza_type="set")
        keptalive = 0
        while Bundle.running:
            try:
                if Bundle.connection == CONNECTION.idle:
                    dbg("bundle [%s] connecting" % (jid.as_utf8(), ))
                    Bundle.connect()
                    Bundle.connection = CONNECTION.connecting

                elif Bundle.connection == CONNECTION.connecting:
                    dbg("bundle [%s] connecting..." % (jid.as_utf8(), ))
                    if Bundle.stream: Bundle.stream.loop_iter(1)

                elif Bundle.connection == CONNECTION.connected:
                    dbg("looping bundle [%s]" % (jid.as_utf8(), ))
                    if Bundle.stream: Bundle.stream.loop_iter(1)