diff options
Diffstat (limited to 'src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java | 182 |
1 files changed, 137 insertions, 45 deletions
diff --git a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java index 0fbcf23..927c0a3 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java @@ -246,6 +246,76 @@ public class ProtocolProviderServiceSipImpl } /** + * Validates the contact identifier and returns an error message if + * applicable and a suggested correction + * + * @param contactId the contact identifier to validate + * @param result Must be supplied as an empty a list. Implementors add + * items: + * <ol> + * <li>is the error message if applicable + * <li>a suggested correction. Index 1 is optional and can only + * be present if there was a validation failure. + * </ol> + * @return true if the contact id is valid, false otherwise + */ + @Override + public boolean validateContactAddress(String contactId, List<String> result) + { + if (result == null) + { + throw new IllegalArgumentException("result must be an empty list"); + } + + result.clear(); + try + { + Address address = parseAddressString(contactId); + if (address.toString().equals(contactId)) + { + return true; + } + else if (((SipUri) address.getURI()).getUser().equals(contactId)) + { + return true; + } + else if (address.toString().equals(address.getURI().getScheme() + ":" + contactId)) + { + return true; + } + else + { + result.add(SipActivator.getResources().getI18NString( + "impl.protocol.sip.INVALID_ADDRESS", new String[] + { contactId })); + result.add(((SipUri) address.getURI()).getUser()); + } + } + catch (Exception ex) + { + logger.error("Validating SIP address failed for " + contactId, ex); + result.add(SipActivator.getResources() + .getI18NString("impl.protocol.sip.INVALID_ADDRESS", new String[] + { contactId })); + + String user = contactId; + String remainder = ""; + int at = contactId.indexOf('@'); + if (at > -1) + { + user = contactId.substring(0, at); + remainder = contactId.substring(at); + } + + // replace invalid characters in user part with hex encoding + String banned = "([^a-z0-9-_.!~*'()&=+$,;?/])+"; + result.add(user.replaceAll(banned, "") + remainder); + } + + return false; + } + + /** * Indicates whether or not this provider must registered * when placing outgoing calls. * @@ -610,50 +680,50 @@ public class ProtocolProviderServiceSipImpl addSupportedOperationSet( OperationSetPresence.class, opSetPersPresence); + } - // Only init messaging and typing if enabled. - boolean isMessagingDisabled - = SipActivator.getConfigurationService() - .getBoolean(IS_MESSAGING_DISABLED, false); + // Only init messaging and typing if enabled. + boolean isMessagingDisabled + = SipActivator.getConfigurationService() + .getBoolean(IS_MESSAGING_DISABLED, false); - if (!isMessagingDisabled) - { - // init instant messaging - this.opSetBasicIM = - new OperationSetBasicInstantMessagingSipImpl(this); + if (!isMessagingDisabled) + { + // init instant messaging + this.opSetBasicIM = + new OperationSetBasicInstantMessagingSipImpl(this); - addSupportedOperationSet( - OperationSetBasicInstantMessaging.class, - opSetBasicIM); + addSupportedOperationSet( + OperationSetBasicInstantMessaging.class, + opSetBasicIM); - // init typing notifications - this.opSetTypingNotif - = new OperationSetTypingNotificationsSipImpl( - this, opSetBasicIM); - addSupportedOperationSet( - OperationSetTypingNotifications.class, - opSetTypingNotif); + // init typing notifications + this.opSetTypingNotif + = new OperationSetTypingNotificationsSipImpl( + this, opSetBasicIM); + addSupportedOperationSet( + OperationSetTypingNotifications.class, + opSetTypingNotif); - addSupportedOperationSet( - OperationSetInstantMessageTransform.class, - new OperationSetInstantMessageTransformImpl()); - } + addSupportedOperationSet( + OperationSetInstantMessageTransform.class, + new OperationSetInstantMessageTransformImpl()); + } - this.opSetSSAccountInfo = - new OperationSetServerStoredAccountInfoSipImpl(this); + this.opSetSSAccountInfo = + new OperationSetServerStoredAccountInfoSipImpl(this); - // Set the display name. - opSetSSAccountInfo.setOurDisplayName(ourDisplayName); + // Set the display name. + opSetSSAccountInfo.setOurDisplayName(ourDisplayName); - // init avatar - addSupportedOperationSet( - OperationSetServerStoredAccountInfo.class, - opSetSSAccountInfo); + // init avatar + addSupportedOperationSet( + OperationSetServerStoredAccountInfo.class, + opSetSSAccountInfo); - addSupportedOperationSet( - OperationSetAvatar.class, - new OperationSetAvatarSipImpl(this, opSetSSAccountInfo)); - } + addSupportedOperationSet( + OperationSetAvatar.class, + new OperationSetAvatarSipImpl(this, opSetSSAccountInfo)); // MWI is enabled by default if(accountID.getAccountPropertyBoolean( @@ -1519,16 +1589,16 @@ public class ProtocolProviderServiceSipImpl Set<ProtocolProviderServiceSipImpl> instances = new HashSet<ProtocolProviderServiceSipImpl>(); BundleContext context = SipActivator.getBundleContext(); - ServiceReference[] references = context.getServiceReferences( - ProtocolProviderService.class.getName(), - null - ); - for(ServiceReference reference : references) + Collection<ServiceReference<ProtocolProviderService>> references = + context.getServiceReferences(ProtocolProviderService.class, + null); + for(ServiceReference<ProtocolProviderService> ref : references) { - Object service = context.getService(reference); + ProtocolProviderService service = context.getService(ref); if(service instanceof ProtocolProviderServiceSipImpl) instances.add((ProtocolProviderServiceSipImpl) service); } + return instances; } catch(InvalidSyntaxException ex) @@ -2390,21 +2460,38 @@ public class ProtocolProviderServiceSipImpl //we don't know how to handle the "tel:" and "callto:" schemes ... or // rather we handle them same as sip so replace: if(uriStr.toLowerCase().startsWith("tel:")) - uriStr = "sip:" + uriStr.substring("tel:".length()); + uriStr = uriStr.substring("tel:".length()); else if(uriStr.toLowerCase().startsWith("callto:")) - uriStr = "sip:" + uriStr.substring("callto:".length()); + uriStr = uriStr.substring("callto:".length()); + else if(uriStr.toLowerCase().startsWith("sips:")) + uriStr = uriStr.substring("sips:".length()); + else if(uriStr.toLowerCase().startsWith("sip:")) + uriStr = uriStr.substring("sip:".length()); + + String user = uriStr; + String remainder = ""; + int at = uriStr.indexOf('@'); + if (at > -1) + { + user = uriStr.substring(0, at); + remainder = uriStr.substring(at); + } + + //replace invalid characters in user part with hex encoding + String banned = "([^a-z0-9-_.!~*'()&=+$,;?/])+"; + user = user.replaceAll(banned, "") + remainder; //Handle default domain name (i.e. transform 1234 -> 1234@sip.com) //assuming that if no domain name is specified then it should be the //same as ours. - if (uriStr.indexOf('@') == -1) + if (at == -1) { //if we have a registrar, then we could append its domain name as //default SipRegistrarConnection src = sipRegistrarConnection; if(src != null && !src.isRegistrarless() ) { - uriStr = uriStr + "@" + uriStr = user + "@" + ((SipURI)src.getAddressOfRecord().getURI()).getHost(); } @@ -2684,6 +2771,11 @@ public class ProtocolProviderServiceSipImpl */ protected void notifyConnectionFailed() { + if (sipRegistrarConnection.isRegistrarless()) + { + return; + } + if(getRegistrationState().equals(RegistrationState.REGISTERED) && sipRegistrarConnection != null) sipRegistrarConnection.setRegistrationState( |