Fix sip address detection

This commit is contained in:
Sylvain Berfini 2013-03-22 11:27:29 +01:00
parent 447a8a50c0
commit f965c84184
2 changed files with 6 additions and 11 deletions

View file

@ -34,7 +34,7 @@
<bool name="show_statusbar_only_on_dialer">true</bool> <bool name="show_statusbar_only_on_dialer">true</bool>
<bool name="lock_statusbar">false</bool> <bool name="lock_statusbar">false</bool>
<bool name="emoticons_in_messages">true</bool> <bool name="emoticons_in_messages">true</bool>
<bool name="only_display_username_if_unknown">true</bool> <bool name="only_display_username_if_unknown">true</bool> <!-- Display username for all sip addresses (if not in contact and display name empty) -->
<bool name="display_messages_time_and_status">true</bool> <!-- Used to show the time of each message arrival --> <bool name="display_messages_time_and_status">true</bool> <!-- Used to show the time of each message arrival -->
<bool name="display_time_aside">false</bool> <!-- if display_messages_time = true, display time on the side of the message instead of below --> <bool name="display_time_aside">false</bool> <!-- if display_messages_time = true, display time on the side of the message instead of below -->

View file

@ -29,13 +29,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall; import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State; import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version; import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.Hacks; import org.linphone.mediastream.video.capture.hwconf.Hacks;
@ -68,19 +67,15 @@ public final class LinphoneUtils {
private LinphoneUtils(){} private LinphoneUtils(){}
private static boolean preventVolumeBarToDisplay = false; private static boolean preventVolumeBarToDisplay = false;
private static final String sipAddressRegExp = "^(sip:)?(\\+)?[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}(:[0-9]{2,5})?$"; //private static final String sipAddressRegExp = "^(sip:)?(\\+)?[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}(:[0-9]{2,5})?$";
private static final String strictSipAddressRegExp = "^sip:(\\+)?[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$"; //private static final String strictSipAddressRegExp = "^sip:(\\+)?[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\\.-][a-z0-9]+)*)+\\.[a-z]{2,}$";
public static boolean isSipAddress(String numberOrAddress) { public static boolean isSipAddress(String numberOrAddress) {
Pattern p = Pattern.compile(sipAddressRegExp); return LinphoneCoreFactory.instance().createLinphoneAddress(numberOrAddress) != null;
Matcher m = p.matcher(numberOrAddress);
return m != null && m.matches();
} }
public static boolean isStrictSipAddress(String numberOrAddress) { public static boolean isStrictSipAddress(String numberOrAddress) {
Pattern p = Pattern.compile(strictSipAddressRegExp); return isSipAddress(numberOrAddress) && numberOrAddress.startsWith("sip:");
Matcher m = p.matcher(numberOrAddress);
return m != null && m.matches();
} }
public static String getUsernameFromAddress(String address) { public static String getUsernameFromAddress(String address) {