Fixes sip tcp ports in pcap file.

Fixes a possible deadlock in spellcheck obtaining chats and an early chat/typing notification while starting.
cusax-fix
Damian Minkov 14 years ago
parent 849a26d315
commit 4e8a4ea55e

@ -83,6 +83,18 @@ public void interceptPacket(Packet packet)
.getLocalAddress().getAddress();
}
byte[] packetBytes;
if(packet instanceof Message)
{
packetBytes = cloneAnonyMessage(packet)
.toXML().getBytes("UTF-8");
}
else
{
packetBytes = packet.toXML().getBytes("UTF-8");
}
packetLogging.logPacket(
PacketLoggingService.ProtocolName.JABBER,
localAddress,
@ -91,7 +103,7 @@ public void interceptPacket(Packet packet)
connection.getPort(),
PacketLoggingService.TransportName.TCP,
true,
packet.toXML().getBytes("UTF-8")
packetBytes
);
}
}
@ -101,6 +113,64 @@ public void interceptPacket(Packet packet)
}
}
/**
* Clones if messages and process subject and bodies.
* @param packet
* @return
*/
private Message cloneAnonyMessage(Packet packet)
{
Message oldMsg = (Message)packet;
// if the message has no body, or the bodies list is empty
if(oldMsg.getBody() == null
&& (oldMsg.getBodies() == null || oldMsg.getBodies().size() == 0))
{
return oldMsg;
}
Message newMsg = new Message();
newMsg.setPacketID(packet.getPacketID());
newMsg.setTo(packet.getTo());
newMsg.setFrom(packet.getFrom());
// we don't modify them, just use existing
for(PacketExtension pex : packet.getExtensions())
newMsg.addExtension(pex);
for(String propName : packet.getPropertyNames())
newMsg.setProperty(propName, packet.getProperty(propName));
newMsg.setError(packet.getError());
newMsg.setType(oldMsg.getType());
newMsg.setThread(oldMsg.getThread());
newMsg.setLanguage(oldMsg.getLanguage());
for(Message.Subject sub : oldMsg.getSubjects())
{
if(sub.getSubject() != null)
newMsg.addSubject(sub.getLanguage(),
new String(new char[sub.getSubject().length()])
.replace('\0', '.'));
else
newMsg.addSubject(sub.getLanguage(), sub.getSubject());
}
for(Message.Body b : oldMsg.getBodies())
{
if(b.getMessage() != null)
newMsg.addBody(b.getLanguage(),
new String(new char[b.getMessage().length()])
.replace('\0', '.'));
else
newMsg.addSubject(b.getLanguage(), b.getMessage());
}
return newMsg;
}
/**
* Process the next packet sent to this packet listener.<p>
* <p/>
@ -118,6 +188,18 @@ public void processPacket(Packet packet)
PacketLoggingService.ProtocolName.JABBER)
&& packet != null && connection.getSocket() != null)
{
byte[] packetBytes;
if(packet instanceof Message)
{
packetBytes = cloneAnonyMessage(packet)
.toXML().getBytes("UTF-8");
}
else
{
packetBytes = packet.toXML().getBytes("UTF-8");
}
packetLogging.logPacket(
PacketLoggingService.ProtocolName.JABBER,
remoteAddress,
@ -126,7 +208,7 @@ public void processPacket(Packet packet)
connection.getSocket().getLocalPort(),
PacketLoggingService.TransportName.TCP,
false,
packet.toXML().getBytes("UTF-8")
packetBytes
);
}
}

@ -7,9 +7,11 @@
package net.java.sip.communicator.impl.protocol.sip;
import gov.nist.core.*;
import gov.nist.javax.sip.*;
import gov.nist.javax.sip.message.*;
import javax.sip.*;
import java.io.*;
import java.net.*;
import java.util.*;
import net.java.sip.communicator.service.packetlogging.*;
@ -31,6 +33,11 @@ public class SipLogger
private static final Logger logger
= Logger.getLogger(SipLogger.class);
/**
* SipStack to use.
*/
private SipStack sipStack;
/*
* Implementation of StackLogger
*/
@ -265,8 +272,8 @@ private void logPacket(SIPMessage message, boolean sender)
PacketLoggingService.ProtocolName.SIP))
return;
boolean isTransportUDP = message.getTopmostVia().getTransport()
.equalsIgnoreCase("UDP");
String transport = message.getTopmostVia().getTransport();
boolean isTransportUDP = transport.equalsIgnoreCase("UDP");
byte[] srcAddr;
int srcPort;
@ -278,14 +285,28 @@ private void logPacket(SIPMessage message, boolean sender)
// byte array with length 4 (ipv4 0.0.0.0)
if(sender)
{
srcPort = message.getLocalPort();
if(message.getLocalAddress() != null)
srcAddr = message.getLocalAddress().getAddress();
else if(message.getRemoteAddress() != null)
srcAddr = new byte[
message.getRemoteAddress().getAddress().length];
if(!isTransportUDP)
{
InetSocketAddress localAddress =
getLocalAddressForDestination(
message.getRemoteAddress(),
message.getRemotePort(),
message.getLocalAddress(),
transport);
srcPort = localAddress.getPort();
srcAddr = localAddress.getAddress().getAddress();
}
else
srcAddr = new byte[4];
{
srcPort = message.getLocalPort();
if(message.getLocalAddress() != null)
srcAddr = message.getLocalAddress().getAddress();
else if(message.getRemoteAddress() != null)
srcAddr = new byte[
message.getRemoteAddress().getAddress().length];
else
srcAddr = new byte[4];
}
dstPort = message.getRemotePort();
if(message.getRemoteAddress() != null)
@ -295,14 +316,28 @@ else if(message.getRemoteAddress() != null)
}
else
{
dstPort = message.getLocalPort();
if(message.getLocalAddress() != null)
dstAddr = message.getLocalAddress().getAddress();
else if(message.getRemoteAddress() != null)
dstAddr = new byte[
message.getRemoteAddress().getAddress().length];
if(!isTransportUDP)
{
InetSocketAddress dstAddress =
getLocalAddressForDestination(
message.getRemoteAddress(),
message.getRemotePort(),
message.getLocalAddress(),
transport);
dstPort = dstAddress.getPort();
dstAddr = dstAddress.getAddress().getAddress();
}
else
dstAddr = new byte[4];
{
dstPort = message.getLocalPort();
if(message.getLocalAddress() != null)
dstAddr = message.getLocalAddress().getAddress();
else if(message.getRemoteAddress() != null)
dstAddr = new byte[
message.getRemoteAddress().getAddress().length];
else
dstAddr = new byte[4];
}
srcPort = message.getRemotePort();
if(message.getRemoteAddress() != null)
@ -311,7 +346,34 @@ else if(message.getRemoteAddress() != null)
srcAddr = new byte[dstAddr.length];
}
byte[] msg = message.toString().getBytes("UTF-8");
byte[] msg = null;
if(message instanceof SIPRequest)
{
SIPRequest req = (SIPRequest)message;
if(req.getMethod().equals(SIPRequest.MESSAGE)
&& message.getContentTypeHeader() != null
&& message.getContentTypeHeader()
.getContentType().equalsIgnoreCase("text"))
{
int len = req.getContentLength().getContentLength();
if(len > 0)
{
SIPRequest newReq = (SIPRequest)req.clone();
byte[] newContent = new byte[len];
Arrays.fill(newContent, (byte)'.');
newReq.setMessageContent(newContent);
msg = newReq.toString().getBytes("UTF-8");
}
}
}
if(msg == null)
{
msg = message.toString().getBytes("UTF-8");
}
packetLogging.logPacket(
PacketLoggingService.ProtocolName.SIP,
srcAddr, srcPort,
@ -320,7 +382,7 @@ else if(message.getRemoteAddress() != null)
PacketLoggingService.TransportName.TCP,
sender, msg);
}
catch(UnsupportedEncodingException e)
catch(Throwable e)
{
logger.error("Cannot obtain message body", e);
}
@ -369,7 +431,10 @@ public void logException(Exception exception)
*
* @param sipStack ignored;
*/
public void setSipStack(SipStack sipStack) {}
public void setSipStack(SipStack sipStack)
{
this.sipStack = sipStack;
}
/**
* Returns a logger name.
@ -392,4 +457,39 @@ public void logTrace(String message)
logger.debug(message);
}
/**
* Returns a local address to use with the specified TCP destination.
* The method forces the JAIN-SIP stack to create
* s and binds (if necessary)
* and return a socket connected to the specified destination address and
* port and then return its local address.
*
* @param dst the destination address that the socket would need to connect
* to.
* @param dstPort the port number that the connection would be established
* with.
* @param localAddress the address that we would like to bind on
* (null for the "any" address).
* @param transport the transport that will be used TCP ot TLS
*
* @return the SocketAddress that this handler would use when connecting to
* the specified destination address and port.
*
* @throws IOException if we fail binding the local socket
*/
public java.net.InetSocketAddress getLocalAddressForDestination(
java.net.InetAddress dst,
int dstPort,
java.net.InetAddress localAddress,
String transport)
throws IOException
{
if(ListeningPoint.TLS.equalsIgnoreCase(transport))
return (java.net.InetSocketAddress)(((SipStackImpl)this.sipStack)
.getLocalAddressForTlsDst(dst, dstPort, localAddress));
else
return (java.net.InetSocketAddress)(((SipStackImpl)this.sipStack)
.getLocalAddressForTcpDst(dst, dstPort, localAddress, 0));
}
}

@ -271,6 +271,21 @@ public void actionPerformed(ActionEvent e)
}
@Override
public boolean equals(Object obj)
{
if(obj instanceof ChatAttachments)
return this.chat.equals(((ChatAttachments)obj).chat);
else
return false;
}
@Override
public int hashCode()
{
return this.chat.hashCode();
}
// Applies corrections from popup menu to chat
private class CorrectionListener
implements ActionListener

@ -153,12 +153,9 @@ synchronized void start(BundleContext bc) throws Exception
.createSpellCheckerWorker(locale).start();
// attaches to uiService so this'll be attached to future chats
synchronized (this.attachedChats)
{
SpellCheckActivator.getUIService().addChatListener(this);
for (Chat chat : SpellCheckActivator.getUIService().getAllChats())
chatCreated(chat);
}
SpellCheckActivator.getUIService().addChatListener(this);
for (Chat chat : SpellCheckActivator.getUIService().getAllChats())
chatCreated(chat);
if (logger.isInfoEnabled())
logger.info("Spell Checker loaded.");
@ -214,6 +211,10 @@ public void chatCreated(Chat chat)
{
ChatAttachments wrapper = new ChatAttachments(chat, this.dict);
// if it contains wrapper for the same chat, don't add it
if(attachedChats.contains(wrapper))
return;
wrapper.setEnabled(enabled);
wrapper.attachListeners();
attachedChats.add(wrapper);

Loading…
Cancel
Save