diff --git a/lib/Dav/PushSpec.php b/lib/Dav/PushSpec.php new file mode 100644 index 0000000..f75b5d7 --- /dev/null +++ b/lib/Dav/PushSpec.php @@ -0,0 +1,35 @@ +. + * + */ + +namespace OCA\DavPush\Dav; + +abstract class PushSpec { + + public const PUSH_PREFIX = '{https://bitfire.at/webdav-push}'; + + public const PUSH_MESSAGE = self::PUSH_PREFIX . 'push-message'; + + public const PROPERTY_PUSH_RESOURCE = self::PUSH_PREFIX . 'push-resource'; + public const PROPERTY_TOPIC = self::PUSH_PREFIX . 'topic'; + public const PROPERTY_TRANSPORTS = self::PUSH_PREFIX . 'transports'; + +} diff --git a/lib/Dav/ServiceDetectionPlugin.php b/lib/Dav/ServiceDetectionPlugin.php index 234d265..2abdd13 100644 --- a/lib/Dav/ServiceDetectionPlugin.php +++ b/lib/Dav/ServiceDetectionPlugin.php @@ -27,6 +27,7 @@ namespace OCA\DavPush\Dav; +use OCA\DavPush\Dav\PushSpec; use OCA\DavPush\Transport\TransportManager; use OCP\IUser; @@ -42,11 +43,6 @@ class ServiceDetectionPlugin extends ServerPlugin { - public const PUSH_PREFIX = '{DAV:Push}'; - public const PROPERTY_PUSH_TRANSPORTS = self::PUSH_PREFIX . 'push-transports'; - public const PROPERTY_PUSH_TOPIC = self::PUSH_PREFIX . 'topic'; - - public function __construct( private IUserSession $userSession, private TransportManager $transportManager, @@ -58,7 +54,7 @@ public function initialize(Server $server): void { } public function propFind(PropFind $propFind, INode $node) { - if (count(array_intersect([self::PROPERTY_PUSH_TRANSPORTS, self::PROPERTY_PUSH_TOPIC], $propFind->getRequestedProperties())) == 0) { + if (count(array_intersect([PushSpec::PROPERTY_TRANSPORTS, PushSpec::PROPERTY_TOPIC], $propFind->getRequestedProperties())) == 0) { return; } @@ -67,7 +63,7 @@ public function propFind(PropFind $propFind, INode $node) { } $propFind->handle( - self::PROPERTY_PUSH_TRANSPORTS, + PushSpec::PROPERTY_TRANSPORTS, function () use ($node) { //$user = $this->userSession->getUser(); //if (!($user instanceof IUser)) { @@ -80,9 +76,7 @@ function () use ($node) { foreach($transports as $transport) { $result[] = [ - (self::PUSH_PREFIX . "transport") => [ - (self::PUSH_PREFIX . $transport->getId()) => $transport->getAdditionalInformation(), - ] + (PushSpec::PUSH_PREFIX . $transport->getId()) => $transport->getAdditionalInformation(), ]; } @@ -93,7 +87,7 @@ function () use ($node) { ); $propFind->handle( - self::PROPERTY_PUSH_TOPIC, + PushSpec::PROPERTY_TOPIC, //function () use ($node) { //$user = $this->userSession->getUser(); //if (!($user instanceof IUser)) { @@ -105,4 +99,4 @@ function () use ($node) { $node->getName() ); } -} \ No newline at end of file +} diff --git a/lib/Dav/SubscriptionManagementPlugin.php b/lib/Dav/SubscriptionManagementPlugin.php index d3890de..5f81603 100644 --- a/lib/Dav/SubscriptionManagementPlugin.php +++ b/lib/Dav/SubscriptionManagementPlugin.php @@ -27,6 +27,7 @@ namespace OCA\DavPush\Dav; +use OCA\DavPush\Dav\PushSpec; use OCA\DavPush\Transport\TransportManager; use OCA\DavPush\Db\Subscription; use OCA\DavPush\Service\SubscriptionService; @@ -103,7 +104,7 @@ private function parsePushRegisterElement(array $subElements) { if(sizeof($errors) === 0) { return [ "errors" => [], - "subscriptionType" => $parsedSubscriptionElement["type"], + "subscriptionType" => str_replace(PushSpec::PUSH_PREFIX, "", $parsedSubscriptionElement["type"]), "subscriptionOptions" => $parsedSubscriptionElement["options"], "requestedSubscriptionExpiration" => $parsedExpiresElement, ]; @@ -122,7 +123,7 @@ private function parseSubscriptionElement(array $subElements): array { if(sizeof($subElements) == 1) { // parse child element $type = $subElements[0]["name"]; - $type = preg_replace('/^\{DAV:Push\}/', '', $type); + $type = str_replace('{' . PushSpec::PUSH_PREFIX . '}', '', $type); $type = preg_replace('/-subscription$/', '', $type); $options = $subElements[0]["value"]; diff --git a/lib/PushTransports/WebPushTransport.php b/lib/PushTransports/WebPushTransport.php index 644447f..535a804 100644 --- a/lib/PushTransports/WebPushTransport.php +++ b/lib/PushTransports/WebPushTransport.php @@ -26,6 +26,7 @@ namespace OCA\DavPush\PushTransports; +use OCA\DavPush\Dav\PushSpec; use OCA\DavPush\Transport\Transport; use OCA\DavPush\Service\WebPushSubscriptionService; use OCA\DavPush\Errors\WebPushSubscriptionNotFound; @@ -43,7 +44,7 @@ private function parseOptions(array $options): array { $result = []; foreach($options as $option) { - if ($option["name"] == "{DAV:Push}push-resource") { + if ($option["name"] == PushSpec::PROPERTY_PUSH_RESOURCE) { $result["pushResource"] = $option["value"]; } } @@ -85,8 +86,12 @@ public function notify(string $userId, string $collectionName, int $subscription $pushResource = $this->webPushSubscriptionService->findBySubscriptionId($subscriptionId)->getPushResource(); - $content = $xmlService->write('{DAV:Push}push-message', [ - '{DAV:Push}topic' => $collectionName, + $content = $xmlService->write(PushSpec::PUSH_MESSAGE, [ + '{DAV:}propstat' => [ + '{DAV:}prop' => [ + PushSpec::PROPERTY_TOPIC => $collectionName + ] + ], ]); $options = [ diff --git a/lib/PushTransports/WebhookTransport.php b/lib/PushTransports/WebhookTransport.php index c6d74b7..9a22374 100644 --- a/lib/PushTransports/WebhookTransport.php +++ b/lib/PushTransports/WebhookTransport.php @@ -26,6 +26,7 @@ namespace OCA\DavPush\PushTransports; +use OCA\DavPush\Dav\PushSpec; use OCA\DavPush\Transport\Transport; class WebhookTransport extends Transport { @@ -35,7 +36,7 @@ public function registerSubscription($options) { $url = False; foreach($options as $option) { - if($option["name"] == "{DAV:Push}endpoint") { + if($option["name"] == "{" . PushSpec::PUSH_PREFIX . "}endpoint") { $url = $option["value"]; } } @@ -65,4 +66,4 @@ public function notify(string $userId, string $collectionName, $data) { $context = stream_context_create($options); $result = file_get_contents($data["url"], false, $context); } -} \ No newline at end of file +}