📄 iqprivacyhandler.java
字号:
// Set the new active list for this session session.setActiveList(list); } } else { // List not found result.setError(PacketError.Condition.item_not_found); } return result; } /** * User has requested that no active list should be used for the current session. Return * acknowledge of success. * * @param packet IQ packet declining active list for the current session. * @param from sender of the IQ packet. * @return acknowledge of success. */ private IQ declineActiveList(IQ packet, JID from) { // Get the user session ClientSession session = sessionManager.getSession(from); // Set that there is no active list for this session session.setActiveList(null); // Return acknowledge of success return IQ.createResultIQ(packet); } /** * User has specified a new default list that should be used for all session. * * @param packet IQ packet setting new default list for all sessions. * @param from sender of the IQ packet. * @param listName name of the new default list for all sessions. * @return acknowledge of success. */ private IQ setDefaultList(IQ packet, JID from, String listName) { IQ result = IQ.createResultIQ(packet); Element childElement = packet.getChildElement().createCopy(); result.setChildElement(childElement); if (sessionManager.getSessionCount(from.getNode()) > 1) { // Current default list is being used by more than one session result.setError(PacketError.Condition.conflict); } else { // Get the list PrivacyList list = manager.getPrivacyList(from.getNode(), listName); if (list != null) { // Get the user session ClientSession session = sessionManager.getSession(from); PrivacyList oldDefaultList = session.getDefaultList(); manager.changeDefaultList(from.getNode(), list, oldDefaultList); // Set the new default list for this session (the only existing session) session.setDefaultList(list); } else { // List not found result.setError(PacketError.Condition.item_not_found); } } return result; } /** * User has specified that there is no default list that should be used for this user. * * @param packet IQ packet declining default list for all sessions. * @param from sender of the IQ packet. * @return acknowledge of success. */ private IQ declineDefaultList(IQ packet, JID from) { IQ result = IQ.createResultIQ(packet); Element childElement = packet.getChildElement().createCopy(); result.setChildElement(childElement); if (sessionManager.getSessionCount(from.getNode()) > 1) { // Current default list is being used by more than one session result.setError(PacketError.Condition.conflict); } else { // Get the user session ClientSession session = sessionManager.getSession(from); // Check if a default list was already defined if (session.getDefaultList() != null) { // Set the existing default list as non-default session.getDefaultList().setDefaultList(false); // Update the database with the new list state provider.updatePrivacyList(from.getNode(), session.getDefaultList()); session.setDefaultList(null); } } return result; } /** * Updates an existing privacy list or creates a new one with the specified items list. The * new list will not become the active or default list by default. The user will have to * send another packet to set the new list as active or default.<p> * * Once the list was updated or created a "privacy list push" will be sent to all * connected resources of the user. * * @param packet IQ packet updating or creating a new privacy list. * @param from sender of the IQ packet. * @param listElement the element containing the list and its items. * @return acknowledge of success. */ private IQ updateOrCreateList(IQ packet, JID from, Element listElement) { IQ result = IQ.createResultIQ(packet); Element childElement = packet.getChildElement().createCopy(); result.setChildElement(childElement); String listName = listElement.attributeValue("name"); PrivacyList list = manager.getPrivacyList(from.getNode(), listName); if (list == null) { list = manager.createPrivacyList(from.getNode(), listName, listElement); } else { // Update existing list list.updateList(listElement); provider.updatePrivacyList(from.getNode(), list); // Make sure that existing user sessions that are using the updated list are poining // to the updated instance. This may happen since PrivacyListManager uses a Cache that // may expire so it's possible to have many instances representing the same privacy // list. Therefore, if a list is modified then we need to make sure that all // instances are replaced with the updated instance. An OR Mapping Tool would have // avoided this issue since identity is ensured. for (ClientSession session : sessionManager.getSessions(from.getNode())) { if (list.equals(session.getDefaultList())) { session.setDefaultList(list); } if (list.equals(session.getActiveList())) { session.setActiveList(list); } } } // Send a "privacy list push" to all connected resources IQ pushPacket = new IQ(IQ.Type.set); Element child = pushPacket.setChildElement("query", "jabber:iq:privacy"); child.addElement("list").addAttribute("name", list.getName()); try { sessionManager.userBroadcast(from.getNode(), pushPacket); } catch (UnauthorizedException e) { // Ignore } return result; } private IQ deleteList(IQ packet, JID from, String listName) { ClientSession currentSession; IQ result = IQ.createResultIQ(packet); Element childElement = packet.getChildElement().createCopy(); result.setChildElement(childElement); // Get the list to delete PrivacyList list = manager.getPrivacyList(from.getNode(), listName); if (list == null) { // List to delete was not found result.setError(PacketError.Condition.item_not_found); return result; } else { currentSession = sessionManager.getSession(from); // Check if the list is being used by another session for (ClientSession session : sessionManager.getSessions(from.getNode())) { if (currentSession == session) { // Ignore the active session for this checking continue; } if (list.equals(session.getDefaultList()) || list.equals(session.getActiveList())) { // List to delete is being used by another session so return a conflict error result.setError(PacketError.Condition.conflict); return result; } } } // Remove the list from the active session (if it was being used) if (list.equals(currentSession.getDefaultList())) { currentSession.setDefaultList(null); } if (list.equals(currentSession.getActiveList())) { currentSession.setActiveList(null); } manager.deletePrivacyList(from.getNode(), listName); return result; } public IQHandlerInfo getInfo() { return info; } public Iterator<String> getFeatures() { ArrayList<String> features = new ArrayList<String>(); features.add("jabber:iq:privacy"); return features.iterator(); } public void userCreated(User user, Map params) { //Do nothing } public void userDeleting(User user, Map params) { // Delete privacy lists owned by the user being deleted manager.deletePrivacyLists(user.getUsername()); } public void userModified(User user, Map params) { //Do nothing } public void initialize(XMPPServer server) { super.initialize(server); sessionManager = server.getSessionManager(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -