public InterceptedPacket(Packet packet, boolean incoming, boolean processed) { packetClass = packet.getClass(); this.element = packet.getElement(); this.incoming = incoming; this.processed = processed; creationDate = new Date(); }
/** * Returns the Element that contains the multiple recipients. * * @param packet packet containing the multiple recipients. * @return the Element that contains the multiple recipients. */ private Element getAddresses(Packet packet) { if (packet instanceof IQ) { return ((IQ) packet).getChildElement().element("addresses"); } else { return packet.getElement().element("addresses"); } }
public Deliverable(Collection<Packet> elements) { this.text = null; this.packets = new ArrayList<>(); for (Packet packet : elements) { // Append packet namespace according XEP-0206 if needed if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) { // use string-based operation here to avoid cascading xmlns wonkery StringBuilder packetXml = new StringBuilder(packet.toXML()); final int noslash = packetXml.indexOf( ">" ); final int slash = packetXml.indexOf( "/>" ); final int insertAt = ( noslash - 1 == slash ? slash : noslash ); packetXml.insert( insertAt, " xmlns=\"jabber:client\""); this.packets.add(packetXml.toString()); } else { this.packets.add(packet.toXML()); } } }
/** * Returns a value that is an appropriate unique and stable stanza ID in * context of XEP-0359: it's either the origin-id value, or a UUID. * * @param packet The stanza for what to return the ID (cannot be null). * @return The ID (never null or empty string). */ public static String generateUniqueAndStableStanzaID( final Packet packet ) { String result = null; final Iterator<Element> existingElementIterator = packet.getElement().elementIterator( QName.get( "origin-id", "urn:xmpp:sid:0" ) ); while (existingElementIterator.hasNext() && (result == null || result.isEmpty() ) ) { final Element element = existingElementIterator.next(); result = element.attributeValue( "id" ); } if ( result == null || result.isEmpty() ) { result = UUID.randomUUID().toString(); Log.debug( "Using newly generated value '{}' for stanza that has id '{}'.", result, packet.getID() ); } else { Log.debug( "Using origin-id provided value '{}' for stanza that has id '{}'.", result, packet.getID() ); } return result; } }
Log.trace( "Added stanza of type '{}' to collection of unacknowledged stanzas (x={}). Collection size is now {}.", packet.getElement().getName(), x, size );
@Override public void deliver(Packet packet) throws UnauthorizedException { final String xml; if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) { // use string-based operation here to avoid cascading xmlns wonkery StringBuilder packetXml = new StringBuilder(packet.toXML()); packetXml.insert(packetXml.indexOf(" "), " xmlns=\"jabber:client\""); xml = packetXml.toString(); } else { xml = packet.toXML(); } if (validate()) { deliverRawText(xml); } else { // use fallback delivery mechanism (offline) getPacketDeliverer().deliver(packet); } }
parentElement = ((IQ) packet).getChildElement(); } else { parentElement = packet.getElement();
buffer.setAutoExpand(true); try { buffer.putString(packet.getElement().asXML(), encoder.get()); if (flashClient) { buffer.put((byte) '\0');
requestWriting(); allowedToWrite = true; xmlSerializer.write(packet.getElement()); if (flashClient) { writer.write('\0');
public AuditPacket(Packet packet, Session session) { element = docFactory.createElement("packet", "http://www.jivesoftware.org"); creationDate = new Date(); if (session != null && session.getStreamID() != null) { element.addAttribute("streamID", session.getStreamID().toString()); } switch (session == null ? 0 : session.getStatus()) { case Session.STATUS_AUTHENTICATED: element.addAttribute("status", "auth"); break; case Session.STATUS_CLOSED: element.addAttribute("status", "closed"); break; case Session.STATUS_CONNECTED: element.addAttribute("status", "connected"); // This is a workaround. Since we don't want to have an incorrect FROM attribute // value we need to clean up the FROM attribute. The FROM attribute will contain // an incorrect value since we are setting a fake JID until the user actually // authenticates with the server. packet.setFrom((String) null); break; default: element.addAttribute("status", "unknown"); break; } element.addAttribute("timestamp", auditFormat.format(creationDate)); element.add(packet.getElement()); }
/** * Delivers the packet to the Connection Manager that in turn will forward it to the * target user. Connection Managers may have one or many connections to the server so * just get any connection to the Connection Manager (uses a random) and use it.<p> * * If the packet to send does not have a TO attribute then wrap the packet with a * special IQ packet. The wrapper IQ packet will be sent to the Connection Manager * and the stream ID of this Client Session will be used for identifying that the wrapped * packet must be sent to the connected user. Since some packets can be exchanged before * the user has a binded JID we need to use the stream ID as the unique identifier. * * @param packet the packet to send to the user. */ @Override public void deliver(Packet packet) { StreamID streamID = session.getStreamID(); ConnectionMultiplexerSession multiplexerSession = multiplexerManager.getMultiplexerSession(connectionManagerName,streamID); if (multiplexerSession != null) { // Wrap packet so that the connection manager can figure out the target session Route wrapper = new Route(streamID); wrapper.setFrom(serverName); wrapper.setTo(connectionManagerName); wrapper.setChildElement(packet.getElement().createCopy()); // Deliver wrapper multiplexerSession.process(wrapper); session.incrementServerPacketCount(); } }
boolean fromServer) { boolean routed = false; Element privateElement = packet.getElement().element(QName.get("private", "urn:xmpp:carbons:2")); boolean isPrivate = privateElement != null; packet.getElement().remove(privateElement);
public InterceptedPacket(Packet packet, boolean incoming, boolean processed) { packetClass = packet.getClass(); this.element = packet.getElement(); this.incoming = incoming; this.processed = processed; creationDate = new Date(); }
/** * Returns the Element that contains the multiple recipients. * * @param packet packet containing the multiple recipients. * @return the Element that contains the multiple recipients. */ private Element getAddresses(Packet packet) { if (packet instanceof IQ) { return ((IQ) packet).getChildElement().element("addresses"); } else { return packet.getElement().element("addresses"); } }
public Deliverable(Collection<Packet> elements) { this.text = null; this.packets = new ArrayList<>(); for (Packet packet : elements) { // Append packet namespace according XEP-0206 if needed if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) { // use string-based operation here to avoid cascading xmlns wonkery StringBuilder packetXml = new StringBuilder(packet.toXML()); final int noslash = packetXml.indexOf( ">" ); final int slash = packetXml.indexOf( "/>" ); final int insertAt = ( noslash - 1 == slash ? slash : noslash ); packetXml.insert( insertAt, " xmlns=\"jabber:client\""); this.packets.add(packetXml.toString()); } else { this.packets.add(packet.toXML()); } } }
Log.trace( "Added stanza of type '{}' to collection of unacknowledged stanzas (x={}). Collection size is now {}.", packet.getElement().getName(), x, size );
public void send(Packet packet) { synchronized (writer) { try { xmlSerializer.write(packet.getElement()); xmlSerializer.flush(); // Keep track of the last time a stanza was sent to the server lastActive = System.currentTimeMillis(); } catch (IOException e) { // Log the exception manager.getLog().error(e); if (!shutdown) { // Connection was lost so try to reconnect connectionLost(); } } } }
@Override public void deliver(Packet packet) throws UnauthorizedException { final String xml; if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) { // use string-based operation here to avoid cascading xmlns wonkery StringBuilder packetXml = new StringBuilder(packet.toXML()); packetXml.insert(packetXml.indexOf(" "), " xmlns=\"jabber:client\""); xml = packetXml.toString(); } else { xml = packet.toXML(); } if (validate()) { deliverRawText(xml); } else { // use fallback delivery mechanism (offline) getPacketDeliverer().deliver(packet); } }
public AuditPacket(Packet packet, Session session) { element = docFactory.createElement("packet", "http://www.jivesoftware.org"); creationDate = new Date(); if (session != null && session.getStreamID() != null) { element.addAttribute("streamID", session.getStreamID().toString()); } switch (session == null ? 0 : session.getStatus()) { case Session.STATUS_AUTHENTICATED: element.addAttribute("status", "auth"); break; case Session.STATUS_CLOSED: element.addAttribute("status", "closed"); break; case Session.STATUS_CONNECTED: element.addAttribute("status", "connected"); // This is a workaround. Since we don't want to have an incorrect FROM attribute // value we need to clean up the FROM attribute. The FROM attribute will contain // an incorrect value since we are setting a fake JID until the user actually // authenticates with the server. packet.setFrom((String) null); break; default: element.addAttribute("status", "unknown"); break; } element.addAttribute("timestamp", auditFormat.format(creationDate)); element.add(packet.getElement()); }
/** * Delivers the packet to the Connection Manager that in turn will forward it to the * target user. Connection Managers may have one or many connections to the server so * just get any connection to the Connection Manager (uses a random) and use it.<p> * * If the packet to send does not have a TO attribute then wrap the packet with a * special IQ packet. The wrapper IQ packet will be sent to the Connection Manager * and the stream ID of this Client Session will be used for identifying that the wrapped * packet must be sent to the connected user. Since some packets can be exchanged before * the user has a binded JID we need to use the stream ID as the unique identifier. * * @param packet the packet to send to the user. */ @Override public void deliver(Packet packet) { StreamID streamID = session.getStreamID(); ConnectionMultiplexerSession multiplexerSession = multiplexerManager.getMultiplexerSession(connectionManagerName,streamID); if (multiplexerSession != null) { // Wrap packet so that the connection manager can figure out the target session Route wrapper = new Route(streamID); wrapper.setFrom(serverName); wrapper.setTo(connectionManagerName); wrapper.setChildElement(packet.getElement().createCopy()); // Deliver wrapper multiplexerSession.process(wrapper); session.incrementServerPacketCount(); } }