diff --git a/MessagesBridge.xcodeproj/project.pbxproj b/MessagesBridge.xcodeproj/project.pbxproj index 2be70e3..1e13936 100644 --- a/MessagesBridge.xcodeproj/project.pbxproj +++ b/MessagesBridge.xcodeproj/project.pbxproj @@ -77,6 +77,8 @@ CD83E166219BE91600F4CCEA /* agentHook.m in Sources */ = {isa = PBXBuildFile; fileRef = CD83E165219BE91600F4CCEA /* agentHook.m */; }; CDE4556421A3578A0041F5DD /* IMChat+Encoded.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE4556321A3578A0041F5DD /* IMChat+Encoded.m */; }; CDE455A121A365AD0041F5DD /* MBIMMarkOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE455A021A365AD0041F5DD /* MBIMMarkOperation.m */; }; + CDE455A421A5308D0041F5DD /* MBIMFetchAttachmentOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE455A321A5308D0041F5DD /* MBIMFetchAttachmentOperation.m */; }; + CDE455A721A531ED0041F5DD /* MBIMDataResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = CDE455A621A531ED0041F5DD /* MBIMDataResponse.m */; }; CDF62335219A895D00690038 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = CDF62334219A895D00690038 /* main.m */; }; CDF62339219A8A5600690038 /* MBIMBridge.h in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C4469219A4BC300F2AC00 /* MBIMBridge.h */; }; CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C446A219A4BC300F2AC00 /* MBIMBridge.m */; }; @@ -221,6 +223,10 @@ CDE4556321A3578A0041F5DD /* IMChat+Encoded.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "IMChat+Encoded.m"; sourceTree = ""; }; CDE4559F21A365AD0041F5DD /* MBIMMarkOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMMarkOperation.h; sourceTree = ""; }; CDE455A021A365AD0041F5DD /* MBIMMarkOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMMarkOperation.m; sourceTree = ""; }; + CDE455A221A5308D0041F5DD /* MBIMFetchAttachmentOperation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMFetchAttachmentOperation.h; sourceTree = ""; }; + CDE455A321A5308D0041F5DD /* MBIMFetchAttachmentOperation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMFetchAttachmentOperation.m; sourceTree = ""; }; + CDE455A521A531ED0041F5DD /* MBIMDataResponse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MBIMDataResponse.h; sourceTree = ""; }; + CDE455A621A531ED0041F5DD /* MBIMDataResponse.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MBIMDataResponse.m; sourceTree = ""; }; CDF62332219A895D00690038 /* kordophoned */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = kordophoned; sourceTree = BUILT_PRODUCTS_DIR; }; CDF62334219A895D00690038 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; CDF62340219A9AAA00690038 /* EmailFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = EmailFoundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/System/Library/PrivateFrameworks/EmailFoundation.framework; sourceTree = DEVELOPER_DIR; }; @@ -345,6 +351,8 @@ children = ( 1AA43E8D219EBB2D00EDF1A7 /* MBIMJSONDataResponse.h */, 1AA43E8E219EBB2D00EDF1A7 /* MBIMJSONDataResponse.m */, + CDE455A521A531ED0041F5DD /* MBIMDataResponse.h */, + CDE455A621A531ED0041F5DD /* MBIMDataResponse.m */, 1AA43E93219EC38E00EDF1A7 /* MBIMHTTPUtilities.h */, 1AA43E94219EC38E00EDF1A7 /* MBIMHTTPUtilities.m */, ); @@ -509,6 +517,8 @@ CD60205B219B623F0024D9C5 /* MBIMMessagesListOperation.m */, CD60205D219B674B0024D9C5 /* MBIMConversationListOperation.h */, CD60205E219B674B0024D9C5 /* MBIMConversationListOperation.m */, + CDE455A221A5308D0041F5DD /* MBIMFetchAttachmentOperation.h */, + CDE455A321A5308D0041F5DD /* MBIMFetchAttachmentOperation.m */, CDE4559F21A365AD0041F5DD /* MBIMMarkOperation.h */, CDE455A021A365AD0041F5DD /* MBIMMarkOperation.m */, CD602060219B68950024D9C5 /* MBIMSendMessageOperation.h */, @@ -785,6 +795,7 @@ 1AA43E91219EBC2C00EDF1A7 /* MBIMHTTPConnection.m in Sources */, CDF62339219A8A5600690038 /* MBIMBridge.h in Sources */, 1AA43E95219EC38E00EDF1A7 /* MBIMHTTPUtilities.m in Sources */, + CDE455A421A5308D0041F5DD /* MBIMFetchAttachmentOperation.m in Sources */, CD83E156219BE10A00F4CCEA /* hooking.m in Sources */, CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */, CDF62335219A895D00690038 /* main.m in Sources */, @@ -794,6 +805,7 @@ CD602062219B68950024D9C5 /* MBIMSendMessageOperation.m in Sources */, CD14F1A1219FE7D600E7DD22 /* MBIMUpdatePollOperation.m in Sources */, CDE455A121A365AD0041F5DD /* MBIMMarkOperation.m in Sources */, + CDE455A721A531ED0041F5DD /* MBIMDataResponse.m in Sources */, CD602056219B5DFD0024D9C5 /* MBIMBridgeOperation.m in Sources */, CD60205F219B674B0024D9C5 /* MBIMConversationListOperation.m in Sources */, CDE4556421A3578A0041F5DD /* IMChat+Encoded.m in Sources */, diff --git a/kordophone/Bridge/Operations/MBIMFetchAttachmentOperation.h b/kordophone/Bridge/Operations/MBIMFetchAttachmentOperation.h new file mode 100644 index 0000000..c85012e --- /dev/null +++ b/kordophone/Bridge/Operations/MBIMFetchAttachmentOperation.h @@ -0,0 +1,17 @@ +// +// MBIMFetchAttachmentOperation.h +// kordophoned +// +// Created by James Magahern on 11/20/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMBridgeOperation.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MBIMFetchAttachmentOperation : MBIMBridgeOperation + +@end + +NS_ASSUME_NONNULL_END diff --git a/kordophone/Bridge/Operations/MBIMFetchAttachmentOperation.m b/kordophone/Bridge/Operations/MBIMFetchAttachmentOperation.m new file mode 100644 index 0000000..8ef6426 --- /dev/null +++ b/kordophone/Bridge/Operations/MBIMFetchAttachmentOperation.m @@ -0,0 +1,71 @@ +// +// MBIMFetchAttachmentOperation.m +// kordophoned +// +// Created by James Magahern on 11/20/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMFetchAttachmentOperation.h" +#import "MBIMDataResponse.h" + +#import + +@implementation MBIMFetchAttachmentOperation + ++ (void)load { [super load]; } + ++ (NSString *)endpointName +{ + return @"attachment"; +} + +- (void)main +{ + NSObject *response = nil; + do { + NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:self.requestURL resolvingAgainstBaseURL:NO]; + + NSString *guid = nil; + for (NSURLQueryItem *queryItem in [urlComponents queryItems]) { + if ([[queryItem name] isEqualToString:@"guid"]) { + guid = [queryItem value]; + break; + } + } + + if (!guid) { + NSLog(@"No query item provided"); + response = [[HTTPErrorResponse alloc] initWithErrorCode:500]; + break; + } + + IMFileTransfer *transfer = [[IMFileTransferCenter sharedInstance] transferForGUID:guid]; + if (!transfer) { + NSLog(@"No transfer found for guid: %@", guid); + response = [[HTTPErrorResponse alloc] initWithErrorCode:404]; + break; + } + + if (![transfer existsAtLocalPath]) { + NSLog(@"We don't have the file for this yet (still downloading to server?)"); + response = [[HTTPErrorResponse alloc] initWithErrorCode:404]; + break; + } + + NSString *localPath = [transfer localPath]; + NSData *responseData = [NSData dataWithContentsOfFile:localPath]; + if (!responseData) { + NSLog(@"Wasn't able to load data from local path: %@", localPath); + response = [[HTTPErrorResponse alloc] initWithErrorCode:404]; + break; + } + + NSString *mimeType = [transfer mimeType]; + response = [[MBIMDataResponse alloc] initWithData:responseData contentType:mimeType]; + } while (0); + + self.serverCompletionBlock(response); +} + +@end diff --git a/kordophone/Bridge/Operations/Utilities/MBIMDataResponse.h b/kordophone/Bridge/Operations/Utilities/MBIMDataResponse.h new file mode 100644 index 0000000..2dce971 --- /dev/null +++ b/kordophone/Bridge/Operations/Utilities/MBIMDataResponse.h @@ -0,0 +1,18 @@ +// +// MBIMDataResponse.h +// kordophoned +// +// Created by James Magahern on 11/20/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface MBIMDataResponse : HTTPDataResponse +- (instancetype)initWithData:(NSData *)data contentType:(NSString *)contentType; +@end + +NS_ASSUME_NONNULL_END diff --git a/kordophone/Bridge/Operations/Utilities/MBIMDataResponse.m b/kordophone/Bridge/Operations/Utilities/MBIMDataResponse.m new file mode 100644 index 0000000..e6ea79d --- /dev/null +++ b/kordophone/Bridge/Operations/Utilities/MBIMDataResponse.m @@ -0,0 +1,32 @@ +// +// MBIMDataResponse.m +// kordophoned +// +// Created by James Magahern on 11/20/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMDataResponse.h" + +@implementation MBIMDataResponse { + NSString *_contentType; +} + +- (instancetype)initWithData:(NSData *)data contentType:(NSString *)contentType +{ + self = [super initWithData:data]; + if (self) { + _contentType = contentType; + } + + return self; +} + +- (NSDictionary *)httpHeaders +{ + return @{ + @"Content-Type" : _contentType + }; +} + +@end diff --git a/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.h b/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.h index be617b3..cf8fef0 100644 --- a/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.h +++ b/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.h @@ -7,9 +7,9 @@ // #import -#import +#import "MBIMDataResponse.h" -@interface MBIMJSONDataResponse : HTTPDataResponse +@interface MBIMJSONDataResponse : MBIMDataResponse + (instancetype)responseWithJSONObject:(id)object; diff --git a/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.m b/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.m index ec59aae..41bd25a 100644 --- a/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.m +++ b/kordophone/Bridge/Operations/Utilities/MBIMJSONDataResponse.m @@ -17,16 +17,8 @@ return nil; } - MBIMJSONDataResponse *response = [[self alloc] initWithData:data]; - + MBIMJSONDataResponse *response = [[self alloc] initWithData:data contentType:@"application/json; charset=utf-8"]; return response; } -- (NSDictionary *)httpHeaders -{ - return @{ - @"Content-Type" : @"application/json; charset=utf-8" - }; -} - @end diff --git a/kordophone/Categories/IMMessageItem+Encoded.m b/kordophone/Categories/IMMessageItem+Encoded.m index 27e25d4..479f3db 100644 --- a/kordophone/Categories/IMMessageItem+Encoded.m +++ b/kordophone/Categories/IMMessageItem+Encoded.m @@ -32,6 +32,21 @@ messageDict[@"date"] = MBIMWebServerFormatISO8601([self time]); messageDict[@"sender"] = [self sender]; + if ([self fileTransferGUIDs]) { + // Support only images right now + NSMutableArray *filteredFileTransferGUIDs = [NSMutableArray array]; + for (NSString *guid in self.fileTransferGUIDs) { + IMFileTransfer *transfer = [[IMFileTransferCenter sharedInstance] transferForGUID:guid]; + if ([[transfer mimeType] containsString:@"image"]) { + [filteredFileTransferGUIDs addObject:guid]; + } + } + + if ([filteredFileTransferGUIDs count]) { + messageDict[@"fileTransferGUIDs"] = filteredFileTransferGUIDs; + } + } + return messageDict; }