Search in sources :

Example 1 with GroupItem

use of net.kano.joscar.ssiitem.GroupItem in project Openfire by igniterealtime.

the class SSIHierarchy method getGroupIdOrCreateNew.

/**
     * Finds the id number of a group specified or creates a new one and returns
     * that id.
     * 
     * @param groupName
     *            Name of the group we are looking for.
     * @return Id number of the group.
     */
public int getGroupIdOrCreateNew(String groupName) {
    for (final GroupItem g : groups.values()) {
        if (groupName.equalsIgnoreCase(g.getGroupName())) {
            return g.getId();
        }
    }
    // Group doesn't exist, lets create a new one.
    final int newGroupId = getNextBuddyId(0);
    final GroupItem newGroup = new GroupItem(groupName, newGroupId);
    request(new CreateItemsCmd(newGroup.toSsiItem()));
    gotGroup(newGroup);
    return newGroupId;
}
Also used : CreateItemsCmd(net.kano.joscar.snaccmd.ssi.CreateItemsCmd) GroupItem(net.kano.joscar.ssiitem.GroupItem)

Example 2 with GroupItem

use of net.kano.joscar.ssiitem.GroupItem 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 3 with GroupItem

use of net.kano.joscar.ssiitem.GroupItem in project Openfire by igniterealtime.

the class BOSConnection method handleSnacPacket.

@Override
protected void handleSnacPacket(SnacPacketEvent e) {
    //        Log.debug("OSCAR bos snac packet received: "+e);
    super.handleSnacPacket(e);
    SnacCommand cmd = e.getSnacCommand();
    if (cmd instanceof ServerReadyCmd) {
        request(new ParamInfoRequest());
        request(new LocRightsRequest());
        request(new SsiRightsRequest());
        request(new SsiDataRequest());
    } else if (cmd instanceof BuddyAddedYouCmd) {
        BuddyAddedYouCmd bay = (BuddyAddedYouCmd) cmd;
        Presence p = new Presence();
        p.setType(Presence.Type.subscribe);
        p.setTo(getMainSession().getJID());
        p.setFrom(getMainSession().getTransport().convertIDToJID(bay.getUin()));
        getMainSession().getTransport().sendPacket(p);
    } else if (cmd instanceof BuddyAuthRequest) {
        BuddyAuthRequest bar = (BuddyAuthRequest) cmd;
        Presence p = new Presence();
        p.setType(Presence.Type.subscribe);
        p.setTo(getMainSession().getJID());
        p.setFrom(getMainSession().getTransport().convertIDToJID(bar.getScreenname()));
        getMainSession().getTransport().sendPacket(p);
        // Auto-accept auth request. (for now)
        // TODO: Evaluate handling this in a non-automated fashion.
        request(new AuthReplyCmd(bar.getScreenname(), null, true));
    } 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 ModifyItemsCmd) {
        ModifyItemsCmd mic = (ModifyItemsCmd) cmd;
        List<SsiItem> items = mic.getItems();
        for (SsiItem item : items) {
            SsiItemObj obj = itemFactory.getItemObj(item);
            if (obj instanceof BuddyItem) {
                BuddyItem bi = (BuddyItem) obj;
                Log.debug("AIM got buddy item " + bi);
                getMainSession().getSsiHierarchy().gotBuddy(bi);
            } else if (obj instanceof GroupItem) {
                GroupItem gi = (GroupItem) obj;
                Log.debug("AIM got group item " + gi);
                getMainSession().getSsiHierarchy().gotGroup(gi);
            }
        }
    }
}
Also used : BuddyAddedYouCmd(net.kano.joscar.snaccmd.ssi.BuddyAddedYouCmd) AuthReplyCmd(net.kano.joscar.snaccmd.ssi.AuthReplyCmd) SsiDataRequest(net.kano.joscar.snaccmd.ssi.SsiDataRequest) ParamInfoRequest(net.kano.joscar.snaccmd.icbm.ParamInfoRequest) LocRightsRequest(net.kano.joscar.snaccmd.loc.LocRightsRequest) BuddyAuthRequest(net.kano.joscar.snaccmd.ssi.BuddyAuthRequest) SsiItem(net.kano.joscar.snaccmd.ssi.SsiItem) ServerReadyCmd(net.kano.joscar.snaccmd.conn.ServerReadyCmd) BuddyItem(net.kano.joscar.ssiitem.BuddyItem) Presence(org.xmpp.packet.Presence) GroupItem(net.kano.joscar.ssiitem.GroupItem) SnacCommand(net.kano.joscar.flapcmd.SnacCommand) SsiRightsRequest(net.kano.joscar.snaccmd.ssi.SsiRightsRequest) ModifyItemsCmd(net.kano.joscar.snaccmd.ssi.ModifyItemsCmd) SsiItemObj(net.kano.joscar.ssiitem.SsiItemObj)

Example 4 with GroupItem

use of net.kano.joscar.ssiitem.GroupItem in project Openfire by igniterealtime.

the class SSIHierarchy method getDefaultGroup.

/**
     * Returns the name of a default group to which a new user should be added,
     * if a new contact item was created without a group.
     * 
     * This method will first check for existing groups. If groups exist. The
     * first group (the group with the lowest ID) will be returned as the
     * default group. If no groups exist, a hardcoded default group name will be
     * used.
     * 
     * @return a group name (never <tt>null</tt>).
     */
private String getDefaultGroup() {
    if (!groups.isEmpty()) {
        // if existing groups are available, use the first one.
        final Integer firstKey = Collections.min(groups.keySet());
        final GroupItem firstKnownGroup = groups.get(firstKey);
        Log.debug("Returning first group as default group name: " + firstKnownGroup.getGroupName());
        return firstKnownGroup.getGroupName();
    } else {
        // in the (unlikely?) situation that we do not know about existing
        // groups, use a hardcoded default one.
        Log.debug("Returning hard coded value as default group name " + "(no existing groups are available).");
        if (TransportType.icq.equals(parent.getTransport().getType())) {
            return DEFAULT_ICQ_GROUP;
        } else {
            return DEFAULT_AIM_GROUP;
        }
    }
}
Also used : GroupItem(net.kano.joscar.ssiitem.GroupItem)

Aggregations

GroupItem (net.kano.joscar.ssiitem.GroupItem)4 SnacCommand (net.kano.joscar.flapcmd.SnacCommand)2 AuthReplyCmd (net.kano.joscar.snaccmd.ssi.AuthReplyCmd)2 SsiItem (net.kano.joscar.snaccmd.ssi.SsiItem)2 BuddyItem (net.kano.joscar.ssiitem.BuddyItem)2 SsiItemObj (net.kano.joscar.ssiitem.SsiItemObj)2 Presence (org.xmpp.packet.Presence)2 Date (java.util.Date)1 List (java.util.List)1 ByteBlock (net.kano.joscar.ByteBlock)1 InfoData (net.kano.joscar.snaccmd.InfoData)1 MyInfoRequest (net.kano.joscar.snaccmd.conn.MyInfoRequest)1 ServerReadyCmd (net.kano.joscar.snaccmd.conn.ServerReadyCmd)1 ServiceRedirect (net.kano.joscar.snaccmd.conn.ServiceRedirect)1 SnacError (net.kano.joscar.snaccmd.error.SnacError)1 ParamInfo (net.kano.joscar.snaccmd.icbm.ParamInfo)1 ParamInfoCmd (net.kano.joscar.snaccmd.icbm.ParamInfoCmd)1 ParamInfoRequest (net.kano.joscar.snaccmd.icbm.ParamInfoRequest)1 SetParamInfoCmd (net.kano.joscar.snaccmd.icbm.SetParamInfoCmd)1 MetaShortInfoCmd (net.kano.joscar.snaccmd.icq.MetaShortInfoCmd)1