From 10e721efd045299579c12941ad53623aace9f5d3 Mon Sep 17 00:00:00 2001 From: Benoit Pradelle Date: Tue, 17 Jul 2007 12:33:52 +0000 Subject: [PATCH] corrections to fit the needs of RFC 3265, 3856 and 3903 --- .../sip/OperationSetPresenceSipImpl.java | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java index 130977894..ba85dde3c 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetPresenceSipImpl.java @@ -30,7 +30,7 @@ /** * Sip presence implementation (SIMPLE). * - * Compliant with rfc3261, rfc3265, rfc3856, rfc3863 and rfc3903 + * Compliant with rfc3261, rfc3265, rfc3856, rfc3863, rfc4480 and rfc3903 * * @author Benoit Pradelle */ @@ -120,12 +120,12 @@ public class OperationSetPresenceSipImpl /** * The default expiration value of a PUBLISH request */ - private static final int PUBLISH_DEFAULT_EXPIRE = 600; + private static final int PUBLISH_DEFAULT_EXPIRE = 3600; /** * The default expiration value of a SUBSCRIBE request */ - private static final int SUBSCRIBE_DEFAULT_EXPIRE = 600; + private static final int SUBSCRIBE_DEFAULT_EXPIRE = 3600; /** * The minimal Expires value for a SUBSCRIBE @@ -553,7 +553,7 @@ public void publishPresenceStatus(PresenceStatus status, // now inform our distant presence agent if we have one if (this.useDistantPA) { - Request req = createPublish(PUBLISH_DEFAULT_EXPIRE); + Request req = createPublish(PUBLISH_DEFAULT_EXPIRE, true); if (status.equals(SipStatusEnum.OFFLINE)) { // remember the callid to be sure that the publish arrived @@ -678,12 +678,14 @@ private void fireProviderStatusChangeEvent(PresenceStatus oldValue) * agent. * * @param expires the expires value to send + * @param insertPresDoc if a presence document has to be added (typically + * = false when refreshing a publication) * * @return a valid Request containing the PUBLISH * * @throws OperationFailedException if something goes wrong */ - private Request createPublish(int expires) + private Request createPublish(int expires, boolean insertPresDoc) throws OperationFailedException { // Address @@ -745,8 +747,15 @@ private Request createPublish(int expires) .getMaxForwardsHeader(); // Content params - byte[] doc = getPidfPresenceStatus((ContactSipImpl) - this.getLocalContact()); + byte[] doc = null; + + if (insertPresDoc) { + doc = getPidfPresenceStatus((ContactSipImpl) + this.getLocalContact()); + } else { + doc = new byte[0]; + } + ContentTypeHeader contTypeHeader; ContentLengthHeader contLengthHeader; try @@ -1005,7 +1014,7 @@ public void subscribe(ContactGroup parentGroup, String contactIdentifier) { logger.debug("let's subscribe " + contactIdentifier); - //if the contact is already in the contact list and is resolved + //if the contact is already in the contact list ContactSipImpl contact = (ContactSipImpl) resolveContactID(contactIdentifier); @@ -1800,7 +1809,7 @@ public void processResponse(ResponseEvent responseEvent) } } // every error cause the subscription to be removed - // as recommended for some cases in rfc3265 + // as recommended in rfc3265 } else { logger.debug("error received from the network" + response); @@ -1837,6 +1846,7 @@ public void processResponse(ResponseEvent responseEvent) SIPETagHeader etHeader = (SIPETagHeader) response.getHeader(SIPETagHeader.NAME); + // must be one (rfc3903) if (etHeader == null) { logger.debug("can't find the ETag header"); return; @@ -1893,7 +1903,7 @@ public void processResponse(ResponseEvent responseEvent) // send a new publish with the new expires value Request req = null; try { - req = createPublish(min.getExpires()); + req = createPublish(min.getExpires(), true); } catch (OperationFailedException e) { logger.error("can't create the new publish request", e); return; @@ -2197,6 +2207,8 @@ public void processRequest(RequestEvent requestEvent) { // we are not concerned by this request, perhaps another // listener is ? + + // don't send a 489 / Bad event answer here return; } @@ -2396,7 +2408,7 @@ public void processRequest(RequestEvent requestEvent) } // interval too brief - if (expires < SUBSCRIBE_MIN_EXPIRE && expires != 0) + if (expires < SUBSCRIBE_MIN_EXPIRE && expires > 0 && expires < 3600) { // send him a 423 Response response = null; @@ -2430,7 +2442,7 @@ public void processRequest(RequestEvent requestEvent) } // is it a subscription refresh ? (no need for synchronize the - // access to ourWatchers) + // access to ourWatchers: read only operation) if (this.ourWatchers.contains(contact)) { contact.getTimeoutTask().cancel(); @@ -3832,7 +3844,13 @@ protected class RePublishTask extends TimerTask public void run() { Request req = null; try { - req = createPublish(PUBLISH_DEFAULT_EXPIRE); + if (distantPAET != null) { + req = createPublish(PUBLISH_DEFAULT_EXPIRE, false); + } else { + // if the last publication failed for any reason, send a + // new publication, not a refresh + req = createPublish(PUBLISH_DEFAULT_EXPIRE, true); + } } catch (OperationFailedException e) { logger.error("can't create a new PUBLISH message", e); return; @@ -4000,7 +4018,7 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) } else if (evt.getNewState().equals( RegistrationState.REGISTERED)) { - logger.debug("enter register state"); + logger.debug("enter registered state"); // send a subscription for every contact Iterator groupsIter = getServerStoredContactListRoot() @@ -4085,6 +4103,7 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) } } + // is this needed ? PresenceStatus oldStatus = getPresenceStatus(); presenceStatus = SipStatusEnum.ONLINE; fireProviderStatusChangeEvent(oldStatus);