Java Code Examples for org.xmpp.packet.IQ#setID()
The following examples show how to use
org.xmpp.packet.IQ#setID() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiplexerStanzaHandler.java From Openfire with Apache License 2.0 | 6 votes |
@Override protected void processIQ(final IQ packet) { if (session.getStatus() != Session.STATUS_AUTHENTICATED) { // Session is not authenticated so return error IQ reply = new IQ(); reply.setChildElement(packet.getChildElement().createCopy()); reply.setID(packet.getID()); reply.setTo(packet.getFrom()); reply.setFrom(packet.getTo()); reply.setError(PacketError.Condition.not_authorized); session.process(reply); return; } // Process the packet packetHandler.handle(packet); }
Example 2
Source File: ComponentStanzaHandler.java From Openfire with Apache License 2.0 | 6 votes |
@Override protected void processIQ(IQ packet) throws UnauthorizedException { if (session.getStatus() != Session.STATUS_AUTHENTICATED) { // Session is not authenticated so return error IQ reply = new IQ(); reply.setChildElement(packet.getChildElement().createCopy()); reply.setID(packet.getID()); reply.setTo(packet.getFrom()); reply.setFrom(packet.getTo()); reply.setError(PacketError.Condition.not_authorized); session.process(reply); return; } // Keep track of the component that sent an IQ get/set if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) { // Handle subsequent bind packets LocalComponentSession componentSession = (LocalComponentSession) session; // Get the external component of this session LocalComponentSession.LocalExternalComponent component = (LocalComponentSession.LocalExternalComponent) componentSession.getExternalComponent(); component.track(packet); } super.processIQ(packet); }
Example 3
Source File: IQRosterHandler.java From Openfire with Apache License 2.0 | 4 votes |
/** * The packet is a typical 'set' or 'get' update targeted at the server. * Notice that the set could be a roster removal in which case we have to * generate a local roster removal update as well as a new roster removal * to send to the the roster item's owner. * * @param packet The packet that triggered this update * @return Either a response to the roster update or null if the packet is corrupt and the session was closed down */ private IQ manageRoster(org.xmpp.packet.Roster packet) throws UnauthorizedException, UserAlreadyExistsException, SharedGroupException { IQ returnPacket = null; JID sender = packet.getFrom(); IQ.Type type = packet.getType(); try { if ((sender.getNode() == null || !RosterManager.isRosterServiceEnabled() || !userManager.isRegisteredUser(sender.getNode())) && IQ.Type.get == type) { // If anonymous user asks for his roster or roster service is disabled then // return an empty roster IQ reply = IQ.createResultIQ(packet); reply.setChildElement("query", "jabber:iq:roster"); return reply; } if (!localServer.isLocal(sender)) { // Sender belongs to a remote server so discard this IQ request Log.warn("Discarding IQ roster packet of remote user: " + packet); return null; } Roster cachedRoster = userManager.getUser(sender.getNode()).getRoster(); if (IQ.Type.get == type) { if (RosterManager.isRosterVersioningEnabled()) { String clientVersion = packet.getChildElement().attributeValue("ver"); String latestVersion = String.valueOf( cachedRoster.hashCode() ); // Whether or not the roster has been modified since the version ID enumerated by the client, ... if (!latestVersion.equals(clientVersion)) { // ... the server MUST either return the complete roster // (including a 'ver' attribute that signals the latest version) returnPacket = cachedRoster.getReset(); returnPacket.getChildElement().addAttribute("ver", latestVersion ); } else { // ... or return an empty IQ-result returnPacket = new org.xmpp.packet.IQ(); } } else { returnPacket = cachedRoster.getReset(); } returnPacket.setType(IQ.Type.result); returnPacket.setTo(sender); returnPacket.setID(packet.getID()); // Force delivery of the response because we need to trigger // a presence probe from all contacts deliverer.deliver(returnPacket); returnPacket = null; } else if (IQ.Type.set == type) { returnPacket = IQ.createResultIQ(packet); // RFC 6121 2.3.3. Error Cases: // The server MUST return a <bad-request/> stanza error to the client if the roster set contains any of the following violations: // The <query/> element contains more than one <item/> child element. if (packet.getItems().size() > 1) { returnPacket.setError(new PacketError(PacketError.Condition.bad_request, PacketError.Type.modify, "Query contains more than one item")); } else { for (org.xmpp.packet.Roster.Item item : packet.getItems()) { if (item.getSubscription() == org.xmpp.packet.Roster.Subscription.remove) { if (removeItem(cachedRoster, packet.getFrom(), item) == null) { // RFC 6121 2.5.3. Error Cases: If the value of the 'jid' attribute specifies an item that is not in the roster, then the server MUST return an <item-not-found/> stanza error. returnPacket.setError(PacketError.Condition.item_not_found); } } else { PacketError error = checkGroups(item.getGroups()); if (error != null) { returnPacket.setError(error); } else { if (cachedRoster.isRosterItem(item.getJID())) { // existing item RosterItem cachedItem = cachedRoster.getRosterItem(item.getJID()); cachedItem.setAsCopyOf(item); cachedRoster.updateRosterItem(cachedItem); } else { // new item cachedRoster.createRosterItem(item); } } } } } } } catch (UserNotFoundException e) { throw new UnauthorizedException(e); } return returnPacket; }
Example 4
Source File: EntityCapabilitiesManagerTest.java From Openfire with Apache License 2.0 | 4 votes |
/** * Tests the CAPS verification string generation based on the * "Simple Generation Example" provided in section 5.2 of XEP-0115 (version * 1.4 and later). */ @Test public void testSimpleGenerationExample() throws Exception { // formulate the result stanza final IQ iq = new IQ(IQ.Type.result); iq.setFrom("[email protected]/chamber"); iq.setTo("[email protected]"); iq.setID("simpleexample1"); final Element query = iq.setChildElement("query", "http://jabber.org/protocol/disco#info"); // Consider an entity whose category is "client", whose service // discovery type is "pc", service discovery name is "Exodus 0.9.1" // (...) final Element identity = query.addElement("identity"); identity.addAttribute("category", "client"); identity.addAttribute("type", "pc"); identity.addAttribute("name", "Exodus 0.9.1"); // (...) and whose supported features are // "http://jabber.org/protocol/disco#info", // "http://jabber.org/protocol/disco#items", // "http://jabber.org/protocol/muc" and // "http://jabber.org/protocol/caps" query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info"); query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items"); query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/muc"); query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/caps"); // Using the SHA-1 algorithm (...) final String verification = EntityCapabilitiesManager.generateVerHash( iq, "sha-1"); // the verification string result must be QgayPKawpkPSDYmwT/WM94uAlu0= assertEquals("QgayPKawpkPSDYmwT/WM94uAlu0=", verification); }
Example 5
Source File: EntityCapabilitiesManagerTest.java From Openfire with Apache License 2.0 | 4 votes |
/** * Tests the CAPS verification string generation based on the * "Complex Generation Example" provided in section 5.3 of XEP-0115 (version * 1.4 and later). */ @Test public void testComplexGenerationExample() throws Exception { // formulate the result stanza final IQ iq = new IQ(IQ.Type.result); iq.setFrom("[email protected]/chamber"); iq.setTo("[email protected]"); iq.setID("simpleexample1"); final Element query = iq.setChildElement("query", "http://jabber.org/protocol/disco#info"); query.addAttribute("node", "http://psi-im.org#q07IKJEyjvHSyhy//CH0CxmKi8w="); // Two identities: "client/pc/Psi" and "client/pc/" final Element identityA = query.addElement("identity"); identityA.addAttribute("category", "client"); identityA.addAttribute("type", "pc"); identityA.addAttribute("name", "Psi 0.11"); identityA.addAttribute("xml:lang", "en"); final Element identityB = query.addElement("identity"); identityB.addAttribute("category", "client"); identityB.addAttribute("type", "pc"); identityB.addAttribute("name", "\u03a8 0.11"); identityB.addAttribute("xml:lang", "el"); // the features: "http://jabber.org/protocol/caps", // http://jabber.org/protocol/disco#info", // "http://jabber.org/protocol/disco#items", // "http://jabber.org/protocol/muc". query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info"); query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items"); query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/muc"); query.addElement("feature").addAttribute("var", "http://jabber.org/protocol/caps"); // extended service discovery forms final Element ext = query.addElement(QName.get("x", "jabber:x:data")); ext.addAttribute("type", "result"); final Element formField = ext.addElement("field"); formField.addAttribute("var", "FORM_TYPE"); formField.addAttribute("type", "hidden"); formField.addElement("value") .setText("urn:xmpp:dataforms:softwareinfo"); final Element ipField = ext.addElement("field"); ipField.addAttribute("var", "ip_version"); ipField.addElement("value").setText("ipv4"); ipField.addElement("value").setText("ipv6"); final Element osField = ext.addElement("field"); osField.addAttribute("var", "os"); osField.addElement("value").setText("Mac"); final Element osvField = ext.addElement("field"); osvField.addAttribute("var", "os_version"); osvField.addElement("value").setText("10.5.1"); final Element softwareField = ext.addElement("field"); softwareField.addAttribute("var", "software"); softwareField.addElement("value").setText("Psi"); final Element softwarevField = ext.addElement("field"); softwarevField.addAttribute("var", "software_version"); softwarevField.addElement("value").setText("0.11"); // Using the SHA-1 algorithm (...) final String verification = EntityCapabilitiesManager.generateVerHash( iq, "SHA-1"); // the verification string result must be q07IKJEyjvHSyhy//CH0CxmKi8w= assertEquals("q07IKJEyjvHSyhy//CH0CxmKi8w=", verification); }