From 8f458ef1b99e7091b541ab809c8e286fd8cd229f Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Fri, 15 Dec 2006 17:28:23 +0000 Subject: [PATCH] Make sure user can unregister even if not completely registered (e.g. when REGISTERING). Issue number: --- .../impl/gui/main/login/LoginManager.java | 16 ++--- .../presence/SimpleStatusSelectorBox.java | 60 +++++++++---------- .../sip/ProtocolProviderServiceSipImpl.java | 12 ++-- .../protocol/sip/SipRegistrarConnection.java | 26 +++++--- .../event/RegistrationStateChangeEvent.java | 9 +-- .../jabber/TestOperationSetPresence.java | 3 +- 6 files changed, 66 insertions(+), 60 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java b/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java index b71b6d26f..642599060 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java @@ -209,12 +209,12 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) .getProtocolPresence(protocolProvider); if (evt.getNewState().equals(RegistrationState.REGISTERED)) { - + this.mainFrame.getStatusPanel() .updateStatus(protocolProvider); - + if(mainFrame.getCallManager().containsCallAccount(protocolProvider)) { - + this.mainFrame.getCallManager() .updateCallAccountStatus(protocolProvider); } @@ -232,7 +232,7 @@ else if (evt.getNewState().equals( if (evt.getReasonCode() == RegistrationStateChangeEvent .REASON_RECONNECTION_RATE_LIMIT_EXCEEDED) { - + String msgText = Messages.getI18NString( "reconnectionLimitExceeded", protocolProvider.getAccountID().getUserID()).getText(); @@ -242,7 +242,7 @@ else if (evt.getNewState().equals( } else if (evt.getReasonCode() == RegistrationStateChangeEvent .REASON_NON_EXISTING_USER_ID) { - + String msgText = Messages.getI18NString( "nonExistingUserId", protocolProvider .getProtocolName()).getText(); @@ -256,7 +256,7 @@ else if (evt.getReasonCode() == RegistrationStateChangeEvent protocolProvider.getAccountID().getAccountAddress()) .getText(); - new ErrorDialog(null, msgText, + new ErrorDialog(null, msgText, Messages.getI18NString("error").getText()).showDialog(); } logger.error(evt.getReason()); @@ -300,7 +300,7 @@ else if (evt.getNewState().equals(RegistrationState.UNREGISTERED)) { } else if (evt.getReasonCode() == RegistrationStateChangeEvent .REASON_CLIENT_LIMIT_REACHED_FOR_IP) { - + String msgText = Messages.getI18NString("limitReachedForIp", protocolProvider.getProtocolName()).getText(); @@ -308,7 +308,7 @@ else if (evt.getReasonCode() == RegistrationStateChangeEvent Messages.getI18NString("error").getText()).showDialog(); } else if (evt.getReasonCode() == RegistrationStateChangeEvent - .REASON_CHANGE_REQUESTED_BY_USER) { + .REASON_USER_REQUEST) { //do nothing } else { diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusSelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusSelectorBox.java index cd431ec7e..2b8111844 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusSelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusSelectorBox.java @@ -23,7 +23,7 @@ * The SimpleStatusSelectorBox is a SIPCommMenu that * contains two statuses ONLINE and OFFLINE. It's used to represent the status * of a protocol provider which doesn't support presence operation set. - * + * * @author Yana Stamcheva */ public class SimpleStatusSelectorBox @@ -41,29 +41,29 @@ public class SimpleStatusSelectorBox private Connecting connecting = new Connecting(); private ProtocolProviderService protocolProvider; - - private ImageIcon onlineIcon + + private ImageIcon onlineIcon = new ImageIcon(ImageLoader.getImage(ImageLoader.SIP_LOGO)); - + private ImageIcon offlineIcon = new ImageIcon(LightGrayFilter.createDisabledImage( ImageLoader.getImage(ImageLoader.SIP_LOGO))); - + private JMenuItem onlineItem = new JMenuItem( Messages.getI18NString("online").getText(), onlineIcon); - + private JMenuItem offlineItem = new JMenuItem( Messages.getI18NString("offline").getText(), offlineIcon); - + private int accountIndex; - + private JLabel titleLabel; - + /** * Creates an instance of SimpleStatusSelectorBox. - * + * * @param mainFrame The main application window. * @param protocolProvider The protocol provider. * @param accountIndex If we have more than one account for a protocol, @@ -76,19 +76,19 @@ public SimpleStatusSelectorBox(MainFrame mainFrame, this.mainFrame = mainFrame; this.protocolProvider = protocolProvider; this.accountIndex = accountIndex; - + String tooltip = "" + protocolProvider.getAccountID().getUserID() + "
Connecting"; - - this.setToolTipText(tooltip); - + + this.setToolTipText(tooltip); + onlineItem.setName("online"); offlineItem.setName("offline"); - + onlineItem.addActionListener(this); offlineItem.addActionListener(this); - + titleLabel = new JLabel(protocolProvider.getAccountID().getUserID()); titleLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); @@ -96,7 +96,7 @@ public SimpleStatusSelectorBox(MainFrame mainFrame, this.add(titleLabel); this.addSeparator(); - + this.add(onlineItem); this.add(offlineItem); } @@ -104,21 +104,21 @@ public SimpleStatusSelectorBox(MainFrame mainFrame, /** * Handles the ActionEvent triggered when one of the items * in the list is selected. - */ + */ public void actionPerformed(ActionEvent e) { JMenuItem menuItem = (JMenuItem) e.getSource(); String itemName = menuItem.getName(); - + if(itemName.equals("online")) { if(!protocolProvider.isRegistered()) { this.mainFrame.getLoginManager().login(protocolProvider); } } else { - if(! protocolProvider.getRegistrationState() + if( !protocolProvider.getRegistrationState() .equals(RegistrationState.UNREGISTERED) - && protocolProvider.getRegistrationState() + && !protocolProvider.getRegistrationState() .equals(RegistrationState.UNREGISTERING)) { try { @@ -139,7 +139,7 @@ public void actionPerformed(ActionEvent e) /** * Starts the timer that changes the images given by the array, thus * creating an animated image that indicates that the user is connecting. - * + * * @param images A BufferedImage array that contains all images * from which to create the animated image indicating the connecting state. */ @@ -156,20 +156,20 @@ public void startConnecting(BufferedImage[] images) * Stops the timer that manages the connecting animated icon. */ public void updateStatus() - { + { this.connecting.stop(); - + if(protocolProvider.isRegistered()) { - setSelected(onlineItem, onlineIcon); + setSelected(onlineItem, onlineIcon); } else { setSelected(offlineItem, offlineIcon); } - + String tooltip = this.getToolTipText(); - + tooltip = tooltip.substring(0, tooltip.lastIndexOf("
")); - + this.setToolTipText(tooltip.concat("
" + onlineItem.getText())); } @@ -208,11 +208,11 @@ public void setAccountIndex(int accountIndex) { this.accountIndex = accountIndex; } - + public void paintComponent(Graphics g) { super.paintComponent(g); - + if(accountIndex > 0) { AntialiasingManager.activateAntialiasing(g); g.setColor(Color.DARK_GRAY); 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 4d6f055a8..041f7d07f 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/ProtocolProviderServiceSipImpl.java @@ -477,7 +477,8 @@ public void register(SecurityAuthority authority) public void unregister() throws OperationFailedException { - if(!isRegistered()) + if(getRegistrationState().equals(RegistrationState.UNREGISTERED) + || getRegistrationState().equals(RegistrationState.UNREGISTERING)) { return; } @@ -1329,16 +1330,17 @@ ContactHeader getRegistrationContactHeader(InetAddress registrarAddress, ContactHeader registrationContactHeader = null; try { - InetAddress localAddress = SipActivator + InetSocketAddress localAddress = SipActivator .getNetworkAddressManagerService() - .getLocalHost(registrarAddress); + .getPublicAddressFor(registrarAddress + , srcListeningPoint.getPort()); SipURI contactURI = addressFactory.createSipURI( ((SipURI)ourSipAddress.getURI()).getUser() - , localAddress.getHostAddress()); + , localAddress.getAddress().getHostAddress()); contactURI.setTransportParam(srcListeningPoint.getTransport()); - contactURI.setPort(srcListeningPoint.getPort()); + contactURI.setPort(localAddress.getPort()); Address contactAddress = addressFactory.createAddress( contactURI ); if (ourDisplayName != null) diff --git a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java index 4c0d5e7f5..2aada6967 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/SipRegistrarConnection.java @@ -429,7 +429,7 @@ public void processOK(ClientTransaction clientTransatcion, if (grantedExpiration <= 0 || requestedExpiration <= 0) { setRegistrationState(RegistrationState.UNREGISTERED - , RegistrationStateChangeEvent.REASON_CHANGE_REQUESTED_BY_USER + , RegistrationStateChangeEvent.REASON_USER_REQUEST , "Registration terminated."); } else @@ -452,8 +452,9 @@ public void processOK(ClientTransaction clientTransatcion, */ public void unregister() throws OperationFailedException { - if (getRegistrationState() != RegistrationState.REGISTERED) + if (getRegistrationState() == RegistrationState.UNREGISTERED) { + logger.trace("Trying to unregister when already unresgistered"); return; } @@ -533,19 +534,22 @@ public void unregister() throws OperationFailedException "Unable to create a unregister transaction" , OperationFailedException.INTERNAL_ERROR , ex); - } try { + + unregisterTransaction.sendRequest(); logger.debug("sent request: " + unregisterRequest); - //emcho: i think we should not set to unregistered here but rather - //wait for the ok response. - // setRegistrationState(RegistrationState.UNREGISTERING, - // RegistrationStateChangeEvent. - // REASON_USER_REQUEST, null); - + //if we're currently registered we'll wait for an ok response + //before changing the status. otherwise we set it immediately. + if(!getRegistrationState().equals(RegistrationState.REGISTERED)) + { + logger.trace("Setting state to UNREGISTERED."); + setRegistrationState(RegistrationState.UNREGISTERED, + RegistrationStateChangeEvent.REASON_USER_REQUEST, null); + } } catch (SipException ex) { @@ -867,6 +871,10 @@ public void processRequest(RequestEvent requestEvent) */ public void processTimeout(TimeoutEvent timeoutEvent) { + //don't alert the user if we're already off + if(getRegistrationState().equals(RegistrationState.UNREGISTERED)) + return; + setRegistrationState( RegistrationState.CONNECTION_FAILED , RegistrationStateChangeEvent.REASON_NOT_SPECIFIED diff --git a/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java b/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java index 28161cb5c..11d519187 100644 --- a/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java +++ b/src/net/java/sip/communicator/service/protocol/event/RegistrationStateChangeEvent.java @@ -38,7 +38,7 @@ public class RegistrationStateChangeEvent extends PropertyChangeEvent * Indicates that the change in the registration state that has just * occurred has been requested by the user. */ - public static final int REASON_CHANGE_REQUESTED_BY_USER = 0; + public static final int REASON_USER_REQUEST = 0; /** * Indicates that the server has refused registration due to a problem with @@ -81,11 +81,6 @@ public class RegistrationStateChangeEvent extends PropertyChangeEvent */ public static final int REASON_INTERNAL_ERROR = 6; - /** - * Indicates that event change has occurred because the user requested it. - */ - public static final int REASON_USER_REQUEST = 7; - /** * Indicates that the specified server was not found (i.e. the fqdn was not * resolved or the ip address was not reachable). @@ -198,7 +193,7 @@ public int getReasonCode() * in a "details box". In the rest of the time, such services should consult * the error code and provide corresponding, localized, reason phrases. * - * @return a non localized String explaining the reason fo the state + * @return a non localized String explaining the reason for the state * transition. */ public String getReason() diff --git a/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetPresence.java b/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetPresence.java index 1cf010dba..ab2434fcf 100644 --- a/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetPresence.java +++ b/test/net/java/sip/communicator/slick/protocol/jabber/TestOperationSetPresence.java @@ -1051,7 +1051,8 @@ public void waitForAuthResponse(long waitFor) { synchronized(this) { - if(isAuthorizationResponseReceived) return; + if(isAuthorizationResponseReceived) + return; try{ wait(waitFor); }