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 @@
package org.jivesoftware.messenger.audit;
import org.xmpp.packet.Packet;
import org.jivesoftware.messenger.Session;
/**
* <p>Use auditors to audit events and messages on the server.</p>
......@@ -28,8 +29,9 @@ public interface Auditor {
* Audit an XMPP packet.
*
* @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).
......
......@@ -60,21 +60,21 @@ public class AuditorImpl implements Auditor {
auditManager = manager;
}
public void audit(Packet packet) {
public void audit(Packet packet, Session session) {
if (auditManager.isEnabled()) {
if (packet instanceof Message) {
if (auditManager.isAuditMessage()) {
writePacket(packet);
writePacket(packet, session);
}
}
else if (packet instanceof Presence) {
if (auditManager.isAuditPresence()) {
writePacket(packet);
writePacket(packet, session);
}
}
else if (packet instanceof IQ) {
if (auditManager.isAuditIQ()) {
writePacket(packet);
writePacket(packet, session);
}
}
}
......@@ -103,10 +103,10 @@ public class AuditorImpl implements Auditor {
}
}
private void writePacket(Packet packet) {
private void writePacket(Packet packet, Session session) {
if (!closed) {
// 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 {
private Element element;
public AuditPacket(Packet packet) {
public AuditPacket(Packet packet, Session session) {
element = docFactory.createElement("packet", "http://www.jivesoftware.org");
Session session = SessionManager.getInstance().getSession(packet.getFrom());
if (session != null) {
if (session.getStreamID() != null) {
element.addAttribute("streamID", session.getStreamID().toString());
}
......@@ -244,6 +242,11 @@ public class AuditorImpl implements Auditor {
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;
case Session.STATUS_STREAMING:
element.addAttribute("status", "stream");
......@@ -252,8 +255,7 @@ public class AuditorImpl implements Auditor {
element.addAttribute("status", "unknown");
break;
}
}
element.addAttribute("timestap", new Date().toString());
element.addAttribute("timestamp", new Date().toString());
element.add(packet.getElement());
}
......
......@@ -188,7 +188,7 @@ public class SocketConnection extends BasicConnection {
Log.error(e);
}
}
auditor.audit(packet);
auditor.audit(packet, session);
session.incrementServerPacketCount();
}
}
......
......@@ -184,14 +184,14 @@ public class SocketReadThread extends Thread {
if ("message".equals(tag)) {
Message packet = new Message(doc);
packet.setFrom(session.getAddress());
auditor.audit(packet);
auditor.audit(packet, session);
router.route(packet);
session.incrementClientPacketCount();
}
else if ("presence".equals(tag)) {
Presence packet = new Presence(doc);
packet.setFrom(session.getAddress());
auditor.audit(packet);
auditor.audit(packet, session);
router.route(packet);
session.incrementClientPacketCount();
// Update the flag that indicates if the user made a clean sign out
......@@ -200,7 +200,7 @@ public class SocketReadThread extends Thread {
else if ("iq".equals(tag)) {
IQ packet = getIQ(doc);
packet.setFrom(session.getAddress());
auditor.audit(packet);
auditor.audit(packet, session);
router.route(packet);
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