diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java index 1e9d5296b..4db094ba6 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetBasicInstantMessagingYahooImpl.java @@ -142,7 +142,7 @@ public void sendInstantMessage(Contact to, Message message) { String toUserID = ((ContactYahooImpl) to).getID(); - byte[] msgBytesToBeSent = message.getContent().getBytes(); + byte[] msgBytesToBeSent = message.getContent().trim().getBytes(); // split the message in parts with max allowed length // and send them all @@ -397,16 +397,9 @@ private void handleNewMessage(SessionEvent ev) String formattedMessage = ev.getMessage(); logger.debug("original message received : " + formattedMessage); - // if the message is decorated by Yahoo, we try to "decode" it first. - if (formattedMessage.startsWith("\u001b")) - { - formattedMessage = processLinks( - messageDecoder.decodeToHTML(formattedMessage)); - } - else - { - formattedMessage = processLinks(formattedMessage); - } + // make sure we always decode message + formattedMessage = processLinks( + messageDecoder.decodeToHTML(formattedMessage)); // now, we try to fix a wrong usage of the size attribute in the // HTML element diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java index 1374bc49d..213b9cc27 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetPersistentPresenceYahooImpl.java @@ -124,7 +124,13 @@ public class OperationSetPersistentPresenceYahooImpl * buddy list. */ private ServerStoredContactListYahooImpl ssContactList = null; - + + /** + * Listens for events that are fired while registering to server. + * After we are registered instance is cleared and never used. + */ + private EarlyEventListener earlyEventListener = null; + /** * Status events are received before subscription one. * And when subscription is received we deliver @@ -422,25 +428,25 @@ public void publishPresenceStatus(PresenceStatus status, parentProvider.unregister(); return; } - + try { if(statusMessage != null) { boolean isAvailable = false; - + if(status.equals(YahooStatusEnum.AVAILABLE)) isAvailable = true; - + // false - away // true - available parentProvider.getYahooSession(). setStatus(statusMessage, isAvailable); } - + parentProvider.getYahooSession().setStatus( scToYahooModesMappings.get(status).longValue()); - + fireProviderPresenceStatusChangeEvent(currentStatus, status); } catch(IOException ex) @@ -469,7 +475,7 @@ public PresenceStatus queryContactStatus(String contactIdentifier) throws IllegalArgumentException, IllegalStateException, OperationFailedException { - + ContactYahooImpl contact = ssContactList.findContactById(contactIdentifier); if(contact == null) { @@ -550,7 +556,7 @@ public void renameServerStoredContactGroup(ContactGroup group, if( !(group instanceof ContactGroupYahooImpl) ) throw new IllegalArgumentException( "The specified group is not an yahoo contact group: " + group); - + throw new UnsupportedOperationException("Renaming group not supported!"); //ssContactList.renameGroup((ContactGroupYahooImpl)group, newName); } @@ -565,6 +571,14 @@ public void renameServerStoredContactGroup(ContactGroup group, public void setAuthorizationHandler(AuthorizationHandler handler) { ssContactList.setAuthorizationHandler(handler); + + // we got a handler. Lets process if something has came + // durring login process + if(earlyEventListener != null) + { + earlyEventListener.processEarlyAuthorizations(); + earlyEventListener = null; + } } /** @@ -595,7 +609,7 @@ public void subscribe(ContactGroup parent, String contactIdentifier) throws if(! (parent instanceof ContactGroupYahooImpl) ) throw new IllegalArgumentException( "Argument is not an yahoo contact group (group=" + parent + ")"); - + ssContactList.addContact((ContactGroupYahooImpl)parent, contactIdentifier); } @@ -787,7 +801,7 @@ private void fireProviderStatusMessageChangeEvent( private void initContactStatuses() { YahooGroup[] groups = parentProvider.getYahooSession().getGroups(); - + for (int i = 0; i < groups.length; i++) { YahooGroup item = groups[i]; @@ -795,10 +809,10 @@ private void initContactStatuses() while(iter.hasNext()) { YahooUser user = (YahooUser)iter.next(); - - ContactYahooImpl sourceContact = - ssContactList.findContactById(user.getId()); - + + ContactYahooImpl sourceContact = + ssContactList.findContactById(user.getId()); + if(sourceContact != null) handleContactStatusChange(sourceContact, user); } @@ -825,16 +839,29 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) + evt.getOldState() + " to: " + evt.getNewState()); - if(evt.getNewState() == RegistrationState.REGISTERED) + if(evt.getNewState() == RegistrationState.REGISTERING) + { + // add new listener waiting for events during login process + earlyEventListener = new EarlyEventListener(); + parentProvider.getYahooSession(). + addSessionListener(earlyEventListener); + } + else if(evt.getNewState() == RegistrationState.REGISTERED) { parentProvider.getYahooSession(). addSessionListener(new StatusChangedListener()); - + ssContactList.setYahooSession(parentProvider.getYahooSession()); - + initContactStatuses(); - + addSubscriptionListener(statusUpdater); + + if(earlyEventListener != null) + { + parentProvider.getYahooSession(). + removeSessionListener(earlyEventListener); + } } else if(evt.getNewState() == RegistrationState.UNREGISTERED || evt.getNewState() == RegistrationState.AUTHENTICATION_FAILED @@ -849,7 +876,7 @@ else if(evt.getNewState() == RegistrationState.UNREGISTERED fireProviderPresenceStatusChangeEvent(oldStatus, currentStatus); - + removeSubscriptionListener(statusUpdater); //send event notifications saying that all our buddies are @@ -884,6 +911,11 @@ else if(evt.getNewState() == RegistrationState.UNREGISTERED , oldContactStatus, YahooStatusEnum.OFFLINE); } } + + // clear listener + parentProvider.getYahooSession(). + removeSessionListener(earlyEventListener); + earlyEventListener = null; } } } @@ -927,7 +959,7 @@ private void fireContactPresenceStatusChangeEvent( private void handleContactStatusChange(YahooUser yFriend) { - ContactYahooImpl sourceContact = + ContactYahooImpl sourceContact = ssContactList.findContactById(yFriend.getId()); if(sourceContact == null) @@ -945,13 +977,13 @@ private void handleContactStatusChange(YahooUser yFriend) return; } // strange - else + else return; } handleContactStatusChange(sourceContact, yFriend); } - + void handleContactStatusChange(ContactYahooImpl sourceContact, YahooUser yFriend) { PresenceStatus oldStatus @@ -961,7 +993,7 @@ void handleContactStatusChange(ContactYahooImpl sourceContact, YahooUser yFriend // statuses maybe the same and only change in status message sourceContact.setStatusMessage(yFriend.getCustomStatusMessage()); - + // when old and new status are the same do nothing - no change if(oldStatus.equals(newStatus)) { @@ -978,14 +1010,14 @@ void handleContactStatusChange(ContactYahooImpl sourceContact, YahooUser yFriend fireContactPresenceStatusChangeEvent(sourceContact, parent, oldStatus, newStatus); } - + private class StatusChangedListener extends SessionAdapter { - public void friendsUpdateReceived(SessionFriendEvent evt) + public void friendsUpdateReceived(SessionFriendEvent evt) { logger.debug("Received a status update for contact " + evt); - + if(evt.getFriend() != null) { handleContactStatusChange(evt.getFriend()); @@ -998,20 +1030,20 @@ else if(evt.getFriends() != null) } } } - + /** * Updates the statuses of newly created persistent contacts */ private class StatusUpdater implements SubscriptionListener { - public void subscriptionCreated(SubscriptionEvent evt) + public void subscriptionCreated(SubscriptionEvent evt) { - ContactYahooImpl contact = + ContactYahooImpl contact = (ContactYahooImpl)evt.getSourceContact(); - + if(!contact.isPersistent() || !contact.isResolved()) return; - + handleContactStatusChange(contact, contact.getSourceContact()); } @@ -1021,4 +1053,29 @@ public void subscriptionMoved(SubscriptionMovedEvent evt) {} public void subscriptionResolved(SubscriptionEvent evt) {} public void contactModified(ContactPropertyChangeEvent evt) {} } + + private class EarlyEventListener + extends SessionAdapter + { + private Vector receivedAuthorizations = + new Vector(); + + public void authorizationReceived(SessionAuthorizationEvent ev) + { + if(ev.isAuthorizationRequest()) + { + logger.trace("authorizationRequestReceived from " + + ev.getFrom()); + receivedAuthorizations.add(ev); + } + } + + public void processEarlyAuthorizations() + { + for (SessionAuthorizationEvent e : receivedAuthorizations) + { + ssContactList.processAuthorizationRequest(e); + } + } + } } diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java index 97f3b7761..50e45e828 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java @@ -53,13 +53,13 @@ public class ProtocolProviderServiceYahooImpl private OperationSetPersistentPresenceYahooImpl persistentPresence = null; private OperationSetTypingNotificationsYahooImpl typingNotifications = null; - + /** * The logo corresponding to the msn protocol. */ private ProtocolIconYahooImpl yahooIcon = new ProtocolIconYahooImpl(); - + /** * Returns the state of the registration of this protocol provider @@ -68,7 +68,7 @@ public class ProtocolProviderServiceYahooImpl */ public RegistrationState getRegistrationState() { - if(yahooSession != null && + if(yahooSession != null && yahooSession.getSessionStatus() == StatusConstants.MESSAGING) return RegistrationState.REGISTERED; else @@ -89,7 +89,7 @@ public RegistrationState getRegistrationState() */ public void register(final SecurityAuthority authority) throws OperationFailedException - { + { if(authority == null) throw new IllegalArgumentException( "The register method needs a valid non-null authority impl " @@ -155,18 +155,23 @@ private void connectAndLogin( SecurityAuthority authority, yahooSession = new YahooSession(); yahooSession.addSessionListener(new YahooConnectionListener()); - + try { + fireRegistrationStateChanged( + getRegistrationState(), + RegistrationState.REGISTERING, + RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null); + yahooSession.login(getAccountID().getUserID(), password); if(yahooSession.getSessionStatus()==StatusConstants.MESSAGING) { persistentPresence.fireProviderPresenceStatusChangeEvent( - persistentPresence.getPresenceStatus(), + persistentPresence.getPresenceStatus(), persistentPresence.yahooStatusToPresenceStatus( yahooSession.getStatus())); - + fireRegistrationStateChanged( getRegistrationState(), RegistrationState.REGISTERED, @@ -236,10 +241,10 @@ public void unregister() void unregister(boolean fireEvent) { RegistrationState currRegState = getRegistrationState(); - + try { - if(yahooSession != null && + if(yahooSession != null && yahooSession.getSessionStatus() == StatusConstants.MESSAGING) yahooSession.logout(); } @@ -247,7 +252,7 @@ void unregister(boolean fireEvent) { logger.error("Cannot logout! ", ex); } - + yahooSession = null; if(fireEvent) @@ -312,12 +317,12 @@ protected void initialize(String screenname, basicInstantMessaging); //initialize the multi user chat operation set - OperationSetMultiUserChatYahooImpl multiUserChatOpSet = + OperationSetMultiUserChatYahooImpl multiUserChatOpSet = new OperationSetMultiUserChatYahooImpl(this); - + supportedOperationSets.put(OperationSetMultiUserChat.class.getName(), multiUserChatOpSet); - + //initialize the typing notifications operation set typingNotifications = new OperationSetTypingNotificationsYahooImpl(this); @@ -423,14 +428,14 @@ public void connectionClosed(SessionEvent ev) RegistrationState.CONNECTION_FAILED, RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null); } - + public void inputExceptionThrown(SessionExceptionEvent ev) { if(ev.getException() instanceof YMSG9BadFormatException) { logger.error("Yahoo protocol exception occured exception", ev.getException()); - logger.error("Yahoo protocol exception occured exception cause", + logger.error("Yahoo protocol exception occured exception cause", ((YMSG9BadFormatException)ev.getException().getCause())); } else @@ -444,13 +449,13 @@ public void inputExceptionThrown(SessionExceptionEvent ev) RegistrationStateChangeEvent.REASON_INTERNAL_ERROR, null); } } - + /** * Returns the yahoo protocol icon. * @return the yahoo protocol icon */ public ProtocolIcon getProtocolIcon() - { + { return yahooIcon; } } diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java index d3e164e4f..1d8616774 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ServerStoredContactListYahooImpl.java @@ -32,9 +32,9 @@ public class ServerStoredContactListYahooImpl * The name of the Volatile group */ private static final String VOLATILE_GROUP_NAME = "NotInContactList"; - + /** - * If there is no group and we add contact with no parent + * If there is no group and we add contact with no parent * a default group is created with name : DEFAULT_GROUP_NAME */ private static final String DEFAULT_GROUP_NAME = "General"; @@ -65,12 +65,12 @@ public class ServerStoredContactListYahooImpl private ContactListModListenerImpl contactListModListenerImpl = new ContactListModListenerImpl(); - + /** * Handler for incoming authorization requests. */ private AuthorizationHandler handler = null; - + private Hashtable addedCustomYahooIds = new Hashtable(); /** @@ -91,7 +91,7 @@ public class ServerStoredContactListYahooImpl this.yahooProvider = provider; rootGroup.setOwnerProvider(provider); } - + /** * Handler for incoming authorization requests. * @@ -329,13 +329,13 @@ public void addContact(String id) throws OperationFailedException { ContactGroupYahooImpl parent = getFirstPersistentGroup(); - + if(parent == null) { // if there is no group create it parent = createUnresolvedContactGroup(DEFAULT_GROUP_NAME); } - + addContact(parent, id); } @@ -363,10 +363,10 @@ public void addContact(final ContactGroupYahooImpl parent, String id) "Contact " + id + " already exists.", OperationFailedException.SUBSCRIPTION_ALREADY_EXISTS); } - + if(id.indexOf("@") > -1 ) - addedCustomYahooIds.put(YahooSession.getYahooUserID(id), id); - + addedCustomYahooIds.put(YahooSession.getYahooUserID(id), id); + try { yahooSession.addFriend(YahooSession.getYahooUserID(id), parent.getGroupName()); @@ -390,7 +390,7 @@ public void addContact(final ContactGroupYahooImpl parent, String id) ContactYahooImpl createVolatileContact(String id) { logger.trace("Creating volatile contact " + id); - ContactYahooImpl newVolatileContact = + ContactYahooImpl newVolatileContact = new ContactYahooImpl(id, this, false, false, true); //Check whether a volatile group already exists and if not create one @@ -442,7 +442,7 @@ ContactYahooImpl createUnresolvedContact(ContactGroup parentGroup, String id) if(parentGroup instanceof ContactGroupYahooImpl) ((ContactGroupYahooImpl)parentGroup). addContact(newUnresolvedContact); - + fireContactAdded(parentGroup, newUnresolvedContact); return newUnresolvedContact; @@ -503,29 +503,29 @@ public void createGroup(String groupName) public void removeGroup(ContactGroupYahooImpl groupToRemove) { // to remove group just remove all the contacts in it - + logger.trace("removing group " + groupToRemove); - + // if its not persistent group just remove it if(!groupToRemove.isPersistent() || !groupToRemove.isResolved()) { rootGroup.removeSubGroup(groupToRemove); - fireGroupEvent(groupToRemove, + fireGroupEvent(groupToRemove, ServerStoredGroupEvent.GROUP_REMOVED_EVENT); return; } - + Vector contacts = groupToRemove.getSourceGroup().getMembers(); - + if(contacts.size() == 0) { // the group is empty just remove it rootGroup.removeSubGroup(groupToRemove); - fireGroupEvent(groupToRemove, + fireGroupEvent(groupToRemove, ServerStoredGroupEvent.GROUP_REMOVED_EVENT); return; } - + Iterator iter = contacts.iterator(); while(iter.hasNext()) { @@ -550,21 +550,21 @@ public void removeGroup(ContactGroupYahooImpl groupToRemove) void removeContact(ContactYahooImpl contactToRemove) { logger.trace("Removing yahoo contact " + contactToRemove.getSourceContact()); - + if(contactToRemove.isVolatile()) { - ContactGroupYahooImpl parent = - (ContactGroupYahooImpl)contactToRemove.getParentContactGroup(); - + ContactGroupYahooImpl parent = + (ContactGroupYahooImpl)contactToRemove.getParentContactGroup(); + parent.removeContact(contactToRemove); fireContactRemoved(parent, contactToRemove); return; } - + try { yahooSession.removeFriend( - contactToRemove.getSourceContact().getId(), + contactToRemove.getSourceContact().getId(), contactToRemove.getParentContactGroup().getGroupName()); } catch(IOException ex) @@ -608,11 +608,11 @@ public void moveContact(ContactYahooImpl contact, try { contactListModListenerImpl. - waitForMove(userID, + waitForMove(userID, contact.getParentContactGroup().getGroupName()); - + yahooSession.addFriend( - userID, + userID, newParent.getGroupName()); } catch(IOException ex) @@ -640,7 +640,7 @@ private ContactGroupYahooImpl getNonPersistentGroup() return null; } - + /** * Returns the first persistent group * @@ -728,15 +728,15 @@ void fireContactResolved( ContactGroup parentGroup, private void initList() { logger.trace("Start init list of " + yahooProvider.getAccountID().getUserID()); - + YahooGroup[] groups = yahooSession.getGroups(); - + for (int i = 0; i < groups.length; i++) { YahooGroup item = groups[i]; - + ContactGroupYahooImpl group = findContactGroup(item.getName()); - + if(group == null) { // create the group as it doesn't exist @@ -760,11 +760,11 @@ private void initList() /** @todo if something to delete . delete it */ } - + logger.trace("Init of group done! : " + group); } } - + /** * @param name Name of the group to search * @return The yahoo group with given name @@ -780,7 +780,78 @@ private YahooGroup findGroup(String name) } return null; } - + + /** + * Process incoming authorization requests. + * @param e the event to process. + */ + void processAuthorizationRequest(SessionAuthorizationEvent ev) + { + if(handler == null) + return; + + Contact srcContact = findContactById(ev.getFrom()); + + // if there is no such contact we create it as + // volatile so we can fire notification + // and then if accepted add it in the protocol + // so we can receive its states + boolean isCurrentlyCreated = false; + if(srcContact == null) + { + srcContact = createVolatileContact(ev.getFrom()); + isCurrentlyCreated = true; + } + + AuthorizationRequest authRequest = new AuthorizationRequest(); + authRequest.setReason(ev.getMessage()); + + AuthorizationResponse authResponse = + handler.processAuthorisationRequest( + authRequest, srcContact); + + if (authResponse.getResponseCode() == AuthorizationResponse.IGNORE) + { + return; + } + else + { + if (authResponse.getResponseCode() == AuthorizationResponse.REJECT) + { + removeContact((ContactYahooImpl)srcContact); + try + { + yahooSession.rejectFriendAuthorization( + ev, ev.getFrom(), authResponse.getReason()); + } + catch(IOException ex) + { + logger.error("cannot send auth deny", ex); + } + } + } + + // else we accepted it + try + { + yahooSession.acceptFriendAuthorization(ev, ev.getFrom()); + } + catch(IOException ex) + { + logger.error("cannot send auth deny", ex); + } + + if(isCurrentlyCreated) + try + { + addContact(ev.getFrom()); + } + catch (OperationFailedException ex) + { + logger.error("Cannot add friend", ex); + } + } + /** * Imulates firing adding contact in group and moving contact to group. * When moving contact it is first adding to the new group then @@ -790,17 +861,17 @@ private class ContactListModListenerImpl extends SessionAdapter { private Hashtable waitMove = new Hashtable(); - + public void waitForMove(String id, String oldParent) { waitMove.put(id, oldParent); } - + public void removeWaitForMove(String id) { waitMove.remove(id); } - + /** * Successfully added a friend * friend - YahooUser of friend @@ -810,61 +881,61 @@ public void removeWaitForMove(String id) public void friendAddedReceived(SessionFriendEvent ev) { logger.trace("Receive event for adding a friend : " + ev); - - ContactGroupYahooImpl group = + + ContactGroupYahooImpl group = findContactGroup(ev.getGroup()); - + if(group == null){ logger.trace("Group not found!" + ev.getGroup()); return; } - + String contactID = ev.getFriend().getId(); ContactYahooImpl contactToAdd = findContactById(contactID); - + // if group is note resolved resolve it // this means newly created group if(!group.isResolved()) { - // if the contact is volatile me must remove it + // if the contact is volatile me must remove it // as new one will be created if(contactToAdd != null && contactToAdd.isVolatile()) { - ContactGroupYahooImpl parent = + ContactGroupYahooImpl parent = (ContactGroupYahooImpl)contactToAdd.getParentContactGroup(); parent.removeContact(contactToAdd); fireContactRemoved(parent, contactToAdd); } - + YahooGroup gr = findGroup(ev.getGroup()); if(gr != null) group.setResolved(gr); - + // contact will be added when resolving the group - + return; } - - + + boolean isVolatile = false; if(contactToAdd == null) { if(addedCustomYahooIds.containsKey(contactID)) { - String expectedContactID = + String expectedContactID = (String)addedCustomYahooIds.remove(contactID); contactToAdd = - new ContactYahooImpl(expectedContactID, ev.getFriend(), + new ContactYahooImpl(expectedContactID, ev.getFriend(), ServerStoredContactListYahooImpl.this, true, true); } else { contactToAdd = - new ContactYahooImpl(ev.getFriend(), + new ContactYahooImpl(ev.getFriend(), ServerStoredContactListYahooImpl.this, true, true); } } @@ -872,17 +943,17 @@ public void friendAddedReceived(SessionFriendEvent ev) { isVolatile = contactToAdd.isVolatile(); } - + //first check is contact is moving from a group Object isWaitingForMove = waitMove.get(contactID); - + if(isWaitingForMove != null && isWaitingForMove instanceof String) { // waits for move into group - // will remove it from old group and will wait for event remove + // will remove it from old group and will wait for event remove // from group, then will fire moved to group event String oldParent = (String)isWaitingForMove; - + group.addContact(contactToAdd); waitMove.put(contactID, group.getSourceGroup()); try @@ -891,19 +962,19 @@ public void friendAddedReceived(SessionFriendEvent ev) } catch(IOException ex) { - logger.info("Cannot Remove(till moving) contact :" + + logger.info("Cannot Remove(till moving) contact :" + contactToAdd + " from group " + oldParent); } return; } - + if(isVolatile) { // we must remove the volatile buddy as we will add - // the persistent one. + // the persistent one. // Volatile buddy is moving from the volatile group // to the new one - ContactGroupYahooImpl parent = + ContactGroupYahooImpl parent = (ContactGroupYahooImpl)contactToAdd.getParentContactGroup(); parent.removeContact(contactToAdd); @@ -919,7 +990,7 @@ public void friendAddedReceived(SessionFriendEvent ev) return; } - + group.addContact(contactToAdd); fireContactAdded(group, contactToAdd); } @@ -933,9 +1004,9 @@ public void friendAddedReceived(SessionFriendEvent ev) public void friendRemovedReceived(SessionFriendEvent ev) { logger.trace("Receive event for removing a friend : " + ev); - + String contactID = ev.getFriend().getId(); - + // first check is this part of move action Object waitForMoveObj = waitMove.get(contactID); if(waitForMoveObj != null && waitForMoveObj instanceof YahooGroup) @@ -943,28 +1014,28 @@ public void friendRemovedReceived(SessionFriendEvent ev) // first get the group - oldParent ContactGroupYahooImpl oldParent = findContactGroup(ev.getGroup()); ContactYahooImpl contactToRemove = oldParent.findContact(contactID); - + oldParent.removeContact(contactToRemove); waitMove.remove(contactID); - - ContactGroupYahooImpl newParent = + + ContactGroupYahooImpl newParent = findContactGroup(((YahooGroup)waitForMoveObj).getName()); - + fireContactMoved(oldParent, newParent, contactToRemove); return; } - + ContactYahooImpl contactToRemove = findContactById(contactID); - + // strange we cannot find the contact to be removed if(contactToRemove == null) return; - + ContactGroupYahooImpl parentGroup = (ContactGroupYahooImpl)contactToRemove.getParentContactGroup(); parentGroup.removeContact(contactToRemove); fireContactRemoved(parentGroup, contactToRemove); - + // check if the group is deleted. If the contact is the last one in // the group. The group is also deleted if(findGroup(ev.getGroup()) == null) @@ -973,7 +1044,7 @@ public void friendRemovedReceived(SessionFriendEvent ev) fireGroupEvent(parentGroup, ServerStoredGroupEvent.GROUP_REMOVED_EVENT); } } - + /** * Someone wants to add us to their friends list * to - the target (us!) @@ -984,21 +1055,21 @@ public void friendRemovedReceived(SessionFriendEvent ev) public void contactRequestReceived(SessionEvent ev) { logger.info("contactRequestReceived : " + ev); - + if(handler == null || ev.getFrom() == null) return; - + ContactYahooImpl contact = findContactById(ev.getFrom()); - + if(contact == null) contact = createVolatileContact(ev.getFrom()); - + AuthorizationRequest request = new AuthorizationRequest(); request.setReason(ev.getMessage()); - - AuthorizationResponse resp = + + AuthorizationResponse resp = handler.processAuthorisationRequest(request, contact); - + if (resp.getResponseCode() == AuthorizationResponse.REJECT) { try{ @@ -1021,14 +1092,14 @@ public void contactRejectionReceived(SessionEvent ev) if(handler == null) return; - + ContactYahooImpl contact = findContactById(ev.getFrom()); - - AuthorizationResponse resp = + + AuthorizationResponse resp = new AuthorizationResponse(AuthorizationResponse.REJECT, ev.getMessage()); handler.processAuthorizationResponse(resp, contact); } - + /** * Invoked on picture received. * @param ev fired event @@ -1036,17 +1107,17 @@ public void contactRejectionReceived(SessionEvent ev) public void pictureReceived(SessionPictureEvent ev) { ContactYahooImpl contact = findContactById(ev.getFrom()); - + if(contact == null) return; - + contact.setImage(ev.getPictureData()); - + parentOperationSet.fireContactPropertyChangeEvent( - ContactPropertyChangeEvent.PROPERTY_IMAGE, + ContactPropertyChangeEvent.PROPERTY_IMAGE, contact, null, ev.getPictureData()); } - + /** * Process Authorization responses * @param ev the event to process @@ -1057,14 +1128,14 @@ public void authorizationReceived(SessionAuthorizationEvent ev) { logger.trace("authorizationAccepted from " + ev.getFrom()); Contact srcContact = findContactById(ev.getFrom()); - + if(srcContact == null) logger.trace("No contact found"); else handler.processAuthorizationResponse( new AuthorizationResponse( - AuthorizationResponse.ACCEPT, - ev.getMessage()), + AuthorizationResponse.ACCEPT, + ev.getMessage()), srcContact); } else if(ev.isAuthorizationDenied()) @@ -1078,7 +1149,7 @@ else if(ev.isAuthorizationDenied()) { handler.processAuthorizationResponse( new AuthorizationResponse( - AuthorizationResponse.REJECT, + AuthorizationResponse.REJECT, ev.getMessage()), srcContact); try @@ -1086,7 +1157,7 @@ else if(ev.isAuthorizationDenied()) removeContact((ContactYahooImpl)srcContact); } catch (Exception ex) { - logger.error("cannot remove denied contact : " + + logger.error("cannot remove denied contact : " + srcContact, ex); } } @@ -1094,61 +1165,7 @@ else if(ev.isAuthorizationDenied()) else if(ev.isAuthorizationRequest()) { logger.trace("authorizationRequestReceived from " + ev.getFrom()); - Contact srcContact = findContactById(ev.getFrom()); - - // if there is no such contact we create it as - // volatile so we can fire notification - // and then if accepted add it in the protocol - // so we can receive its states - boolean isCurrentlyCreated = false; - if(srcContact == null) - { - srcContact = createVolatileContact(ev.getFrom()); - isCurrentlyCreated = true; - } - - AuthorizationRequest authRequest = new AuthorizationRequest(); - authRequest.setReason(ev.getMessage()); - - AuthorizationResponse authResponse = - handler.processAuthorisationRequest( - authRequest, srcContact); - - if (authResponse.getResponseCode() == AuthorizationResponse.IGNORE) - return; - else - if (authResponse.getResponseCode() == AuthorizationResponse.REJECT) - { - removeContact((ContactYahooImpl)srcContact); - try - { - yahooSession.rejectFriendAuthorization( - ev, ev.getFrom(), authResponse.getReason()); - }catch(IOException ex) - { - logger.error("cannot send auth deny", ex); - } - } - - // else we accepted it - try - { - yahooSession.acceptFriendAuthorization(ev, ev.getFrom()); - } - catch(IOException ex) - { - logger.error("cannot send auth deny", ex); - } - - if(isCurrentlyCreated) - try - { - addContact(ev.getFrom()); - } - catch (OperationFailedException ex) - { - logger.error("Cannot add friend", ex); - } + processAuthorizationRequest(ev); } } }