def session_started(self): """ Stream-related plugin setup (stanza handler registration, etc). Send bot presence, set message handler for chat message and call session_started for all loaded plugins. """ JabberClient.session_started(self) presence = Presence(); presence.set_priority(20); self.stream.send(presence) # Set up handlers for supported <iq/> queries self.stream.set_iq_get_handler('query', 'jabber:iq:version', self.get_version) # Set up handlers for <presence/> stanzas self.stream.set_presence_handler('subscribe', self.presence_control) self.stream.set_presence_handler('subscribed', self.presence_control) self.stream.set_presence_handler('unsubscribe', self.presence_control) self.stream.set_presence_handler('unsubscribed', self.presence_control) self.stream.set_message_handler("chat", self.message_chat) self.stream.set_message_handler("normal", self.plugins_message_normal) for plugin in self.plugins.values(): try: plugin.session_started(self.stream) except StandardError: self.print_exception() self.logger.info("Plugin call failed")
def set_register(self, iq): """Handler for jabber:iq:register 'set' queries. This does not do anything usefull (registration data is ignored), but shows how to parse request and use Presence stanzas for subscription handling.""" to = iq.get_to() if to and to != self.jid: iq = iq.make_error_response("feature-not-implemented") self.stream.send(iq) return True remove = iq.xpath_eval("r:query/r:remove", {"r": "jabber:iq:register"}) if remove: m = Message(from_jid=iq.get_to(), to_jid=iq.get_from(), stanza_type="chat", body=u"Unregistered") self.stream.send(m) p = Presence(from_jid=iq.get_to(), to_jid=iq.get_from(), stanza_type="unsubscribe") self.stream.send(p) p = Presence(from_jid=iq.get_to(), to_jid=iq.get_from(), stanza_type="unsubscribed") self.stream.send(p) return True username = iq.xpath_eval("r:query/r:username", {"r": "jabber:iq:register"}) if username: username = username[0].getContent() else: username = u"" password = iq.xpath_eval("r:query/r:password", {"r": "jabber:iq:register"}) if password: password = password[0].getContent() else: password = u"" m = Message(from_jid=iq.get_to(), to_jid=iq.get_from(), stanza_type="chat", body=u"Registered with username '%s' and password '%s'" " (both ignored)" % (username, password)) self.stream.send(m) p = Presence(from_jid=iq.get_to(), to_jid=iq.get_from(), stanza_type="subscribe") self.stream.send(p) iq = iq.make_result_response() self.stream.send(iq) return True
def sendSubscribe(self, to, msg): toJID = JID(to) p = Presence(to_jid=toJID, from_jid=self.jid, stanza_type='subscribe', status=msg) self.stream.send(p)
def skype_bad_credentials(): dbg("skype_bad_credentials", 3) Bundle.safe_send( Presence(to_jid=Master, stanza_type="error", error_cond='not-authorized'))
def session_started(self): self.stream.send(Presence()) self.stream.set_presence_handler("subscribe", self.presence_control) self.stream.set_presence_handler("subscribed", self.presence_control) self.stream.set_presence_handler("unsubscribe", self.presence_control) self.stream.set_presence_handler("unsubscribed", self.presence_control)
def _Disconnect(self): log.debug('logging out %r', self.want_try_again) with self.lock: pres = Presence(stanza_type="unavailable", status='Logged Out') try: self.stream.send(pres) except AttributeError: pass self.connect_killed = True self.disconnect() try: self.stop_timer_loops() except AttributeError: print_exc() if getattr(self, 'idle_loop', None) is not None: del self.idle_loop[:] if self.interface_providers is not None: del self.interface_providers[:] self.interface_providers = None if self.stream is not None: self.stream = None log.debug('1logged out %r', self.want_try_again) self.offline_reason = None # self.disconnected() log.debug('1logged out %r', self.want_try_again) common.protocol.Disconnect(self)
def onPresence(self, stanza): self.logger.debug('Got presence data %s' % stanza.serialize()) p = Presence(stanza_type=stanza.get_type(), to_jid=stanza.get_from(), from_jid=stanza.get_to(), show=None) self.stream.send(p)
def show_presence(self): p = Presence(to_jid=self.room_state.room_jid, status='lobby') args_node = p.add_new_content(None, 'args') args_node.newChild(None, 'alias', self.bot_nick) args_node.newChild(None, 'aliasPrintable', urllib.quote(self.bot_nick)) args_node.newChild(None, 'cache', self.ia_avatarcache) args_node.newChild(None, 'location', urllib.quote('Ashburn, VA, US')) args_node.newChild(None, 'tagline', 'Legions Server') args_node.newChild(None, 'anonymous', '0') canhost_node = args_node.newChild(None, 'canHost', 'true') canhost_node.setProp('type', 'boolean') # maxplayers_node = args_node.newChild(None, 'maxplayers', str(self.size_limit)) # maxplayers_node.setProp('type', 'number') args_node.newChild(None, 'state', self.state) stream = self.room_state.manager.stream stream.send(p)
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)
def presence(self, stanza): """Handle 'available' (without 'type') and 'unavailable' <presence/> stanzas -- echo them back.""" p = Presence(stanza_type=stanza.get_type(), to_jid=stanza.get_from(), from_jid=stanza.get_to(), show=stanza.get_show(), status=stanza.get_status()) self.stream.send(p) return True
def session_started(self): """Handle session started event. May be overriden in derived classes. This one requests the user's roster and sends the initial presence.""" print u'SESSION STARTED' self.request_roster() p = Presence() self.stream.send(p) print u'ConnectToParty' if self._channel: self.connectToMUC()
def message(self, stanza): """Message handler for the component. Echoes the message back if its type is not 'error' or 'headline', also sets own presence status to the message body. Please note that all message types but 'error' will be passed to the handler for 'normal' message unless some dedicated handler process them. :returns: `True` to indicate, that the stanza should not be processed any further.""" subject = stanza.get_subject() body = stanza.get_body() t = stanza.get_type() print u'Message from %s received.' % (unicode(stanza.get_from(), )), if subject: print u'Subject: "%s".' % (subject, ), if body: print u'Body: "%s".' % (body, ), if t: print u'Type: "%s".' % (t, ) else: print u'Type: "normal".' if stanza.get_type() == "headline": # 'headline' messages should never be replied to return True if subject: subject = u"Re: " + subject if body: print "Sending text to cleverbot" driver_cleverbot.get("http://www.cleverbot.com?" + \ urllib.urlencode({'say': body, 'b': 'Say'})) print "Waiting for cleverbot response" resp = wait_for_clever_response(driver_cleverbot) if resp is not None: print "Cleverbot says", resp.text body = resp.text m = Message(to_jid=stanza.get_from(), from_jid=stanza.get_to(), stanza_type=stanza.get_type(), subject=subject, body=body) if body: p = Presence(status=body) return [m, p] return m
def session_started(self): log("session_started: jid:%s" % (self.jid.as_utf8(), )) self.connection = CONNECTION.connected JabberClient.session_started(self) self.stream.set_message_handler("normal", self.message) self.stream.set_presence_handler("subscribe", self.subscription) self.stream.set_iq_set_handler("command", "http://vipadia.com/skype", self.vipadia_command) global Connected Connected = True self.safe_send( Presence(to_jid=self.config.master, stanza_type="subscribe"))
def get_presence(stanza): if not is_presence(stanza): return None p = Presence(stanza) presence = p.get_type() if presence: return presence presence = p.get_status() if presence: return presence presence = p.get_show() if presence: return presence return p.serialize()
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()
def message(self,stanza): """Message handler for the component. Echoes the message back if its type is not 'error' or 'headline', also sets own presence status to the message body. Please note that all message types but 'error' will be passed to the handler for 'normal' message unless some dedicated handler process them. :returns: `True` to indicate, that the stanza should not be processed any further.""" subject=stanza.get_subject() body=stanza.get_body() t=stanza.get_type() print u'Message from %s received.' % (unicode(stanza.get_from(),)), if subject: print u'Subject: "%s".' % (subject,), if body: print u'Body: "%s".' % (body,), if t: print u'Type: "%s".' % (t,) else: print u'Type: "normal".' % (t,) if stanza.get_type()=="headline": # 'headline' messages should never be replied to return True if subject: subject=u"Re: "+subject m=Message( to_jid=stanza.get_from(), from_jid=stanza.get_to(), stanza_type=stanza.get_type(), subject=subject, body=body) self.stream.send(m) if body: p=Presence(status=body) self.stream.send(p) return True
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()
def message(self, stanza): """Handle incoming messages""" print 'Handling message' subject = stanza.get_subject() body = stanza.get_body() sender = stanza.get_from().as_utf8().split('/')[0] t = stanza.get_type() print ' ... sender = %s' % sender print ' ... subject = %s' % subject print ' ... body = %s' % body print ' ... type = %s' % t # If this is a text message, then we respond if stanza.get_type() != 'headline' and body: verb = body.split(' ')[0] verb = verb.lower() status_message = '' # Force users to be authenticated before they can do anything if not self.authenticated.has_key(sender): if verb == 'auth': if self.passwd.authenticate(sender, body[5:]): result = 'Welcome' status_message = 'Authenticated' self.authenticated[sender] = True else: status_message = 'Who are you?' result = 'Sorry, try again' else: status_message = 'Who are you?' result = 'You need to authenticate.\nUse auth <password>' # If we are authenticated, then other commands work elif verb == 'help': if len(body) == 4: sorted_verbs = verbs.keys() sorted_verbs.sort() result = 'Registered verbs are: %s\nTry help <verb> ' \ 'to learn more about a verb.' % \ ', '.join(sorted_verbs) status_message = 'Helping' else: help_target = body.split(' ')[1] help_target = help_target.lower() if not verbs.has_key(help_target): result = 'No such command -- try help to find out which ' \ 'commands do exist' status_message = 'Nothing to see here' else: plugin_name = verbs[help_target] try: result = plugins[plugin_name].Help(help_target) status_message = plugins[plugin_name].Status() except: result = 'No help available for this verb' status_message = 'Bummer' # And now we go looking for a plugin to execute the verb elif verbs.has_key(verb): plugin_name = verbs[verb] body = body[len(verb) + 1:] print 'Passing %s to %s (with %s)' % (verb, plugin_name, body) result = plugins[plugin_name].Command(verb, body) status_message = plugins[plugin_name].Status() else: result = 'Command not known' status_message = 'Huh?' p = Presence(status=status_message) self.stream.send(p) m = Message(to_jid=stanza.get_from(), from_jid=stanza.get_to(), stanza_type=stanza.get_type(), subject=subject, body=Normalize(result)) self.stream.send(m) print ' ... recipient = %s' % stanza.get_from() print ' ... body = %s' % Normalize(result) return True
def presence_push(self): pres = Presence() self.send_presence(pres)
def sendUnsubscribe(self, to): toJID = JID(to) p = Presence(to_jid=toJID, from_jid=self.jid, stanza_type='unsubscribe') self.stream.send(p)
def session_started(self): self.stream.send(Presence())
def sendPresence(self, showMsg): p = Presence(show=showMsg, from_jid=self.jid) self.stream.send(p)
def available(self, stanza): dbg("available:\n%s" % (fmt_evt(stanza), ), 3) if not self.attached: return True to = stanza.get_to() if to != self.jid: err("misdirected available!\n%s" % (fmt_evt(stanza), )) return True frm = stanza.get_from() if (frm.domain not in (Master, Muc)): err("available untrusted source! jid:%s stanza:\n%s" % (self.jid, fmt_evt(stanza))) return True if frm == Master: # Set our skype status appropriately show = stanza.get_show() if show == 'away': status = 'AWAY' elif show == 'dnd': status = 'DND' elif show == 'xa': status = 'NA' else: status = 'ONLINE' self.skype.ChangeUserStatus(status) mood = stanza.get_status() marketing_mood = "%s%s%s" % ( (Marketing_message and Marketing_message or ""), ((Marketing_message and mood) and " - " or ""), (mood and mood or "")) self.skype.CurrentUserProfile.MoodText = marketing_mood else: if frm.domain == Muc: ## MUC ## if from a [email protected] then do some muc stuff: gid = frm.node if gid not in GIDs: dbg("unknown gid: %s" % (gid), ) return True ## Find that chat, get its member list and send initial ## presences from other chat members Nicks[gid] = frm.resource chatid = GIDs[gid] chat = self.skype.Chat(chatid) for member in chat.Members: try: MembersLock.acquire() Members[chatid][member.Handle] = None finally: MembersLock.release() ## presence for existing members *must* come first if member.Handle == self.skypeuser: continue self.safe_send( Presence(to_jid="%s@%s/%s" % (gid, Muc, member.Handle))) self.safe_send( Presence(to_jid="%s@%s/%s" % (gid, Muc, frm.resource))) if chatid in Msgs: for msg in Msgs[chatid]: skype_OnMessageStatus(msg, "RECEIVED") del Msgs[chatid] return True
def skype_OnOnlineStatus(user, status): try: dbg("skype_OnOnlineStatus: user:%s status:%s" % (user, status), 3) pres = Presence(to_jid="%s@%s" % (user.Handle, Master)) if status == 'OFFLINE': pres.set_type('unavailable') elif status == 'AWAY': pres.set_show('away') elif status == 'NA': pres.set_show('xa') #?? elif status == 'DND': pres.set_show('dnd') elif status == 'INVISIBLE': pres.set_type('unavailable') if (user.Handle != Bundle.skypeuser and user.MoodText != None): pres.set_status(user.MoodText) Bundle.safe_send(pres) except Exception, exc: log_stacktrace(exc)
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)
def set_register(self, iq): #dbg("set_register:\n%s" % (fmt_evt(iq),)) # Do not log the password dbg("set_register: from:%s to:%s" % (iq.get_from().as_utf8(), iq.get_to().as_utf8())) StLock.acquire() try: frm = get_from(iq) to = iq.get_to() removes = iq.xpath_eval("reg:query/reg:remove", { "reg": "jabber:iq:register", }) if len(removes) > 0: self.regdb.remove_credentials(frm.bare().as_utf8()) self.safe_send( Presence(from_jid=to, to_jid=frm.bare(), stanza_type="unsubscribe")) self.safe_send( Presence(from_jid=to, to_jid=frm.bare(), stanza_type="unsubscribed")) self.safe_send( Presence(from_jid=to, to_jid=frm.bare(), stanza_type="unavailable")) return True usernames = iq.xpath_eval("reg:query/reg:username", { "reg": "jabber:iq:register", }) username = usernames[0].getContent() passwords = iq.xpath_eval("reg:query/reg:password", { "reg": "jabber:iq:register", }) password = passwords[0].getContent() ## check username/password for validity... if ("'" in username or '"' in username or ' ' in username or ' ' in password): self.safe_send(iq.make_error_response("not-acceptable")) return True ujid = frm.bare().as_utf8() self.regdb.remove_credentials(ujid) self.regdb.set_credentials_plain(ujid, username, password) self.safe_send(iq.make_result_response()) self.safe_send( Presence( from_jid=to, to_jid=frm, stanza_type="subscribe", )) return True finally: StLock.release()
def vipadia_command(self, iq): dbg("vipadia_command:\n%s" % (fmt_evt(iq), )) StLock.acquire() try: items = iq.xpath_eval("v:command/v:item", { "v": "http://vipadia.com/skype", }) for item in items: command = item.prop("command") if command == "subscribe": djid = JID(item.prop("djid")) if djid not in St['dialbacks']: self.safe_send(iq.make_result_response()) return True self.safe_send( Presence(to_jid=St['dialbacks'][djid], from_jid=item.prop("from"), stanza_type="subscribe")) elif command == "subscribed": frm = JID("%s@%s" % (item.prop("from"), self.config.component)) ujid = St['dialbacks'][get_from(iq)] self.safe_send( Presence(to_jid=ujid, from_jid=frm, stanza_type="subscribed")) elif command == "register-subscribe": jid = JID(item.prop("jid")) self.safe_send( Presence(to_jid=jid.bare(), from_jid=self.config.component, stanza_type="subscribe")) elif command == "register-available": jid = JID(item.prop("jid")) fake_available = Presence(to_jid=self.config.component, from_jid=jid) self.presence_available(fake_available) elif command == "out-subscribe": frm = JID("%s@%s" % (item.prop("from"), self.config.component)) iq_frm = get_from(iq) if iq_frm not in St['dialbacks']: self.safe_send(iq.make_result_response()) return True ujid = St['dialbacks'][iq_frm] self.safe_send( Presence(to_jid=ujid, from_jid=frm, stanza_type="subscribe")) elif command == "slave-online": frm = get_from(iq) digest = str(item.prop("digest")) if not self.is_valid_slave(frm.as_utf8(), digest): err("invalid slave! frm:%s iq:\n%s" % (frm.as_utf8(), fmt_evt(iq))) self.safe_send(iq.make_error_response("forbidden")) return True capacity = int(item.prop("capacity")) base = int(item.prop("base")) St['slaves'][frm] = None St['slots'][frm] = {} dbg(" before St['slots']:%s" % (St['slots'], )) for i in range(base, base + capacity): if i not in St['slots'][frm]: St['slots'][frm][i] = None dbg(" after St['slots']:%s" % (St['slots'], )) self.safe_send( Presence(to_jid=frm, from_jid=self.config.component, stanza_type="subscribe")) elif command == "spawn": ujid = item.prop("ujid") skypeuser = item.prop("skypeuser") skypesecret = item.prop("skypesecret") errstr = self._spawn(JID(ujid), skypeuser, skypesecret) if errstr: err("_spawn error! errstr:%s" % (errstr, )) else: err("unknown command! command:%s\n%s" % ( command, fmt_evt(iq), )) self.safe_send( iq.make_error_response("feature-not-implemented")) return True self.safe_send(iq.make_result_response()) return True finally: StLock.release()
def onProbe(self, stanza): p = Presence(stanza_type=stanza.get_type(), to_jid=stanza.get_from(), from_jid=stanza.get_to(), show=None) self.stream.send(p)
def _send_suicide(self, djid): dbg("_send_suicide: djid:%s" % (djid.as_utf8(), )) self.safe_send( Presence(to_jid=djid, from_jid=self.config.component, stanza_type="unavailable"))
def session_started(self): self.get_stream().set_message_handler('chat', self.got_message) self.get_stream().send(Presence())
def presence_unavailable(self, stanza): dbg("presence_unavailable:\n%s" % (fmt_evt(stanza), )) StLock.acquire() try: global St frm = get_from(stanza) dbg("frm:%s" % (frm.as_utf8(), )) if (frm.node, frm.domain) == (self.config.dialback, self.config.domain): ## from the bundle djid = frm dbg(" djid:%s" % (djid.as_utf8(), )) if djid not in St['dialbacks']: err("unknown bundle! djid:%s St['dialbacks']:%s" % ( djid.as_utf8(), St['dialbacks'], )) return True if djid not in St['dialback_slave']: err("unknown bundle! djid:%s St['dialback_slave']:%s" % ( djid.as_utf8(), St['dialback_slave'], )) return True ujid = St['dialbacks'][djid] self.safe_send( Presence(to_jid=ujid, from_jid=self.config.component, stanza_type="unavailable")) to = stanza.get_to() if (to.node, to.domain) == (None, self.config.component): # log it self.regdb.log_stop(ujid.as_utf8(), "") del St['dialbacks'][djid] if djid in St['dialback_online']: del St['dialback_online'][djid] if ujid in St['users']: del St['users'][ujid] if ujid in St['userjids']: del St['userjids'][ujid] dbg(" before unavail: St['slots']:%s St['dialback_slave']:%s" % (St['slots'], St['dialback_slave'])) if djid in St['dialback_slave']: slavejid, screen = St['dialback_slave'][djid] del St['dialback_slave'][djid] if slavejid in St['slaves']: St['slots'][slavejid][screen] = None else: del St['slots'][slavejid][screen] if len(St['slots'][slavejid]) == 0: del St['slots'][slavejid] dbg(" after unavail: St['slots']:%s St['dialback_slave']:%s" % (St['slots'], St['dialback_slave'])) elif frm in St['slots']: ## from a slave; delete unused slots del St['slaves'][frm] slots = St['slots'][frm].keys() for i in slots: if not St['slots'][frm][i]: del St['slots'][frm][i] if len(St['slots'][frm]) == 0: del St['slots'][frm] else: ## from the user ujid = frm.bare() if ujid not in St['users']: dbg("unknown user! ujid:%s" % (ujid.as_utf8(), )) return True ## if there are no more resources for this user, then suicide if ujid in St['userjids'] and frm in St['userjids'][ujid]: del St['userjids'][ujid][frm] if len(St['userjids'][ujid]) == 0: del St['userjids'][ujid] djid = St['users'][ujid] self._send_suicide(djid) return True finally: StLock.release()