diff --git a/README.md b/README.md index 2afe40e..81e68e5 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,18 @@ For questions, suggestions etc. use [Github discussions](https://github.com/bitf We're happy about contributions, but please let us know in the discussions before. Then make the changes in your own repository and send a pull request. +> [!NOTE] +> dav4jvm is currently being rewritten to use ktor instead of OkHttp to allow Kotlin Multiplatform support, and other engines. +> +> In the mean time, there are two packages available: +> - `at.bitfire.dav4jvm.okhttp` (the current one, using OkHttp, JVM only) +> - `at.bitfire.dav4jvm.ktor` (new package, uses ktor, supports Kotlin Multiplatform) +> +> There's some common code shared between both packages, **and we cannot guarantee** that all of it is excluded from cross-dependencies (generic code using ktor-specific functions). +> The usages are most likely indicated in the kdoc, but something might be missing. +> +> Take this into consideration if you are going to exclude the ktor dependency on your project. + ## Installation diff --git a/src/main/kotlin/at/bitfire/dav4jvm/HttpHeaderNames.kt b/src/main/kotlin/at/bitfire/dav4jvm/HttpHeaderNames.kt new file mode 100644 index 0000000..759cd03 --- /dev/null +++ b/src/main/kotlin/at/bitfire/dav4jvm/HttpHeaderNames.kt @@ -0,0 +1,25 @@ +/* + * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details. + * + * 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 https://mozilla.org/MPL/2.0/. + * + * SPDX-License-Identifier: MPL-2.0 + */ + +package at.bitfire.dav4jvm + +object HttpHeaderNames { + /** [RFC4229 Section-2.1.2](https://datatracker.ietf.org/doc/html/rfc4229#section-2.1.2) */ + const val Accept: String = "Accept" + + /** [RFC4229 Section-2.1.5](https://datatracker.ietf.org/doc/html/rfc4229#section-2.1.5) */ + const val AcceptEncoding: String = "Accept-Encoding" + + /** [RFC4229 Section-2.1.45](https://datatracker.ietf.org/doc/html/rfc4229#section-2.1.45) */ + const val ETag: String = "ETag" + + /** [RFC6638 Section-8.2](https://datatracker.ietf.org/doc/html/rfc6638#section-8.2) */ + const val ScheduleTag: String = "Schedule-Tag" +} diff --git a/src/main/kotlin/at/bitfire/dav4jvm/XmlReader.kt b/src/main/kotlin/at/bitfire/dav4jvm/XmlReader.kt index f0d9661..3b01ee7 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/XmlReader.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/XmlReader.kt @@ -158,6 +158,8 @@ class XmlReader( * Processes all the tags named [tagName], and sends every tag that has the [CONTENT_TYPE] * attribute with [onNewType]. * + * **Requires Ktor.** + * * @param tagName The name of the tag that contains the [CONTENT_TYPE] attribute value. * @param onNewType Called every time a new [ContentType] is found. */ diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/ScheduleTag.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/ScheduleTag.kt index 74f5e81..b7eed4d 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/ScheduleTag.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/ScheduleTag.kt @@ -10,13 +10,12 @@ package at.bitfire.dav4jvm.property.caldav +import at.bitfire.dav4jvm.HttpHeaderNames import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.QuotedStringUtils import at.bitfire.dav4jvm.XmlReader -import at.bitfire.dav4jvm.property.webdav.GetETag import io.ktor.client.statement.HttpResponse -import io.ktor.http.HttpHeaders import okhttp3.Response import org.xmlpull.v1.XmlPullParser @@ -29,11 +28,16 @@ data class ScheduleTag( @JvmField val NAME = Property.Name(NS_CALDAV, "schedule-tag") + /** + * Creates a [ScheduleTag] from an HTTP response's `Schedule-Tag` header. + * + * **Requires Ktor.** + */ fun fromHttpResponse(response: HttpResponse) = - response.headers[HttpHeaders.ScheduleTag]?.let { ScheduleTag(it) } + response.headers[HttpHeaderNames.ScheduleTag]?.let { ScheduleTag(it) } fun fromResponse(response: Response) = - response.header(HttpHeaders.ScheduleTag)?.let { ScheduleTag(it) } + response.header(HttpHeaderNames.ScheduleTag)?.let { ScheduleTag(it) } } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/SupportedCalendarData.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/SupportedCalendarData.kt index b8cc67f..ad81b79 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/SupportedCalendarData.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/caldav/SupportedCalendarData.kt @@ -31,6 +31,11 @@ data class SupportedCalendarData( } + /** + * Checks whether the supported calendar data includes JCal (application/calendar+json). + * + * **Requires Ktor.** + */ fun hasJCal() = types .map { ContentType.parse(it) } .any { ContentType.Application.contains(it) && "calendar+json".equals(it.contentSubtype, true) } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/carddav/SupportedAddressData.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/carddav/SupportedAddressData.kt index b860f81..43f6669 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/carddav/SupportedAddressData.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/carddav/SupportedAddressData.kt @@ -31,9 +31,20 @@ class SupportedAddressData( } + /** + * Checks whether the supported address data includes vCard 4.0 (`text/vcard; version=4.0`). + * + * **Requires Ktor.** + */ fun hasVCard4() = types .map { try { ContentType.parse(it) } catch (_: Exception) { ContentType.Any } } .any { "text/vcard; version=4.0".equals(it.toString(), true) } + + /** + * Checks whether the supported address data includes JCard (`application/vcard+json`). + * + * **Requires Ktor.** + */ fun hasJCard() = types .map { try { ContentType.parse(it) } catch (_: Exception) { ContentType.Any } } .any { ContentType.Application.contains(it) && "vcard+json".equals(it.contentSubtype, true) } diff --git a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt index 8fcb082..c1f7736 100644 --- a/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt +++ b/src/main/kotlin/at/bitfire/dav4jvm/property/webdav/GetETag.kt @@ -10,12 +10,12 @@ package at.bitfire.dav4jvm.property.webdav +import at.bitfire.dav4jvm.HttpHeaderNames import at.bitfire.dav4jvm.Property import at.bitfire.dav4jvm.PropertyFactory import at.bitfire.dav4jvm.QuotedStringUtils import at.bitfire.dav4jvm.XmlReader import io.ktor.client.statement.HttpResponse -import io.ktor.http.HttpHeaders import okhttp3.Response import org.xmlpull.v1.XmlPullParser @@ -33,11 +33,16 @@ data class GetETag( @JvmField val NAME = Property.Name(NS_WEBDAV, "getetag") + /** + * Creates a [GetETag] from an HTTP response's `ETag` header. + * + * **Requires Ktor.** + */ fun fromHttpResponse(response: HttpResponse) = - response.headers[HttpHeaders.ETag]?.let { GetETag(it) } + response.headers[HttpHeaderNames.ETag]?.let { GetETag(it) } fun fromResponse(response: Response) = - response.header("ETag")?.let { GetETag(it) } + response.header(HttpHeaderNames.ETag)?.let { GetETag(it) } } /**