basetransport.java

来自「基于Jabber协议的即时消息服务器」· Java 代码 · 共 1,590 行 · 第 1/5 页

JAVA
1,590 行
字号
        Log.debug(getType().toString()+": contactAdded "+roster.getUsername()+":"+item.getJid());        if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {            // Not ours, not our problem.            return;        }        if (item.getJid().getNode() == null) {            // Gateway itself, don't care.            return;        }        try {            TransportSession session = sessionManager.getSession(roster.getUsername());            session.addContact(item);        }        catch (NotFoundException e) {            // Well we just don't care then.        }    }    /**     * Handles deletions from a roster.  We don't really care because we hear about these via unsubscribes.     *     * @see org.jivesoftware.wildfire.roster.RosterEventListener#contactDeleted(org.jivesoftware.wildfire.roster.Roster, org.jivesoftware.wildfire.roster.RosterItem)     */    public void contactDeleted(Roster roster, RosterItem item) {        Log.debug(getType().toString()+": contactDeleted "+roster.getUsername()+":"+item.getJid());//        if (!item.getJid().getDomain().equals(this.getJID().getDomain())) {//            // Not ours, not our problem.//            return;//        }//        if (item.getJid().getNode() == null) {//            // TODO: The gateway itself was removed?//            return;//        }//        try {//            TransportSession session = sessionManager.getSession(roster.getUsername());//            session.removeContact(item);//        }//        catch (NotFoundException e) {//            // TODO: Should maybe do something about this//        }    }    /**     * Handles notifications of a roster being loaded.  Not sure we care.     *     * @see org.jivesoftware.wildfire.roster.RosterEventListener#rosterLoaded(org.jivesoftware.wildfire.roster.Roster)     */    public void rosterLoaded(Roster roster) {        Log.debug(getType().toString()+": rosterLoaded "+roster.getUsername());        // Don't care        // TODO: Evaluate if we could use this, maybe an opportunity to clean up.    }    /**     * Handles a session coming online (available).     *     * @see org.jivesoftware.wildfire.user.PresenceEventListener#availableSession(org.jivesoftware.wildfire.ClientSession, org.xmpp.packet.Presence)     */    public void availableSession(ClientSession clSession, Presence packet) {        Log.debug(getType().toString()+": availableSession "+clSession+":"+packet);        JID from = packet.getFrom();        Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);        if (registrations.isEmpty()) {            // User is not registered with us.            return;        }        Registration registration = registrations.iterator().next();        // A user's resource has come online.        TransportSession session;        try {            session = sessionManager.getSession(from);            if (session.hasResource(from.getResource())) {                Log.debug("An existing resource has changed status: " + from);                if (session.getPriority(from.getResource()) != packet.getPriority()) {                    session.updatePriority(from.getResource(), packet.getPriority());                }                if (session.isHighestPriority(from.getResource())) {                    // Well, this could represent a status change.                    session.updateStatus(getPresenceType(packet), packet.getStatus());                }            }            else {                Log.debug("A new resource has come online: " + from);                // This is a new resource, lets send them what we know.                session.addResource(from.getResource(), packet.getPriority());                // Tell the new resource what the state of their buddy list is.                session.resendContactStatuses(from);                // If this priority is the highest, treat it's status as golden                if (session.isHighestPriority(from.getResource())) {                    session.updateStatus(getPresenceType(packet), packet.getStatus());                }            }        }        catch (NotFoundException e) {            Log.debug("A new session has come online: " + from);            session = this.registrationLoggedIn(registration, from, getPresenceType(packet), packet.getStatus(), packet.getPriority());            sessionManager.storeSession(from, session);        }    }    /**     * Handles a session going offline (unavailable).     *     * @see org.jivesoftware.wildfire.user.PresenceEventListener#unavailableSession(org.jivesoftware.wildfire.ClientSession, org.xmpp.packet.Presence)     */    public void unavailableSession(ClientSession clSession, Presence packet) {        Log.debug(getType().toString()+": unavailableSession "+clSession+":"+packet);        JID from = packet.getFrom();        Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);        if (registrations.isEmpty()) {            // User is not registered with us.            return;        }        // A user's resource has gone offline.        TransportSession session;        try {            session = sessionManager.getSession(from);            if (session.getResourceCount() > 1) {                String resource = from.getResource();                // Just one of the resources, lets adjust accordingly.                if (session.isHighestPriority(resource)) {                    Log.debug("A high priority resource (of multiple) has gone offline: " + from);                    // Ooh, the highest resource went offline, drop to next highest.                    session.removeResource(resource);                    // Lets check the next highest resource for what it's presence is.                    SessionManager sessionManager = SessionManager.getInstance();                    String user = from.getNode();                    String nextResource = session.getJIDWithHighestPriority().getResource();                    if (sessionManager.getSessionCount(user) > 0) {                        for (ClientSession cSession : sessionManager.getSessions(user)) {                            Presence p = cSession.getPresence();                            if (p.getFrom().getResource().equals(nextResource)) {                                presenceChanged(cSession, cSession.getPresence());                            }                        }                    }                }                else {                    Log.debug("A low priority resource (of multiple) has gone offline: " + from);                    // Meh, lower priority, big whoop.                    session.removeResource(resource);                }            }            else {                Log.debug("A final resource has gone offline: " + from);                // No more resources, byebye.                if (session.isLoggedIn()) {                    this.registrationLoggedOut(session);                }                sessionManager.removeSession(from);            }        }        catch (NotFoundException e) {            Log.debug("Ignoring unavailable presence for inactive seession.");        }    }    /**     * Handles a session's priority changing.     *     * @see org.jivesoftware.wildfire.user.PresenceEventListener#presencePriorityChanged(org.jivesoftware.wildfire.ClientSession, org.xmpp.packet.Presence)     */    public void presencePriorityChanged(ClientSession clSession, Presence packet) {        Log.debug(getType().toString()+": presencePriorityChanged "+clSession+":"+packet);        JID from = packet.getFrom();        Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);        if (registrations.isEmpty()) {            // User is not registered with us.            return;        }        TransportSession session;        try {            session = sessionManager.getSession(from);            if (session.hasResource(from.getResource())) {                Log.debug("An existing resource has changed status: " + from);                if (session.getPriority(from.getResource()) != packet.getPriority()) {                    session.updatePriority(from.getResource(), packet.getPriority());                }                if (session.isHighestPriority(from.getResource())) {                    // Well, this could represent a status change.                    session.updateStatus(getPresenceType(packet), packet.getStatus());                }            }        }        catch (NotFoundException e) {            // Not actually logged in.        }    }    /**     * Handles a session's status changing.     *     * @see org.jivesoftware.wildfire.user.PresenceEventListener#presenceChanged(org.jivesoftware.wildfire.ClientSession, org.xmpp.packet.Presence)     */    public void presenceChanged(ClientSession clSession, Presence packet) {        Log.debug(getType().toString()+": presenceChanged "+clSession+":"+packet);        JID from = packet.getFrom();        Collection<Registration> registrations = registrationManager.getRegistrations(from, this.transportType);        if (registrations.isEmpty()) {            // User is not registered with us.            return;        }        TransportSession session;        try {            session = sessionManager.getSession(from);            if (session.hasResource(from.getResource())) {                Log.debug("An existing resource has changed status: " + from);                if (session.isHighestPriority(from.getResource())) {                    // Well, this could represent a status change.                    session.updateStatus(getPresenceType(packet), packet.getStatus());                }            }        }        catch (NotFoundException e) {            // Not actually logged in.        }    }    /**     * Will handle logging in to the legacy service.     *     * @param registration Registration used for log in.     * @param jid JID that is logged into the transport.     * @param presenceType Type of presence.     * @param verboseStatus Longer status description.     * @param priority Priority of the session (from presence packet).     * @return A session instance for the new login.     */    public abstract TransportSession registrationLoggedIn(Registration registration, JID jid, PresenceType presenceType, String verboseStatus, Integer priority);    /**     * Will handle logging out of the legacy service.     *     * @param session TransportSession to be logged out.     */    public abstract void registrationLoggedOut(TransportSession session);    /**     * Returns the terminology used for a username on the legacy service.     *     * @return String term for username.     */    public abstract String getTerminologyUsername();    /**     * Returns the terminology used for a password on the legacy service.     *     * @return String term for password.     */    public abstract String getTerminologyPassword();    /**     * Returns the terminology used for a nickname on the legacy service.     *     * You can return null to indicate that this is not supported by the legacy service.     *     * @return String term for nickname.     */    public abstract String getTerminologyNickname();    /**     * Returns instructions for registration in legacy complient terminology.     *     * You would write this out as if the entry textfields for the username and password     * are after it/on the same page.  So something along these lines would be good:     * Please enter your legacy username and password.     *     * @return String phrase for registration.     */    public abstract String getTerminologyRegistration();    /**     * Is a password required for this service?     *     * @return True or false whether the password is required.     */    public abstract Boolean isPasswordRequired();    /**     * Is a nickname required for this service?     *     * @return True or false whether the nickname is required.     */    public abstract Boolean isNicknameRequired();    /**     * Is the specified username valid?     *     * @param username Username to validate.     * @return True or false whether the passed username is valud for the service.     */    public abstract Boolean isUsernameValid(String username);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?