aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/net/java/sip/communicator/impl/protocol/sip/ContactSipImpl.java36
-rw-r--r--test/net/java/sip/communicator/slick/protocol/sip/TestProtocolProviderServiceSipImpl.java25
2 files changed, 57 insertions, 4 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ContactSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ContactSipImpl.java
index 0d0b5e8..3bd574e 100644
--- a/src/net/java/sip/communicator/impl/protocol/sip/ContactSipImpl.java
+++ b/src/net/java/sip/communicator/impl/protocol/sip/ContactSipImpl.java
@@ -535,9 +535,7 @@ public class ContactSipImpl
if(obj instanceof String)
{
String sobj = (String)obj;
-
- if(sobj.startsWith("sip:"))
- sobj = sobj.substring(4);
+ sobj = stripScheme(stripAddress(sobj));
if(getAddress().equalsIgnoreCase(sobj))
return true;
@@ -556,6 +554,38 @@ public class ContactSipImpl
}
/**
+ * Get rid of any parameters, ports etc. within a sip contact
+ * @param address the address to strip
+ * @return [sip[s]:]user@host without any params or port numbers.
+ */
+ static String stripAddress(String address)
+ {
+ if (address != null && address.length() > 0)
+ {
+ int idx = address.indexOf(':', 5);
+ if (idx > -1)
+ address = address.substring(0, idx);
+ idx = address.indexOf(';');
+ if (idx > -1)
+ address = address.substring(0, idx);
+ }
+ return address;
+ }
+
+ /**
+ * @param from address to strip
+ * @return the address, stripped from either "sip:" or "sips:"
+ */
+ public static String stripScheme(String from)
+ {
+ int i = from.substring(0, 5).indexOf(':');
+
+ if(from.startsWith("sip") && i > 0)
+ return from.substring(i + 1);
+ return from;
+ }
+
+ /**
* Returns the presence operation set that this contact belongs
* to.
*
diff --git a/test/net/java/sip/communicator/slick/protocol/sip/TestProtocolProviderServiceSipImpl.java b/test/net/java/sip/communicator/slick/protocol/sip/TestProtocolProviderServiceSipImpl.java
index b475ac9..a799668 100644
--- a/test/net/java/sip/communicator/slick/protocol/sip/TestProtocolProviderServiceSipImpl.java
+++ b/test/net/java/sip/communicator/slick/protocol/sip/TestProtocolProviderServiceSipImpl.java
@@ -19,7 +19,9 @@ package net.java.sip.communicator.slick.protocol.sip;
import java.util.*;
+import javax.sip.address.*;
import junit.framework.*;
+import net.java.sip.communicator.impl.protocol.sip.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@@ -150,7 +152,7 @@ public class TestProtocolProviderServiceSipImpl
/**
- * Verifies that all operation sets have the type they are declarded to
+ * Verifies that all operation sets have the type they are declared to
* have.
*
* @throws java.lang.Exception if a class indicated in one of the keys
@@ -175,6 +177,27 @@ public class TestProtocolProviderServiceSipImpl
}
/**
+ * Tests the <tt>equals()</tt> implementation of the SIP Contact class
+ */
+ public void testContactSipImpl() throws Exception
+ {
+ ProtocolProviderServiceSipImpl provider =
+ (ProtocolProviderServiceSipImpl) fixture.provider1;
+ Address reference =
+ provider.parseAddressString("sip:User@Host");
+ Contact referenceContact = new ContactSipImpl(reference, provider);
+
+ assertTrue("Cannot find user-only part in a SIP Contact compare",
+ referenceContact.equals("User"));
+ assertTrue("Cannot find SIP Contact using strings",
+ referenceContact.equals("sip:User@Host"));
+ assertTrue("Cannot find SIP Contact when protocol is secure",
+ referenceContact.equals("sips:User@Host"));
+ assertTrue("Cannot find SIP Contact when port is specified",
+ referenceContact.equals("sip:User@Host:5060"));
+ }
+
+ /**
* A class that would plugin as a registration listener to a protocol
* provider and simply record all events that it sees and notifyAll()
* if it sees an event that notifies us of a completed