/** * Returns true if roster item represents a rejected subscription request. * * @param item The roster item. * @return True, if the roster item represents a rejected subscription request. */ private static boolean isSubscriptionRejected(RosterItem item) { return item.getSubStatus() == RosterItem.SUB_NONE && item.getRecvStatus() == RosterItem.RECV_NONE && item.getAskStatus() == RosterItem.AskType.NONE; }
@Override public boolean canProbePresence(JID prober, String probee) throws UserNotFoundException { if (probee.equals(prober.getNode()) && XMPPServer.getInstance().isLocal(prober)) { return true; } RosterItem item = rosterManager.getRoster(probee).getRosterItem(prober); return item.getSubStatus() == RosterItem.SUB_FROM || item.getSubStatus() == RosterItem.SUB_BOTH; }
/** * Returns true if the the prober is allowed to see the presence of the probee. * * @param prober the user that is trying to probe the presence of another user. * @param probee the username of the uset that is being probed. * @return true if the the prober is allowed to see the presence of the probee. * @throws UserNotFoundException If the probee does not exist in the local server or the prober * is not present in the roster of the probee. */ private boolean canProbePresence(JID prober, JID probee) throws UserNotFoundException { Roster roster; roster = XMPPServer.getInstance().getRosterManager().getRoster(prober.getNode()); RosterItem item = roster.getRosterItem(probee); if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) { return true; } return false; }
@Override public Iterator<Element> getUserItems(String name, JID senderJID) { List<Element> answer = new ArrayList<>(); try { User user = UserManager.getInstance().getUser(name); RosterItem item = user.getRoster().getRosterItem(senderJID); // If the requesting entity is subscribed to the account's presence then // answer the user's "available resources" if (item.getSubStatus() == RosterItem.SUB_FROM || item.getSubStatus() == RosterItem.SUB_BOTH) { for (Session session : SessionManager.getInstance().getSessions(name)) { Element element = DocumentHelper.createElement("item"); element.addAttribute("jid", session.getAddress().toString()); answer.add(element); } } return answer.iterator(); } catch (UserNotFoundException e) { return answer.iterator(); } }
@Override public void updateItem(String username, RosterItem item) { Connection con = null; PreparedStatement pstmt = null; long rosterID = item.getID(); try { con = DbConnectionManager.getConnection(); // Update existing roster item pstmt = con.prepareStatement(UPDATE_ROSTER_ITEM); pstmt.setInt(1, item.getSubStatus().getValue()); pstmt.setInt(2, item.getAskStatus().getValue()); pstmt.setInt(3, item.getRecvStatus().getValue()); pstmt.setString(4, item.getNickname()); pstmt.setLong(5, rosterID); pstmt.executeUpdate(); // Close now the statement (do not wait to be GC'ed) DbConnectionManager.fastcloseStmt(pstmt); // Delete old group list pstmt = con.prepareStatement(DELETE_ROSTER_ITEM_GROUPS); pstmt.setLong(1, rosterID); pstmt.executeUpdate(); insertGroups(rosterID, item.getGroups().iterator(), con); } catch (SQLException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } finally { DbConnectionManager.closeConnection(pstmt, con); } }
oldSub = item.getSubStatus(); oldRecv = item.getRecvStatus(); if (oldAsk != item.getAskStatus() || oldSub != item.getSubStatus() || oldRecv != item.getRecvStatus()) { roster.updateRosterItem(item); if (item.getSubStatus() != RosterItem.SUB_NONE || item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE) { roster.broadcast(item, false); return oldSub != item.getSubStatus();
@Override public RosterItem createItem(String username, RosterItem item) throws UserAlreadyExistsException { Connection con = null; PreparedStatement pstmt = null; try { long rosterID = SequenceManager.nextID(JiveConstants.ROSTER); con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(CREATE_ROSTER_ITEM); pstmt.setString(1, username); pstmt.setLong(2, rosterID); pstmt.setString(3, item.getJid().toBareJID()); pstmt.setInt(4, item.getSubStatus().getValue()); pstmt.setInt(5, item.getAskStatus().getValue()); pstmt.setInt(6, item.getRecvStatus().getValue()); pstmt.setString(7, item.getNickname()); pstmt.executeUpdate(); item.setID(rosterID); insertGroups(rosterID, item.getGroups().iterator(), con); } catch (SQLException e) { Log.warn("Error trying to insert a new row in ofRoster", e); throw new UserAlreadyExistsException(item.getJid().toBareJID()); } finally { DbConnectionManager.closeConnection(pstmt, con); } return item; }
if (item.isOnlyShared() && item.getSubStatus() == RosterItem.SUB_FROM) { continue; org.xmpp.packet.Roster.Subscription sub = org.xmpp.packet.Roster.Subscription.valueOf(item.getSubStatus() .getName()); if (item.getSubStatus() != RosterItem.SUB_NONE || item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE && !isSubscriptionRejected(item)) { roster.addItem(item.getJid(), item.getNickname(), ask, sub, groups);
RosterItem item = roster.getRosterItem(owner); return item != null && (RosterItem.SUB_BOTH == item.getSubStatus() || RosterItem.SUB_FROM == item.getSubStatus());
contactSubscription = item.getSubStatus();
@Override public void run() { // Send the last published items for the contacts on availableSessionJID's roster. try { final XMPPServer server = XMPPServer.getInstance(); final Roster roster = server.getRosterManager().getRoster(availableSessionJID.getNode()); for (final RosterItem item : roster.getRosterItems()) { if (server.isLocal(item.getJid()) && (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO)) { PEPService pepService = pepServiceManager.getPEPService(item.getJid().toBareJID()); if (pepService != null) { pepService.sendLastPublishedItems(availableSessionJID); } } } } catch (UserNotFoundException e) { // Do nothing } } }
if (optimize && item.isOnlyShared() && item.getSubStatus() == RosterItem.SUB_FROM) { return; roster.addItem(item.getJid(), item.getNickname(), getAskStatus(item.getAskStatus()), org.xmpp.packet.Roster.Subscription.valueOf(item.getSubStatus().getName()), groups); broadcast(roster);
/** * Determine and call the update method based on the item's subscription state. * <p/> * * @param item The item to be updated * @param action The new state change request * @param isSending True if the roster owner of the item is sending the new state change request */ private static void updateState(RosterItem item, Presence.Type action, boolean isSending) { Change change = getStateChange(item.getSubStatus(), action, isSending); if (change.getNewAsk() != null && change.getNewAsk() != item.getAskStatus()) { item.setAskStatus(change.getNewAsk()); } if (change.getNewSub() != null && change.getNewSub() != item.getSubStatus()) { item.setSubStatus(change.getNewSub()); } if (change.getNewRecv() != null && change.getNewRecv() != item.getRecvStatus()) { item.setRecvStatus(change.getNewRecv()); } }
Roster roster = rosterManager.getRoster(username); RosterItem item = roster.getRosterItem(packet.getFrom()); if (item.getSubStatus() == RosterItem.SUB_FROM || item.getSubStatus() == RosterItem.SUB_BOTH) { probePresence(packet.getFrom(), packet.getTo()); if ((item.getSubStatus() == RosterItem.SUB_NONE && item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE) || (item.getSubStatus() == RosterItem.SUB_TO && item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE)) { error = PacketError.Condition.forbidden;
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) { packet.setTo(item.getJid()); if (list != null && list.shouldBlockPacket(packet)) {
if (item.getSubStatus() != RosterItem.SUB_FROM) { item.setNickname(UserNameManager.getUserName(jid)); rosterItems.put(item.getJid().toBareJID(), item);
if (item.getSubStatus() != RosterItem.SUB_NONE) { throw new UserNotFoundException(item.getJid().toBareJID()); if (item.getSubStatus() != RosterItem.SUB_NONE || item.getRecvStatus() != RosterItem.RECV_SUBSCRIBE && !isSubscriptionRejected(item)) { broadcast(item, true);
session.getAddress().asBareJID(), false)); if (item.getSubStatus() == RosterItem.SUB_TO || item.getSubStatus() == RosterItem.SUB_BOTH) { presenceManager.probePresence(session.getAddress(), item.getJid());
RosterItem.SubType subType = itemToRemove.getSubStatus();
final Roster roster = rm.getRoster(senderJID.getNode()); for (final RosterItem item : roster.getRosterItems()) { if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) { createSubscriptionToPEPService(pepService, item .getJid(), senderJID);