Skip to content

Commit 8b59413

Browse files
ArnyminerZrfc2822
andauthored
Incorporate latest changes from WebDAV-Push (#60)
* 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]>
1 parent fbd95a5 commit 8b59413

File tree

16 files changed

+409
-103
lines changed

16 files changed

+409
-103
lines changed

src/main/kotlin/at/bitfire/dav4jvm/PropertyRegistry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ object PropertyRegistry {
5959
at.bitfire.dav4jvm.property.carddav.MaxResourceSize.Factory,
6060
Owner.Factory,
6161
PushMessage.Factory,
62-
PushSubscribe.Factory,
62+
PushRegister.Factory,
6363
PushTransports.Factory,
6464
QuotaAvailableBytes.Factory,
6565
QuotaUsedBytes.Factory,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
package at.bitfire.dav4jvm.property.push
8+
9+
import at.bitfire.dav4jvm.Property
10+
import at.bitfire.dav4jvm.PropertyFactory
11+
import at.bitfire.dav4jvm.XmlReader
12+
import org.xmlpull.v1.XmlPullParser
13+
14+
/**
15+
* Represents a [NS_WEBDAV_PUSH]`:auth-secret` property.
16+
*
17+
* Experimental! See https://github.com/bitfireAT/webdav-push/
18+
*/
19+
data class AuthSecret(
20+
val secret: String? = null
21+
): Property {
22+
23+
companion object {
24+
25+
@JvmField
26+
val NAME = Property.Name(NS_WEBDAV_PUSH, "auth-secret")
27+
28+
}
29+
30+
31+
object Factory: PropertyFactory {
32+
33+
override fun getName() = NAME
34+
35+
override fun create(parser: XmlPullParser): AuthSecret =
36+
AuthSecret(XmlReader(parser).readText())
37+
38+
}
39+
40+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package at.bitfire.dav4jvm.property.push
2+
3+
import at.bitfire.dav4jvm.Property
4+
import at.bitfire.dav4jvm.PropertyFactory
5+
import at.bitfire.dav4jvm.XmlReader
6+
import org.xmlpull.v1.XmlPullParser
7+
8+
/**
9+
* Represents a [NS_WEBDAV_PUSH]`:client-public-key` property.
10+
*
11+
* Experimental! See https://github.com/bitfireAT/webdav-push/
12+
*/
13+
data class ClientPublicKey(
14+
val type: String? = null,
15+
val key: String? = null
16+
): Property {
17+
18+
companion object {
19+
20+
@JvmField
21+
val NAME = Property.Name(NS_WEBDAV_PUSH, "client-public-key")
22+
23+
}
24+
25+
26+
object Factory : PropertyFactory {
27+
28+
override fun getName() = NAME
29+
30+
override fun create(parser: XmlPullParser): ClientPublicKey {
31+
return ClientPublicKey(
32+
type = parser.getAttributeValue(null, "type"),
33+
key = XmlReader(parser).readText()
34+
)
35+
}
36+
37+
}
38+
39+
}

src/main/kotlin/at/bitfire/dav4jvm/property/push/PushMessage.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
package at.bitfire.dav4jvm.property.push
88

9+
import at.bitfire.dav4jvm.PropStat
910
import at.bitfire.dav4jvm.Property
1011
import at.bitfire.dav4jvm.PropertyFactory
1112
import at.bitfire.dav4jvm.XmlReader
1213
import org.xmlpull.v1.XmlPullParser
1314

1415
/**
15-
* Represents a `{DAV:Push}push-message` property.
16+
* Represents a [NS_WEBDAV_PUSH]`:push-message` property.
1617
*
1718
* Experimental! See https://github.com/bitfireAT/webdav-push/
1819
*/
19-
class PushMessage(
20-
val topic: String?
20+
data class PushMessage(
21+
val propStat: PropStat? = null
2122
): Property {
2223

2324
companion object {
@@ -32,7 +33,15 @@ class PushMessage(
3233

3334
override fun getName() = NAME
3435

35-
override fun create(parser: XmlPullParser) = PushMessage(XmlReader(parser).readTextProperty(Topic.NAME))
36+
override fun create(parser: XmlPullParser): PushMessage {
37+
var propStat: PropStat? = null
38+
39+
XmlReader(parser).processTag(PropStat.NAME) {
40+
propStat = PropStat.parse(parser)
41+
}
42+
43+
return PushMessage(propStat)
44+
}
3645

3746
}
3847

src/main/kotlin/at/bitfire/dav4jvm/property/push/PushSubscribe.kt renamed to src/main/kotlin/at/bitfire/dav4jvm/property/push/PushRegister.kt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,56 @@ import at.bitfire.dav4jvm.Property
1111
import at.bitfire.dav4jvm.PropertyFactory
1212
import at.bitfire.dav4jvm.XmlReader
1313
import at.bitfire.dav4jvm.XmlUtils.propertyName
14-
import org.xmlpull.v1.XmlPullParser
1514
import java.time.Instant
15+
import org.xmlpull.v1.XmlPullParser
1616

1717
/**
18-
* Represents a `{DAV:Push}push-subscribe` property.
18+
* Represents a [NS_WEBDAV_PUSH]`:push-register` property.
1919
*
2020
* Experimental! See https://github.com/bitfireAT/webdav-push/
2121
*/
22-
class PushSubscribe: Property {
22+
data class PushRegister(
23+
val expires: Instant? = null,
24+
val subscription: Subscription? = null
25+
): Property {
2326

2427
companion object {
2528

2629
@JvmField
27-
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-subscribe")
30+
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-register")
2831

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

3134
}
3235

33-
var expires: Instant? = null
34-
var subscription: Subscription? = null
35-
3636

3737
object Factory: PropertyFactory {
3838

3939
override fun getName() = NAME
4040

41-
override fun create(parser: XmlPullParser): PushSubscribe {
42-
val subscribe = PushSubscribe()
41+
override fun create(parser: XmlPullParser): PushRegister {
42+
var register = PushRegister()
4343

4444
val depth = parser.depth
4545
var eventType = parser.eventType
4646
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
4747
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1)
4848
when (parser.propertyName()) {
4949
EXPIRES ->
50-
subscribe.expires = XmlReader(parser).readText()?.let {
51-
HttpUtils.parseDate(it)
52-
}
50+
register = register.copy(
51+
expires = XmlReader(parser).readText()?.let {
52+
HttpUtils.parseDate(it)
53+
}
54+
)
5355
Subscription.NAME ->
54-
subscribe.subscription = Subscription.Factory.create(parser)
56+
register = register.copy(
57+
subscription = Subscription.Factory.create(parser)
58+
)
5559
}
5660
eventType = parser.next()
5761
}
5862

59-
return subscribe
63+
return register
6064
}
6165

6266
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
package at.bitfire.dav4jvm.property.push
8+
9+
import at.bitfire.dav4jvm.Property
10+
import at.bitfire.dav4jvm.PropertyFactory
11+
import at.bitfire.dav4jvm.XmlReader
12+
import org.xmlpull.v1.XmlPullParser
13+
import java.net.URI
14+
import java.net.URISyntaxException
15+
16+
/**
17+
* Represents a [NS_WEBDAV_PUSH]`:push-resource` property.
18+
*
19+
* Experimental! See https://github.com/bitfireAT/webdav-push/
20+
*/
21+
data class PushResource(
22+
val uri: URI? = null
23+
): Property {
24+
25+
companion object {
26+
27+
@JvmField
28+
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-resource")
29+
30+
}
31+
32+
33+
object Factory: PropertyFactory {
34+
35+
override fun getName() = NAME
36+
37+
override fun create(parser: XmlPullParser): PushResource =
38+
PushResource(
39+
uri = XmlReader(parser).readText()?.let { uri ->
40+
try {
41+
URI(uri)
42+
} catch (_: URISyntaxException) {
43+
null
44+
}
45+
}
46+
)
47+
48+
}
49+
50+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package at.bitfire.dav4jvm.property.push
2+
3+
import at.bitfire.dav4jvm.Property
4+
5+
/**
6+
* Identifies a property as a push transport.
7+
*/
8+
interface PushTransport: Property

src/main/kotlin/at/bitfire/dav4jvm/property/push/PushTransports.kt

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,41 @@ package at.bitfire.dav4jvm.property.push
88

99
import at.bitfire.dav4jvm.Property
1010
import at.bitfire.dav4jvm.PropertyFactory
11-
import at.bitfire.dav4jvm.XmlReader
1211
import at.bitfire.dav4jvm.XmlUtils.propertyName
1312
import org.xmlpull.v1.XmlPullParser
1413

1514
/**
16-
* Represents a `{DAV:Push}push-transports` property.
15+
* Represents a [NS_WEBDAV_PUSH]`:push-transports` property.
1716
*
1817
* Experimental! See https://github.com/bitfireAT/webdav-push/
1918
*/
2019
class PushTransports private constructor(
21-
val transports: Set<Property.Name>
20+
val transports: Set<PushTransport>
2221
): Property {
2322

2423
companion object {
2524
@JvmField
26-
val NAME = Property.Name(NS_WEBDAV_PUSH, "push-transports")
27-
28-
val TRANSPORT = Property.Name(NS_WEBDAV_PUSH, "transport")
29-
val WEB_PUSH = Property.Name(NS_WEBDAV_PUSH, "web-push")
25+
val NAME = Property.Name(NS_WEBDAV_PUSH, "transports")
3026
}
3127

32-
fun hasWebPush() = transports.contains(WEB_PUSH)
28+
fun hasWebPush() = transports.any { it is WebPush }
3329

3430

3531
object Factory: PropertyFactory {
3632

3733
override fun getName() = NAME
3834

3935
override fun create(parser: XmlPullParser): PushTransports {
40-
val transports = mutableListOf<Property.Name>()
41-
XmlReader(parser).processTag(TRANSPORT) {
42-
val depth = parser.depth
43-
var eventType = parser.eventType
44-
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
45-
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1)
46-
transports += parser.propertyName()
47-
eventType = parser.next()
36+
val transports = mutableListOf<PushTransport>()
37+
val depth = parser.depth
38+
var eventType = parser.eventType
39+
while (!(eventType == XmlPullParser.END_TAG && parser.depth == depth)) {
40+
if (eventType == XmlPullParser.START_TAG && parser.depth == depth + 1) {
41+
when (parser.propertyName()) {
42+
WebPush.NAME -> transports += WebPush.Factory.create(parser)
43+
}
4844
}
45+
eventType = parser.next()
4946
}
5047
return PushTransports(transports.toSet())
5148
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package at.bitfire.dav4jvm.property.push
2+
3+
import at.bitfire.dav4jvm.Property
4+
import at.bitfire.dav4jvm.PropertyFactory
5+
import at.bitfire.dav4jvm.XmlReader
6+
import org.xmlpull.v1.XmlPullParser
7+
8+
/**
9+
* Represents a [NS_WEBDAV_PUSH]`:server-public-key` property.
10+
*
11+
* Experimental! See https://github.com/bitfireAT/webdav-push/
12+
*/
13+
data class ServerPublicKey(
14+
val type: String? = null,
15+
val key: String? = null
16+
): Property {
17+
18+
companion object {
19+
20+
@JvmField
21+
val NAME = Property.Name(NS_WEBDAV_PUSH, "server-public-key")
22+
23+
}
24+
25+
26+
object Factory : PropertyFactory {
27+
28+
override fun getName() = NAME
29+
30+
override fun create(parser: XmlPullParser): ServerPublicKey {
31+
return ServerPublicKey(
32+
type = parser.getAttributeValue(null, "type"),
33+
key = XmlReader(parser).readText()
34+
)
35+
}
36+
37+
}
38+
39+
}

src/main/kotlin/at/bitfire/dav4jvm/property/push/Subscription.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import at.bitfire.dav4jvm.XmlReader
1212
import org.xmlpull.v1.XmlPullParser
1313

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

2323
companion object {

0 commit comments

Comments
 (0)