-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tobiasKaminsky <[email protected]>
- Loading branch information
1 parent
a5cdfbd
commit e7685aa
Showing
10 changed files
with
283 additions
and
77 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
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
38 changes: 38 additions & 0 deletions
38
library/src/main/java/com/nextcloud/operations/dav/BasicAuthInterceptor.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,38 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2022 Tobias Kaminsky | ||
* Copyright (C) 2022 Nextcloud GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package com.nextcloud.operations.dav | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
|
||
class BasicAuthInterceptor(val credentials: String) : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val request = chain.request() | ||
val authRequest = request | ||
.newBuilder() | ||
.header("Authorization", credentials) | ||
.build() | ||
|
||
return chain.proceed(authRequest) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
library/src/main/java/com/nextcloud/operations/dav/MkColMethod.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,41 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2022 Tobias Kaminsky | ||
* Copyright (C) 2022 Nextcloud GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package com.nextcloud.operations.dav | ||
|
||
import at.bitfire.dav4jvm.DavResource | ||
import com.nextcloud.common.NextcloudClient | ||
import okhttp3.HttpUrl.Companion.toHttpUrl | ||
|
||
/** | ||
* Webdav MkCol method that uses OkHttp with new NextcloudClient | ||
*/ | ||
class MkColMethod(val uri: String) : OkHttpDavMethodBase() { | ||
override fun createDavResource(nextcloudClient: NextcloudClient) { | ||
val httpURL = uri.toHttpUrl() | ||
val davResource = DavResource(nextcloudClient.client, httpURL) | ||
davResource.mkCol(null) { | ||
// log response | ||
response = it | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
library/src/main/java/com/nextcloud/operations/dav/OkHttpDavMethodBase.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,55 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2022 Tobias Kaminsky | ||
* Copyright (C) 2022 Nextcloud GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package com.nextcloud.operations.dav | ||
|
||
import com.nextcloud.common.NextcloudClient | ||
import com.nextcloud.common.OkHttpMethodBase | ||
import okhttp3.Response | ||
|
||
abstract class OkHttpDavMethodBase { | ||
var response: Response? = null | ||
|
||
fun execute(nextcloudClient: NextcloudClient) { | ||
nextcloudClient.client = nextcloudClient.client | ||
.newBuilder() | ||
.followRedirects(false) | ||
.addInterceptor(BasicAuthInterceptor(nextcloudClient.credentials)) | ||
.build() | ||
|
||
createDavResource(nextcloudClient) | ||
} | ||
|
||
abstract fun createDavResource(nextcloudClient: NextcloudClient) | ||
|
||
open fun statusCode(): Int { | ||
return response?.code ?: OkHttpMethodBase.UNKNOWN_STATUS_CODE | ||
} | ||
|
||
fun releaseConnection() { | ||
response?.body?.close() | ||
} | ||
|
||
fun succeeded(): Boolean { | ||
return response?.isSuccessful ?: false | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
library/src/main/java/com/nextcloud/operations/dav/PropFindMethod.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,59 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Tobias Kaminsky | ||
* Copyright (C) 2022 Tobias Kaminsky | ||
* Copyright (C) 2022 Nextcloud GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package com.nextcloud.operations.dav | ||
|
||
import at.bitfire.dav4jvm.DavResource | ||
import at.bitfire.dav4jvm.DavResponseCallback | ||
import at.bitfire.dav4jvm.Property | ||
import at.bitfire.dav4jvm.Response | ||
import com.nextcloud.common.NextcloudClient | ||
import com.nextcloud.common.OkHttpMethodBase | ||
import okhttp3.HttpUrl.Companion.toHttpUrl | ||
|
||
/** | ||
* Webdav Propfind method that uses OkHttp with new NextcloudClient | ||
*/ | ||
class PropFindMethod( | ||
val uri: String, | ||
val properties: ArrayList<Property.Name>, | ||
private val depth: Int | ||
) : OkHttpDavMethodBase() { | ||
var davResponse: Response? = null | ||
|
||
override fun createDavResource(nextcloudClient: NextcloudClient) { | ||
val httpURL = uri.toHttpUrl() | ||
val davResource = DavResource(nextcloudClient.client, httpURL) | ||
val callback: DavResponseCallback = { response, _ -> | ||
davResponse = response | ||
} | ||
davResource.propfind(depth, *properties.toTypedArray(), callback = callback) | ||
} | ||
|
||
fun davResponse(): Response? { | ||
return davResponse | ||
} | ||
|
||
override fun statusCode(): Int { | ||
return davResponse?.status?.code ?: OkHttpMethodBase.UNKNOWN_STATUS_CODE | ||
} | ||
} |
Oops, something went wrong.