@Override public int hashCodeForPacket(Packet packet) { if (packet.getStanzaTo() != null) { return packet.getStanzaTo().hashCode(); } if (packet.getTo() != null) { return packet.getTo().hashCode(); } return super.hashCodeForPacket(packet); }
/** * Method description * * @param ios * @param p * @return a value of <code>boolean</code> */ public boolean writePacketToSocket(IO ios, Packet p) { if (ios != null) { if (log.isLoggable(Level.FINER) && !log.isLoggable(Level.FINEST)) { log.log( Level.FINER, "{0}, Processing packet: {1}, type: {2}", new Object[] {ios, p.getElemName(), p.getType()}); } if (log.isLoggable(Level.FINEST)) { log.log(Level.FINEST, "{0}, Writing packet: {1}", new Object[] {ios, p}); } // synchronized (ios) { ios.addPacketToSend(p); if (ios.writeInProgress.tryLock()) { try { ios.processWaitingPackets(); SocketThread.addSocketService(ios); return true; } catch (Exception e) { log.log(Level.WARNING, ios + "Exception during writing packets: ", e); try { ios.stop(); } catch (Exception e1) { log.log(Level.WARNING, ios + "Exception stopping XMPPIOService: ", e1); } // end of try-catch } finally { ios.writeInProgress.unlock(); } } } else { if (log.isLoggable(Level.FINE)) { log.log( Level.FINE, "Can''t find service for packet: <{0}> {1}, service id: {2}", new Object[] {p.getElemName(), p.getTo(), getServiceId(p)}); } } // end of if (ios != null) else return false; }
/** * Make sure that the received packet has a TO and FROM values defined and that it was sent from a * previously validated domain. If the packet does not matches any of the above conditions then a * PacketRejectedException will be thrown. * * @param packet the received packet. * @throws PacketRejectedException if the packet does not include a TO or FROM or if the packet * was sent from a domain that was not previously validated. */ private void packetReceived(Packet packet) throws PacketRejectedException { if (packet.getTo() == null || packet.getFrom() == null) { Log.debug( "Closing IncomingServerSession due to packet with no TO or FROM: " + packet.toXML()); // Send a stream error saying that the packet includes no TO or FROM StreamError error = new StreamError(StreamError.Condition.improper_addressing); connection.deliverRawText(error.toXML()); // Close the underlying connection connection.close(); open = false; throw new PacketRejectedException("Packet with no TO or FROM attributes"); } else if (!((IncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) { Log.debug( "Closing IncomingServerSession due to packet with invalid domain: " + packet.toXML()); // Send a stream error saying that the packet includes an invalid FROM StreamError error = new StreamError(StreamError.Condition.invalid_from); connection.deliverRawText(error.toXML()); // Close the underlying connection connection.close(); open = false; throw new PacketRejectedException("Packet with no TO or FROM attributes"); } }
public Packet doAction(Packet packet) throws PacketRejectedException { SessionManager sessionManager = SessionManager.getInstance(); ClientSession clientSession = sessionManager.getSession(packet.getFrom()); Packet rejectPacket; String pfFrom = JiveGlobals.getProperty("pf.From", "packetfilter"); if (packet instanceof Message) { Message in = (Message) packet.createCopy(); if (clientSession != null && in.getBody() != null) { in.setFrom(new JID(pfFrom)); String rejectMessage = JiveGlobals.getProperty( "pf.rejectMessage", "Your message was rejected by the packet filter"); in.setBody(rejectMessage); in.setType(Message.Type.error); in.setTo(packet.getFrom()); String rejectSubject = JiveGlobals.getProperty("pf.rejectSubject", "Rejected"); in.setSubject(rejectSubject); clientSession.process(in); } } else if (packet instanceof Presence) { rejectPacket = new Presence(); rejectPacket.setTo(packet.getFrom()); rejectPacket.setError(PacketError.Condition.forbidden); } else if (packet instanceof IQ) { rejectPacket = new IQ(); rejectPacket.setTo(packet.getFrom()); rejectPacket.setError(PacketError.Condition.forbidden); } if (doLog()) { Log.info("Rejecting packet from " + packet.getFrom() + " to " + packet.getTo()); } throw new PacketRejectedException(); }
/** * Method description * * @param packet * @return a value of <code>String</code> */ protected String getServiceId(Packet packet) { return getServiceId(packet.getTo()); }