Commit 459288d1 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Refactoring fix.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@719 b35dd754-fafc-0310-a699-88a17e54d16e
parent f2ee21b9
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
package org.jivesoftware.messenger.audit; package org.jivesoftware.messenger.audit;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.jivesoftware.messenger.Session;
/** /**
* <p>Use auditors to audit events and messages on the server.</p> * <p>Use auditors to audit events and messages on the server.</p>
...@@ -28,8 +29,9 @@ public interface Auditor { ...@@ -28,8 +29,9 @@ public interface Auditor {
* Audit an XMPP packet. * Audit an XMPP packet.
* *
* @param packet the packet being audited * @param packet the packet being audited
* @param session the session used for sending or receiving the packet
*/ */
void audit(Packet packet); void audit(Packet packet, Session session);
/** /**
* Audit any packet that was dropped (undeliverables, etc). * Audit any packet that was dropped (undeliverables, etc).
......
...@@ -60,21 +60,21 @@ public class AuditorImpl implements Auditor { ...@@ -60,21 +60,21 @@ public class AuditorImpl implements Auditor {
auditManager = manager; auditManager = manager;
} }
public void audit(Packet packet) { public void audit(Packet packet, Session session) {
if (auditManager.isEnabled()) { if (auditManager.isEnabled()) {
if (packet instanceof Message) { if (packet instanceof Message) {
if (auditManager.isAuditMessage()) { if (auditManager.isAuditMessage()) {
writePacket(packet); writePacket(packet, session);
} }
} }
else if (packet instanceof Presence) { else if (packet instanceof Presence) {
if (auditManager.isAuditPresence()) { if (auditManager.isAuditPresence()) {
writePacket(packet); writePacket(packet, session);
} }
} }
else if (packet instanceof IQ) { else if (packet instanceof IQ) {
if (auditManager.isAuditIQ()) { if (auditManager.isAuditIQ()) {
writePacket(packet); writePacket(packet, session);
} }
} }
} }
...@@ -103,10 +103,10 @@ public class AuditorImpl implements Auditor { ...@@ -103,10 +103,10 @@ public class AuditorImpl implements Auditor {
} }
} }
private void writePacket(Packet packet) { private void writePacket(Packet packet, Session session) {
if (!closed) { if (!closed) {
// Add to the logging queue this new entry that will be saved later // Add to the logging queue this new entry that will be saved later
logQueue.add(new AuditPacket(packet.createCopy())); logQueue.add(new AuditPacket(packet.createCopy(), session));
} }
} }
...@@ -228,10 +228,8 @@ public class AuditorImpl implements Auditor { ...@@ -228,10 +228,8 @@ public class AuditorImpl implements Auditor {
private Element element; private Element element;
public AuditPacket(Packet packet) { public AuditPacket(Packet packet, Session session) {
element = docFactory.createElement("packet", "http://www.jivesoftware.org"); element = docFactory.createElement("packet", "http://www.jivesoftware.org");
Session session = SessionManager.getInstance().getSession(packet.getFrom());
if (session != null) {
if (session.getStreamID() != null) { if (session.getStreamID() != null) {
element.addAttribute("streamID", session.getStreamID().toString()); element.addAttribute("streamID", session.getStreamID().toString());
} }
...@@ -244,6 +242,11 @@ public class AuditorImpl implements Auditor { ...@@ -244,6 +242,11 @@ public class AuditorImpl implements Auditor {
break; break;
case Session.STATUS_CONNECTED: case Session.STATUS_CONNECTED:
element.addAttribute("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; break;
case Session.STATUS_STREAMING: case Session.STATUS_STREAMING:
element.addAttribute("status", "stream"); element.addAttribute("status", "stream");
...@@ -252,8 +255,7 @@ public class AuditorImpl implements Auditor { ...@@ -252,8 +255,7 @@ public class AuditorImpl implements Auditor {
element.addAttribute("status", "unknown"); element.addAttribute("status", "unknown");
break; break;
} }
} element.addAttribute("timestamp", new Date().toString());
element.addAttribute("timestap", new Date().toString());
element.add(packet.getElement()); element.add(packet.getElement());
} }
......
...@@ -188,7 +188,7 @@ public class SocketConnection extends BasicConnection { ...@@ -188,7 +188,7 @@ public class SocketConnection extends BasicConnection {
Log.error(e); Log.error(e);
} }
} }
auditor.audit(packet); auditor.audit(packet, session);
session.incrementServerPacketCount(); session.incrementServerPacketCount();
} }
} }
......
...@@ -184,14 +184,14 @@ public class SocketReadThread extends Thread { ...@@ -184,14 +184,14 @@ public class SocketReadThread extends Thread {
if ("message".equals(tag)) { if ("message".equals(tag)) {
Message packet = new Message(doc); Message packet = new Message(doc);
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
auditor.audit(packet); auditor.audit(packet, session);
router.route(packet); router.route(packet);
session.incrementClientPacketCount(); session.incrementClientPacketCount();
} }
else if ("presence".equals(tag)) { else if ("presence".equals(tag)) {
Presence packet = new Presence(doc); Presence packet = new Presence(doc);
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
auditor.audit(packet); auditor.audit(packet, session);
router.route(packet); router.route(packet);
session.incrementClientPacketCount(); session.incrementClientPacketCount();
// Update the flag that indicates if the user made a clean sign out // Update the flag that indicates if the user made a clean sign out
...@@ -200,7 +200,7 @@ public class SocketReadThread extends Thread { ...@@ -200,7 +200,7 @@ public class SocketReadThread extends Thread {
else if ("iq".equals(tag)) { else if ("iq".equals(tag)) {
IQ packet = getIQ(doc); IQ packet = getIQ(doc);
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
auditor.audit(packet); auditor.audit(packet, session);
router.route(packet); router.route(packet);
session.incrementClientPacketCount(); session.incrementClientPacketCount();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment