From 2d0fd5b290d32cbbdcace5cef61d140720fdeb97 Mon Sep 17 00:00:00 2001 From: James Magahern Date: Mon, 12 Nov 2018 22:11:36 -0800 Subject: [PATCH] Moved stuff around and you can see convos, messages, and send messages! --- .gitmodules | 3 + .../DebugDefaults.xcconfig | 0 .../OSXDebugDefaults.xcconfig | 0 .../OSXReleaseDefaults.xcconfig | 0 .../ReleaseDefaults.xcconfig | 0 GCDWebServer | 1 + MessagesBridge.xcodeproj/project.pbxproj | 320 +++++--- .../xcschemes/kordophoned.xcscheme | 91 +++ MessagesBridge/AppDelegate.h | 15 - MessagesBridge/AppDelegate.m | 33 - .../AppIcon.appiconset/Contents.json | 58 -- MessagesBridge/Assets.xcassets/Contents.json | 6 - MessagesBridge/Base.lproj/MainMenu.xib | 692 ------------------ MessagesBridge/Bridge/MBIMBridge.m | 123 ---- MessagesBridge/Info.plist | 32 - MessagesBridge/main.m | 13 - .../SOAPlugInControllerProtocol.h | 0 MessagesBridge/README.md => README.md | 0 .../Bridge/MBIMBridge.h | 4 + kordophone/Bridge/MBIMBridge.m | 271 +++++++ .../kordophone.entitlements | 0 kordophone/main.m | 24 + 22 files changed, 604 insertions(+), 1082 deletions(-) create mode 100644 .gitmodules rename {MessagesBridge/Config Files => Config Files}/DebugDefaults.xcconfig (100%) rename {MessagesBridge/Config Files => Config Files}/OSXDebugDefaults.xcconfig (100%) rename {MessagesBridge/Config Files => Config Files}/OSXReleaseDefaults.xcconfig (100%) rename {MessagesBridge/Config Files => Config Files}/ReleaseDefaults.xcconfig (100%) create mode 160000 GCDWebServer create mode 100644 MessagesBridge.xcodeproj/xcshareddata/xcschemes/kordophoned.xcscheme delete mode 100644 MessagesBridge/AppDelegate.h delete mode 100644 MessagesBridge/AppDelegate.m delete mode 100644 MessagesBridge/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 MessagesBridge/Assets.xcassets/Contents.json delete mode 100644 MessagesBridge/Base.lproj/MainMenu.xib delete mode 100644 MessagesBridge/Bridge/MBIMBridge.m delete mode 100644 MessagesBridge/Info.plist delete mode 100644 MessagesBridge/main.m rename {MessagesBridge/Pilfered Headers => Pilfered Headers}/SOAPlugInControllerProtocol.h (100%) rename MessagesBridge/README.md => README.md (100%) rename {MessagesBridge => kordophone}/Bridge/MBIMBridge.h (81%) create mode 100644 kordophone/Bridge/MBIMBridge.m rename MessagesBridge/MessagesBridge.entitlements => kordophone/kordophone.entitlements (100%) create mode 100644 kordophone/main.m diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2d85876 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "GCDWebServer"] + path = GCDWebServer + url = https://github.com/swisspol/GCDWebServer.git diff --git a/MessagesBridge/Config Files/DebugDefaults.xcconfig b/Config Files/DebugDefaults.xcconfig similarity index 100% rename from MessagesBridge/Config Files/DebugDefaults.xcconfig rename to Config Files/DebugDefaults.xcconfig diff --git a/MessagesBridge/Config Files/OSXDebugDefaults.xcconfig b/Config Files/OSXDebugDefaults.xcconfig similarity index 100% rename from MessagesBridge/Config Files/OSXDebugDefaults.xcconfig rename to Config Files/OSXDebugDefaults.xcconfig diff --git a/MessagesBridge/Config Files/OSXReleaseDefaults.xcconfig b/Config Files/OSXReleaseDefaults.xcconfig similarity index 100% rename from MessagesBridge/Config Files/OSXReleaseDefaults.xcconfig rename to Config Files/OSXReleaseDefaults.xcconfig diff --git a/MessagesBridge/Config Files/ReleaseDefaults.xcconfig b/Config Files/ReleaseDefaults.xcconfig similarity index 100% rename from MessagesBridge/Config Files/ReleaseDefaults.xcconfig rename to Config Files/ReleaseDefaults.xcconfig diff --git a/GCDWebServer b/GCDWebServer new file mode 160000 index 0000000..7df4653 --- /dev/null +++ b/GCDWebServer @@ -0,0 +1 @@ +Subproject commit 7df465336eb3e975fdc498e2ac8a845f3ae56a34 diff --git a/MessagesBridge.xcodeproj/project.pbxproj b/MessagesBridge.xcodeproj/project.pbxproj index fe974af..dc9c6ee 100644 --- a/MessagesBridge.xcodeproj/project.pbxproj +++ b/MessagesBridge.xcodeproj/project.pbxproj @@ -7,27 +7,88 @@ objects = { /* Begin PBXBuildFile section */ - 1A0C444C219A38E100F2AC00 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C444B219A38E100F2AC00 /* AppDelegate.m */; }; - 1A0C444E219A38E200F2AC00 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1A0C444D219A38E200F2AC00 /* Assets.xcassets */; }; - 1A0C4451219A38E200F2AC00 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1A0C444F219A38E200F2AC00 /* MainMenu.xib */; }; - 1A0C4454219A38E200F2AC00 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C4453219A38E200F2AC00 /* main.m */; }; - 1A0C4460219A45B400F2AC00 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C445F219A45B400F2AC00 /* Foundation.framework */; }; - 1A0C4462219A45BA00F2AC00 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C4461219A45B900F2AC00 /* AppKit.framework */; }; - 1A0C4465219A45C700F2AC00 /* MessagesKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C4463219A45C700F2AC00 /* MessagesKit.framework */; }; - 1A0C4466219A45C700F2AC00 /* MessagesHelperKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C4464219A45C700F2AC00 /* MessagesHelperKit.framework */; }; - 1A0C4468219A45D500F2AC00 /* IMCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C4467219A45D500F2AC00 /* IMCore.framework */; }; - 1A0C446B219A4BC300F2AC00 /* MBIMBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A0C446A219A4BC300F2AC00 /* MBIMBridge.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 */; }; + CDF6233D219A8AF700690038 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C445F219A45B400F2AC00 /* Foundation.framework */; }; + CDF6233E219A8AFC00690038 /* IMCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A0C4467219A45D500F2AC00 /* IMCore.framework */; }; + CDF6233F219A8B0100690038 /* GCDWebServers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDF62324219A869000690038 /* GCDWebServers.framework */; }; + CDF62343219A9BE200690038 /* ContactsFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDF62342219A9BE200690038 /* ContactsFoundation.framework */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + CDF6231D219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 8DD76FB20486AB0100D96B5E; + remoteInfo = "GCDWebServer (Mac)"; + }; + CDF6231F219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E2DDD1F61BE69EE4002CE867; + remoteInfo = "GCDWebServer (iOS)"; + }; + CDF62321219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E2DDD1C71BE698A8002CE867; + remoteInfo = "GCDWebServer (tvOS)"; + }; + CDF62323219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = CEE28CD11AE004D800F4023C; + remoteInfo = "GCDWebServers (Mac)"; + }; + CDF62325219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = CEE28CEF1AE0051F00F4023C; + remoteInfo = "GCDWebServers (iOS)"; + }; + CDF62327219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E2DDD18B1BE69404002CE867; + remoteInfo = "GCDWebServers (tvOS)"; + }; + CDF62329219A869000690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E24039251BA09207000B7089; + remoteInfo = "Tests (Mac)"; + }; + CDF6233B219A8A6600690038 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = CEE28CD01AE004D800F4023C; + remoteInfo = "GCDWebServers (Mac)"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + CDF62330219A895D00690038 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ - 1A0C4447219A38E100F2AC00 /* MessagesBridge.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MessagesBridge.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 1A0C444A219A38E100F2AC00 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 1A0C444B219A38E100F2AC00 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 1A0C444D219A38E200F2AC00 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 1A0C4450219A38E200F2AC00 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; - 1A0C4452219A38E200F2AC00 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 1A0C4453219A38E200F2AC00 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 1A0C4455219A38E200F2AC00 /* MessagesBridge.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MessagesBridge.entitlements; sourceTree = ""; }; + 1A0C4455219A38E200F2AC00 /* kordophone.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = kordophone.entitlements; sourceTree = ""; }; 1A0C445D219A458400F2AC00 /* SOAPlugInControllerProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SOAPlugInControllerProtocol.h; sourceTree = ""; }; 1A0C445F219A45B400F2AC00 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 1A0C4461219A45B900F2AC00 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; }; @@ -41,18 +102,22 @@ 1A33B43C219A5ACD0034485A /* OSXDebugDefaults.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = OSXDebugDefaults.xcconfig; sourceTree = ""; }; 1A33B43D219A5ACD0034485A /* ReleaseDefaults.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ReleaseDefaults.xcconfig; sourceTree = ""; }; 1A33B43E219A5BD80034485A /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + CDF62312219A869000690038 /* GCDWebServer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GCDWebServer.xcodeproj; path = GCDWebServer/GCDWebServer.xcodeproj; 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; }; + CDF62342219A9BE200690038 /* ContactsFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ContactsFoundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/System/Library/PrivateFrameworks/ContactsFoundation.framework; sourceTree = DEVELOPER_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 1A0C4444219A38E100F2AC00 /* Frameworks */ = { + CDF6232F219A895D00690038 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 1A0C4468219A45D500F2AC00 /* IMCore.framework in Frameworks */, - 1A0C4465219A45C700F2AC00 /* MessagesKit.framework in Frameworks */, - 1A0C4466219A45C700F2AC00 /* MessagesHelperKit.framework in Frameworks */, - 1A0C4462219A45BA00F2AC00 /* AppKit.framework in Frameworks */, - 1A0C4460219A45B400F2AC00 /* Foundation.framework in Frameworks */, + CDF62343219A9BE200690038 /* ContactsFoundation.framework in Frameworks */, + CDF6233F219A8B0100690038 /* GCDWebServers.framework in Frameworks */, + CDF6233E219A8AFC00690038 /* IMCore.framework in Frameworks */, + CDF6233D219A8AF700690038 /* Foundation.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -62,7 +127,11 @@ 1A0C443E219A38E100F2AC00 = { isa = PBXGroup; children = ( - 1A0C4449219A38E100F2AC00 /* MessagesBridge */, + 1A33B43E219A5BD80034485A /* README.md */, + CDF62312219A869000690038 /* GCDWebServer.xcodeproj */, + CDF62333219A895D00690038 /* kordophone */, + 1A33B439219A5ACD0034485A /* Config Files */, + 1A0C445C219A457C00F2AC00 /* Pilfered Headers */, 1A0C4448219A38E100F2AC00 /* Products */, 1A0C445E219A45B400F2AC00 /* Frameworks */, ); @@ -71,29 +140,11 @@ 1A0C4448219A38E100F2AC00 /* Products */ = { isa = PBXGroup; children = ( - 1A0C4447219A38E100F2AC00 /* MessagesBridge.app */, + CDF62332219A895D00690038 /* kordophoned */, ); name = Products; sourceTree = ""; }; - 1A0C4449219A38E100F2AC00 /* MessagesBridge */ = { - isa = PBXGroup; - children = ( - 1A0C445C219A457C00F2AC00 /* Pilfered Headers */, - 1A0C444A219A38E100F2AC00 /* AppDelegate.h */, - 1A0C444B219A38E100F2AC00 /* AppDelegate.m */, - 1A0C446D219A4BCD00F2AC00 /* Bridge */, - 1A0C444D219A38E200F2AC00 /* Assets.xcassets */, - 1A0C444F219A38E200F2AC00 /* MainMenu.xib */, - 1A0C4452219A38E200F2AC00 /* Info.plist */, - 1A0C4453219A38E200F2AC00 /* main.m */, - 1A0C4455219A38E200F2AC00 /* MessagesBridge.entitlements */, - 1A33B43E219A5BD80034485A /* README.md */, - 1A33B439219A5ACD0034485A /* Config Files */, - ); - path = MessagesBridge; - sourceTree = ""; - }; 1A0C445C219A457C00F2AC00 /* Pilfered Headers */ = { isa = PBXGroup; children = ( @@ -105,6 +156,8 @@ 1A0C445E219A45B400F2AC00 /* Frameworks */ = { isa = PBXGroup; children = ( + CDF62342219A9BE200690038 /* ContactsFoundation.framework */, + CDF62340219A9AAA00690038 /* EmailFoundation.framework */, 1A0C4467219A45D500F2AC00 /* IMCore.framework */, 1A0C4464219A45C700F2AC00 /* MessagesHelperKit.framework */, 1A0C4463219A45C700F2AC00 /* MessagesKit.framework */, @@ -134,25 +187,50 @@ path = "Config Files"; sourceTree = ""; }; + CDF62313219A869000690038 /* Products */ = { + isa = PBXGroup; + children = ( + CDF6231E219A869000690038 /* GCDWebServer */, + CDF62320219A869000690038 /* GCDWebServer.app */, + CDF62322219A869000690038 /* GCDWebServer.app */, + CDF62324219A869000690038 /* GCDWebServers.framework */, + CDF62326219A869000690038 /* GCDWebServers.framework */, + CDF62328219A869000690038 /* GCDWebServers.framework */, + CDF6232A219A869000690038 /* Tests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + CDF62333219A895D00690038 /* kordophone */ = { + isa = PBXGroup; + children = ( + 1A0C446D219A4BCD00F2AC00 /* Bridge */, + 1A0C4455219A38E200F2AC00 /* kordophone.entitlements */, + CDF62334219A895D00690038 /* main.m */, + ); + path = kordophone; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 1A0C4446219A38E100F2AC00 /* MessagesBridge */ = { + CDF62331219A895D00690038 /* kordophoned */ = { isa = PBXNativeTarget; - buildConfigurationList = 1A0C4458219A38E200F2AC00 /* Build configuration list for PBXNativeTarget "MessagesBridge" */; + buildConfigurationList = CDF62336219A895D00690038 /* Build configuration list for PBXNativeTarget "kordophoned" */; buildPhases = ( - 1A0C4443219A38E100F2AC00 /* Sources */, - 1A0C4444219A38E100F2AC00 /* Frameworks */, - 1A0C4445219A38E100F2AC00 /* Resources */, + CDF6232E219A895D00690038 /* Sources */, + CDF6232F219A895D00690038 /* Frameworks */, + CDF62330219A895D00690038 /* CopyFiles */, ); buildRules = ( ); dependencies = ( + CDF6233C219A8A6600690038 /* PBXTargetDependency */, ); - name = MessagesBridge; - productName = MessagesBridge; - productReference = 1A0C4447219A38E100F2AC00 /* MessagesBridge.app */; - productType = "com.apple.product-type.application"; + name = kordophoned; + productName = kordophone; + productReference = CDF62332219A895D00690038 /* kordophoned */; + productType = "com.apple.product-type.tool"; }; /* End PBXNativeTarget section */ @@ -163,7 +241,7 @@ LastUpgradeCheck = 1100; ORGANIZATIONNAME = "James Magahern"; TargetAttributes = { - 1A0C4446219A38E100F2AC00 = { + CDF62331219A895D00690038 = { CreatedOnToolsVersion = 11.0; }; }; @@ -179,48 +257,91 @@ mainGroup = 1A0C443E219A38E100F2AC00; productRefGroup = 1A0C4448219A38E100F2AC00 /* Products */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = CDF62313219A869000690038 /* Products */; + ProjectRef = CDF62312219A869000690038 /* GCDWebServer.xcodeproj */; + }, + ); projectRoot = ""; targets = ( - 1A0C4446219A38E100F2AC00 /* MessagesBridge */, + CDF62331219A895D00690038 /* kordophoned */, ); }; /* End PBXProject section */ -/* Begin PBXResourcesBuildPhase section */ - 1A0C4445219A38E100F2AC00 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 1A0C444E219A38E200F2AC00 /* Assets.xcassets in Resources */, - 1A0C4451219A38E200F2AC00 /* MainMenu.xib in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; +/* Begin PBXReferenceProxy section */ + CDF6231E219A869000690038 /* GCDWebServer */ = { + isa = PBXReferenceProxy; + fileType = "compiled.mach-o.executable"; + path = GCDWebServer; + remoteRef = CDF6231D219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXResourcesBuildPhase section */ + CDF62320219A869000690038 /* GCDWebServer.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = GCDWebServer.app; + remoteRef = CDF6231F219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + CDF62322219A869000690038 /* GCDWebServer.app */ = { + isa = PBXReferenceProxy; + fileType = wrapper.application; + path = GCDWebServer.app; + remoteRef = CDF62321219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + CDF62324219A869000690038 /* GCDWebServers.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GCDWebServers.framework; + remoteRef = CDF62323219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + CDF62326219A869000690038 /* GCDWebServers.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GCDWebServers.framework; + remoteRef = CDF62325219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + CDF62328219A869000690038 /* GCDWebServers.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = GCDWebServers.framework; + remoteRef = CDF62327219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + CDF6232A219A869000690038 /* Tests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = Tests.xctest; + remoteRef = CDF62329219A869000690038 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ /* Begin PBXSourcesBuildPhase section */ - 1A0C4443219A38E100F2AC00 /* Sources */ = { + CDF6232E219A895D00690038 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 1A0C4454219A38E200F2AC00 /* main.m in Sources */, - 1A0C444C219A38E100F2AC00 /* AppDelegate.m in Sources */, - 1A0C446B219A4BC300F2AC00 /* MBIMBridge.m in Sources */, + CDF62339219A8A5600690038 /* MBIMBridge.h in Sources */, + CDF6233A219A8A5600690038 /* MBIMBridge.m in Sources */, + CDF62335219A895D00690038 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXVariantGroup section */ - 1A0C444F219A38E200F2AC00 /* MainMenu.xib */ = { - isa = PBXVariantGroup; - children = ( - 1A0C4450219A38E200F2AC00 /* Base */, - ); - name = MainMenu.xib; - sourceTree = ""; +/* Begin PBXTargetDependency section */ + CDF6233C219A8A6600690038 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = "GCDWebServers (Mac)"; + targetProxy = CDF6233B219A8A6600690038 /* PBXContainerItemProxy */; }; -/* End PBXVariantGroup section */ +/* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ 1A0C4456219A38E200F2AC00 /* Debug */ = { @@ -342,24 +463,13 @@ }; name = Release; }; - 1A0C4459219A38E200F2AC00 /* Debug */ = { + CDF62337219A895D00690038 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1A33B43C219A5ACD0034485A /* OSXDebugDefaults.xcconfig */; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = MessagesBridge/MessagesBridge.entitlements; - CODE_SIGN_IDENTITY = "-"; - CODE_SIGN_STYLE = Manual; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = MessagesBridge/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = net.buzzert.MessagesBridge; + CLANG_ENABLE_MODULES = NO; + CODE_SIGN_ENTITLEMENTS = kordophone/kordophone.entitlements; + CODE_SIGN_STYLE = Automatic; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = macosx.internal; SYSTEM_FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -368,23 +478,13 @@ }; name = Debug; }; - 1A0C445A219A38E200F2AC00 /* Release */ = { + CDF62338219A895D00690038 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = MessagesBridge/MessagesBridge.entitlements; - CODE_SIGN_IDENTITY = "-"; - CODE_SIGN_STYLE = Manual; - COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = MessagesBridge/Info.plist; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/../Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = net.buzzert.MessagesBridge; + CLANG_ENABLE_MODULES = NO; + CODE_SIGN_ENTITLEMENTS = kordophone/kordophone.entitlements; + CODE_SIGN_STYLE = Automatic; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = macosx.internal; SYSTEM_FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -405,11 +505,11 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 1A0C4458219A38E200F2AC00 /* Build configuration list for PBXNativeTarget "MessagesBridge" */ = { + CDF62336219A895D00690038 /* Build configuration list for PBXNativeTarget "kordophoned" */ = { isa = XCConfigurationList; buildConfigurations = ( - 1A0C4459219A38E200F2AC00 /* Debug */, - 1A0C445A219A38E200F2AC00 /* Release */, + CDF62337219A895D00690038 /* Debug */, + CDF62338219A895D00690038 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/MessagesBridge.xcodeproj/xcshareddata/xcschemes/kordophoned.xcscheme b/MessagesBridge.xcodeproj/xcshareddata/xcschemes/kordophoned.xcscheme new file mode 100644 index 0000000..c103900 --- /dev/null +++ b/MessagesBridge.xcodeproj/xcshareddata/xcschemes/kordophoned.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MessagesBridge/AppDelegate.h b/MessagesBridge/AppDelegate.h deleted file mode 100644 index 86ea015..0000000 --- a/MessagesBridge/AppDelegate.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// AppDelegate.h -// MessagesBridge -// -// Created by James Magahern on 11/12/18. -// Copyright © 2018 James Magahern. All rights reserved. -// - -#import - -@interface AppDelegate : NSObject - - -@end - diff --git a/MessagesBridge/AppDelegate.m b/MessagesBridge/AppDelegate.m deleted file mode 100644 index 471e24d..0000000 --- a/MessagesBridge/AppDelegate.m +++ /dev/null @@ -1,33 +0,0 @@ -// -// AppDelegate.m -// MessagesBridge -// -// Created by James Magahern on 11/12/18. -// Copyright © 2018 James Magahern. All rights reserved. -// - -#import "AppDelegate.h" -#import "MBIMBridge.h" - -@interface AppDelegate () -@property (weak) IBOutlet NSWindow *window; -@property (nonatomic, strong) MBIMBridge *bridge; -@end - -@implementation AppDelegate - -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification -{ - self.bridge = [[MBIMBridge alloc] init]; - [self.bridge connect]; -} - - - - -- (void)applicationWillTerminate:(NSNotification *)aNotification { - // Insert code here to tear down your application -} - - -@end diff --git a/MessagesBridge/Assets.xcassets/AppIcon.appiconset/Contents.json b/MessagesBridge/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 2db2b1c..0000000 --- a/MessagesBridge/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "images" : [ - { - "idiom" : "mac", - "size" : "16x16", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "16x16", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "32x32", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "32x32", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "128x128", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "128x128", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "256x256", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "256x256", - "scale" : "2x" - }, - { - "idiom" : "mac", - "size" : "512x512", - "scale" : "1x" - }, - { - "idiom" : "mac", - "size" : "512x512", - "scale" : "2x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/MessagesBridge/Assets.xcassets/Contents.json b/MessagesBridge/Assets.xcassets/Contents.json deleted file mode 100644 index da4a164..0000000 --- a/MessagesBridge/Assets.xcassets/Contents.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/MessagesBridge/Base.lproj/MainMenu.xib b/MessagesBridge/Base.lproj/MainMenu.xib deleted file mode 100644 index c60269e..0000000 --- a/MessagesBridge/Base.lproj/MainMenu.xib +++ /dev/null @@ -1,692 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/MessagesBridge/Bridge/MBIMBridge.m b/MessagesBridge/Bridge/MBIMBridge.m deleted file mode 100644 index 15d7cd8..0000000 --- a/MessagesBridge/Bridge/MBIMBridge.m +++ /dev/null @@ -1,123 +0,0 @@ -// -// MBIMBridge.m -// MessagesBridge -// -// Created by James Magahern on 11/12/18. -// Copyright © 2018 James Magahern. All rights reserved. -// - -#import "MBIMBridge.h" - -#import -#import - -#import -#import - -static NSString *const MBIMBridgeToken = @"net.buzzert.MBIMBridge"; - -@implementation MBIMBridge - -- (instancetype)init -{ - self = [super init]; - if (self) { - [self registerForNotifications]; - - [sDaemonController setDelegate:self]; - [sDaemonListener addHandler:self]; - } - - return self; -} - -#pragma mark - -#pragma mark Connection - -- (void)connect -{ - if (![sDaemonController hasListenerForID: MBIMBridgeToken]) { - if (![sDaemonController addListenerID:MBIMBridgeToken capabilities:(kFZListenerCapFileTransfers | kFZListenerCapManageStatus | kFZListenerCapChats | kFZListenerCapMessageHistory | kFZListenerCapIDQueries | kFZListenerCapSendMessages)]) { - NSLog(@"Failed to connect to imagent"); - } - } -} - -- (void)disconnect -{ - [sDaemonController removeListenerID:MBIMBridgeToken]; -} - -#pragma mark - -#pragma mark Notifications - -- (void)registerForNotifications -{ - (void)[IMChatRegistry sharedInstance]; - - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_messageReceived:) name:IMChatMessageReceivedNotification object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_chatRegistryDidLoad:) name:IMChatRegistryDidLoadNotification object:nil]; - - [[NSNotificationCenter defaultCenter] addObserverForName: IMChatRegistryUnreadCountChangedNotification - object: nil - queue: [NSOperationQueue mainQueue] - usingBlock:^(NSNotification *note) { - NSLog(@"Unread count changed: %d", (int)[[IMChatRegistry sharedInstance] unreadCount]); - }]; -} - -- (void)_messageReceived:(NSNotification *)notification -{ - NSLog(@"Received!"); - - // Automated reply - IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]]; - IMHandle *handle = [[iMessageAccount arrayOfAllIMHandles] firstObject]; - - /* this caused a crazy loop for some reason!! */ - - /* - NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:@"This is a test automated reply. Please ignore."]; - IMMessage *reply = [IMMessage fromMeIMHandle:handle withText:replyAttrString fileTransferGUIDs:@[] flags:kIMMessageFinished]; - - IMChat *chat = [notification object]; - [chat sendMessage:reply]; - */ -} - -- (void)_chatRegistryDidLoad:(NSNotification *)notification -{ - NSLog(@"Loaded chat registry. %lu existing chats", (unsigned long)[sChatRegistry numberOfExistingChats]); -} - -#pragma mark - -#pragma mark Daemon lifecycle - -- (void)daemonControllerWillConnect -{ - NSLog(@"About to connect to daemon"); -} - -- (void)daemonControllerDidConnect -{ - NSLog(@"Did connect to daemon"); - - IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]]; - if (iMessageAccount) { - NSLog(@"iMessage account connected: %@", iMessageAccount); - } else { - NSLog(@"Was not able to connect to iMessage account"); - } -} - -- (void)daemonControllerDidDisconnect -{ - NSLog(@"Did disconnect from daemon"); -} - -- (void)daemonConnectionLost -{ - NSLog(@"Connection lost to daemon"); -} - -@end diff --git a/MessagesBridge/Info.plist b/MessagesBridge/Info.plist deleted file mode 100644 index 0d13e4a..0000000 --- a/MessagesBridge/Info.plist +++ /dev/null @@ -1,32 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIconFile - - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleVersion - 1 - LSMinimumSystemVersion - $(MACOSX_DEPLOYMENT_TARGET) - NSHumanReadableCopyright - Copyright © 2018 James Magahern. All rights reserved. - NSMainNibFile - MainMenu - NSPrincipalClass - NSApplication - - diff --git a/MessagesBridge/main.m b/MessagesBridge/main.m deleted file mode 100644 index 7ff9331..0000000 --- a/MessagesBridge/main.m +++ /dev/null @@ -1,13 +0,0 @@ -// -// main.m -// MessagesBridge -// -// Created by James Magahern on 11/12/18. -// Copyright © 2018 James Magahern. All rights reserved. -// - -#import - -int main(int argc, const char * argv[]) { - return NSApplicationMain(argc, argv); -} diff --git a/MessagesBridge/Pilfered Headers/SOAPlugInControllerProtocol.h b/Pilfered Headers/SOAPlugInControllerProtocol.h similarity index 100% rename from MessagesBridge/Pilfered Headers/SOAPlugInControllerProtocol.h rename to Pilfered Headers/SOAPlugInControllerProtocol.h diff --git a/MessagesBridge/README.md b/README.md similarity index 100% rename from MessagesBridge/README.md rename to README.md diff --git a/MessagesBridge/Bridge/MBIMBridge.h b/kordophone/Bridge/MBIMBridge.h similarity index 81% rename from MessagesBridge/Bridge/MBIMBridge.h rename to kordophone/Bridge/MBIMBridge.h index d0fd1a3..679a960 100644 --- a/MessagesBridge/Bridge/MBIMBridge.h +++ b/kordophone/Bridge/MBIMBridge.h @@ -11,6 +11,10 @@ NS_ASSUME_NONNULL_BEGIN @interface MBIMBridge : NSObject ++ (instancetype)sharedInstance; + +- (instancetype)init NS_UNAVAILABLE; + - (void)connect; - (void)disconnect; diff --git a/kordophone/Bridge/MBIMBridge.m b/kordophone/Bridge/MBIMBridge.m new file mode 100644 index 0000000..75d5d28 --- /dev/null +++ b/kordophone/Bridge/MBIMBridge.m @@ -0,0 +1,271 @@ +// +// MBIMBridge.m +// MessagesBridge +// +// Created by James Magahern on 11/12/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import "MBIMBridge.h" + +#import + +#import +#import + +#import +#import + +static NSString *const MBIMBridgeToken = @"net.buzzert.MBIMBridge"; + +static NSString *const kAPIEndpointConversationList = @"conversations"; +static NSString *const kAPIEndpointConversationContents = @"messages"; +static NSString *const kAPIEndpointSendMessage = @"sendMessage"; + +@interface MBIMBridge (/* INTERNAL */) +@property (nonatomic, strong) GCDWebServer *webServer; + +- (instancetype)_init; +@end + +@implementation MBIMBridge + ++ (instancetype)sharedInstance +{ + static dispatch_once_t onceToken; + static __strong MBIMBridge *sharedBridge = nil; + dispatch_once(&onceToken, ^{ + sharedBridge = [[MBIMBridge alloc] _init]; + }); + + return sharedBridge; +} + +- (instancetype)_init +{ + self = [super init]; + if (self) { + [self registerForNotifications]; + [self startWebServer]; + + [sDaemonController setDelegate:self]; + [sDaemonListener addHandler:self]; + } + + return self; +} + +#pragma mark - +#pragma mark Connection + +- (void)connect +{ + if (![sDaemonController hasListenerForID: MBIMBridgeToken]) { + if (![sDaemonController addListenerID:MBIMBridgeToken capabilities:(kFZListenerCapFileTransfers | kFZListenerCapManageStatus | kFZListenerCapChats | kFZListenerCapMessageHistory | kFZListenerCapIDQueries | kFZListenerCapSendMessages)]) { + NSLog(@"Failed to connect to imagent"); + } + } +} + +- (void)disconnect +{ + [sDaemonController removeListenerID:MBIMBridgeToken]; +} + +#pragma mark - +#pragma mark Notifications + +- (void)registerForNotifications +{ + (void)[IMChatRegistry sharedInstance]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_messageReceived:) name:IMChatMessageReceivedNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_chatRegistryDidLoad:) name:IMChatRegistryDidLoadNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_chatItemsDidChange:) name:IMChatItemsDidChangeNotification object:nil]; + + [[NSNotificationCenter defaultCenter] addObserverForName: IMChatRegistryUnreadCountChangedNotification + object: nil + queue: [NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) { + NSLog(@"Unread count changed: %d", (int)[[IMChatRegistry sharedInstance] unreadCount]); + }]; +} + +- (void)_messageReceived:(NSNotification *)notification +{ + NSLog(@"Received!"); + + // Sending a message + /* + IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]]; + IMHandle *handle = [[iMessageAccount arrayOfAllIMHandles] firstObject]; + + NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:@"This is a test automated reply. Please ignore."]; + IMMessage *reply = [IMMessage fromMeIMHandle:handle withText:replyAttrString fileTransferGUIDs:@[] flags:kIMMessageFinished]; + + IMChat *chat = [notification object]; + [chat sendMessage:reply]; + */ +} + +- (void)_chatRegistryDidLoad:(NSNotification *)notification +{ + NSLog(@"Loaded chat registry. %lu existing chats", (unsigned long)[sChatRegistry numberOfExistingChats]); +} + +- (void)_chatItemsDidChange:(NSNotification *)notification +{ + NSLog(@"chat items changed: %@", notification); +} + +- (BOOL)_sendMessage:(NSString *)messageBody toChatWithGUID:(NSString *)chatGUID +{ + IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]]; + IMHandle *handle = [[iMessageAccount arrayOfAllIMHandles] firstObject]; + + NSAttributedString *replyAttrString = [[NSAttributedString alloc] initWithString:messageBody]; + IMMessage *reply = [IMMessage fromMeIMHandle:handle withText:replyAttrString fileTransferGUIDs:@[] flags:kIMMessageFinished]; + + IMChat *chat = [sChatRegistry existingChatWithGUID:chatGUID]; + if (!chat) { + NSLog(@"Chat does not exist: %@", chatGUID); + return NO; + } + + [chat sendMessage:reply]; + + return YES; +} + +#pragma mark - +#pragma mark Web Server initialization + +- (void)startWebServer +{ + [GCDWebServer setLogLevel:3]; + + __auto_type __weak weakSelf = self; + self.webServer = [[GCDWebServer alloc] init]; + [self.webServer addDefaultHandlerForMethod:@"GET" + requestClass:[GCDWebServerRequest class] + processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) { return [weakSelf _handleWebServerRequest:request]; }]; + + [self.webServer addDefaultHandlerForMethod:@"POST" + requestClass:[GCDWebServerURLEncodedFormRequest class] + processBlock:^GCDWebServerResponse * _Nullable(__kindof GCDWebServerRequest * _Nonnull request) { return [weakSelf _handleWebServerPOST:(GCDWebServerURLEncodedFormRequest *)request]; }]; + + [self.webServer startWithPort:8080 bonjourName:nil]; +} + +- (GCDWebServerResponse *)_handleWebServerPOST:(__kindof GCDWebServerURLEncodedFormRequest * _Nonnull)request +{ + NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:[request URL] resolvingAgainstBaseURL:NO]; + NSString *endpoint = [[urlComponents path] lastPathComponent]; + + if ([endpoint isEqualToString:kAPIEndpointSendMessage]) { + NSDictionary *args = [request arguments]; + + NSString *guid = [args objectForKey:@"guid"]; + NSString *messageBody = [args objectForKey:@"body"]; + BOOL result = [self _sendMessage:messageBody toChatWithGUID:guid]; + if (result) { + return [GCDWebServerDataResponse responseWithStatusCode:200]; + } else { + return [GCDWebServerDataResponse responseWithStatusCode:500]; + } + } + + return [GCDWebServerDataResponse responseWithStatusCode:404]; +} + +- (GCDWebServerResponse *)_handleWebServerRequest:(__kindof GCDWebServerRequest * _Nonnull)request +{ + NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:[request URL] resolvingAgainstBaseURL:NO]; + NSString *endpoint = [[urlComponents path] lastPathComponent]; + + if ([endpoint isEqualToString:kAPIEndpointConversationList]) { + NSArray *chats = [sChatRegistry allExistingChats]; + + NSMutableArray *conversations = [NSMutableArray array]; + for (IMChat *chat in chats) { + NSMutableDictionary *chatDict = [NSMutableDictionary dictionary]; + chatDict[@"guid"] = [chat guid]; + chatDict[@"displayName"] = [chat displayName]; + chatDict[@"date"] = GCDWebServerFormatRFC822([chat lastFinishedMessageDate]); + + [conversations addObject:chatDict]; + } + + return [GCDWebServerDataResponse responseWithJSONObject:conversations]; + } + + if ([endpoint isEqualToString:kAPIEndpointConversationContents]) { + 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"); + return [GCDWebServerDataResponse responseWithStatusCode:500]; + } + + IMChat *chat = [sChatRegistry existingChatWithGUID:guid]; + if (!chat) { + NSLog(@"Chat with guid: %@ not found", guid); + return [GCDWebServerDataResponse responseWithStatusCode:500]; + } + + // Load messages + [chat loadMessagesBeforeDate:[NSDate date] limit:50 loadImmediately:YES]; + + NSMutableArray *messages = [NSMutableArray array]; + for (IMMessageItem *imMessage in [[chat chatItems] messages]) { + NSMutableDictionary *messageDict = [NSMutableDictionary dictionary]; + messageDict[@"text"] = [[imMessage body] string]; + messageDict[@"date"] = GCDWebServerFormatRFC822([imMessage time]); + messageDict[@"sender"] = [imMessage sender]; + [messages addObject:messageDict]; + } + + return [GCDWebServerDataResponse responseWithJSONObject:messages]; + } + + + return [GCDWebServerDataResponse responseWithStatusCode:404]; +} + +#pragma mark - +#pragma mark Daemon lifecycle + +- (void)daemonControllerWillConnect +{ + NSLog(@"About to connect to daemon"); +} + +- (void)daemonControllerDidConnect +{ + NSLog(@"Did connect to daemon"); + + IMAccount *iMessageAccount = [[IMAccountController sharedInstance] bestAccountForService:[IMServiceImpl iMessageService]]; + if (iMessageAccount) { + NSLog(@"iMessage account connected: %@", iMessageAccount); + } else { + NSLog(@"Was not able to connect to iMessage account"); + } +} + +- (void)daemonControllerDidDisconnect +{ + NSLog(@"Did disconnect from daemon"); +} + +- (void)daemonConnectionLost +{ + NSLog(@"Connection lost to daemon"); +} + +@end diff --git a/MessagesBridge/MessagesBridge.entitlements b/kordophone/kordophone.entitlements similarity index 100% rename from MessagesBridge/MessagesBridge.entitlements rename to kordophone/kordophone.entitlements diff --git a/kordophone/main.m b/kordophone/main.m new file mode 100644 index 0000000..fde00de --- /dev/null +++ b/kordophone/main.m @@ -0,0 +1,24 @@ +// +// main.m +// kordophone +// +// Created by James Magahern on 11/12/18. +// Copyright © 2018 James Magahern. All rights reserved. +// + +#import + +#import "MBIMBridge.h" + +int main(int argc, const char * argv[]) { + @autoreleasepool { + MBIMBridge *bridge = [MBIMBridge sharedInstance]; + [bridge connect]; + + BOOL running = YES; + while (running) { + [[NSRunLoop currentRunLoop] run]; + } + } + return 0; +}