Skip to content

Commit

Permalink
Incorporate latest changes from WebDAV-Push (#60)
Browse files Browse the repository at this point in the history
* Updated Push namespace

Signed-off-by: Arnau Mora Gras <[email protected]>

* Implemented updates from new definitions

Signed-off-by: Arnau Mora Gras <[email protected]>

* Added encryption properties

Signed-off-by: Arnau Mora Gras <[email protected]>

* Added generic public key class

Signed-off-by: Arnau Mora Gras <[email protected]>

* Replaced namespaces in docs

Signed-off-by: Arnau Mora Gras <[email protected]>

* Got rid of unused const

Signed-off-by: Arnau Mora Gras <[email protected]>

* Formatting

Signed-off-by: Arnau Mora Gras <[email protected]>

* Moved file

Signed-off-by: Arnau Mora Gras <[email protected]>

* Got rid of `PushPublicKey.Factory`

Signed-off-by: Arnau Mora Gras <[email protected]>

* Renamed `resource` to `uri`

Signed-off-by: Arnau Mora Gras <[email protected]>

* Simplified expression

Signed-off-by: Arnau Mora Gras <[email protected]>

* Added `ServerPublicKey` to test

Signed-off-by: Arnau Mora Gras <[email protected]>

* Typos

Signed-off-by: Arnau Mora Gras <[email protected]>

* Made all properties data classes to comply with #61

Signed-off-by: Arnau Mora Gras <[email protected]>

* Fixed constructor

Signed-off-by: Arnau Mora Gras <[email protected]>

* Minor changes (drop PushPublicKey)

---------

Signed-off-by: Arnau Mora Gras <[email protected]>
Co-authored-by: Ricki Hirner <[email protected]>
  • Loading branch information
ArnyminerZ and rfc2822 authored Dec 2, 2024
1 parent fbd95a5 commit 8b59413
Show file tree
Hide file tree
Showing 16 changed files with 409 additions and 103 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/at/bitfire/dav4jvm/PropertyRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object PropertyRegistry {
at.bitfire.dav4jvm.property.carddav.MaxResourceSize.Factory,
Owner.Factory,
PushMessage.Factory,
PushSubscribe.Factory,
PushRegister.Factory,
PushTransports.Factory,
QuotaAvailableBytes.Factory,
QuotaUsedBytes.Factory,
Expand Down
40 changes: 40 additions & 0 deletions src/main/kotlin/at/bitfire/dav4jvm/property/push/AuthSecret.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser

/**
* Represents a [NS_WEBDAV_PUSH]`:auth-secret` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
data class AuthSecret(
val secret: String? = null
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "auth-secret")

}


object Factory: PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): AuthSecret =
AuthSecret(XmlReader(parser).readText())

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser

/**
* Represents a [NS_WEBDAV_PUSH]`:client-public-key` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
data class ClientPublicKey(
val type: String? = null,
val key: String? = null
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "client-public-key")

}


object Factory : PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): ClientPublicKey {
return ClientPublicKey(
type = parser.getAttributeValue(null, "type"),
key = XmlReader(parser).readText()
)
}

}

}
17 changes: 13 additions & 4 deletions src/main/kotlin/at/bitfire/dav4jvm/property/push/PushMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.PropStat
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser

/**
* Represents a `{DAV:Push}push-message` property.
* Represents a [NS_WEBDAV_PUSH]`:push-message` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
class PushMessage(
val topic: String?
data class PushMessage(
val propStat: PropStat? = null
): Property {

companion object {
Expand All @@ -32,7 +33,15 @@ class PushMessage(

override fun getName() = NAME

override fun create(parser: XmlPullParser) = PushMessage(XmlReader(parser).readTextProperty(Topic.NAME))
override fun create(parser: XmlPullParser): PushMessage {
var propStat: PropStat? = null

XmlReader(parser).processTag(PropStat.NAME) {
propStat = PropStat.parse(parser)
}

return PushMessage(propStat)
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,56 @@ import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import at.bitfire.dav4jvm.XmlUtils.propertyName
import org.xmlpull.v1.XmlPullParser
import java.time.Instant
import org.xmlpull.v1.XmlPullParser

/**
* Represents a `{DAV:Push}push-subscribe` property.
* Represents a [NS_WEBDAV_PUSH]`:push-register` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
class PushSubscribe: Property {
data class PushRegister(
val expires: Instant? = null,
val subscription: Subscription? = null
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-subscribe")
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-register")

val EXPIRES = Property.Name(NS_WEBDAV_PUSH, "expires")

}

var expires: Instant? = null
var subscription: Subscription? = null


object Factory: PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): PushSubscribe {
val subscribe = PushSubscribe()
override fun create(parser: XmlPullParser): PushRegister {
var register = PushRegister()

val depth = parser.depth
var eventType = parser.eventType
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1)
when (parser.propertyName()) {
EXPIRES ->
subscribe.expires = XmlReader(parser).readText()?.let {
HttpUtils.parseDate(it)
}
register = register.copy(
expires = XmlReader(parser).readText()?.let {
HttpUtils.parseDate(it)
}
)
Subscription.NAME ->
subscribe.subscription = Subscription.Factory.create(parser)
register = register.copy(
subscription = Subscription.Factory.create(parser)
)
}
eventType = parser.next()
}

return subscribe
return register
}

}
Expand Down
50 changes: 50 additions & 0 deletions src/main/kotlin/at/bitfire/dav4jvm/property/push/PushResource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser
import java.net.URI
import java.net.URISyntaxException

/**
* Represents a [NS_WEBDAV_PUSH]`:push-resource` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
data class PushResource(
val uri: URI? = null
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-resource")

}


object Factory: PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): PushResource =
PushResource(
uri = XmlReader(parser).readText()?.let { uri ->
try {
URI(uri)
} catch (_: URISyntaxException) {
null
}
}
)

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.Property

/**
* Identifies a property as a push transport.
*/
interface PushTransport: Property
29 changes: 13 additions & 16 deletions src/main/kotlin/at/bitfire/dav4jvm/property/push/PushTransports.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,41 @@ package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import at.bitfire.dav4jvm.XmlUtils.propertyName
import org.xmlpull.v1.XmlPullParser

/**
* Represents a `{DAV:Push}push-transports` property.
* Represents a [NS_WEBDAV_PUSH]`:push-transports` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
class PushTransports private constructor(
val transports: Set<Property.Name>
val transports: Set<PushTransport>
): Property {

companion object {
@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-transports")

val TRANSPORT = Property.Name(NS_WEBDAV_PUSH, "transport")
val WEB_PUSH = Property.Name(NS_WEBDAV_PUSH, "web-push")
val NAME = Property.Name(NS_WEBDAV_PUSH, "transports")
}

fun hasWebPush() = transports.contains(WEB_PUSH)
fun hasWebPush() = transports.any { it is WebPush }


object Factory: PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): PushTransports {
val transports = mutableListOf<Property.Name>()
XmlReader(parser).processTag(TRANSPORT) {
val depth = parser.depth
var eventType = parser.eventType
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1)
transports += parser.propertyName()
eventType = parser.next()
val transports = mutableListOf<PushTransport>()
val depth = parser.depth
var eventType = parser.eventType
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1) {
when (parser.propertyName()) {
WebPush.NAME -> transports += WebPush.Factory.create(parser)
}
}
eventType = parser.next()
}
return PushTransports(transports.toSet())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package at.bitfire.dav4jvm.property.push

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser

/**
* Represents a [NS_WEBDAV_PUSH]`:server-public-key` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
data class ServerPublicKey(
val type: String? = null,
val key: String? = null
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "server-public-key")

}


object Factory : PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser): ServerPublicKey {
return ServerPublicKey(
type = parser.getAttributeValue(null, "type"),
key = XmlReader(parser).readText()
)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser

/**
* Represents a `{DAV:Push}subscription` property.
* Represents a [NS_WEBDAV_PUSH]`:subscription` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
class Subscription private constructor(
val webPushSubscription: WebPushSubscription?
data class Subscription private constructor(
val webPushSubscription: WebPushSubscription? = null
): Property {

companion object {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/at/bitfire/dav4jvm/property/push/Topic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import at.bitfire.dav4jvm.XmlReader
import org.xmlpull.v1.XmlPullParser

/**
* Represents a `{DAV:Push}topic` property.
* Represents a [NS_WEBDAV_PUSH]`:topic` property.
*
* Experimental! See https://github.com/bitfireAT/webdav-push/
*/
class Topic private constructor(
val topic: String?
data class Topic(
val topic: String? = null
): Property {

companion object {
Expand Down
Loading

0 comments on commit 8b59413

Please sign in to comment.