Search in sources :

Example 11 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class BOSConnection method handleSnacResponse.

@Override
protected void handleSnacResponse(SnacResponseEvent e) {
    super.handleSnacResponse(e);
    //        Log.debug("OSCAR bos snac response received: "+e);
    SnacCommand cmd = e.getSnacCommand();
    if (cmd instanceof LocRightsCmd) {
        request(new SetInfoCmd(new InfoData("oscargateway", null, getMainSession().getCapabilities(), null)));
        request(new MyInfoRequest());
    } else if (cmd instanceof ParamInfoCmd) {
        ParamInfoCmd pic = (ParamInfoCmd) cmd;
        ParamInfo info = pic.getParamInfo();
        request(new SetParamInfoCmd(new ParamInfo(0, info.getFlags() | ParamInfo.FLAG_TYPING_NOTIFICATION, 8000, info.getMaxSenderWarning(), info.getMaxReceiverWarning(), 0)));
    } else if (cmd instanceof ServiceRedirect) {
        ServiceRedirect sr = (ServiceRedirect) cmd;
        getMainSession().connectToService(sr.getSnacFamily(), sr.getRedirectHost(), sr.getCookie());
    } else if (cmd instanceof SsiDataCmd) {
        SsiDataCmd sdc = (SsiDataCmd) cmd;
        List<SsiItem> items = sdc.getItems();
        for (SsiItem item : items) {
            SsiItemObj obj = itemFactory.getItemObj(item);
            if (obj instanceof BuddyItem) {
                BuddyItem bi = (BuddyItem) obj;
                Log.debug("OSCAR: got buddy item " + bi);
                getMainSession().getSsiHierarchy().gotBuddy(bi);
            } else if (obj instanceof GroupItem) {
                GroupItem gi = (GroupItem) obj;
                Log.debug("OSCAR: got group item " + gi);
                getMainSession().getSsiHierarchy().gotGroup(gi);
            } else if (obj instanceof IconItem) {
                IconItem ii = (IconItem) obj;
                Log.debug("OSCAR: got icon item " + ii);
                getMainSession().getSsiHierarchy().gotIconItem(ii);
            } else if (obj instanceof VisibilityItem) {
                VisibilityItem vi = (VisibilityItem) obj;
                Log.debug("OSCAR: got visibility item " + vi);
                getMainSession().getSsiHierarchy().gotVisibilityItem(vi);
            } else {
                Log.debug("OSCAR: got item we're not handling " + obj);
            }
        }
        if (sdc.getLastModDate() != 0) {
            request(new ActivateSsiCmd());
            clientReady();
            getMainSession().setLoginStatus(TransportLoginStatus.LOGGED_IN);
            getMainSession().gotCompleteSSI();
        }
    } else if (cmd instanceof OfflineMsgIcqCmd) {
        OfflineMsgIcqCmd omic = (OfflineMsgIcqCmd) cmd;
        String sn = String.valueOf(omic.getFromUIN());
        Date whenSent = omic.getDate();
        ByteBlock block = omic.getIcqData();
        final int len = LEBinaryTools.getUShort(block, 12) - 1;
        String msg = OscarTools.getString(block.subBlock(14, len), null);
        msg = StringUtils.unescapeFromXML(OscarTools.stripHtml(msg));
        // TODO: Translate offline message note
        getMainSession().getTransport().sendOfflineMessage(getMainSession().getJID(), getMainSession().getTransport().convertIDToJID(sn), msg, whenSent, "Offline Message");
    } else if (cmd instanceof OfflineMsgDoneCmd) {
        request(new OfflineMsgIcqAckCmd(getMainSession().getUIN(), (int) getMainSession().nextIcqId()));
    } else if (cmd instanceof MetaShortInfoCmd) {
    //            MetaShortInfoCmd msic = (MetaShortInfoCmd)cmd;
    //            Log.debug("RECEIVED META SHORT INFO: "+msic);
    //            getMainSession().updateRosterNickname(String.valueOf(msic.getUIN()), msic.getNickname());
    } else if (cmd instanceof AuthReplyCmd) {
        AuthReplyCmd ar = (AuthReplyCmd) cmd;
        if (ar.isAccepted()) {
            Presence p = new Presence();
            p.setType(Presence.Type.subscribed);
            p.setTo(getMainSession().getJID());
            p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
            getMainSession().getTransport().sendPacket(p);
        } else {
            Presence p = new Presence();
            p.setType(Presence.Type.unsubscribed);
            p.setTo(getMainSession().getJID());
            p.setFrom(getMainSession().getTransport().convertIDToJID(ar.getSender()));
            getMainSession().getTransport().sendPacket(p);
        }
    } else if (cmd instanceof AuthFutureCmd) {
        AuthFutureCmd af = (AuthFutureCmd) cmd;
        Presence p = new Presence();
        p.setType(Presence.Type.subscribe);
        p.setTo(getMainSession().getJID());
        p.setFrom(getMainSession().getTransport().convertIDToJID(af.getUin()));
        getMainSession().getTransport().sendPacket(p);
    } else if (cmd instanceof SnacError) {
        SnacError se = (SnacError) cmd;
        if (se.getErrorCode() == SnacError.CODE_REFUSED_BY_CLIENT) {
            getMainSession().getTransport().sendMessage(getMainSession().getJID(), getMainSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.aim.msgrefused", "kraken"));
        }
    //TODO: Tons more errors that can be caught.  Gotta catch 'em all!  =)  (please don't sue me Nintendo)
    }
}
Also used : MyInfoRequest(net.kano.joscar.snaccmd.conn.MyInfoRequest) OfflineMsgIcqCmd(net.kano.joscar.snaccmd.icq.OfflineMsgIcqCmd) MetaShortInfoCmd(net.kano.joscar.snaccmd.icq.MetaShortInfoCmd) SetInfoCmd(net.kano.joscar.snaccmd.loc.SetInfoCmd) SsiItem(net.kano.joscar.snaccmd.ssi.SsiItem) VisibilityItem(net.kano.joscar.ssiitem.VisibilityItem) IconItem(net.kano.joscar.ssiitem.IconItem) ByteBlock(net.kano.joscar.ByteBlock) Presence(org.xmpp.packet.Presence) List(java.util.List) GroupItem(net.kano.joscar.ssiitem.GroupItem) SetParamInfoCmd(net.kano.joscar.snaccmd.icbm.SetParamInfoCmd) ParamInfo(net.kano.joscar.snaccmd.icbm.ParamInfo) SsiDataCmd(net.kano.joscar.snaccmd.ssi.SsiDataCmd) OfflineMsgIcqAckCmd(net.kano.joscar.snaccmd.icq.OfflineMsgIcqAckCmd) LocRightsCmd(net.kano.joscar.snaccmd.loc.LocRightsCmd) ParamInfoCmd(net.kano.joscar.snaccmd.icbm.ParamInfoCmd) SetParamInfoCmd(net.kano.joscar.snaccmd.icbm.SetParamInfoCmd) OfflineMsgDoneCmd(net.kano.joscar.snaccmd.icq.OfflineMsgDoneCmd) AuthReplyCmd(net.kano.joscar.snaccmd.ssi.AuthReplyCmd) Date(java.util.Date) ActivateSsiCmd(net.kano.joscar.snaccmd.ssi.ActivateSsiCmd) BuddyItem(net.kano.joscar.ssiitem.BuddyItem) AuthFutureCmd(net.kano.joscar.snaccmd.ssi.AuthFutureCmd) SnacError(net.kano.joscar.snaccmd.error.SnacError) InfoData(net.kano.joscar.snaccmd.InfoData) SnacCommand(net.kano.joscar.flapcmd.SnacCommand) ServiceRedirect(net.kano.joscar.snaccmd.conn.ServiceRedirect) SsiItemObj(net.kano.joscar.ssiitem.SsiItemObj)

Example 12 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class RegistrationHandler method handleDeregister.

/**
     * Processes an IQ-register request that is expressing the wish to
     * deregister from a gateway.
     *
     * @param packet the IQ-register stanza.
     */
private void handleDeregister(final IQ packet) {
    final IQ result = IQ.createResultIQ(packet);
    if (packet.getChildElement().elements().size() != 1) {
        Log.debug("Cannot process this stanza - exactly one" + " childelement of <remove> expected:" + packet.toXML());
        final IQ error = IQ.createResultIQ(packet);
        error.setError(Condition.bad_request);
        parent.sendPacket(error);
        return;
    }
    final JID from = packet.getFrom();
    final JID to = packet.getTo();
    // Tell the end user the transport went byebye.
    final Presence unavailable = new Presence(Presence.Type.unavailable);
    unavailable.setTo(from);
    unavailable.setFrom(to);
    this.parent.sendPacket(unavailable);
    try {
        deleteRegistration(from);
    } catch (UserNotFoundException e) {
        Log.debug("Error cleaning up contact list of: " + from);
        result.setError(Condition.registration_required);
    }
    parent.sendPacket(result);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 13 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class TransportBuddy method sendOfflinePresenceIfAvailable.

/**
     * Sends an offline presence for a contact only if it is currently online.
     *
     * In case you are wondering why, this is useful when a resource goes offline and we want to indicate all contacts are offline.
     *
     * @param to JID to send presence updates to.
     */
public void sendOfflinePresenceIfAvailable(JID to) {
    if (!presence.equals(PresenceType.unavailable)) {
        Presence p = new Presence();
        p.setType(Presence.Type.unavailable);
        p.setTo(to);
        p.setFrom(jid);
        getManager().sendPacket(p);
    }
}
Also used : Presence(org.xmpp.packet.Presence)

Example 14 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class TransportBuddy method setAvatar.

/**
     * Sets the current avatar for this contact.
     *
     * @param avatar Avatar instance to associate with this contact.
     */
public void setAvatar(Avatar avatar) {
    boolean triggerUpdate = false;
    if ((avatar != null && this.avatar == null) || (avatar == null && this.avatar != null) || (avatar != null && !this.avatar.getXmppHash().equals(avatar.getXmppHash()))) {
        triggerUpdate = true;
    }
    this.avatar = avatar;
    this.avatarSet = true;
    if (triggerUpdate) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, presence);
        if (!verboseStatus.equals("")) {
            p.setStatus(verboseStatus);
        }
        Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
        if (avatar != null) {
            vcard.addElement("photo").addCDATA(avatar.getXmppHash());
            vcard.addElement("hash").addCDATA(avatar.getXmppHash());
        }
        getManager().sendPacket(p);
    }
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence)

Example 15 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class TransportBuddy method setVerboseStatus.

/**
     * Sets the current verbose status.
     *
     * @param newstatus New verbose status.
     */
public void setVerboseStatus(String newstatus) {
    if (newstatus == null) {
        newstatus = "";
    }
    if (!verboseStatus.equals(newstatus)) {
        Presence p = new Presence();
        p.setTo(getManager().getSession().getJID());
        p.setFrom(jid);
        getManager().getSession().getTransport().setUpPresencePacket(p, presence);
        if (!newstatus.equals("")) {
            p.setStatus(newstatus);
        }
        if (avatarSet && avatar != null) {
            Element vcard = p.addChildElement("x", NameSpace.VCARD_TEMP_X_UPDATE);
            vcard.addElement("photo").addCDATA(avatar.getXmppHash());
            vcard.addElement("hash").addCDATA(avatar.getXmppHash());
        }
        getManager().sendPacket(p);
    }
    verboseStatus = newstatus;
    lastActivityTimestamp = new Date().getTime();
    lastActivityEvent = verboseStatus;
}
Also used : Element(org.dom4j.Element) Presence(org.xmpp.packet.Presence) Date(java.util.Date)

Aggregations

Presence (org.xmpp.packet.Presence)109 JID (org.xmpp.packet.JID)38 Element (org.dom4j.Element)34 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)20 Message (org.xmpp.packet.Message)17 IQ (org.xmpp.packet.IQ)16 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)14 NotFoundException (org.jivesoftware.util.NotFoundException)12 ArrayList (java.util.ArrayList)11 MUCRole (org.jivesoftware.openfire.muc.MUCRole)10 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)9 DefaultElement (org.dom4j.tree.DefaultElement)8 IOException (java.io.IOException)7 SQLException (java.sql.SQLException)7 GroupJID (org.jivesoftware.openfire.group.GroupJID)7 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)7 Date (java.util.Date)6 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)6 ConflictException (org.jivesoftware.openfire.muc.ConflictException)6 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)6