aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2012-04-23 11:47:23 +0000
committerDamian Minkov <damencho@jitsi.org>2012-04-23 11:47:23 +0000
commit4e8a4ea55e98494b92c1fc7ac4425455360fdaed (patch)
tree3b5eff48025b226edf40aae03111e87a27f08571 /src
parent849a26d3154f972db9ceb439931bc5ab3c11c11f (diff)
downloadjitsi-4e8a4ea55e98494b92c1fc7ac4425455360fdaed.zip
jitsi-4e8a4ea55e98494b92c1fc7ac4425455360fdaed.tar.gz
jitsi-4e8a4ea55e98494b92c1fc7ac4425455360fdaed.tar.bz2
Fixes sip tcp ports in pcap file.
Fixes a possible deadlock in spellcheck obtaining chats and an early chat/typing notification while starting.
Diffstat (limited to 'src')
-rw-r--r--src/net/java/sip/communicator/impl/protocol/jabber/debugger/SmackPacketDebugger.java86
-rw-r--r--src/net/java/sip/communicator/impl/protocol/sip/SipLogger.java138
-rw-r--r--src/net/java/sip/communicator/plugin/spellcheck/ChatAttachments.java15
-rw-r--r--src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java13
4 files changed, 225 insertions, 27 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/debugger/SmackPacketDebugger.java b/src/net/java/sip/communicator/impl/protocol/jabber/debugger/SmackPacketDebugger.java
index 411fcd2..77aa3eb 100644
--- a/src/net/java/sip/communicator/impl/protocol/jabber/debugger/SmackPacketDebugger.java
+++ b/src/net/java/sip/communicator/impl/protocol/jabber/debugger/SmackPacketDebugger.java
@@ -83,6 +83,18 @@ public class SmackPacketDebugger
.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 class SmackPacketDebugger
connection.getPort(),
PacketLoggingService.TransportName.TCP,
true,
- packet.toXML().getBytes("UTF-8")
+ packetBytes
);
}
}
@@ -102,6 +114,64 @@ public class SmackPacketDebugger
}
/**
+ * 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/>
* A single thread is responsible for invoking all listeners, so
@@ -118,6 +188,18 @@ public class SmackPacketDebugger
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 class SmackPacketDebugger
connection.getSocket().getLocalPort(),
PacketLoggingService.TransportName.TCP,
false,
- packet.toXML().getBytes("UTF-8")
+ packetBytes
);
}
}
diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipLogger.java b/src/net/java/sip/communicator/impl/protocol/sip/SipLogger.java
index c225130..02c1950 100644
--- a/src/net/java/sip/communicator/impl/protocol/sip/SipLogger.java
+++ b/src/net/java/sip/communicator/impl/protocol/sip/SipLogger.java
@@ -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 @@ public class SipLogger
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 @@ public class SipLogger
// 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 @@ public class SipLogger
}
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 @@ public class SipLogger
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 @@ public class SipLogger
PacketLoggingService.TransportName.TCP,
sender, msg);
}
- catch(UnsupportedEncodingException e)
+ catch(Throwable e)
{
logger.error("Cannot obtain message body", e);
}
@@ -369,7 +431,10 @@ public class SipLogger
*
* @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 class SipLogger
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));
+ }
}
diff --git a/src/net/java/sip/communicator/plugin/spellcheck/ChatAttachments.java b/src/net/java/sip/communicator/plugin/spellcheck/ChatAttachments.java
index b7f5b34..4954dab 100644
--- a/src/net/java/sip/communicator/plugin/spellcheck/ChatAttachments.java
+++ b/src/net/java/sip/communicator/plugin/spellcheck/ChatAttachments.java
@@ -271,6 +271,21 @@ class ChatAttachments
}
+ @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
diff --git a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java
index 54abc61..bc2765b 100644
--- a/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java
+++ b/src/net/java/sip/communicator/plugin/spellcheck/SpellChecker.java
@@ -153,12 +153,9 @@ class SpellChecker
.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 @@ class SpellChecker
{
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);