Diff
Modified: trunk/Source/WebKit/ChangeLog (286532 => 286533)
--- trunk/Source/WebKit/ChangeLog 2021-12-04 15:28:47 UTC (rev 286532)
+++ trunk/Source/WebKit/ChangeLog 2021-12-04 16:08:56 UTC (rev 286533)
@@ -1,3 +1,36 @@
+2021-12-04 Brady Eidson <beid...@apple.com>
+
+ Add command line `webpushtool` for daemon development and debugging.
+ https://bugs.webkit.org/show_bug.cgi?id=233845
+
+ Reviewed by Tim Horton.
+
+ No behavior change.
+
+ This utility will eventually be quite fleshed out.
+
+ For now, it can act as a terminal that prints debug messages from webpushd.
+
+ * Configurations/webpushtool.xcconfig: Added.
+ * Resources/webpushtool.entitlements: Added.
+ * WebKit.xcodeproj/project.pbxproj:
+ * WebKit.xcodeproj/xcshareddata/xcschemes/webpushtool.xcscheme: Added.
+
+ * webpushd/webpushtool/WebPushToolConnection.h: Added.
+ * webpushd/webpushtool/WebPushToolConnection.mm: Added.
+ (WebPushTool::Connection::create):
+ (WebPushTool::maybeConnectToService):
+ (WebPushTool::Connection::Connection):
+ (WebPushTool::Connection::connectToService):
+ (WebPushTool::Connection::startAction):
+ (WebPushTool::Connection::startDebugStreamAction):
+ (WebPushTool::Connection::sendAuditToken):
+ (WebPushTool::Connection::connectionDropped):
+ (WebPushTool::Connection::messageReceived):
+ * webpushd/webpushtool/WebPushToolMain.mm: Added.
+ (printUsageAndTerminate):
+ (main):
+
2021-12-04 Brent Fulgham <bfulg...@apple.com>
[Cocoa] Launch Captive Portal WebContent process when requested
Added: trunk/Source/WebKit/Configurations/webpushtool.xcconfig (0 => 286533)
--- trunk/Source/WebKit/Configurations/webpushtool.xcconfig (rev 0)
+++ trunk/Source/WebKit/Configurations/webpushtool.xcconfig 2021-12-04 16:08:56 UTC (rev 286533)
@@ -0,0 +1,35 @@
+// Copyright (C) 2021 Apple Inc. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+// 1. Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "BaseTarget.xcconfig"
+
+PRODUCT_NAME = webpushtool;
+SKIP_INSTALL = YES;
+
+EXCLUDED_SOURCE_FILE_NAMES[sdk=appletv*] = *;
+EXCLUDED_SOURCE_FILE_NAMES[sdk=watch*] = *;
+
+OTHER_LDFLAGS = -l WTF -framework Foundation -framework CoreFoundation;
+LIBRARY_SEARCH_PATHS = $(BUILT_PRODUCTS_DIR);
+
+CODE_SIGN_ENTITLEMENTS = Resources/webpushtool.entitlements;
Added: trunk/Source/WebKit/Resources/webpushtool.entitlements (0 => 286533)
--- trunk/Source/WebKit/Resources/webpushtool.entitlements (rev 0)
+++ trunk/Source/WebKit/Resources/webpushtool.entitlements 2021-12-04 16:08:56 UTC (rev 286533)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>com.apple.private.webkit.webpush</key>
+ <true/>
+</dict>
+</plist>
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (286532 => 286533)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-12-04 15:28:47 UTC (rev 286532)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-12-04 16:08:56 UTC (rev 286533)
@@ -14,6 +14,7 @@
BCFFCA8A160D6DEA003DF315 /* Add XPCServices symlink */,
);
dependencies = (
+ 517B5F6D275B07C3002DC22D /* PBXTargetDependency */,
5C1579DF27165E0800ED5280 /* PBXTargetDependency */,
5CAF7AA926F93F9F0003F19E /* PBXTargetDependency */,
5742A2FA2535619D00B7BA14 /* PBXTargetDependency */,
@@ -1023,6 +1024,8 @@
517A53101F47A86200DCDC0A /* WebSWClientConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 517A530D1F47A84300DCDC0A /* WebSWClientConnectionMessages.h */; };
517B5F2E2757382A002DC22D /* WebPushDaemonConnectionConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 517B5F2D2757382A002DC22D /* WebPushDaemonConnectionConfiguration.h */; };
517B5F2F2757382B002DC22D /* WebPushDaemonConnectionConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 517B5F2D2757382A002DC22D /* WebPushDaemonConnectionConfiguration.h */; };
+ 517B5F65275A8D7F002DC22D /* WebPushToolMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517B5F64275A8D7E002DC22D /* WebPushToolMain.mm */; };
+ 517B5F68275A9A78002DC22D /* WebPushToolConnection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 517B5F67275A9A78002DC22D /* WebPushToolConnection.mm */; };
517CF0E3163A486C00C2950E /* NetworkProcessConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517CF0E1163A486C00C2950E /* NetworkProcessConnectionMessageReceiver.cpp */; };
517CF0E3163A486C00C2950F /* CacheStorageEngineConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517CF0E1163A486C00C2950F /* CacheStorageEngineConnectionMessageReceiver.cpp */; };
517CF0E4163A486C00C2950E /* NetworkProcessConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 517CF0E2163A486C00C2950E /* NetworkProcessConnectionMessages.h */; };
@@ -2127,6 +2130,13 @@
remoteGlobalIDString = C0CE72851247E66800BC0EC4;
remoteInfo = "Derived Sources";
};
+ 517B5F6C275B07C3002DC22D /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 517B5F5A275A8D3E002DC22D;
+ remoteInfo = webpushtool;
+ };
5742A2E72535613F00B7BA14 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project object */;
@@ -4387,6 +4397,12 @@
517A530D1F47A84300DCDC0A /* WebSWClientConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebSWClientConnectionMessages.h; path = DerivedSources/WebKit2/WebSWClientConnectionMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
517A530E1F47A84300DCDC0A /* WebSWClientConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebSWClientConnectionMessageReceiver.cpp; path = DerivedSources/WebKit2/WebSWClientConnectionMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
517B5F2D2757382A002DC22D /* WebPushDaemonConnectionConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPushDaemonConnectionConfiguration.h; sourceTree = "<group>"; };
+ 517B5F5B275A8D3E002DC22D /* webpushtool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = webpushtool; sourceTree = BUILT_PRODUCTS_DIR; };
+ 517B5F64275A8D7E002DC22D /* WebPushToolMain.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPushToolMain.mm; sourceTree = "<group>"; };
+ 517B5F66275A9A78002DC22D /* WebPushToolConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPushToolConnection.h; sourceTree = "<group>"; };
+ 517B5F67275A9A78002DC22D /* WebPushToolConnection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPushToolConnection.mm; sourceTree = "<group>"; };
+ 517B5F6A275AA199002DC22D /* webpushtool.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = webpushtool.xcconfig; sourceTree = "<group>"; };
+ 517B5F6B275AE50B002DC22D /* webpushtool.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; name = webpushtool.entitlements; path = Resources/webpushtool.entitlements; sourceTree = "<group>"; };
517CF0E1163A486C00C2950E /* NetworkProcessConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkProcessConnectionMessageReceiver.cpp; path = DerivedSources/WebKit2/NetworkProcessConnectionMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
517CF0E1163A486C00C2950F /* CacheStorageEngineConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CacheStorageEngineConnectionMessageReceiver.cpp; path = DerivedSources/WebKit2/CacheStorageEngineConnectionMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
517CF0E2163A486C00C2950E /* NetworkProcessConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkProcessConnectionMessages.h; path = DerivedSources/WebKit2/NetworkProcessConnectionMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -6447,6 +6463,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 517B5F58275A8D3E002DC22D /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
5742A2ED2535613F00B7BA14 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@@ -6542,6 +6565,7 @@
CD95493526159004008372D9 /* libWebKitSwift.dylib */,
A16E66002581930800EE1749 /* MediaFormatReader.bundle */,
8DC2EF5B0486A6940098B216 /* WebKit.framework */,
+ 517B5F5B275A8D3E002DC22D /* webpushtool */,
);
name = Products;
sourceTree = "<group>";
@@ -6784,6 +6808,7 @@
5C8BC796218CB58A00813886 /* SafeBrowsing.xcassets */,
E1D26A4C1759634E0095BFD1 /* WebContentProcess.xib */,
E133FD891423DD7F00FC7BFB /* WebKit.icns */,
+ 517B5F6B275AE50B002DC22D /* webpushtool.entitlements */,
);
name = Resources;
sourceTree = "<group>";
@@ -6935,6 +6960,7 @@
CD09FD0A26152E2300E4ACF1 /* WebKitSwift.xcconfig */,
37119A7C20CCB64E002C6DC9 /* WebKitTargetConditionals.xcconfig */,
5C1579DD27165BE500ED5280 /* webpushd.xcconfig */,
+ 517B5F6A275AA199002DC22D /* webpushtool.xcconfig */,
);
path = Configurations;
sourceTree = "<group>";
@@ -9427,6 +9453,16 @@
name = mac;
sourceTree = "<group>";
};
+ 517B5F63275A8D5C002DC22D /* webpushtool */ = {
+ isa = PBXGroup;
+ children = (
+ 517B5F66275A9A78002DC22D /* WebPushToolConnection.h */,
+ 517B5F67275A9A78002DC22D /* WebPushToolConnection.mm */,
+ 517B5F64275A8D7E002DC22D /* WebPushToolMain.mm */,
+ );
+ path = webpushtool;
+ sourceTree = "<group>";
+ };
518E8EF116B208F000E91429 /* Authentication */ = {
isa = PBXGroup;
children = (
@@ -9905,6 +9941,7 @@
5C157A0A2717C9F100ED5280 /* webpushd */ = {
isa = PBXGroup;
children = (
+ 517B5F63275A8D5C002DC22D /* webpushtool */,
5160E954274B887100567388 /* AppBundleRequest.h */,
5160E953274B887100567388 /* AppBundleRequest.mm */,
5CBB6D4D271F67CC00FD1A5D /* com.apple.webkit.webpushd.plist */,
@@ -13979,6 +14016,22 @@
productReference = 372EBB462017E64300085064 /* com.apple.WebKit.WebContent.Development.xpc */;
productType = "com.apple.product-type.xpc-service";
};
+ 517B5F5A275A8D3E002DC22D /* webpushtool */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 517B5F62275A8D3E002DC22D /* Build configuration list for PBXNativeTarget "webpushtool" */;
+ buildPhases = (
+ 517B5F57275A8D3E002DC22D /* Sources */,
+ 517B5F58275A8D3E002DC22D /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = webpushtool;
+ productName = webpushtool;
+ productReference = 517B5F5B275A8D3E002DC22D /* webpushtool */;
+ productType = "com.apple.product-type.tool";
+ };
5742A2E52535613F00B7BA14 /* WebAuthn */ = {
isa = PBXNativeTarget;
buildConfigurationList = 5742A2F32535613F00B7BA14 /* Build configuration list for PBXNativeTarget "WebAuthn" */;
@@ -14197,6 +14250,9 @@
LastSwiftUpdateCheck = 1300;
LastUpgradeCheck = 1140;
TargetAttributes = {
+ 517B5F5A275A8D3E002DC22D = {
+ CreatedOnToolsVersion = 13.0;
+ };
5325BDCD21DFF47700A0DEE1 = {
CreatedOnToolsVersion = 10.1;
ProvisioningStyle = Automatic;
@@ -14254,6 +14310,7 @@
942DB232257EE6D4009BD80A /* EmptyDSTROOT */,
5CAF7A9926F93A750003F19E /* adattributiond */,
5C1579CC27165B2F00ED5280 /* webpushd */,
+ 517B5F5A275A8D3E002DC22D /* webpushtool */,
);
};
/* End PBXProject section */
@@ -15005,6 +15062,15 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 517B5F57275A8D3E002DC22D /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 517B5F68275A9A78002DC22D /* WebPushToolConnection.mm in Sources */,
+ 517B5F65275A8D7F002DC22D /* WebPushToolMain.mm in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
5742A2EA2535613F00B7BA14 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@@ -15570,6 +15636,11 @@
target = C0CE72851247E66800BC0EC4 /* Derived Sources */;
targetProxy = 37F7407812721F740093869B /* PBXContainerItemProxy */;
};
+ 517B5F6D275B07C3002DC22D /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 517B5F5A275A8D3E002DC22D /* webpushtool */;
+ targetProxy = 517B5F6C275B07C3002DC22D /* PBXContainerItemProxy */;
+ };
5742A2E62535613F00B7BA14 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = E1AC2E2720F7B94C00B0897D /* Unlock Keychain */;
@@ -15819,6 +15890,27 @@
};
name = Production;
};
+ 517B5F5F275A8D3E002DC22D /* Debug */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 517B5F6A275AA199002DC22D /* webpushtool.xcconfig */;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ 517B5F60275A8D3E002DC22D /* Release */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 517B5F6A275AA199002DC22D /* webpushtool.xcconfig */;
+ buildSettings = {
+ };
+ name = Release;
+ };
+ 517B5F61275A8D3E002DC22D /* Production */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = 517B5F6A275AA199002DC22D /* webpushtool.xcconfig */;
+ buildSettings = {
+ };
+ name = Production;
+ };
5325BDCE21DFF47800A0DEE1 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = BCB86F4B116AAACD00CE20B7 /* WebKit.xcconfig */;
@@ -16233,6 +16325,16 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Production;
};
+ 517B5F62275A8D3E002DC22D /* Build configuration list for PBXNativeTarget "webpushtool" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 517B5F5F275A8D3E002DC22D /* Debug */,
+ 517B5F60275A8D3E002DC22D /* Release */,
+ 517B5F61275A8D3E002DC22D /* Production */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Production;
+ };
5325BDD121DFF47800A0DEE1 /* Build configuration list for PBXAggregateTarget "Apply Configuration to XCFileLists" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Added: trunk/Source/WebKit/WebKit.xcodeproj/xcshareddata/xcschemes/webpushtool.xcscheme (0 => 286533)
--- trunk/Source/WebKit/WebKit.xcodeproj/xcshareddata/xcschemes/webpushtool.xcscheme (rev 0)
+++ trunk/Source/WebKit/WebKit.xcodeproj/xcshareddata/xcschemes/webpushtool.xcscheme 2021-12-04 16:08:56 UTC (rev 286533)
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "1300"
+ version = "1.7">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "517B5F5A275A8D3E002DC22D"
+ BuildableName = "webpushtool"
+ BlueprintName = "webpushtool"
+ ReferencedContainer = "container:WebKit.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ </Testables>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "517B5F5A275A8D3E002DC22D"
+ BuildableName = "webpushtool"
+ BlueprintName = "webpushtool"
+ ReferencedContainer = "container:WebKit.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "517B5F5A275A8D3E002DC22D"
+ BuildableName = "webpushtool"
+ BlueprintName = "webpushtool"
+ ReferencedContainer = "container:WebKit.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+ <InstallAction
+ buildConfiguration = "Release">
+ </InstallAction>
+</Scheme>
Added: trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h (0 => 286533)
--- trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h (rev 0)
+++ trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.h 2021-12-04 16:08:56 UTC (rev 286533)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <memory>
+#include <wtf/RetainPtr.h>
+#include <wtf/WeakPtr.h>
+#include <wtf/spi/darwin/XPCSPI.h>
+
+namespace WebPushTool {
+
+enum class Action {
+ StreamDebugMessages,
+};
+
+class Connection : public CanMakeWeakPtr<Connection> {
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ static std::unique_ptr<Connection> create(Action, bool preferTestService);
+ Connection(Action, bool preferTestService);
+
+ void connectToService();
+
+private:
+ void messageReceived(xpc_object_t);
+ void connectionDropped();
+
+ void startAction();
+ void startDebugStreamAction();
+
+ void sendAuditToken();
+
+ Action m_action;
+ RetainPtr<xpc_connection_t> m_connection;
+ const char* m_serviceName;
+};
+
+} // namespace WebPushTool
Added: trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm (0 => 286533)
--- trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm (rev 0)
+++ trunk/Source/WebKit/webpushd/webpushtool/WebPushToolConnection.mm 2021-12-04 16:08:56 UTC (rev 286533)
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebPushToolConnection.h"
+
+#import <mach/mach_init.h>
+#import <mach/task.h>
+#import <pal/spi/cocoa/ServersSPI.h>
+#import <wtf/RetainPtr.h>
+
+namespace WebPushTool {
+
+std::unique_ptr<Connection> Connection::create(Action action, bool preferTestService)
+{
+ return makeUnique<Connection>(action, preferTestService);
+}
+
+static mach_port_t maybeConnectToService(const char* serviceName)
+{
+ mach_port_t bsPort;
+ task_get_special_port(mach_task_self(), TASK_BOOTSTRAP_PORT, &bsPort);
+
+ mach_port_t servicePort;
+ kern_return_t err = bootstrap_look_up(bsPort, serviceName, &servicePort);
+
+ if (err == KERN_SUCCESS)
+ return servicePort;
+
+ return MACH_PORT_NULL;
+}
+
+Connection::Connection(Action action, bool preferTestService)
+ : m_action(action)
+{
+ if (preferTestService)
+ m_serviceName = "org.webkit.webpushtestdaemon.service";
+ else
+ m_serviceName = "com.apple.webkit.webpushd.service";
+
+ m_connection = adoptNS(xpc_connection_create_mach_service(m_serviceName, dispatch_get_main_queue(), 0));
+
+ xpc_connection_set_event_handler(m_connection.get(), [this, weakThis = WeakPtr { *this }](xpc_object_t event) {
+ if (!weakThis)
+ return;
+
+ if (event == XPC_ERROR_CONNECTION_INVALID) {
+ printf("Failed to start listening for connections to mach service\n");
+ connectionDropped();
+ return;
+ }
+
+ if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
+ printf("Connection closed\n");
+ connectionDropped();
+ return;
+ }
+
+ if (xpc_get_type(event) == XPC_TYPE_DICTIONARY) {
+ messageReceived(event);
+ return;
+ }
+
+ RELEASE_ASSERT_NOT_REACHED();
+ });
+}
+
+void Connection::connectToService()
+{
+ if (!m_connection)
+ return;
+
+ auto result = maybeConnectToService(m_serviceName);
+ if (result == MACH_PORT_NULL)
+ printf("Waiting for service '%s' to be available\n", m_serviceName);
+
+ while (result == MACH_PORT_NULL) {
+ usleep(1000);
+ result = maybeConnectToService(m_serviceName);
+ }
+
+ xpc_connection_activate(m_connection.get());
+
+ sendAuditToken();
+ startAction();
+}
+
+void Connection::startAction()
+{
+ switch (m_action) {
+ case Action::StreamDebugMessages:
+ startDebugStreamAction();
+ break;
+ };
+}
+
+void Connection::startDebugStreamAction()
+{
+ auto dictionary = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
+ std::array<uint8_t, 1> encodedMessage { 1 };
+ xpc_dictionary_set_uint64(dictionary.get(), "protocol version", 1);
+ xpc_dictionary_set_uint64(dictionary.get(), "message type", 5);
+ xpc_dictionary_set_data(dictionary.get(), "encoded message", encodedMessage.data(), encodedMessage.size());
+
+ xpc_connection_send_message(m_connection.get(), dictionary.get());
+
+ printf("Now streaming debug messages\n");
+}
+
+void Connection::sendAuditToken()
+{
+ audit_token_t token = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ mach_msg_type_number_t auditTokenCount = TASK_AUDIT_TOKEN_COUNT;
+ kern_return_t result = task_info(mach_task_self(), TASK_AUDIT_TOKEN, (task_info_t)(&token), &auditTokenCount);
+ if (result != KERN_SUCCESS) {
+ printf("Unable to get audit token to send\n");
+ return;
+ }
+
+ std::array<uint8_t, 42> encodedMessage;
+ encodedMessage.fill(0);
+ encodedMessage[1] = 1;
+ encodedMessage[2] = 32;
+ memcpy(&encodedMessage[10], &token, sizeof(token));
+ auto dictionary = adoptNS(xpc_dictionary_create(nullptr, nullptr, 0));
+ xpc_dictionary_set_uint64(dictionary.get(), "protocol version", 1);
+ xpc_dictionary_set_uint64(dictionary.get(), "message type", 6);
+ xpc_dictionary_set_data(dictionary.get(), "encoded message", encodedMessage.data(), encodedMessage.size());
+ xpc_connection_send_message(m_connection.get(), dictionary.get());
+}
+
+void Connection::connectionDropped()
+{
+ m_connection = nullptr;
+ CFRunLoopStop(CFRunLoopGetCurrent());
+}
+
+void Connection::messageReceived(xpc_object_t message)
+{
+ const char* debugMessage = xpc_dictionary_get_string(message, "debug message");
+ if (!debugMessage)
+ return;
+
+ printf("%s\n", debugMessage);
+}
+
+} // namespace WebPushTool
Added: trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm (0 => 286533)
--- trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm (rev 0)
+++ trunk/Source/WebKit/webpushd/webpushtool/WebPushToolMain.mm 2021-12-04 16:08:56 UTC (rev 286533)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebPushToolConnection.h"
+#import <Foundation/Foundation.h>
+#import <optional>
+
+__attribute__((__noreturn__))
+static void printUsageAndTerminate(NSString *message)
+{
+ fprintf(stderr, "%s\n\n", message.UTF8String);
+
+ fprintf(stderr, "Usage: webpushtool [options]\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, " --development Connects to mach service \"org.webkit.webpushtestdaemon.service\" (Default)\n");
+ fprintf(stderr, " --production Connects to mach service \"com.apple.webkit.webpushd.service\"\n");
+ fprintf(stderr, " --streamDebugMessages Stream debug messages from webpushd\n");
+ fprintf(stderr, "\n");
+
+ exit(-1);
+}
+
+int main(int, const char **)
+{
+ bool preferTestService = true;
+ std::optional<WebPushTool::Action> action;
+
+ @autoreleasepool {
+ NSArray *arguments = [[NSProcessInfo processInfo] arguments];
+ if (arguments.count == 1)
+ printUsageAndTerminate(@"No arguments provided");
+
+ for (NSString *argument in [arguments subarrayWithRange:NSMakeRange(1, arguments.count - 1)]) {
+ if ([argument isEqualToString:@"--production"])
+ preferTestService = false;
+ if ([argument isEqualToString:@"--development"])
+ preferTestService = true;
+ else if ([argument isEqualToString:@"--streamDebugMessages"])
+ action = ""
+ else
+ printUsageAndTerminate([NSString stringWithFormat:@"Invalid option provided: %@", argument]);
+ }
+ }
+
+ if (!action)
+ printUsageAndTerminate(@"No action provided");
+
+ auto connection = WebPushTool::Connection::create(*action, preferTestService);
+ connection->connectToService();
+
+ CFRunLoopRun();
+ return 0;
+}