Search in sources :

Example 1 with NotFoundException

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

the class Bookmark method loadFromDb.

/**
     * Loads a bookmark from the database.
     *
     * @throws NotFoundException if the bookmark could not be loaded.
     */
private void loadFromDb() throws NotFoundException {
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_BOOKMARK);
        pstmt.setLong(1, bookmarkID);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new NotFoundException("Bookmark not found: " + bookmarkID);
        }
        this.type = Type.valueOf(rs.getString(1));
        this.name = rs.getString(2);
        this.value = rs.getString(3);
        this.global = rs.getInt(4) == 1;
        rs.close();
        pstmt.close();
    } catch (SQLException sqle) {
        Log.error(sqle.getMessage(), sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NotFoundException(org.jivesoftware.util.NotFoundException) PreparedStatement(java.sql.PreparedStatement)

Example 2 with NotFoundException

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

the class IRCListener method updateCommand.

@Override
@SuppressWarnings("unchecked")
protected void updateCommand(InCommand inCommand) {
    Log.debug("IRC: Received incoming command:" + inCommand);
    if (inCommand instanceof CtcpMessage) {
        CtcpMessage cm = (CtcpMessage) inCommand;
        if (cm.getAction().equals("VERSION")) {
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "VERSION", "IMGateway" + getSession().getTransport().getVersionString() + ":Java:-"));
        } else if (cm.getAction().equals("PING")) {
            String timestamp = cm.getMessage();
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "PING", timestamp));
        } else if (cm.getAction().equals("TIME")) {
            Date current = new Date();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ZZZZZ");
            getSession().getConnection().sendCommand(new CtcpNotice(cm.getSource().getNick(), "TIME", format.format(current)));
        } else if (cm.getAction().equals("ACTION")) {
            if (cm.isPrivateToUs(getSession().getConnection().getClientState())) {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(cm.getSource().getNick()), "/me " + cm.getMessage());
            } else {
                getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(cm.getDest(), cm.getSource().getNick()), "/me " + cm.getMessage(), Message.Type.groupchat);
            }
        }
    } else if (inCommand instanceof MessageCommand) {
        MessageCommand mc = (MessageCommand) inCommand;
        if (mc.isPrivateToUs(getSession().getConnection().getClientState())) {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(mc.getSource().getNick()), IRCStringUtils.stripControlChars(mc.getMessage()));
        } else {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(mc.getDest(), mc.getSource().getNick()), IRCStringUtils.stripControlChars(mc.getMessage()), Message.Type.groupchat);
        }
    } else if (inCommand instanceof NoticeCommand) {
        NoticeCommand nc = (NoticeCommand) inCommand;
        if (nc.getFrom() != null) {
            getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(nc.getFrom().getNick()), IRCStringUtils.stripControlChars(nc.getNotice()));
        }
    } else if (inCommand instanceof JoinCommand) {
        JoinCommand jc = (JoinCommand) inCommand;
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(jc.getChannel());
            mucSession.getContacts().add(jc.getUser().getNick());
            Presence p = new Presence();
            p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(jc.getChannel(), jc.getUser().getNick()));
            p.setTo(getSession().getJID());
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "member");
            item.addAttribute("role", "participant");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof PartCommand) {
        PartCommand pc = (PartCommand) inCommand;
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(pc.getChannel());
            mucSession.getContacts().remove(pc.getUser().getNick());
            Presence p = new Presence();
            p.setType(Presence.Type.unavailable);
            p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(pc.getChannel(), pc.getUser().getNick()));
            p.setTo(getSession().getJID());
            if (pc.getReason() != null && !pc.getReason().equals("")) {
                p.setStatus(pc.getReason());
            }
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof QuitCommand) {
        QuitCommand qc = (QuitCommand) inCommand;
        for (MUCTransportSession session : getSession().getMUCSessionManager().getSessions()) {
            if (((IRCMUCSession) session).getContacts().contains(qc.getUser().getNick())) {
                ((IRCMUCSession) session).getContacts().remove(qc.getUser().getNick());
                Presence p = new Presence();
                p.setType(Presence.Type.unavailable);
                p.setFrom(getSession().getTransport().getMUCTransport().convertIDToJID(((IRCMUCSession) session).roomname, qc.getUser().getNick()));
                p.setTo(getSession().getJID());
                if (qc.getReason() != null && !qc.getReason().equals("")) {
                    p.setStatus(qc.getReason());
                }
                Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                Element item = elem.addElement("item");
                item.addAttribute("affiliation", "none");
                item.addAttribute("role", "none");
                getSession().getTransport().sendPacket(p);
            }
        }
    } else if (inCommand instanceof InviteCommand) {
        InviteCommand ic = (InviteCommand) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        Message m = new Message();
        m.setTo(getSession().getJID());
        m.setFrom(mucTransport.convertIDToJID(ic.getChannel(), null));
        Element x = m.addChildElement("x", "http://jabber.org/protocol/muc#user");
        Element invite = x.addElement("invite");
        invite.addAttribute("from", getSession().getTransport().convertIDToJID(ic.getSourceString()).toBareJID());
        getSession().getTransport().sendPacket(m);
    } else if (inCommand instanceof KickCommand) {
        KickCommand kc = (KickCommand) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(kc.getChannel());
            mucSession.getContacts().add(kc.getKicked().getNick());
            Presence p = new Presence();
            p.setType(Presence.Type.unavailable);
            p.setFrom(mucTransport.convertIDToJID(kc.getChannel(), kc.getKicked().getNick()));
            p.setTo(getSession().getJID());
            Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = elem.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            Element actor = item.addElement("actor");
            actor.addAttribute("jid", getSession().getTransport().convertIDToJID(kc.getKicker().getNick()).toBareJID());
            Element reason = item.addElement("reason");
            reason.addText(kc.getComment());
            Element status = elem.addElement("status");
            status.addAttribute("code", "307");
            getSession().getTransport().sendPacket(p);
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
        if (kc.kickedUs(getSession().getConnection().getClientState())) {
            getSession().getMUCSessionManager().removeSession(kc.getChannel());
        }
    } else if (inCommand instanceof ChannelModeCommand) {
    //ChannelModeCommand cmc = (ChannelModeCommand)inCommand;
    // TODO: Fix up martyr to handle this then handle it here
    } else if (inCommand instanceof NickCommand) {
    //NickCommand nc = (NickCommand)inCommand;
    // TODO: Map to MUC event  (someone's nick just changed)
    } else if (inCommand instanceof ModeCommand) {
    //ModeCommand mc = (ModeCommand)inCommand;
    // TODO: Map to MUC event  (your mode just changed)
    } else if (inCommand instanceof TopicCommand) {
        TopicCommand tc = (TopicCommand) inCommand;
        Channel channel = getSession().getConnection().getClientState().getChannel(tc.getChannel());
        if (channel != null) {
            BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
            Message m = new Message();
            m.setType(Message.Type.groupchat);
            m.setTo(getSession().getJID());
            m.setFrom(mucTransport.convertIDToJID(channel.getName(), channel.getTopicAuthor()));
            m.setSubject(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(channel.getTopic()));
            mucTransport.sendPacket(m);
        }
    } else if (inCommand instanceof TopicInfoReply) {
        TopicInfoReply tir = (TopicInfoReply) inCommand;
        Channel channel = getSession().getConnection().getClientState().getChannel(tir.getChannel());
        if (channel != null) {
            BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
            Message m = new Message();
            m.setType(Message.Type.groupchat);
            m.setTo(getSession().getJID());
            m.setFrom(mucTransport.convertIDToJID(channel.getName(), channel.getTopicAuthor()));
            m.setSubject(net.sf.kraken.util.StringUtils.removeInvalidXMLCharacters(channel.getTopic()));
            mucTransport.sendPacket(m);
        }
    } else if (inCommand instanceof NamesReply) {
        NamesReply nr = (NamesReply) inCommand;
        String channelName = nr.getChannel();
        List<MUCTransportRoomMember> members = new ArrayList<MUCTransportRoomMember>();
        for (String nick : nr.getNames()) {
            members.add(new MUCTransportRoomMember(getSession().getTransport().getMUCTransport().convertIDToJID(channelName, nick)));
        }
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRoomMembers(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(channelName, null), members);
    } else if (inCommand instanceof NamesEndReply) {
        NamesEndReply ner = (NamesEndReply) inCommand;
        BaseMUCTransport mucTransport = getSession().getTransport().getMUCTransport();
        try {
            IRCMUCSession mucSession = (IRCMUCSession) getSession().getMUCSessionManager().getSession(ner.getChannel());
            mucSession.getContacts().clear();
            Member myMember = null;
            Channel channel = getSession().getConnection().getClientState().getChannel(ner.getChannel());
            if (channel != null) {
                Enumeration members = channel.getMembers();
                while (members.hasMoreElements()) {
                    Member member = (Member) members.nextElement();
                    if (member.getNick().getNick().equals(mucSession.getNickname()) || member.getNick().getNick().equals(getSession().getRegistration().getNickname())) {
                        // Aha, this is us, save for the end.
                        myMember = member;
                        continue;
                    }
                    Presence p = new Presence();
                    p.setTo(getSession().getJID());
                    if (member.hasOps()) {
                        // Moderator.
                        mucSession.getContacts().add(member.getNick().getNick());
                        p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), member.getNick().getNick()));
                        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                        Element item = elem.addElement("item");
                        item.addAttribute("affiliation", "admin");
                        item.addAttribute("role", "moderator");
                    } else {
                        // Regular participant.
                        mucSession.getContacts().add(member.getNick().getNick());
                        p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), member.getNick().getNick()));
                        Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                        Element item = elem.addElement("item");
                        item.addAttribute("affiliation", "member");
                        item.addAttribute("role", "participant");
                    }
                    mucTransport.sendPacket(p);
                }
            }
            if (myMember != null) {
                Presence p = new Presence();
                p.setTo(getSession().getJID());
                p.setFrom(mucTransport.convertIDToJID(ner.getChannel(), mucSession.getNickname()));
                Element elem = p.addChildElement("x", "http://jabber.org/protocol/muc#user");
                Element item = elem.addElement("item");
                if (myMember.hasOps()) {
                    item.addAttribute("affiliation", "admin");
                    item.addAttribute("role", "moderator");
                } else {
                    item.addAttribute("affiliation", "member");
                    item.addAttribute("role", "participant");
                }
                Element status = elem.addElement("status");
                status.addAttribute("code", "110");
                mucTransport.sendPacket(p);
            }
        } catch (NotFoundException e) {
            Log.debug("Received information for IRC session that doesn't exist.");
        }
    } else if (inCommand instanceof ListStartReply) {
    // Do nothing.
    } else if (inCommand instanceof ListReply) {
        ListReply lr = (ListReply) inCommand;
        String channelName = lr.getChannel();
        MUCTransportRoom mucRoom = getSession().getTransport().getMUCTransport().getCachedRoom(channelName);
        if (mucRoom == null) {
            mucRoom = new MUCTransportRoom(getSession().getTransport().getMUCTransport().convertIDToJID(channelName, ""), channelName);
        }
        mucRoom.setTopic(lr.getTopic());
        mucRoom.setOccupant_count(lr.getMemberCount());
        getSession().getTransport().getMUCTransport().cacheRoom(mucRoom);
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRoomInfo(getSession().getJID(), getSession().getTransport().getMUCTransport().convertIDToJID(mucRoom.getName(), null), mucRoom);
    } else if (inCommand instanceof ListEndReply) {
        // This will be ignored if no one asked for it.
        getSession().getTransport().getMUCTransport().sendRooms(getSession().getJID(), getSession().getTransport().getMUCTransport().getCachedRooms());
    } else if (inCommand instanceof IsonCommand) {
        IsonCommand ic = (IsonCommand) inCommand;
        List<String> newNicks = new ArrayList<String>();
        for (String nick : ic.getNicks()) {
            newNicks.add(nick.toLowerCase());
        }
        Log.debug("IRC: Got ISON for " + ic.getDest() + " of: " + ic.getNicks());
        for (TransportBuddy buddy : getSession().getBuddyManager().getBuddies()) {
            if (!newNicks.contains(buddy.getName())) {
                // Previously online nick went offline
                buddy.setPresence(PresenceType.unavailable);
            } else {
                // Previously online nick is still online
                buddy.setPresence(PresenceType.available);
            }
        }
    } else if (inCommand instanceof UnAwayReply) {
        getSession().setPresence(PresenceType.available);
    } else if (inCommand instanceof NowAwayReply) {
        getSession().setPresence(PresenceType.away);
    } else if (inCommand instanceof AwayReply) {
        AwayReply ar = (AwayReply) inCommand;
        getSession().getTransport().sendMessage(getSession().getJID(), getSession().getTransport().convertIDToJID(ar.getNick()), LocaleUtils.getLocalizedString("gateway.irc.autoreply", "kraken") + " " + ar.getMessage());
    }
}
Also used : CtcpNotice(f00f.net.irc.martyr.commands.CtcpNotice) Message(org.xmpp.packet.Message) CtcpMessage(f00f.net.irc.martyr.commands.CtcpMessage) JoinCommand(f00f.net.irc.martyr.commands.JoinCommand) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) NickCommand(f00f.net.irc.martyr.commands.NickCommand) UnAwayReply(f00f.net.irc.martyr.replies.UnAwayReply) AwayReply(f00f.net.irc.martyr.replies.AwayReply) NowAwayReply(f00f.net.irc.martyr.replies.NowAwayReply) UnAwayReply(f00f.net.irc.martyr.replies.UnAwayReply) InviteCommand(f00f.net.irc.martyr.commands.InviteCommand) TopicInfoReply(f00f.net.irc.martyr.replies.TopicInfoReply) PartCommand(f00f.net.irc.martyr.commands.PartCommand) ListStartReply(f00f.net.irc.martyr.replies.ListStartReply) NamesReply(f00f.net.irc.martyr.replies.NamesReply) KickCommand(f00f.net.irc.martyr.commands.KickCommand) Presence(org.xmpp.packet.Presence) ModeCommand(f00f.net.irc.martyr.commands.ModeCommand) ChannelModeCommand(f00f.net.irc.martyr.commands.ChannelModeCommand) ArrayList(java.util.ArrayList) List(java.util.List) MUCTransportRoomMember(net.sf.kraken.muc.MUCTransportRoomMember) Member(f00f.net.irc.martyr.clientstate.Member) NamesEndReply(f00f.net.irc.martyr.replies.NamesEndReply) BaseMUCTransport(net.sf.kraken.muc.BaseMUCTransport) IsonCommand(f00f.net.irc.martyr.commands.IsonCommand) MUCTransportSession(net.sf.kraken.muc.MUCTransportSession) Enumeration(java.util.Enumeration) TopicCommand(f00f.net.irc.martyr.commands.TopicCommand) NowAwayReply(f00f.net.irc.martyr.replies.NowAwayReply) MessageCommand(f00f.net.irc.martyr.commands.MessageCommand) Channel(f00f.net.irc.martyr.clientstate.Channel) TransportBuddy(net.sf.kraken.roster.TransportBuddy) CtcpMessage(f00f.net.irc.martyr.commands.CtcpMessage) NoticeCommand(f00f.net.irc.martyr.commands.NoticeCommand) MUCTransportRoomMember(net.sf.kraken.muc.MUCTransportRoomMember) ListEndReply(f00f.net.irc.martyr.replies.ListEndReply) Date(java.util.Date) ListReply(f00f.net.irc.martyr.replies.ListReply) MUCTransportRoom(net.sf.kraken.muc.MUCTransportRoom) QuitCommand(f00f.net.irc.martyr.commands.QuitCommand) ChannelModeCommand(f00f.net.irc.martyr.commands.ChannelModeCommand) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with NotFoundException

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

the class SimpleListener method processRequest.

public void processRequest(RequestEvent requestEvent) {
    ServerTransaction serverTransaction = requestEvent.getServerTransaction();
    Dialog dialog = null;
    if (serverTransaction != null) {
        Log.debug("SimpleListener(" + myUsername + ").processRequest:  Getting dialog");
        dialog = serverTransaction.getDialog();
    }
    int responseCode = 200;
    Log.debug("SimpleListener(" + myUsername + ").processRequest:  Received a request event:  \n" + requestEvent.getRequest().toString());
    String fromAddr = "";
    Request request = requestEvent.getRequest();
    if (request.getHeader(FromHeader.NAME) != null) {
        FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
        Address fromAddress = fromHeader.getAddress();
        //			String displayName = fromAddress.getDisplayName();
        URI fromUri = fromAddress.getURI();
        if (fromUri != null) {
            if (fromUri.isSipURI()) {
                SipURI fromSipUri = (SipURI) fromUri;
                fromAddr = fromSipUri.getUser() + "@" + fromSipUri.getHost();
            } else {
                fromAddr = fromUri.toString();
            }
        }
    }
    Log.debug("SimpleListener(" + myUsername + ").processRequest:  FromAddr = " + fromAddr);
    Log.debug("SimpleListener(" + myUsername + ").processRequest:  Request method = '" + request.getMethod() + "'");
    if (request.getMethod().equals(Request.MESSAGE)) {
        Log.debug("SimpleListener(" + myUsername + ").processRequest:  Starting MESSAGE request handling process.");
        JID senderJid = getSession().getTransport().convertIDToJID(fromAddr);
        String msgContent = new String((byte[]) request.getContent());
        Log.debug("SimpleListener(" + myUsername + ").processRequest:  Forwarding MESSAGE request as XMPP message, setting from = " + senderJid + " and content = '" + msgContent + "'");
        getSession().getTransport().sendMessage(getSession().getJID(), senderJid, msgContent);
        getSession().sendResponse(responseCode, request, serverTransaction);
    } else if (request.getMethod().equals(Request.NOTIFY)) {
        SubscriptionStateHeader subscriptionStateHeader = (SubscriptionStateHeader) request.getHeader(SubscriptionStateHeader.NAME);
        Log.debug("SimpleListener(" + myUsername + ").processRequest:  NOTIFY request handling process started.");
        if (subscriptionStateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.ACTIVE)) {
            Log.debug("SimpleListener(" + myUsername + ").processRequest:  NOTIFY Active!");
            int expires = subscriptionStateHeader.getExpires();
            Log.debug("SimpleListener(" + myUsername + ").processRequest:  NOTIFY Expiry = " + expires);
            try {
                if (expires > 0) {
                    String content = "";
                    if (request.getContent() != null)
                        content = new String((byte[]) request.getContent());
                    if (content.length() > 0) {
                        SimplePresence simplePresence = SimplePresence.parseSimplePresence(content);
                        try {
                            SimpleBuddy buddy = getSession().getBuddyManager().getBuddy(getSession().getTransport().convertIDToJID(fromAddr));
                            String verboseStatus = null;
                            if (simplePresence.getTupleStatus().isOpen()) {
                                switch(simplePresence.getRpid()) {
                                    case ON_THE_PHONE:
                                        // TODO: Translate this
                                        verboseStatus = "On Phone";
                                }
                            }
                            buddy.setPresenceAndStatus(((SimpleTransport) getSession().getTransport()).convertSIPStatusToXMPP(simplePresence), verboseStatus);
                        } catch (NotFoundException e) {
                            // Not in our contact list.  Ignore.
                            Log.debug("SIMPLE: Received presense notification for contact we don't care about: " + fromAddr);
                        }
                    }
                } else {
                    Presence p = new Presence();
                    p.setType(Presence.Type.unsubscribed);
                    p.setTo(getSession().getJID());
                    p.setFrom(getSession().getTransport().convertIDToJID(fromAddr));
                    getSession().getTransport().sendPacket(p);
                }
                Log.debug("SimpleListener(" + myUsername + ").processRequest:  Sending XMPP presence packet.");
            } catch (Exception ex) {
                Log.debug("SimpleListener(" + myUsername + ").processRequest:  Exception occured when processing NOTIFY packet...", ex);
            }
        } else if (subscriptionStateHeader.getState().equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
            Presence p = new Presence();
            p.setType(Presence.Type.unsubscribed);
            p.setTo(getSession().getJID());
            p.setFrom(getSession().getTransport().convertIDToJID(fromAddr));
            getSession().getTransport().sendPacket(p);
        }
        getSession().sendResponse(responseCode, request, serverTransaction);
    } else if (request.getMethod().equals(Request.SUBSCRIBE)) {
        Log.debug("SimpleListener for " + myUsername + ":  SUBSCRIBE request handling process.");
        ServerTransaction transaction = getSession().sendResponse(202, request, serverTransaction);
        Log.debug("SimpleListener for " + myUsername + ":  SUBSCRIBE should be followed by a NOTIFY");
        // Send NOTIFY packet.
        try {
            if (transaction != null)
                getSession().sendNotify(transaction.getDialog());
            else
                getSession().sendNotify(dialog);
        } catch (Exception e) {
            Log.debug("SimpleListener for " + myUsername + ":  Unable to prepare NOTIFY packet.", e);
        }
    }
}
Also used : Address(javax.sip.address.Address) JID(org.xmpp.packet.JID) FromHeader(javax.sip.header.FromHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) Request(javax.sip.message.Request) NotFoundException(org.jivesoftware.util.NotFoundException) SipURI(javax.sip.address.SipURI) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) NotFoundException(org.jivesoftware.util.NotFoundException) Dialog(javax.sip.Dialog) Presence(org.xmpp.packet.Presence) ServerTransaction(javax.sip.ServerTransaction)

Example 4 with NotFoundException

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

the class SSIHierarchy method gotBuddy.

/**
     * We've been told about a buddy that exists on the buddy list.
     * 
     * @param buddyItem
     *            the buddy we've been told about.
     */
public void gotBuddy(BuddyItem buddyItem) {
    updateHighestId(buddyItem);
    final TransportBuddyManager<OSCARBuddy> buddyManager = parent.getBuddyManager();
    try {
        final JID jid = parent.getTransport().convertIDToJID(buddyItem.getScreenname());
        final OSCARBuddy oscarBuddy = buddyManager.getBuddy(jid);
        oscarBuddy.tieBuddyItem(buddyItem, false);
    } catch (NotFoundException ee) {
        final OSCARBuddy oscarBuddy = new OSCARBuddy(buddyManager, buddyItem);
        buddyManager.storeBuddy(oscarBuddy);
    }
}
Also used : JID(org.xmpp.packet.JID) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 5 with NotFoundException

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

the class SSIHierarchy method syncContactGroupsAndNickname.

/**
     * Synchronizes the basic characteristics of one contact, including:
     * <ul>
     * <li>the list of groups a contact is a member of</li>
     * <li>nicknames</li>
     * </ul>
     * 
     * As an OSCAR contact must be in at least one group, a default group is
     * used if the provided group list is empty or <tt>null</tt>.
     * 
     * @param contact
     *            Screen name/UIN of the contact.
     * @param nickname
     *            Nickname of the contact (should not be <tt>null</tt>)
     * @param grouplist
     *            List of groups the contact should be a member of.
     * @see SSIHierarchy#getDefaultGroup()
     */
public void syncContactGroupsAndNickname(String contact, String nickname, List<String> grouplist) {
    if (grouplist == null) {
        grouplist = new ArrayList<String>();
    }
    if (grouplist.isEmpty()) {
        Log.debug("No groups provided for the sync of contact " + contact + ". Using default group.");
        grouplist.add(getDefaultGroup());
    }
    Log.debug("Syncing contact = " + contact + ", nickname = " + nickname + ", grouplist = " + grouplist);
    OSCARBuddy oscarBuddy = null;
    try {
        final JID jid = parent.getTransport().convertIDToJID(contact);
        oscarBuddy = parent.getBuddyManager().getBuddy(jid);
        Log.debug("Found related oscarbuddy: " + oscarBuddy);
    } catch (NotFoundException e) {
        Log.debug("Didn't find related oscarbuddy. One will be created.");
    }
    //TODO: Should we do a premodcmd here and postmodcmd at the end and not have separate ones?
    // Stored 'removed' list of buddy items for later use
    final List<BuddyItem> freeBuddyItems = new ArrayList<BuddyItem>();
    // We'll keep the buddy items around for potential modification instead of deletion.
    if (oscarBuddy != null) {
        for (BuddyItem buddy : oscarBuddy.getBuddyItems()) {
            //                if (buddy.getScreenname().equalsIgnoreCase(contact)) {
            if (!groups.containsKey(buddy.getGroupId())) {
                // Well this is odd, a group we don't know about?  Nuke it.
                Log.debug("Removing " + buddy + " because of unknown group");
                freeBuddyItems.add(buddy);
            //                        request(new DeleteItemsCmd(buddy.toSsiItem()));
            //                        oscarBuddy.removeBuddyItem(buddy.getGroupId(), true);
            } else if (!grouplist.contains(groups.get(buddy.getGroupId()).getGroupName())) {
                Log.debug("Removing " + buddy + " because not in list of groups");
                freeBuddyItems.add(buddy);
            //                        request(new DeleteItemsCmd(buddy.toSsiItem()));
            //                        oscarBuddy.removeBuddyItem(buddy.getGroupId(), true);
            } else {
                // nothing to delete? lets update Aliases then.
                if (buddy.getAlias() == null || !buddy.getAlias().equals(nickname)) {
                    Log.debug("Updating alias for " + buddy);
                    buddy.setAlias(nickname);
                    request(new PreModCmd());
                    request(new ModifyItemsCmd(buddy.toSsiItem()));
                    request(new PostModCmd());
                    updateHighestId(buddy);
                    oscarBuddy.tieBuddyItem(buddy, true);
                }
            }
        //                }
        }
    }
    // Now, lets take the known good list of groups and add whatever is missing on the server.
    for (String group : grouplist) {
        Integer groupId = getGroupIdOrCreateNew(group);
        if (isMemberOfGroup(groupId, contact)) {
            // Already a member, moving on
            continue;
        }
        Integer newBuddyId = 1;
        if (highestBuddyIdPerGroup.containsKey(groupId)) {
            newBuddyId = getNextBuddyId(groupId);
        }
        if (freeBuddyItems.size() > 0) {
            // Moving a freed buddy item
            // TODO: This isn't working.. why?  Returns RESULT_ID_TAKEN
            //                BuddyItem buddy = freeBuddyItems.remove(0);
            //                if (oscarBuddy != null) {
            //                    oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
            //                }
            //                buddy.setGroupid(groupId);
            //                buddy.setId(newBuddyId);
            //                buddy.setAlias(nickname);
            //                request(new ModifyItemsCmd(buddy.toSsiItem()));
            //                if (oscarBuddy == null) {
            //                    oscarBuddy = new OSCARBuddy(getBuddyManager(), buddy);
            //                    // TODO: translate this
            //                    request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
            //                }
            //                else {
            //                    oscarBuddy.tieBuddyItem(buddy, false);
            //                }
            request(new PreModCmd());
            BuddyItem buddy = freeBuddyItems.remove(0);
            BuddyItem newBuddy = new BuddyItem(buddy);
            newBuddy.setGroupid(groupId);
            newBuddy.setId(newBuddyId);
            newBuddy.setAlias(nickname);
            request(new DeleteItemsCmd(buddy.toSsiItem()));
            if (oscarBuddy != null) {
                oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
            }
            request(new CreateItemsCmd(newBuddy.toSsiItem()));
            if (oscarBuddy == null) {
                oscarBuddy = new OSCARBuddy(parent.getBuddyManager(), newBuddy);
                // TODO: translate this
                request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
            } else {
                oscarBuddy.tieBuddyItem(newBuddy, false);
            }
            request(new PostModCmd());
        } else {
            // Creating a new buddy item
            final BuddyItem newBuddy = new BuddyItem(contact, groupId, newBuddyId);
            newBuddy.setAlias(nickname);
            updateHighestId(newBuddy);
            //  TODO: Should we be doing this for AIM too?
            if (parent.getTransport().getType().equals(TransportType.icq)) {
                newBuddy.setAwaitingAuth(true);
            }
            request(new PreModCmd());
            request(new CreateItemsCmd(newBuddy.toSsiItem()));
            request(new PostModCmd());
            if (oscarBuddy == null) {
                oscarBuddy = new OSCARBuddy(parent.getBuddyManager(), newBuddy);
                // TODO: translate this
                request(new BuddyAuthRequest(contact, "Automated add request on behalf of user."));
            } else {
                oscarBuddy.tieBuddyItem(newBuddy, true);
            }
        }
    }
    // Now, lets remove any leftover buddy items that we're no longer using.
    for (BuddyItem buddy : freeBuddyItems) {
        request(new DeleteItemsCmd(buddy.toSsiItem()));
        if (oscarBuddy != null) {
            oscarBuddy.removeBuddyItem(buddy.getGroupId(), false);
        }
    }
    // Lastly, lets store the final buddy item after we've modified it, making sure to update groups first.
    if (oscarBuddy != null) {
        //            oscarBuddy.populateGroupList();
        parent.getBuddyManager().storeBuddy(oscarBuddy);
    }
}
Also used : DeleteItemsCmd(net.kano.joscar.snaccmd.ssi.DeleteItemsCmd) JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) NotFoundException(org.jivesoftware.util.NotFoundException) BuddyAuthRequest(net.kano.joscar.snaccmd.ssi.BuddyAuthRequest) PostModCmd(net.kano.joscar.snaccmd.ssi.PostModCmd) BuddyItem(net.kano.joscar.ssiitem.BuddyItem) PreModCmd(net.kano.joscar.snaccmd.ssi.PreModCmd) CreateItemsCmd(net.kano.joscar.snaccmd.ssi.CreateItemsCmd) ModifyItemsCmd(net.kano.joscar.snaccmd.ssi.ModifyItemsCmd)

Aggregations

NotFoundException (org.jivesoftware.util.NotFoundException)67 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)29 Element (org.dom4j.Element)17 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 MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)4 UserRequest (org.jivesoftware.xmpp.workgroup.request.UserRequest)4 KrakenPlugin (net.sf.kraken.KrakenPlugin)3 Registration (net.sf.kraken.registration.Registration)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3