Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0422e78 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Don't rely on ServiceLoader because it's unreliable in Android environments; update okhttp

parent b389e243
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,11 @@ dav4jvm needs a working XmlPullParser (XPP). On Android, the system already come
XPP and you don't need to include one; on other systems, you may need to
import for instance `org.ogce:xpp3` to get dav4jvm to work.

## Custom properties

If you use custom WebDAV properties, register the corresponding factories with `PropertyRegistery.register()`
before calling other dav4jvm methods.


## Contact / License

+5 −11
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ import org.jetbrains.dokka.gradle.DokkaTask

object Libs {
    // okhttp HTTP library
    const val okhttpVersion = "4.5.0"
    const val okhttpVersion = "4.6.0"

    // XmlPullParser library
    const val xpp3Version = "1.1.6"
@@ -15,10 +15,10 @@ repositories {
}

plugins {
    kotlin("jvm") version "1.3.71"
    kotlin("jvm") version "1.3.72"

    id("com.github.kukuhyoniatmoko.buildconfigkotlin") version "1.0.5"
    id("org.jetbrains.dokka") version "0.10.0"
    id("org.jetbrains.dokka") version "0.10.1"
    maven
}

@@ -36,17 +36,11 @@ tasks {
dependencies {
    implementation(kotlin("stdlib"))

    // okhttp
    api(platform("com.squareup.okhttp3:okhttp-bom:${Libs.okhttpVersion}"))
    api("com.squareup.okhttp3:okhttp")
    // use Kotlin-friendly okhttp 2.x
    implementation("com.squareup.okio:okio:2.+")

    api("com.squareup.okhttp3:okhttp:${Libs.okhttpVersion}")
    implementation("org.apache.commons:commons-lang3:3.9")

    api("org.ogce:xpp3:${Libs.xpp3Version}")

    testImplementation("com.squareup.okhttp3:mockwebserver")
    testImplementation("com.squareup.okhttp3:mockwebserver:${Libs.okhttpVersion}")
}

buildConfigKotlin {
+14 −14
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ class BasicDigestAuthHandler(
        domain?.let {
            val host = request.url.host
            if (!domain.equals(UrlUtils.hostToDomain(host), true)) {
                Constants.log.warning("Not authenticating against $host because it doesn't belong to $domain")
                Dav4jvm.log.warning("Not authenticating against $host because it doesn't belong to $domain")
                return null
            }
        }
@@ -69,7 +69,7 @@ class BasicDigestAuthHandler(
            // we're not processing a 401 response

            if (basicAuth == null && digestAuth == null && request.isHttps) {
                Constants.log.fine("Trying Basic auth preemptively")
                Dav4jvm.log.fine("Trying Basic auth preemptively")
                basicAuth = Challenge("Basic", "")
            }

@@ -82,7 +82,7 @@ class BasicDigestAuthHandler(
                when {
                    "Basic".equals(challenge.scheme, true) -> {
                        basicAuth?.let {
                            Constants.log.warning("Basic credentials didn't work last time -> aborting")
                            Dav4jvm.log.warning("Basic credentials didn't work last time -> aborting")
                            basicAuth = null
                            return null
                        }
@@ -90,7 +90,7 @@ class BasicDigestAuthHandler(
                    }
                    "Digest".equals(challenge.scheme, true) -> {
                        if (digestAuth != null && !"true".equals(challenge.authParams["stale"], true)) {
                            Constants.log.warning("Digest credentials didn't work last time and server nonce has not expired -> aborting")
                            Dav4jvm.log.warning("Digest credentials didn't work last time and server nonce has not expired -> aborting")
                            digestAuth = null
                            return null
                        }
@@ -105,12 +105,12 @@ class BasicDigestAuthHandler(
        // we MUST prefer Digest auth [https://tools.ietf.org/html/rfc2617#section-4.6]
        when {
            digestAuth != null -> {
                Constants.log.fine("Adding Digest authorization request for ${request.url}")
                Dav4jvm.log.fine("Adding Digest authorization request for ${request.url}")
                return digestRequest(request, digestAuth)
            }

            basicAuth != null -> {
                Constants.log.fine("Adding Basic authorization header for ${request.url}")
                Dav4jvm.log.fine("Adding Basic authorization header for ${request.url}")

                /* In RFC 2617 (obsolete), there was no encoding for credentials defined, although
                 one can interpret it as "use ISO-8859-1 encoding". This has been clarified by RFC 7617,
@@ -123,7 +123,7 @@ class BasicDigestAuthHandler(
            }

            response != null ->
                Constants.log.warning("No supported authentication scheme")
                Dav4jvm.log.warning("No supported authentication scheme")
        }

        return null
@@ -148,13 +148,13 @@ class BasicDigestAuthHandler(
        if (realm != null)
            params.add("realm=${quotedString(realm)}")
        else {
            Constants.log.warning("No realm provided, aborting Digest auth")
            Dav4jvm.log.warning("No realm provided, aborting Digest auth")
            return null
        }
        if (nonce != null)
            params.add("nonce=${quotedString(nonce)}")
        else {
            Constants.log.warning("No nonce provided, aborting Digest auth")
            Dav4jvm.log.warning("No nonce provided, aborting Digest auth")
            return null
        }
        if (opaque != null)
@@ -183,7 +183,7 @@ class BasicDigestAuthHandler(
                else ->
                    null
            }
            Constants.log.finer("A1=$a1")
            Dav4jvm.log.finer("A1=$a1")

            val a2: String? = when (qop) {
                Protection.Auth ->
@@ -193,18 +193,18 @@ class BasicDigestAuthHandler(
                        val body = request.body
                        "$method:$digestURI:" + (if (body != null) h(body) else h(""))
                    } catch(e: IOException) {
                        Constants.log.warning("Couldn't get entity-body for hash calculation")
                        Dav4jvm.log.warning("Couldn't get entity-body for hash calculation")
                        null
                    }
                }
            }
            Constants.log.finer("A2=$a2")
            Dav4jvm.log.finer("A2=$a2")

            if (a1 != null && a2 != null)
                response = kd(h(a1), "$nonce:$ncValue:$clientNonce:${qop.qop}:${h(a2)}")

        } else {
            Constants.log.finer("Using legacy Digest auth")
            Dav4jvm.log.finer("Using legacy Digest auth")

            // legacy (backwards compatibility with RFC 2069)
            if (algorithm == Algorithm.MD5) {
@@ -238,7 +238,7 @@ class BasicDigestAuthHandler(
                    MD5_SESSION.algorithm.equals(paramValue, true) ->
                        MD5_SESSION
                    else -> {
                        Constants.log.warning("Ignoring unknown hash algorithm: $paramValue")
                        Dav4jvm.log.warning("Ignoring unknown hash algorithm: $paramValue")
                        null
                    }
                }
+1 −4
Original line number Diff line number Diff line
@@ -6,13 +6,10 @@

package at.bitfire.dav4jvm

import BuildConfig
import java.util.logging.Logger

object Constants {
object Dav4jvm {

    var log = Logger.getLogger("dav4jvm")!!

    const val okhttpVersion = BuildConfig.okhttpVersion

}
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import java.util.logging.Logger
class DavAddressBook @JvmOverloads constructor(
        httpClient: OkHttpClient,
        location: HttpUrl,
        log: Logger = Constants.log
        log: Logger = Dav4jvm.log
): DavCollection(httpClient, location, log) {

    companion object {
Loading