Search in sources :

Example 46 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class BasicFlapConnection method handleSnacPacket.

@Override
protected void handleSnacPacket(SnacPacketEvent e) {
    Log.debug("OSCAR snac packet received: " + e);
    SnacCommand cmd = e.getSnacCommand();
    if (cmd instanceof ServerReadyCmd) {
        ServerReadyCmd src = (ServerReadyCmd) cmd;
        setSnacFamilies(src.getSnacFamilies());
        Collection<SnacFamilyInfo> familyInfos = SnacFamilyInfoFactory.getDefaultFamilyInfos(src.getSnacFamilies());
        setSnacFamilyInfos(familyInfos);
        getMainSession().registerSnacFamilies(this);
        request(new ClientVersionsCmd(familyInfos));
        request(new RateInfoRequest());
    } else if (cmd instanceof RecvImIcbm) {
        RecvImIcbm icbm = (RecvImIcbm) cmd;
        String sn = icbm.getSenderInfo().getScreenname();
        InstantMessage message = icbm.getMessage();
        String msg = StringUtils.convertFromHtml(message.getMessage());
        getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(sn), msg);
    } else if (cmd instanceof OldIcbm) {
        OldIcbm oicbm = (OldIcbm) cmd;
        if (oicbm.getMessageType() == OldIcbm.MTYPE_PLAIN) {
            String uin = String.valueOf(oicbm.getSender());
            String msg = StringUtils.convertFromHtml(oicbm.getReason());
            Log.debug("Got ICBM message " + uin + " with " + msg + "\n" + oicbm);
            //                InstantMessage message = oicbm.getMessage();
            //                Log.debug("Got ICBM message "+uin+" with "+message+"\n"+oicbm);
            //                String msg = StringUtils.unescapeFromXML(OscarTools.stripHtml(message.getMessage()));
            getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(uin), msg);
        }
    } else if (cmd instanceof WarningNotification) {
        WarningNotification wn = (WarningNotification) cmd;
        MiniUserInfo warner = wn.getWarner();
        if (warner == null) {
            getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.warninganon", "kraken", Arrays.asList(wn.getNewLevel().toString())), Message.Type.headline);
        } else {
            Log.debug("*** " + warner.getScreenname() + " warned you up to " + wn.getNewLevel() + "%");
            getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.warningdirect", "kraken", Arrays.asList(warner.getScreenname(), wn.getNewLevel().toString())), Message.Type.headline);
        }
    } else if (cmd instanceof ExtraInfoAck) {
        ExtraInfoAck eia = (ExtraInfoAck) cmd;
        List<ExtraInfoBlock> extraInfo = eia.getExtraInfos();
        if (extraInfo != null) {
            for (ExtraInfoBlock i : extraInfo) {
                ExtraInfoData data = i.getExtraData();
                final byte[] pendingAvatar = getMainSession().getSsiHierarchy().getPendingAvatarData();
                if (JiveGlobals.getBooleanProperty("plugin.gateway." + getMainSession().getTransport().getType() + ".avatars", true) && (data.getFlags() & ExtraInfoData.FLAG_UPLOAD_ICON) != 0 && pendingAvatar != null) {
                    Log.debug("OSCAR: Server has indicated that it wants our icon.");
                    request(new UploadIconCmd(ByteBlock.wrap(pendingAvatar)), new SnacRequestAdapter() {

                        @Override
                        public void handleResponse(SnacResponseEvent e) {
                            SnacCommand cmd = e.getSnacCommand();
                            if (cmd instanceof UploadIconAck && pendingAvatar != null) {
                                UploadIconAck iconAck = (UploadIconAck) cmd;
                                if (iconAck.getCode() == UploadIconAck.CODE_DEFAULT || iconAck.getCode() == UploadIconAck.CODE_SUCCESS) {
                                    ExtraInfoBlock iconInfo = iconAck.getIconInfo();
                                    if (iconInfo == null) {
                                        Log.debug("OSCAR: Got icon ack with no iconInfo: " + iconAck);
                                    }
                                    Log.debug("OSCAR: Successfully set icon.");
                                    try {
                                        MessageDigest md = MessageDigest.getInstance("MD5");
                                        md.update(pendingAvatar);
                                        getMainSession().getAvatar().setLegacyIdentifier(org.jivesoftware.util.StringUtils.encodeHex(md.digest()));
                                    } catch (NoSuchAlgorithmException ee) {
                                        Log.error("No algorithm found for MD5!", ee);
                                    }
                                } else if (iconAck.getCode() == UploadIconAck.CODE_BAD_FORMAT) {
                                    Log.debug("OSCAR: Uploaded icon was not in an unaccepted format.");
                                } else if (iconAck.getCode() == UploadIconAck.CODE_TOO_LARGE) {
                                    Log.debug("OSCAR: Uploaded icon was too large to be accepted.");
                                } else {
                                    Log.debug("OSCAR: Got unknown code from UploadIconAck: " + iconAck.getCode());
                                }
                            } else if (cmd instanceof SnacError) {
                                Log.debug("Got SnacError while setting icon: " + cmd);
                            }
                            // Clear the pending binary data from Krakens memory.
                            getMainSession().getSsiHierarchy().clearPendingAvatar();
                        }
                    });
                }
            }
        }
    } else if (cmd instanceof BuddyStatusCmd) {
        BuddyStatusCmd bsc = (BuddyStatusCmd) cmd;
        FullUserInfo info = bsc.getUserInfo();
        PresenceType pType = PresenceType.available;
        String vStatus = "";
        if (info.getAwayStatus()) {
            pType = PresenceType.away;
        }
        if ((info.getFlags() & FullUserInfo.MASK_WIRELESS) != 0) {
            pType = PresenceType.xa;
            vStatus = "Mobile: ";
        }
        if (getMainSession().getTransport().getType().equals(TransportType.icq) && info.getScreenname().matches("/^\\d+$/")) {
            pType = ((OSCARTransport) getMainSession().getTransport()).convertICQStatusToXMPP(info.getIcqStatus());
        }
        List<ExtraInfoBlock> extraInfo = info.getExtraInfoBlocks();
        if (extraInfo != null) {
            for (ExtraInfoBlock i : extraInfo) {
                ExtraInfoData data = i.getExtraData();
                if (i.getType() == ExtraInfoBlock.TYPE_AVAILMSG) {
                    ByteBlock msgBlock = data.getData();
                    int len = BinaryTools.getUShort(msgBlock, 0);
                    if (len >= 0) {
                        byte[] msgBytes = msgBlock.subBlock(2, len).toByteArray();
                        String msg;
                        try {
                            msg = new String(msgBytes, "UTF-8");
                        } catch (UnsupportedEncodingException e1) {
                            continue;
                        }
                        if (msg.length() > 0) {
                            vStatus = vStatus + msg;
                        }
                    }
                } else if (i.getType() == ExtraInfoBlock.TYPE_ICONHASH && JiveGlobals.getBooleanProperty("plugin.gateway." + getMainSession().getTransport().getType() + ".avatars", true)) {
                    try {
                        OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(info.getScreenname()));
                        Avatar curAvatar = oscarBuddy.getAvatar();
                        if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(org.jivesoftware.util.StringUtils.encodeHex(i.getExtraData().getData().toByteArray()))) {
                            IconRequest req = new IconRequest(info.getScreenname(), i.getExtraData());
                            request(req, new SnacRequestAdapter() {

                                @Override
                                public void handleResponse(SnacResponseEvent e) {
                                    SnacCommand cmd = e.getSnacCommand();
                                    if (cmd instanceof IconDataCmd) {
                                        IconDataCmd idc = (IconDataCmd) cmd;
                                        if (idc.getIconData().getLength() > 0 && idc.getIconData().getLength() != 90) {
                                            Log.debug("Got icon data: " + idc);
                                            if (getMainSession().getBuddyManager().isActivated()) {
                                                try {
                                                    OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(idc.getScreenname()));
                                                    oscarBuddy.setAvatar(new Avatar(getMainSession().getTransport().convertIDToJID(idc.getScreenname()), org.jivesoftware.util.StringUtils.encodeHex(idc.getIconInfo().getExtraData().getData().toByteArray()), idc.getIconData().toByteArray()));
                                                } catch (NotFoundException ee) {
                                                // Apparently we don't care about this contact.
                                                } catch (IllegalArgumentException ee) {
                                                    Log.debug("OSCAR: Got null avatar, ignoring.");
                                                }
                                            }
                                        }
                                    }
                                }

                                @Override
                                public void handleTimeout(SnacRequestTimeoutEvent e) {
                                    Log.debug("Time out while waiting for icon data.");
                                }
                            });
                        }
                    } catch (NotFoundException ee) {
                    // Apparently we don't care about this contact.
                    }
                }
            }
        }
        if (getMainSession().getBuddyManager().isActivated()) {
            try {
                OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(info.getScreenname()));
                oscarBuddy.setPresenceAndStatus(pType, vStatus);
            } catch (NotFoundException ee) {
                // Apparently we don't care about this contact.
                Log.debug("OSCAR: Received presense notification for contact we don't care about: " + info.getScreenname());
            }
        } else {
            getMainSession().getBuddyManager().storePendingStatus(getMainSession().getTransport().convertIDToJID(info.getScreenname()), pType, vStatus);
        }
    } else if (cmd instanceof BuddyOfflineCmd) {
        BuddyOfflineCmd boc = (BuddyOfflineCmd) cmd;
        if (getMainSession().getBuddyManager().isActivated()) {
            try {
                OSCARBuddy oscarBuddy = getMainSession().getBuddyManager().getBuddy(getMainSession().getTransport().convertIDToJID(boc.getScreenname()));
                oscarBuddy.setPresence(PresenceType.unavailable);
            } catch (NotFoundException ee) {
            // Apparently we don't care about this contact.
            }
        } else {
            getMainSession().getBuddyManager().storePendingStatus(getMainSession().getTransport().convertIDToJID(boc.getScreenname()), PresenceType.unavailable, null);
        }
    } else if (cmd instanceof TypingCmd) {
        TypingCmd tc = (TypingCmd) cmd;
        String sn = tc.getScreenname();
        final ChatStateEventSource chatStateEventSource = getMainSession().getTransport().getChatStateEventSource();
        final JID receiver = getMainSession().getJID();
        final JID sender = getMainSession().getTransport().convertIDToJID(sn);
        if (tc.getTypingState() == TypingCmd.STATE_TYPING) {
            chatStateEventSource.isComposing(sender, receiver);
        } else if (tc.getTypingState() == TypingCmd.STATE_PAUSED) {
            chatStateEventSource.sendIsPaused(sender, receiver);
        } else if (tc.getTypingState() == TypingCmd.STATE_NO_TEXT) {
            chatStateEventSource.isInactive(sender, receiver);
        }
    }
}
Also used : SnacRequestAdapter(net.kano.joscar.snac.SnacRequestAdapter) PresenceType(net.sf.kraken.type.PresenceType) NotFoundException(org.jivesoftware.util.NotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) FullUserInfo(net.kano.joscar.snaccmd.FullUserInfo) WarningNotification(net.kano.joscar.snaccmd.conn.WarningNotification) ExtraInfoData(net.kano.joscar.snaccmd.ExtraInfoData) SnacRequestTimeoutEvent(net.kano.joscar.snac.SnacRequestTimeoutEvent) ServerReadyCmd(net.kano.joscar.snaccmd.conn.ServerReadyCmd) ChatStateEventSource(net.sf.kraken.util.chatstate.ChatStateEventSource) ByteBlock(net.kano.joscar.ByteBlock) BuddyOfflineCmd(net.kano.joscar.snaccmd.buddy.BuddyOfflineCmd) List(java.util.List) RateInfoRequest(net.kano.joscar.snaccmd.conn.RateInfoRequest) MessageDigest(java.security.MessageDigest) IconDataCmd(net.kano.joscar.snaccmd.icon.IconDataCmd) RecvImIcbm(net.kano.joscar.snaccmd.icbm.RecvImIcbm) IconRequest(net.kano.joscar.snaccmd.icon.IconRequest) TypingCmd(net.kano.joscar.snaccmd.icbm.TypingCmd) JID(org.xmpp.packet.JID) ClientVersionsCmd(net.kano.joscar.snaccmd.conn.ClientVersionsCmd) InstantMessage(net.kano.joscar.snaccmd.icbm.InstantMessage) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Avatar(net.sf.kraken.avatars.Avatar) BuddyStatusCmd(net.kano.joscar.snaccmd.buddy.BuddyStatusCmd) SnacFamilyInfo(net.kano.joscar.snaccmd.conn.SnacFamilyInfo) ExtraInfoBlock(net.kano.joscar.snaccmd.ExtraInfoBlock) SnacError(net.kano.joscar.snaccmd.error.SnacError) UploadIconCmd(net.kano.joscar.snaccmd.icon.UploadIconCmd) OldIcbm(net.kano.joscar.snaccmd.icbm.OldIcbm) SnacResponseEvent(net.kano.joscar.snac.SnacResponseEvent) UploadIconAck(net.kano.joscar.snaccmd.icon.UploadIconAck) SnacCommand(net.kano.joscar.flapcmd.SnacCommand) MiniUserInfo(net.kano.joscar.snaccmd.MiniUserInfo) ExtraInfoAck(net.kano.joscar.snaccmd.conn.ExtraInfoAck)

Example 47 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class XMPPSession method logIn.

/**
     * @see net.sf.kraken.session.TransportSession#logIn(net.sf.kraken.type.PresenceType, String)
     */
@Override
public void logIn(PresenceType presenceType, String verboseStatus) {
    final org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(org.jivesoftware.smack.packet.Presence.Type.available);
    if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".avatars", true) && getAvatar() != null) {
        Avatar avatar = getAvatar();
        // Same thing in this case, so lets go ahead and set them.
        avatar.setLegacyIdentifier(avatar.getXmppHash());
        VCardUpdateExtension ext = new VCardUpdateExtension();
        ext.setPhotoHash(avatar.getLegacyIdentifier());
        presence.addExtension(ext);
    }
    final Presence.Mode pMode = ((XMPPTransport) getTransport()).convertGatewayStatusToXMPP(presenceType);
    if (pMode != null) {
        presence.setMode(pMode);
    }
    if (verboseStatus != null && verboseStatus.trim().length() > 0) {
        presence.setStatus(verboseStatus);
    }
    setPendingPresenceAndStatus(presenceType, verboseStatus);
    if (!this.isLoggedIn()) {
        listener = new XMPPListener(this);
        presenceHandler = new XMPPPresenceHandler(this);
        runThread = new Thread() {

            @Override
            public void run() {
                String userName = generateUsername(registration.getUsername());
                conn = new XMPPConnection(config);
                try {
                    conn.getSASLAuthentication().registerSASLMechanism("DIGEST-MD5", MySASLDigestMD5Mechanism.class);
                    if (getTransport().getType().equals(TransportType.facebook) && registration.getUsername().equals("{PLATFORM}")) {
                        conn.getSASLAuthentication().registerSASLMechanism("X-FACEBOOK-PLATFORM", FacebookConnectSASLMechanism.class);
                        conn.getSASLAuthentication().supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
                    }
                    Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
                    conn.connect();
                    conn.addConnectionListener(listener);
                    try {
                        conn.addPacketListener(presenceHandler, new PacketTypeFilter(org.jivesoftware.smack.packet.Presence.class));
                        // Use this to filter out anything we don't care about
                        conn.addPacketListener(listener, new OrFilter(new PacketTypeFilter(GoogleMailBoxPacket.class), new PacketExtensionFilter(GoogleNewMailExtension.ELEMENT_NAME, GoogleNewMailExtension.NAMESPACE)));
                        conn.login(userName, registration.getPassword(), xmppResource);
                        // send initial presence.
                        conn.sendPacket(presence);
                        conn.getChatManager().addChatListener(listener);
                        conn.getRoster().addRosterListener(listener);
                        if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".avatars", !TransportType.facebook.equals(getTransport().getType())) && getAvatar() != null) {
                            new Thread() {

                                @Override
                                public void run() {
                                    Avatar avatar = getAvatar();
                                    VCard vCard = new VCard();
                                    try {
                                        vCard.load(conn);
                                        vCard.setAvatar(Base64.decode(avatar.getImageData()), avatar.getMimeType());
                                        vCard.save(conn);
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Error while updating vcard for avatar change.", e);
                                    } catch (NotFoundException e) {
                                        Log.debug("XMPP: Unable to find avatar while setting initial.", e);
                                    }
                                }
                            }.start();
                        }
                        setLoginStatus(TransportLoginStatus.LOGGED_IN);
                        syncUsers();
                        if (getTransport().getType().equals(TransportType.gtalk) && JiveGlobals.getBooleanProperty("plugin.gateway.gtalk.mailnotifications", true)) {
                            conn.sendPacket(new IQWithPacketExtension(generateFullJID(getRegistration().getUsername()), new GoogleUserSettingExtension(null, true, null), IQ.Type.SET));
                            conn.sendPacket(new IQWithPacketExtension(generateFullJID(getRegistration().getUsername()), new GoogleMailNotifyExtension()));
                            mailCheck = new MailCheck();
                            timer.schedule(mailCheck, timerInterval, timerInterval);
                        }
                    } catch (XMPPException e) {
                        Log.debug(getTransport().getType() + " user's login/password does not appear to be correct: " + getRegistration().getUsername(), e);
                        setFailureStatus(ConnectionFailureReason.USERNAME_OR_PASSWORD_INCORRECT);
                        sessionDisconnectedNoReconnect(LocaleUtils.getLocalizedString("gateway.xmpp.passwordincorrect", "kraken"));
                    }
                } catch (XMPPException e) {
                    Log.debug(getTransport().getType() + " user is not able to connect: " + getRegistration().getUsername(), e);
                    setFailureStatus(ConnectionFailureReason.CAN_NOT_CONNECT);
                    sessionDisconnected(LocaleUtils.getLocalizedString("gateway.xmpp.connectionfailed", "kraken"));
                }
            }
        };
        runThread.start();
    }
}
Also used : FacebookConnectSASLMechanism(net.sf.kraken.protocols.xmpp.mechanisms.FacebookConnectSASLMechanism) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) GoogleMailBoxPacket(net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket) VCardUpdateExtension(net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension) Presence(org.jivesoftware.smack.packet.Presence) VCard(org.jivesoftware.smackx.packet.VCard) GoogleUserSettingExtension(net.sf.kraken.protocols.xmpp.packet.GoogleUserSettingExtension) MySASLDigestMD5Mechanism(net.sf.kraken.protocols.xmpp.mechanisms.MySASLDigestMD5Mechanism) GoogleMailNotifyExtension(net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension) Presence(org.jivesoftware.smack.packet.Presence) org.jivesoftware.smack(org.jivesoftware.smack) IQWithPacketExtension(net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) OrFilter(org.jivesoftware.smack.filter.OrFilter) Avatar(net.sf.kraken.avatars.Avatar) PacketExtensionFilter(org.jivesoftware.smack.filter.PacketExtensionFilter)

Example 48 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class YahooSession method updateContact.

/**
     * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void updateContact(YahooBuddy contact) {
    // Yahoo requires each user to be in at least one group.
    if (contact.getGroups() == null || contact.getGroups().isEmpty()) {
        List<String> defaultGroup = new ArrayList<String>();
        defaultGroup.add(DEFAULT_GROUPNAME);
        contact.setGroups(defaultGroup);
    }
    String yahooContact = getTransport().convertJIDToID(contact.getJID());
    PseudoRosterItem rosterItem;
    if (pseudoRoster.hasItem(yahooContact)) {
        rosterItem = pseudoRoster.getItem(yahooContact);
        rosterItem.setNickname(contact.getNickname());
    } else {
        rosterItem = pseudoRoster.createItem(yahooContact, contact.getNickname(), null);
    }
    try {
        YahooBuddy yBuddy = getBuddyManager().getBuddy(contact.getJID());
        yBuddy.pseudoRosterItem = rosterItem;
        for (String newGroup : yBuddy.getGroups()) {
            if (!yBuddy.yahooUser.getGroupIds().contains(newGroup)) {
                // Add new group to user
                yBuddy.yahooUser.addGroupId(newGroup);
            }
        }
        for (String oldGroup : yBuddy.yahooUser.getGroupIds()) {
            if (!yBuddy.getGroups().contains(oldGroup)) {
            // Remove group from user
            // TODO: This needs to be implemented...
            //yBuddy.yahooUser.removeGroupId(oldGroup);
            }
        }
    } catch (NotFoundException e) {
        Log.debug("Yahoo: Updated buddy not found in buddy manager: " + yahooContact);
    }
}
Also used : ArrayList(java.util.ArrayList) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 49 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class SimpleSession method updateContact.

/**
     * @see net.sf.kraken.session.TransportSession#updateContact(net.sf.kraken.roster.TransportBuddy)
     */
@Override
public void updateContact(SimpleBuddy contact) {
    Log.debug("SimpleSession(" + jid.getNode() + ").updateContact:  I was called!");
    JID destJid = contact.getJID();
    String destId = getTransport().convertJIDToID(destJid);
    PseudoRosterItem rosterItem;
    if (pseudoRoster.hasItem(destId)) {
        rosterItem = pseudoRoster.getItem(destId);
        rosterItem.setNickname(contact.getNickname());
    } else {
        rosterItem = pseudoRoster.createItem(destId, contact.getNickname(), null);
    }
    try {
        SimpleBuddy simpleBuddy = getBuddyManager().getBuddy(destJid);
        simpleBuddy.pseudoRosterItem = rosterItem;
    } catch (NotFoundException e) {
        Log.debug("SIMPLE: Newly added buddy not found in buddy manager: " + destId);
    }
}
Also used : JID(org.xmpp.packet.JID) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 50 with NotFoundException

use of org.jivesoftware.util.NotFoundException in project Openfire by igniterealtime.

the class XMPPPresenceHandler method handlePresenceMode.

/**
	 * Handles incoming presence stanzas that relate to presence status / mode
	 * changes. Ignores others.
	 * 
	 * @param presence
	 *            the stanza
	 */
private void handlePresenceMode(final org.jivesoftware.smack.packet.Presence presence) {
    if (!session.getBuddyManager().isActivated()) {
        session.getBuddyManager().storePendingStatus(session.getTransport().convertIDToJID(presence.getFrom()), ((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
    } else {
        // TODO: Need to handle resources and priorities!
        try {
            final XMPPBuddy xmppBuddy = session.getBuddyManager().getBuddy(session.getTransport().convertIDToJID(presence.getFrom()));
            Log.debug("XMPP: Presence changed detected type " + presence.getType() + " and mode " + presence.getMode() + " for " + presence.getFrom());
            xmppBuddy.setPresenceAndStatus(((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + session.getTransport().getType() + ".avatars", true)) {
                PacketExtension pe = presence.getExtension("x", NameSpace.VCARD_TEMP_X_UPDATE);
                if (pe != null) {
                    DefaultPacketExtension dpe = (DefaultPacketExtension) pe;
                    String hash = dpe.getValue("photo");
                    final String from = presence.getFrom();
                    if (hash != null) {
                        Avatar curAvatar = xmppBuddy.getAvatar();
                        if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(hash)) {
                            new Thread() {

                                @Override
                                public void run() {
                                    VCard vcard = new VCard();
                                    try {
                                        vcard.load(session.conn, from);
                                        xmppBuddy.setAvatar(new Avatar(xmppBuddy.getJID(), from, vcard.getAvatar()));
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Failed to load XMPP avatar: ", e);
                                    } catch (IllegalArgumentException e) {
                                        Log.debug("XMPP: Got null avatar, ignoring.");
                                    }
                                }
                            }.start();
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            Log.debug("XMPP: Received presence notification for contact that's not in the buddy manager of user " + session.getJID() + ". GTalk is known to do this occasionally: " + presence.getFrom());
        // We cannot add this buddy to the buddy manager, as that would result into an auto-accept of the contact sending the data.
        }
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) NotFoundException(org.jivesoftware.util.NotFoundException) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard) Avatar(net.sf.kraken.avatars.Avatar)

Aggregations

NotFoundException (org.jivesoftware.util.NotFoundException)64 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)28 Element (org.dom4j.Element)16 JID (org.xmpp.packet.JID)15 ArrayList (java.util.ArrayList)10 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 ResultSet (java.sql.ResultSet)7 TransportSession (net.sf.kraken.session.TransportSession)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Avatar (net.sf.kraken.avatars.Avatar)5 TransportBuddy (net.sf.kraken.roster.TransportBuddy)5 Packet (org.xmpp.packet.Packet)5 Date (java.util.Date)4 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)4 KrakenPlugin (net.sf.kraken.KrakenPlugin)3 Registration (net.sf.kraken.registration.Registration)3 PluginManager (org.jivesoftware.openfire.container.PluginManager)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3