-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PushTransports for service discovery
- Loading branch information
Showing
7 changed files
with
142 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/at/bitfire/dav4jvm/property/push/PushTransports.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.XmlUtils | ||
import at.bitfire.dav4jvm.XmlUtils.propertyName | ||
import org.xmlpull.v1.XmlPullParser | ||
|
||
class PushTransports private constructor( | ||
val transports: Set<Property.Name> | ||
): 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") | ||
} | ||
|
||
fun hasWebPush() = transports.contains(WEB_PUSH) | ||
|
||
|
||
object Factory: PropertyFactory { | ||
|
||
override fun getName() = NAME | ||
|
||
override fun create(parser: XmlPullParser): PushTransports { | ||
val transports = mutableListOf<Property.Name>() | ||
XmlUtils.processTag(parser, 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() | ||
} | ||
} | ||
return PushTransports(transports.toSet()) | ||
} | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/at/bitfire/dav4jvm/property/push/Subscription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.XmlUtils | ||
import org.xmlpull.v1.XmlPullParser | ||
|
||
class Subscription private constructor( | ||
val webPushSubscription: WebPushSubscription | ||
): Property { | ||
|
||
companion object { | ||
|
||
@JvmField | ||
val NAME = Property.Name(NS_WEBDAV_PUSH, "subscription") | ||
|
||
} | ||
|
||
|
||
object Factory: PropertyFactory { | ||
|
||
override fun getName() = NAME | ||
|
||
override fun create(parser: XmlPullParser): Subscription? { | ||
// currently we only support WebPushSubscription | ||
var webPushSubscription: WebPushSubscription? = null | ||
|
||
XmlUtils.processTag(parser, WebPushSubscription.NAME) { | ||
webPushSubscription = WebPushSubscription.Factory.create(parser) | ||
} | ||
|
||
return webPushSubscription?.let { | ||
Subscription(webPushSubscription = it) | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters