Radically reduced EAS memory usage

pull/67/head
Ludovic Marcotte 2014-12-04 11:27:10 -05:00
parent 47094b6d91
commit fe9ad9c6e9
6 changed files with 69 additions and 32 deletions

View File

@ -86,15 +86,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
return nil; return nil;
} }
data = [[NSData alloc] initWithBytes: xml length: xml_len]; data = [NSData dataWithBytesNoCopy: xml length: xml_len freeWhenDone: YES];
#if WBXMLDEBUG #if WBXMLDEBUG
[data writeToFile: @"/tmp/protocol.decoded" atomically: YES]; [data writeToFile: @"/tmp/protocol.decoded" atomically: YES];
#endif #endif
free(xml); return data;
return AUTORELEASE(data);
} }
@ -138,15 +136,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
return nil; return nil;
} }
data = [[NSData alloc] initWithBytes: wbxml length: wbxml_len]; data = [NSData dataWithBytesNoCopy: wbxml length: wbxml_len freeWhenDone: YES];
#if WBXMLDEBUG #if WBXMLDEBUG
[data writeToFile: @"/tmp/protocol.encoded" atomically: YES]; [data writeToFile: @"/tmp/protocol.encoded" atomically: YES];
#endif #endif
free(wbxml);
wbxml_conv_xml2wbxml_destroy(conv); wbxml_conv_xml2wbxml_destroy(conv);
return AUTORELEASE(data); return data;
} }
@end @end

View File

@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "SOGoActiveSyncDispatcher+Sync.h" #import "SOGoActiveSyncDispatcher+Sync.h"
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h> #import <Foundation/NSCalendarDate.h>
#import <Foundation/NSNull.h> #import <Foundation/NSNull.h>
#import <Foundation/NSProcessInfo.h> #import <Foundation/NSProcessInfo.h>
@ -114,22 +115,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
forKey: (NSString *) theFolderKey forKey: (NSString *) theFolderKey
{ {
SOGoCacheGCSObject *o; SOGoCacheGCSObject *o;
NSDictionary *values;
NSString *key; NSString *key;
key = [NSString stringWithFormat: @"%@+%@", [context objectForKey: @"DeviceId"], theFolderKey]; key = [NSString stringWithFormat: @"%@+%@", [context objectForKey: @"DeviceId"], theFolderKey];
values = [theFolderMetadata copy];
o = [SOGoCacheGCSObject objectWithName: key inContainer: nil]; o = [SOGoCacheGCSObject objectWithName: key inContainer: nil];
[o setObjectType: ActiveSyncFolderCacheObject]; [o setObjectType: ActiveSyncFolderCacheObject];
[o setTableUrl: [self folderTableURL]]; [o setTableUrl: [self folderTableURL]];
[o reloadIfNeeded]; //[o reloadIfNeeded];
[[o properties] removeObjectForKey: @"SyncKey"]; [[o properties] removeObjectForKey: @"SyncKey"];
[[o properties] removeObjectForKey: @"SyncCache"]; [[o properties] removeObjectForKey: @"SyncCache"];
[[o properties] removeObjectForKey: @"DateCache"]; [[o properties] removeObjectForKey: @"DateCache"];
[[o properties] removeObjectForKey: @"MoreAvailable"]; [[o properties] removeObjectForKey: @"MoreAvailable"];
[[o properties] addEntriesFromDictionary: theFolderMetadata]; [[o properties] addEntriesFromDictionary: values];
[o save]; [o save];
[values release];
} }
- (NSMutableDictionary *) _folderMetadataForKey: (NSString *) theFolderKey - (NSMutableDictionary *) _folderMetadataForKey: (NSString *) theFolderKey
@ -534,6 +538,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{ {
NSMutableDictionary *folderMetadata, *dateCache, *syncCache; NSMutableDictionary *folderMetadata, *dateCache, *syncCache;
NSAutoreleasePool *pool;
NSMutableString *s; NSMutableString *s;
BOOL more_available; BOOL more_available;
@ -635,6 +640,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
allComponents = [theCollection syncTokenFieldsWithProperties: nil matchingSyncToken: theSyncKey fromDate: theFilterType]; allComponents = [theCollection syncTokenFieldsWithProperties: nil matchingSyncToken: theSyncKey fromDate: theFilterType];
allComponents = [allComponents sortedArrayUsingDescriptors: [NSArray arrayWithObjects: [[NSSortDescriptor alloc] initWithKey: @"c_lastmodified" ascending:YES], nil]]; allComponents = [allComponents sortedArrayUsingDescriptors: [NSArray arrayWithObjects: [[NSSortDescriptor alloc] initWithKey: @"c_lastmodified" ascending:YES], nil]];
// Check for the WindowSize // Check for the WindowSize
max = [allComponents count]; max = [allComponents count];
@ -643,14 +649,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
for (i = 0; i < max; i++) for (i = 0; i < max; i++)
{ {
pool = [[NSAutoreleasePool alloc] init];
// Check for the WindowSize and slice accordingly // Check for the WindowSize and slice accordingly
if (return_count >= theWindowSize) if (return_count >= theWindowSize)
{ {
more_available = YES; more_available = YES;
// -1 to make sure that we miss no event in case there are more with the same c_lastmodified // -1 to make sure that we miss no event in case there are more with the same c_lastmodified
*theLastServerKey = [NSString stringWithFormat: @"%d", [[component objectForKey: @"c_lastmodified"] intValue] - 1]; *theLastServerKey = [[NSString alloc] initWithFormat: @"%d", [[component objectForKey: @"c_lastmodified"] intValue] - 1];
DESTROY(pool);
break; break;
} }
@ -747,6 +756,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[s appendString: @"</Add>"]; [s appendString: @"</Add>"];
return_count++; return_count++;
DESTROY(pool);
} }
} // for ... } // for ...
@ -763,6 +774,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[self _setFolderMetadata: folderMetadata [self _setFolderMetadata: folderMetadata
forKey: [NSString stringWithFormat: @"%@/%@", component_name, [theCollection nameInContainer]]]; forKey: [NSString stringWithFormat: @"%@/%@", component_name, [theCollection nameInContainer]]];
RELEASE(*theLastServerKey);
} }
break; break;
case ActiveSyncMailFolder: case ActiveSyncMailFolder:
@ -830,6 +843,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
for (; k < [allCacheObjects count]; k++) for (; k < [allCacheObjects count]; k++)
{ {
pool = [[NSAutoreleasePool alloc] init];
// Check for the WindowSize and slice accordingly // Check for the WindowSize and slice accordingly
if (return_count >= theWindowSize) if (return_count >= theWindowSize)
{ {
@ -837,8 +852,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
more_available = YES; more_available = YES;
lastSequence = ([[aCacheObject sequence] isEqual: [NSNull null]] ? @"1" : [aCacheObject sequence]); lastSequence = ([[aCacheObject sequence] isEqual: [NSNull null]] ? @"1" : [aCacheObject sequence]);
*theLastServerKey = [NSString stringWithFormat: @"%@-%@", [aCacheObject uid], lastSequence]; *theLastServerKey = [[NSString alloc] initWithFormat: @"%@-%@", [aCacheObject uid], lastSequence];
//NSLog(@"Reached windowSize - lastUID will be: %@", *theLastServerKey); //NSLog(@"Reached windowSize - lastUID will be: %@", *theLastServerKey);
DESTROY(pool);
break; break;
} }
@ -919,7 +935,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
} }
} }
} DESTROY(pool);
} // for (; k < ...)
if (more_available) if (more_available)
{ {
@ -933,6 +950,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
} }
[self _setFolderMetadata: folderMetadata forKey: [self _getNameInCache: theCollection withType: theFolderType]]; [self _setFolderMetadata: folderMetadata forKey: [self _getNameInCache: theCollection withType: theFolderType]];
RELEASE(*theLastServerKey);
} // default: } // default:
break; break;
} // switch (folderType) ... } // switch (folderType) ...
@ -1119,11 +1138,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[self processSyncGetChanges: theDocumentElement [self processSyncGetChanges: theDocumentElement
inCollection: collection inCollection: collection
withWindowSize: windowSize withWindowSize: windowSize
//withWindowSize: 5
withSyncKey: syncKey withSyncKey: syncKey
withFolderType: folderType withFolderType: folderType
withFilterType: [NSCalendarDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]] withFilterType: [NSCalendarDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]]
//withFilterType: [NSCalendarDate dateFromFilterType: @"7"]
inBuffer: changeBuffer inBuffer: changeBuffer
lastServerKey: &lastServerKey]; lastServerKey: &lastServerKey];
} }
@ -1310,7 +1327,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
BOOL changeDetected; BOOL changeDetected;
// We initialize our output buffer // We initialize our output buffer
output = [NSMutableString string]; output = [[NSMutableString alloc] init];
[output appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"]; [output appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
[output appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"]; [output appendString: @"<!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\">"];
@ -1366,8 +1383,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[output appendString: s]; [output appendString: s];
[output appendString: @"</Collections></Sync>"]; [output appendString: @"</Collections></Sync>"];
d = [[output dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml]; // Avoid overloading the autorelease pool here, as Sync command can
// generate fairly large responses.
d = [output dataUsingEncoding: NSUTF8StringEncoding];
RELEASE(output);
d = [d xml2wbxml];
[theResponse setContent: d]; [theResponse setContent: d];
} }

View File

@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SOGoActiveSyncDispatcher.h" #include "SOGoActiveSyncDispatcher.h"
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h> #import <Foundation/NSCalendarDate.h>
#import <Foundation/NSProcessInfo.h> #import <Foundation/NSProcessInfo.h>
#import <Foundation/NSTimeZone.h> #import <Foundation/NSTimeZone.h>
@ -2329,21 +2330,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
context: (id) theContext context: (id) theContext
{ {
id <DOMElement> documentElement; id <DOMElement> documentElement;
NSAutoreleasePool *pool;
id builder, dom; id builder, dom;
SEL aSelector; SEL aSelector;
NSString *cmdName, *deviceId; NSString *cmdName, *deviceId;
NSData *d; NSData *d;
pool = [[NSAutoreleasePool alloc] init];
ASSIGN(context, theContext); ASSIGN(context, theContext);
// Get the device ID, device type and "stash" them // Get the device ID, device type and "stash" them
deviceId = [[theRequest uri] deviceId]; deviceId = [[theRequest uri] deviceId];
[context setObject: deviceId forKey: @"DeviceId"]; [context setObject: deviceId forKey: @"DeviceId"];
[context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"]; [context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"];
[context setObject: [[theRequest uri] attachmentName] forKey: @"AttachmentName"]; [context setObject: [[theRequest uri] attachmentName] forKey: @"AttachmentName"];
cmdName = [[theRequest uri] command]; cmdName = [[theRequest uri] command];
// We make sure our cache table exists // We make sure our cache table exists
@ -2379,6 +2382,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{ {
d = [[theRequest content] wbxml2xml]; d = [[theRequest content] wbxml2xml];
} }
documentElement = nil; documentElement = nil;
if (!d) if (!d)
@ -2414,8 +2418,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[theResponse setHeader: @"Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,ResolveRecipients,ValidateCert" forKey: @"MS-ASProtocolCommands"]; [theResponse setHeader: @"Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,ResolveRecipients,ValidateCert" forKey: @"MS-ASProtocolCommands"];
[theResponse setHeader: @"2.0,2.1,2.5,12.0,12.1,14.0,14.1" forKey: @"MS-ASProtocolVersions"]; [theResponse setHeader: @"2.0,2.1,2.5,12.0,12.1,14.0,14.1" forKey: @"MS-ASProtocolVersions"];
RELEASE(context); RELEASE(context);
RELEASE(pool);
return nil; return nil;
} }

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SOGoMailObject+ActiveSync.h" #include "SOGoMailObject+ActiveSync.h"
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h> #import <Foundation/NSCalendarDate.h>
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h> #import <Foundation/NSException.h>
@ -511,7 +510,6 @@ struct GlobalObjectId {
// //
- (NSString *) activeSyncRepresentationInContext: (WOContext *) _context - (NSString *) activeSyncRepresentationInContext: (WOContext *) _context
{ {
NSAutoreleasePool *pool;
NSData *d, *globalObjId; NSData *d, *globalObjId;
NSArray *attachmentKeys; NSArray *attachmentKeys;
NSMutableString *s; NSMutableString *s;
@ -704,10 +702,6 @@ struct GlobalObjectId {
// Body - namespace 17 // Body - namespace 17
preferredBodyType = [[context objectForKey: @"BodyPreferenceType"] intValue]; preferredBodyType = [[context objectForKey: @"BodyPreferenceType"] intValue];
// Make use of a local pool here as _preferredBodyDataUsingType:nativeType: will consume
// a significant amout of RAM and file descriptors
pool = [[NSAutoreleasePool alloc] init];
nativeBodyType = 1; nativeBodyType = 1;
d = [self _preferredBodyDataUsingType: preferredBodyType nativeType: &nativeBodyType]; d = [self _preferredBodyDataUsingType: preferredBodyType nativeType: &nativeBodyType];
@ -747,9 +741,7 @@ struct GlobalObjectId {
} }
[s appendString: @"</Body>"]; [s appendString: @"</Body>"];
} }
DESTROY(pool);
// Attachments -namespace 16 // Attachments -namespace 16
attachmentKeys = [self fetchFileAttachmentKeys]; attachmentKeys = [self fetchFileAttachmentKeys];
if ([attachmentKeys count]) if ([attachmentKeys count])

1
NEWS
View File

@ -3,6 +3,7 @@
Enhancements Enhancements
- Improved the SAML2 documentation - Improved the SAML2 documentation
- Radically reduced AES memory usage
Bug fixes Bug fixes
- Now possible to specify the username attribute for SAML2 (SOGoSAML2LoginAttribute) (#2381) - Now possible to specify the username attribute for SAML2 (SOGoSAML2LoginAttribute) (#2381)

View File

@ -36,6 +36,7 @@
#import <NGExtensions/NGBase64Coding.h> #import <NGExtensions/NGBase64Coding.h>
#import <NGExtensions/NSNull+misc.h> #import <NGExtensions/NSNull+misc.h>
#import <NGExtensions/NSObject+Logs.h> #import <NGExtensions/NSObject+Logs.h>
#import <SOGo/SOGoCache.h>
#import <SOGo/NSObject+Utilities.h> #import <SOGo/NSObject+Utilities.h>
#import <SOGo/NSString+Utilities.h> #import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoDomainDefaults.h> #import <SOGo/SOGoDomainDefaults.h>
@ -96,10 +97,29 @@ static EOAttribute *textColumn = nil;
- (void) dealloc - (void) dealloc
{ {
//NSLog(@"SOGoCacheGCSObject: -dealloc for name: %@", nameInContainer);
[tableUrl release]; [tableUrl release];
[super dealloc]; [super dealloc];
} }
+ (id) objectWithName: (NSString *) key inContainer: (id) theContainer
{
SOGoCache *cache;
id o;
cache = [SOGoCache sharedCache];
o = [cache objectNamed: key inContainer: theContainer];
if (!o)
{
o = [super objectWithName: key inContainer: theContainer];
//NSLog(@"Caching object with key: %@", key);
[cache registerObject: o withName: key inContainer: theContainer];
}
return o;
}
- (void) setTableUrl: (NSURL *) newTableUrl - (void) setTableUrl: (NSURL *) newTableUrl
{ {
ASSIGN (tableUrl, newTableUrl); ASSIGN (tableUrl, newTableUrl);