@Override protected Jid getAddressToCompare(Stanza stanza) { return stanza.getFrom(); }
@Override protected Jid getJidToMatchFrom(Stanza stanza) { return stanza.getFrom(); }
@Override protected Jid getJidToInspect(Stanza stanza) { return stanza.getFrom(); }
@Override protected Jid getJidToInspect(Stanza stanza) { return stanza.getFrom(); }
@Override public String getMessage() { StringBuilder sb = new StringBuilder(); if (stanza != null) { Jid from = stanza.getFrom(); if (from != null) { sb.append("XMPP error reply received from " + from + ": "); } } sb.append(error); if (request != null) { sb.append(" as result of the following request: "); sb.append(request); } return sb.toString(); }
protected void logCommonAttributes(StringBuilder sb) { if (getTo() != null) { sb.append("to=").append(to).append(','); } if (getFrom() != null) { sb.append("from=").append(from).append(','); } if (hasStanzaIdSet()) { sb.append("id=").append(id).append(','); } }
@Override public boolean accept(Stanza packet) { // First filter out everything that is not an IQ stanza and does not have the correct ID set. if (!iqAndIdFilter.accept(packet)) return false; // Second, check if the from attributes are correct and log potential IQ spoofing attempts if (fromFilter.accept(packet)) { return true; } else { String msg = String.format("Rejected potentially spoofed reply to IQ-packet. Filter settings: " + "packetId=%s, to=%s, local=%s, server=%s. Received packet with from=%s", packetId, to, local, server, packet.getFrom()); LOGGER.log(Level.WARNING, msg , packet); return false; } }
@Override public void processStanza(Stanza packet) { if (!entityCapsEnabled()) return; CapsExtension capsExtension = CapsExtension.from(packet); Jid from = packet.getFrom(); addCapsExtensionInfo(from, capsExtension); }
private boolean isFromProvisioningService(Stanza stanza, boolean log) { Jid provisioningServer; try { provisioningServer = getConfiguredProvisioningServer(); } catch (NotConnectedException | InterruptedException | NoResponseException | XMPPErrorException e) { LOGGER.log(Level.WARNING, "Could determine provisioning server", e); return false; } if (provisioningServer == null) { if (log) { LOGGER.warning("Ignoring request '" + stanza + "' because no provisioning server configured."); } return false; } if (!provisioningServer.equals(stanza.getFrom())) { if (log) { LOGGER.warning("Ignoring request '" + stanza + "' because not from provisioning server '" + provisioningServer + "'."); } return false; } return true; } }
protected Stanza(Stanza p) { id = p.getStanzaId(); to = p.getTo(); from = p.getFrom(); error = p.error; // Copy extensions for (ExtensionElement pe : p.getExtensions()) { addExtension(pe); } }
public static Version createResultFor(Stanza request, Version version) { Version result = new Version(version); result.setStanzaId(request.getStanzaId()); result.setTo(request.getFrom()); return result; } }
@Override public void processStanza(Stanza packet) throws NotConnectedException { DeliveryReceipt dr = DeliveryReceipt.from((Message) packet); // notify listeners of incoming receipt for (ReceiptReceivedListener l : receiptReceivedListeners) { l.onReceiptReceived(packet.getFrom(), packet.getTo(), dr.getId(), packet); } } }, MESSAGES_WITH_DELIVERY_RECEIPT);
@Override public void processStanza(Stanza packet) throws NotConnectedException, InterruptedException { final Jid from = packet.getFrom(); final XMPPConnection connection = connection(); switch (autoReceiptMode) { case disabled: return; case ifIsSubscribed: if (!Roster.getInstanceFor(connection).isSubscribedToMyPresence(from)) { return; } break; case always: break; } final Message messageWithReceiptRequest = (Message) packet; Message ack = receiptMessageFor(messageWithReceiptRequest); if (ack == null) { LOGGER.warning("Received message stanza with receipt request from '" + from + "' without a stanza ID set. Message: " + messageWithReceiptRequest); return; } connection.sendStanza(ack); } }, MESSAGES_WITH_DELIVERY_RECEIPT_REQUEST);
@Override public void verify(Stanza request, Stanza response) { assertEquals(response.getFrom(), request.getTo()); }
@Override public boolean accept(Stanza packet) { // sender equals remote peer if (!packet.getFrom().equals(remoteJID)) { return false; } DataPacketExtension data; if (packet instanceof Data) { data = ((Data) packet).getDataPacketExtension(); } else { // stanza contains data packet extension data = packet.getExtension( DataPacketExtension.ELEMENT, DataPacketExtension.NAMESPACE); if (data == null) { return false; } } // session ID equals this session ID if (!data.getSessionID().equals(byteStreamRequest.getSessionID())) { return false; } return true; }
/** * Add to, from, id and 'xml:lang' attributes * * @param xml the {@link XmlStringBuilder}. * @param enclosingNamespace the enclosing XML namespace. * @return the set namespace for this stanza. */ protected String addCommonAttributes(XmlStringBuilder xml, String enclosingNamespace) { String namespace; if (enclosingNamespace == null || !enclosingNamespace.equals(StreamOpen.CLIENT_NAMESPACE) || !enclosingNamespace.equals(StreamOpen.SERVER_NAMESPACE)) { namespace = StreamOpen.CLIENT_NAMESPACE; } else { namespace = enclosingNamespace; } xml.xmlnsAttribute(namespace); xml.optAttribute("to", getTo()); xml.optAttribute("from", getFrom()); xml.optAttribute("id", getStanzaId()); xml.xmllangAttribute(getLanguage()); return namespace; }
@Override public void sendStanza(Stanza packet) throws NotConnectedException, InterruptedException { super.sendStanza(packet); if (packet instanceof IQ && !timeout) { timeout = false; // Set reply packet to match one being sent. We haven't started the // other thread yet so this is still safe. IQ replyPacket = replyQ.peek(); // If no reply has been set via addIQReply, then we create a simple reply if (replyPacket == null) { replyPacket = IQ.createResultIQ((IQ) packet); replyQ.add(replyPacket); } replyPacket.setStanzaId(packet.getStanzaId()); replyPacket.setTo(packet.getFrom()); if (replyPacket.getType() == null) { replyPacket.setType(Type.result); } new ProcessQueue(replyQ).start(); } }
@Test public void forwardedTest() throws Exception { XmlPullParser parser; String control; Forwarded fwd; control = XMLBuilder.create("forwarded") .a("xmlns", "urn:xmpp:forwarded:0") .e("message") .a("from", "romeo@montague.com") .asString(outputProperties); parser = PacketParserUtils.getParserFor(control); fwd = new ForwardedProvider().parse(parser); // no delay in packet assertEquals(null, fwd.getDelayInformation()); // check message assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom())); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); assertEquals("forwarded", parser.getName()); }
@Test public void forwardedWithDelayTest() throws Exception { XmlPullParser parser; String control; Forwarded fwd; // @formatter:off control = XMLBuilder.create("forwarded").a("xmlns", "urn:xmpp:forwarded:0") .e("message").a("from", "romeo@montague.com").up() .e("delay").ns(DelayInformation.NAMESPACE).a("stamp", "2010-07-10T23:08:25Z") .asString(outputProperties); // @formatter:on parser = PacketParserUtils.getParserFor(control); fwd = new ForwardedProvider().parse(parser); // assert there is delay information in packet DelayInformation delay = fwd.getDelayInformation(); assertNotNull(delay); // check message assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom())); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); assertEquals("forwarded", parser.getName()); }
@Test public void carbonSentTest() throws Exception { XmlPullParser parser; String control; CarbonExtension cc; Forwarded fwd; control = XMLBuilder.create("sent") .e("forwarded") .a("xmlns", "urn:xmpp:forwarded:0") .e("message") .a("from", "romeo@montague.com") .asString(outputProperties); parser = PacketParserUtils.getParserFor(control); cc = new CarbonManagerProvider().parse(parser); fwd = cc.getForwarded(); // meta assertEquals(CarbonExtension.Direction.sent, cc.getDirection()); // no delay in packet assertEquals(null, fwd.getDelayInformation()); // check message assertThat("romeo@montague.com", equalsCharSequence(fwd.getForwardedStanza().getFrom())); // check end of tag assertEquals(XmlPullParser.END_TAG, parser.getEventType()); assertEquals("sent", parser.getName()); }