Fixed the GetChanges detection and added FilterType decoding

pull/17/head
Ludovic Marcotte 2014-01-16 15:13:09 -05:00
parent 24663682d6
commit 343f2d8bfe
3 changed files with 58 additions and 4 deletions

View File

@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@interface NSDate (ActiveSync)
+ (NSDate *) dateFromFilterType: (NSString *) theFilterType;
- (NSString *) activeSyncRepresentation;
@end

View File

@ -32,8 +32,58 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import <Foundation/NSString.h>
#import <Foundation/NSTimeZone.h>
#define ONE_DAY 86400
@implementation NSDate (ActiveSync)
//
// See http://msdn.microsoft.com/en-us/library/gg709713(v=exchg.80).aspx for available types
//
+ (NSDate *) dateFromFilterType: (NSString *) theFilterType
{
NSDate *d;
d = [self alloc];
if (d)
{
int value;
switch ([theFilterType intValue])
{
case 1:
value = ONE_DAY;
break;
case 2:
value = 3 * ONE_DAY;
break;
case 3:
value = 7 * ONE_DAY;
break;
case 4:
value = 14 * ONE_DAY;
break;
case 5:
value = 30 * ONE_DAY;
break;
case 6:
value = 90 * ONE_DAY;
break;
case 7:
value = 180 * ONE_DAY;
break;
case 0:
case 8:
default:
return nil;
}
return [d initWithTimeIntervalSinceNow: -value];
}
return d;
}
- (NSString *) activeSyncRepresentation
{
return [self descriptionWithCalendarFormat: @"%Y%m%dT%H%M%SZ" timeZone: [NSTimeZone timeZoneWithName: @"GMT"] locale: nil];

View File

@ -98,6 +98,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "iCalToDo+ActiveSync.h"
#include "NGDOMElement+ActiveSync.h"
#include "NGVCard+ActiveSync.h"
#include "NSDate+ActiveSync.h"
#include "NSData+ActiveSync.h"
#include "NSString+ActiveSync.h"
#include "SOGoActiveSyncConstants.h"
@ -445,7 +446,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- (void) processSyncGetChanges: (id <DOMElement>) theDocumentElement
inCollection: (id) theCollection
withSyncKey: (NSString *) theSyncKey
withType: (SOGoMicrosoftActiveSyncFolderType) theFolderType
withFolderType: (SOGoMicrosoftActiveSyncFolderType) theFolderType
withFilterType: (NSDate *) theFilterType
inBuffer: (NSMutableString *) theBuffer
{
int i;
@ -743,9 +745,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
value = [theDocumentElement getElementsByTagName: @"GetChanges"];
getChanges = YES;
if ([value count])
if ([value count] && [[[value lastObject] textValue] length])
getChanges = [[[value lastObject] textValue] boolValue];
first_sync = NO;
if ([syncKey isEqualToString: @"0"])
@ -776,7 +778,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[self processSyncGetChanges: theDocumentElement
inCollection: collection
withSyncKey: syncKey
withType: folderType
withFolderType: folderType
withFilterType: [NSDate dateFromFilterType: [[(id)[theDocumentElement getElementsByTagName: @"FilterType"] lastObject] textValue]]
inBuffer: theBuffer];
}