(fix) handle base64 encoded EAS protocol version

pull/217/head
Ludovic Marcotte 2016-06-23 11:20:40 -04:00
parent 79ec4a02fe
commit 3597c2eef1
6 changed files with 38 additions and 11 deletions

View File

@ -52,6 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- (NSString *) itemid; - (NSString *) itemid;
- (BOOL) acceptsMultiPart; - (BOOL) acceptsMultiPart;
- (NSData *) convertHexStringToBytes; - (NSData *) convertHexStringToBytes;
- (NSString *) protocolVersion;
@end @end

View File

@ -135,6 +135,27 @@ static NSArray *easCommandParameters = nil;
return o; return o;
} }
- (NSString *) protocolVersion
{
NSMutableArray *components;
components = [NSMutableArray arrayWithArray: [[[self componentsSeparatedByString: @"?"] lastObject] componentsSeparatedByString: @"&"]];
// We handle BASE64 encoded queryStrings. See http://msdn.microsoft.com/en-us/library/ee160227%28v=exchg.80%29.aspx for details.
if ([components count] == 1)
{
NSData *queryString;
const char* qs_bytes;
queryString = [[components objectAtIndex: 0] dataByDecodingBase64];
qs_bytes = (const char*)[queryString bytes];
return [NSString stringWithFormat:@"%.1f", (float)((uint8_t)qs_bytes[0]/10)];
}
return nil;
}
- (NSString *) _valueForParameter: (NSString *) theParameter - (NSString *) _valueForParameter: (NSString *) theParameter
{ {
NSMutableArray *components; NSMutableArray *components;

View File

@ -3347,6 +3347,12 @@ void handle_eas_terminate(int signum)
[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"];
// Save ASProtocolVersion to context
if ([[context request] headerForKey: @"MS-ASProtocolVersion"])
[context setObject: [[context request] headerForKey: @"MS-ASProtocolVersion"] forKey: @"ASProtocolVersion"];
else
[context setObject: [[theRequest uri] protocolVersion] forKey: @"ASProtocolVersion"];
cmdName = [[theRequest uri] command]; cmdName = [[theRequest uri] command];
// We make sure our cache table exists // We make sure our cache table exists

View File

@ -1003,7 +1003,7 @@ struct GlobalObjectId {
[s appendFormat: @"<GlobalObjId xmlns=\"Email:\">%@</GlobalObjId>", [globalObjId activeSyncRepresentationInContext: context]]; [s appendFormat: @"<GlobalObjId xmlns=\"Email:\">%@</GlobalObjId>", [globalObjId activeSyncRepresentationInContext: context]];
// We set the right message type - we must set AS version to 14.1 for this // We set the right message type - we must set AS version to 14.1 for this
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"14.1"]) if ([[context valueForKey: @"ASProtocolVersion"] floatValue] >= 14.1)
[s appendFormat: @"<MeetingMessageType xmlns=\"Email2:\">%d</MeetingMessageType>", 1]; [s appendFormat: @"<MeetingMessageType xmlns=\"Email2:\">%d</MeetingMessageType>", 1];
[s appendString: @"</MeetingRequest>"]; [s appendString: @"</MeetingRequest>"];
@ -1169,7 +1169,7 @@ struct GlobalObjectId {
truncated = 0; truncated = 0;
} }
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{ {
[s appendFormat: @"<Body xmlns=\"Email:\">%@</Body>", content]; [s appendFormat: @"<Body xmlns=\"Email:\">%@</Body>", content];
[s appendFormat: @"<BodyTruncated xmlns=\"Email:\">%d</BodyTruncated>", truncated]; [s appendFormat: @"<BodyTruncated xmlns=\"Email:\">%d</BodyTruncated>", truncated];
@ -1204,7 +1204,7 @@ struct GlobalObjectId {
{ {
int i; int i;
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
[s appendString: @"<Attachments xmlns=\"Email:\">"]; [s appendString: @"<Attachments xmlns=\"Email:\">"];
else else
[s appendString: @"<Attachments xmlns=\"AirSyncBase:\">"]; [s appendString: @"<Attachments xmlns=\"AirSyncBase:\">"];
@ -1219,12 +1219,12 @@ struct GlobalObjectId {
// FileReference must be a unique identifier across the whole store. We use the following structure: // FileReference must be a unique identifier across the whole store. We use the following structure:
// mail/<foldername>/<message UID/<pathofpart> // mail/<foldername>/<message UID/<pathofpart>
// mail/INBOX/2 // mail/INBOX/2
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
[s appendFormat: @"<AttName>mail/%@/%@/%@</AttName>", [[[self container] relativeImap4Name] stringByEscapingURL], [self nameInContainer], [value objectForKey: @"path"]]; [s appendFormat: @"<AttName>mail/%@/%@/%@</AttName>", [[[self container] relativeImap4Name] stringByEscapingURL], [self nameInContainer], [value objectForKey: @"path"]];
else else
[s appendFormat: @"<FileReference>mail/%@/%@/%@</FileReference>", [[[self container] relativeImap4Name] stringByEscapingURL], [self nameInContainer], [value objectForKey: @"path"]]; [s appendFormat: @"<FileReference>mail/%@/%@/%@</FileReference>", [[[self container] relativeImap4Name] stringByEscapingURL], [self nameInContainer], [value objectForKey: @"path"]];
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{ {
[s appendFormat: @"<AttMethod>%d</AttMethod>", 1]; [s appendFormat: @"<AttMethod>%d</AttMethod>", 1];
[s appendFormat: @"<AttSize>%d</AttSize>", [[value objectForKey: @"size"] intValue]]; [s appendFormat: @"<AttSize>%d</AttSize>", [[value objectForKey: @"size"] intValue]];
@ -1267,8 +1267,7 @@ struct GlobalObjectId {
[s appendFormat: @"</Categories>"]; [s appendFormat: @"</Categories>"];
} }
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"14.0"] || if ([[context valueForKey: @"ASProtocolVersion"] floatValue] >= 14.0)
[[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"14.1"])
{ {
id value; id value;
NSString *reference; NSString *reference;

View File

@ -244,7 +244,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details. // otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details.
o = [o activeSyncRepresentationInContext: context]; o = [o activeSyncRepresentationInContext: context];
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{ {
[s appendFormat: @"<Body xmlns=\"Calendar:\">%@</Body>", o]; [s appendFormat: @"<Body xmlns=\"Calendar:\">%@</Body>", o];
[s appendString: @"<BodyTruncated xmlns=\"Calendar:\">0</BodyTruncated>"]; [s appendString: @"<BodyTruncated xmlns=\"Calendar:\">0</BodyTruncated>"];
@ -487,7 +487,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
} }
// FIXME: merge with iCalToDo // FIXME: merge with iCalToDo
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{ {
if ((o = [theValues objectForKey: @"Body"])) if ((o = [theValues objectForKey: @"Body"]))
[self setComment: o]; [self setComment: o];

View File

@ -127,7 +127,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details. // otherwise it'll prevent WP8 phones from sync'ing. See #3028 for details.
o = [o activeSyncRepresentationInContext: context]; o = [o activeSyncRepresentationInContext: context];
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{ {
[s appendFormat: @"<Body xmlns=\"Tasks:\">%@</Body>", o]; [s appendFormat: @"<Body xmlns=\"Tasks:\">%@</Body>", o];
[s appendString: @"<BodyTruncated xmlns=\"Tasks:\">0</BodyTruncated>"]; [s appendString: @"<BodyTruncated xmlns=\"Tasks:\">0</BodyTruncated>"];
@ -161,7 +161,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[self setSummary: o]; [self setSummary: o];
// FIXME: merge with iCalEvent // FIXME: merge with iCalEvent
if ([[[context request] headerForKey: @"MS-ASProtocolVersion"] isEqualToString: @"2.5"]) if ([[context valueForKey: @"ASProtocolVersion"] isEqualToString: @"2.5"])
{ {
if ((o = [theValues objectForKey: @"Body"])) if ((o = [theValues objectForKey: @"Body"]))
[self setComment: o]; [self setComment: o];