Skip to content

Commit

Permalink
(fix) now cache heartbeat and folders during EAS ping ops (fixes #3606)
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Apr 1, 2016
1 parent f113f86 commit 80d29f2
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions ActiveSync/SOGoActiveSyncDispatcher.m
Expand Up @@ -2084,19 +2084,37 @@ - (void) processPing: (id <DOMElement>) theDocumentElement

if (![allCollections count])
{
// We received an empty Ping request. Return status '3' to ask client to resend the request with complete body.
s = [NSMutableString string];
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[s appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
[s appendString: @"<Ping xmlns=\"Ping:\">"];
[s appendString: @"<Status>3</Status>"];
[s appendString: @"</Ping>"];
heartbeatInterval = [[[o properties] objectForKey: @"PingHeartbeatInterval"] intValue];

d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml];
if (debugOn)
[self logWithFormat: @"EAS - Empty Ping request - using cached HeatbeatInterval (%d)", heartbeatInterval];

[theResponse setContent: d];
if (heartbeatInterval > defaultInterval || heartbeatInterval == 0)
{
heartbeatInterval = defaultInterval;
status = 5;
}

return;
allFoldersID = [[o properties] objectForKey: @"PingCachedFolders"];
if (![allFoldersID count])
{
// We received an empty Ping request. Return status '3' to ask client to resend the request with complete body.
s = [NSMutableString string];
[s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[s appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
[s appendString: @"<Ping xmlns=\"Ping:\">"];
[s appendString: @"<Status>3</Status>"];
[s appendString: @"</Ping>"];

d = [[s dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml];

[theResponse setContent: d];

return;
}

if (debugOn)
[self logWithFormat: @"EAS - Empty Ping request - using cached folders %@", allFoldersID];
}
else
{
Expand All @@ -2106,6 +2124,16 @@ - (void) processPing: (id <DOMElement>) theDocumentElement
collectionId = [[(id) [aCollection getElementsByTagName: @"Id"] lastObject] textValue];
[allFoldersID addObject: collectionId];
}

if (![allFoldersID isEqualToArray: [[o properties] objectForKey: @"PingCachedFolders"]])
{
if (debugOn)
[self logWithFormat: @"EAS - Ping - Save folderlist to cache (HeartbeatInterval: %d) (%@)", heartbeatInterval, allFoldersID];

[[o properties] setObject: [NSNumber numberWithInteger: heartbeatInterval] forKey: @"PingHeartbeatInterval"];
[[o properties] setObject: allFoldersID forKey: @"PingCachedFolders"];
[o save];
}
}

foldersWithChanges = [NSMutableArray array];
Expand Down

0 comments on commit 80d29f2

Please sign in to comment.