Java Code Examples for org.xmpp.packet.Packet#getFrom()
The following examples show how to use
org.xmpp.packet.Packet#getFrom() .
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: RoutingTableImpl.java From Openfire with Apache License 2.0 | 6 votes |
/** * Returns true if the specified packet must only be route to available client sessions. * * @param packet the packet to route. * @param fromServer true if the packet was created by the server. * @return true if the specified packet must only be route to available client sessions. */ private boolean routeOnlyAvailable(Packet packet, boolean fromServer) { if (fromServer) { // Packets created by the server (no matter their FROM value) must always be delivered no // matter the available presence of the user return false; } boolean onlyAvailable = true; JID from = packet.getFrom(); boolean hasSender = from != null; if (packet instanceof IQ) { onlyAvailable = hasSender && !(serverName.equals(from.getDomain()) && from.getResource() == null) && !componentsCache.containsKey(from.getDomain()); } else if (packet instanceof Message || packet instanceof Presence) { onlyAvailable = !hasSender || (!serverName.equals(from.toString()) && !componentsCache.containsKey(from.getDomain())); } return onlyAvailable; }
Example 2
Source File: PrivacyList.java From Openfire with Apache License 2.0 | 6 votes |
/** * Returns true if the specified packet must be blocked based on this privacy list rules. * Rules are going to be analyzed based on their order (in ascending order). When a rule * is matched then communication will be blocked or allowed based on that rule. No more * further analysis is going to be made. * * @param packet the packet to analyze if it must be blocked. * @return true if the specified packet must be blocked based on this privacy list rules. */ public boolean shouldBlockPacket(Packet packet) { if (packet.getFrom() == null) { // Sender is the server so it's not denied return false; } // Iterate over the rules and check each rule condition Roster roster = getRoster(); for (PrivacyItem item : items) { if (item.matchesCondition(packet, roster, userJID)) { if (item.isAllow()) { return false; } if (Log.isDebugEnabled()) { Log.debug("PrivacyList: Packet was blocked: " + packet); } return true; } } // If no rule blocked the communication then allow the packet to flow return false; }
Example 3
Source File: TransportHandler.java From Openfire with Apache License 2.0 | 6 votes |
@Override public void process(Packet packet) throws UnauthorizedException, PacketException { boolean handled = false; String host = packet.getTo().getDomain(); for (Channel<Packet> channel : transports.values()) { if (channel.getName().equalsIgnoreCase(host)) { channel.add(packet); handled = true; } } if (!handled) { JID recipient = packet.getTo(); JID sender = packet.getFrom(); packet.setError(PacketError.Condition.remote_server_timeout); packet.setFrom(recipient); packet.setTo(sender); try { deliverer.deliver(packet); } catch (PacketException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } } }
Example 4
Source File: AuditManagerImpl.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) { if (!processed) { // Ignore packets sent or received by users that are present in the ignore list JID from = packet.getFrom(); JID to = packet.getTo(); if ((from == null || !ignoreList.contains(from.getNode())) && (to == null || !ignoreList.contains(to.getNode()))) { auditor.audit(packet, session); } } }
Example 5
Source File: InternalComponentManager.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void sendPacket(Component component, Packet packet) { if (packet != null && packet.getFrom() == null) { throw new IllegalArgumentException("Packet with no FROM address was received from component."); } PacketRouter router = XMPPServer.getInstance().getPacketRouter(); if (router != null) { router.route(packet); } }
Example 6
Source File: S2STestService.java From Openfire with Apache License 2.0 | 5 votes |
/** * Keeps a log of the XMPP traffic, releasing the wait lock on response received. */ @Override public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException { if (ping.getTo() == null || packet.getFrom() == null || packet.getTo() == null) { return; } if (!processed && (ping.getTo().getDomain().equals(packet.getFrom().getDomain()) || ping.getTo().getDomain().equals(packet.getTo().getDomain()))) { // Log all traffic to and from the domain. xml.append(packet.toXML()); xml.append('\n'); // If we've received our IQ response, stop the test. if ( packet instanceof IQ ) { final IQ iq = (IQ) packet; if ( iq.isResponse() && ping.getID().equals( iq.getID() ) && ping.getTo().equals( iq.getFrom() ) ) { Log.info("Successful server to server response received."); waitUntil.release(); } } } }
Example 7
Source File: BookmarkInterceptor.java From openfire-ofmeet-plugin with Apache License 2.0 | 4 votes |
@Override public void interceptPacket( Packet packet, Session session, boolean incoming, boolean processed ) throws PacketRejectedException { // Interested only in pre-processed, outgoing stanzas. if ( processed || incoming ) { return; } // OF-1591 - I can't quite explain these. Maybe the session has been closed before the outgoing server promise timed out? if ( session == null ) { return; } // Only interested in stanzas that are either: // - from the server itself. // - sent 'on behalf of' the user that is the recipient of the stanza ('from' matches session address). if ( packet.getFrom() != null && !packet.getFrom().asBareJID().equals( session.getAddress().asBareJID() ) && !packet.getFrom().toBareJID().equals( XMPPServer.getInstance().getServerInfo().getXMPPDomain() ) ) { return; } final Element storageElement = findStorageElement( packet ); if ( storageElement == null ) { return; } final URL url = ofMeetPlugin.getWebappURL(); if ( url == null ) { return; } addBookmark( storageElement, url ); }
Example 8
Source File: MUCRole.java From Openfire with Apache License 2.0 | 4 votes |
/** * When sending data to a user that joined the room through FMUC (when the user is a user that is local to a remote * chatroom that joined our room as a 'joining FMUC node'), then we'll need to add an 'fmuc' element to all data * that we send it. * * The data that is to be added must include the 'from' address representing the FMUC role for the occupant that * sent the stanza. We either use the reported FMUC address as passed down from other FMUC nodes, or we use the * address of users connected locally to our server. * * This method will add an 'fmuc' child element to the stanza when the user is a user that joined through FMUC (is * a member of a room that federates with the MUC room local to our server). * * If the provided stanza already contains an FMUC element with relevant data, this data is left unchanged. * * @param packet The stanza to augment */ default void augmentOutboundStanzaWithFMUCData( @Nonnull Packet packet ) { if ( !isRemoteFmuc() ) { Log.trace( "Recipient '{}' is not in a remote FMUC room. No need to augment stanza with FMUC data.", this.getUserAddress() ); return; } Log.trace( "Sending data to recipient '{}' that has joined local room '{}' through a federated remote room (FMUC). Outbound stanza is required to include FMUC data: {}", this.getUserAddress(), this.getChatRoom().getJID(), packet ); // Data that was sent to us from a(nother) FMUC node might already have this value. If not, we need to ensure that this is added. Element fmuc = packet.getElement().element(QName.get("fmuc", "http://isode.com/protocol/fmuc")); if ( fmuc == null ) { fmuc = packet.getElement().addElement(QName.get("fmuc", "http://isode.com/protocol/fmuc")); } if ( fmuc.attributeValue( "from" ) != null && !fmuc.attributeValue( "from" ).trim().isEmpty() ) { Log.trace( "Outbound stanza already includes FMUC data. No need to include further data." ); return; } final JID reportingFmucAddress; if (packet.getFrom().getResource() == null) { Log.trace( "Sender is the room itself: '{}'", packet.getFrom() ); reportingFmucAddress = this.getChatRoom().getRole().getRoleAddress(); } else { Log.trace( "Sender is an occupant of the room: '{}'", packet.getFrom() ); // Determine the role of the entity that sent the message. final Set<MUCRole> sender = new HashSet<>(); try { sender.addAll( this.getChatRoom().getOccupantsByNickname(packet.getFrom().getResource()) ); } catch ( UserNotFoundException e ) { Log.trace( "Unable to identify occupant '{}'", packet.getFrom() ); } // If this users is user joined through FMUC, use the FMUC-reported address, otherwise, use the local address. switch ( sender.size() ) { case 0: Log.warn("Cannot add required FMUC data to outbound stanza. Unable to determine the role of the sender of stanza sent over FMUC: {}", packet); return; case 1: final MUCRole role = sender.iterator().next(); if ( role.isRemoteFmuc() ) { reportingFmucAddress = role.getReportedFmucAddress(); } else { reportingFmucAddress = role.getUserAddress(); } break; default: // The user has more than one role, which probably means it joined the room from more than one device. // At this point in the code flow, we can't determine anymore which full JID caused the stanza to be sent. // As a fallback, send the _bare_ JID of the user (which should be equal for all its resources). // TODO verify if the compromise is acceptable in the XEP. final Set<JID> bareJids = sender.stream() .map(r -> { if ( r.isRemoteFmuc() ) { return r.getReportedFmucAddress().asBareJID(); } else { return r.getUserAddress().asBareJID(); } }) .collect(Collectors.toSet()); if ( bareJids.size() == 1 ) { Log.warn("Sender '{}' has more than one role in room '{}', indicating that the user joined the room from more than one device. Using its bare instead of full JID for FMUC reporting.", packet.getFrom(), this.getChatRoom().getJID()); reportingFmucAddress = bareJids.iterator().next().asBareJID(); } else { throw new IllegalStateException("Unable to deduce one FMUC address for occupant address '" + packet.getFrom() + "'."); } break; } } Log.trace( "Adding 'from' FMUC data to outbound stanza, using FMUC address of sender of data, that has been determined to be '{}'.", reportingFmucAddress ); fmuc.addAttribute("from", reportingFmucAddress.toString() ); }
Example 9
Source File: MultiUserChatServiceImpl.java From Openfire with Apache License 2.0 | 4 votes |
@Override public void processPacket(final Packet packet) { Log.trace( "Routing stanza: {}", packet.toXML() ); if (!isServiceEnabled()) { Log.trace( "Service is disabled. Ignoring stanza." ); return; } // The MUC service will receive all the packets whose domain matches the domain of the MUC // service. This means that, for instance, a disco request should be responded by the // service itself instead of relying on the server to handle the request. try { // Check if the packet is a disco request or a packet with namespace iq:register if (packet instanceof IQ) { if (process((IQ)packet)) { Log.trace( "Done processing IQ stanza." ); return; } } else if (packet instanceof Message) { final Message msg = (Message) packet; if (msg.getType() == Message.Type.error) { // Bounced message, drop user. removeUser(packet.getFrom()); Log.trace( "Done processing Message stanza." ); return; } } else if (packet instanceof Presence) { final Presence pres = (Presence) packet; if (pres.getType() == Presence.Type.error) { // Bounced presence, drop user. removeUser(packet.getFrom()); Log.trace( "Done processing Presence stanza." ); return; } } if ( packet.getTo().getNode() == null ) { Log.trace( "Stanza was addressed at the service itself, which by now should have been handled." ); if ( packet instanceof IQ && ((IQ) packet).isRequest() ) { final IQ reply = IQ.createResultIQ( (IQ) packet ); reply.setChildElement( ((IQ) packet).getChildElement().createCopy() ); reply.setError( PacketError.Condition.feature_not_implemented ); router.route( reply ); } Log.debug( "Ignoring stanza addressed at conference service: {}", packet.toXML() ); } else { Log.trace( "The stanza is a normal packet that should possibly be sent to the room." ); final JID recipient = packet.getTo(); final String roomName = recipient != null ? recipient.getNode() : null; final JID userJid = packet.getFrom(); Log.trace( "Stanza recipient: {}, room name: {}, sender: {}", recipient, roomName, userJid ); try (final AutoCloseableReentrantLock.AutoCloseableLock ignored = new AutoCloseableReentrantLock(MultiUserChatServiceImpl.class, userJid.toString()).lock()) { if ( !packet.getElement().elements(FMUCHandler.FMUC).isEmpty() ) { Log.trace( "Stanza is a FMUC stanza." ); final MUCRoom chatRoom = getChatRoom(roomName); if ( chatRoom != null ) { chatRoom.getFmucHandler().process(packet); } else { Log.warn( "Unable to process FMUC stanza, as room it's addressed to does not exist: {}", roomName ); // FIXME need to send error back in case of IQ request, and FMUC join. Might want to send error back in other cases too. } } else { Log.trace( "Stanza is a regular MUC stanza." ); getChatUser(userJid, roomName).process(packet); } } } } catch (final Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } }