Commit e3db2aa9 authored by Ricki Hirner's avatar Ricki Hirner 🐑
Browse files

WIP

parent 0e99ffde
Pipeline #161688091 failed with stages
in 2 minutes and 7 seconds
......@@ -6,8 +6,10 @@
package at.bitfire.dav4jvm
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.exception.DavException
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.GetETag
import okhttp3.HttpUrl
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
......@@ -26,6 +28,10 @@ class DavAddressBook @JvmOverloads constructor(
companion object {
val MIME_VCARD3_UTF8 = "text/vcard;charset=utf-8".toMediaType()
val MIME_VCARD4 = "text/vcard;version=4.0".toMediaType()
val ADDRESSBOOK_QUERY = Property.Name(XmlUtils.NS_CARDDAV, "addressbook-query")
val ADDRESSBOOK_MULTIGET = Property.Name(XmlUtils.NS_CARDDAV, "addressbook-multiget")
val FILTER = Property.Name(XmlUtils.NS_CARDDAV, "filter")
}
/**
......@@ -52,14 +58,12 @@ class DavAddressBook @JvmOverloads constructor(
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.startTag(XmlUtils.NS_CARDDAV, "addressbook-query")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
serializer.startTag(XmlUtils.NS_WEBDAV, "getetag")
serializer.endTag(XmlUtils.NS_WEBDAV, "getetag")
serializer.endTag(XmlUtils.NS_WEBDAV, "prop")
serializer.startTag(XmlUtils.NS_CARDDAV, "filter")
serializer.endTag(XmlUtils.NS_CARDDAV, "filter")
serializer.endTag(XmlUtils.NS_CARDDAV, "addressbook-query")
serializer.insertTag(ADDRESSBOOK_QUERY) {
insertTag(PROP) {
insertTag(GetETag.NAME)
}
insertTag(FILTER)
}
serializer.endDocument()
followRedirects {
......@@ -99,6 +103,7 @@ class DavAddressBook @JvmOverloads constructor(
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.insertTag()
serializer.startTag(XmlUtils.NS_CARDDAV, "addressbook-multiget")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
serializer.startTag(XmlUtils.NS_WEBDAV, "getcontenttype") // to determine the character set
......
......@@ -6,6 +6,7 @@
package at.bitfire.dav4jvm
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.exception.DavException
import at.bitfire.dav4jvm.exception.HttpException
import at.bitfire.dav4jvm.property.CalendarData
......@@ -34,6 +35,16 @@ class DavCalendar @JvmOverloads constructor(
val MIME_ICALENDAR = "text/calendar".toMediaType()
val MIME_ICALENDAR_UTF8 = "text/calendar;charset=utf-8".toMediaType()
val CALENDAR_QUERY = Property.Name(XmlUtils.NS_CALDAV, "calendar-query")
val CALENDAR_MULTIGET = Property.Name(XmlUtils.NS_CALDAV, "calendar-multiget")
val FILTER = Property.Name(XmlUtils.NS_CALDAV, "filter")
val COMP_FILTER = Property.Name(XmlUtils.NS_CALDAV, "comp-filter")
const val COMP_FILTER_NAME = "name"
val TIME_RANGE = Property.Name(XmlUtils.NS_CALDAV, "time-range")
const val TIME_RANGE_START = "start"
const val TIME_RANGE_END = "end"
private val timeFormatUTC = SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'", Locale.US)
init {
timeFormatUTC.timeZone = TimeZone.getTimeZone("UTC")
......@@ -74,28 +85,27 @@ class DavCalendar @JvmOverloads constructor(
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.startTag(XmlUtils.NS_CALDAV, "calendar-query")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
serializer.startTag(XmlUtils.NS_WEBDAV, "getetag")
serializer.endTag(XmlUtils.NS_WEBDAV, "getetag")
serializer.endTag(XmlUtils.NS_WEBDAV, "prop")
serializer.startTag(XmlUtils.NS_CALDAV, "filter")
serializer.startTag(XmlUtils.NS_CALDAV, "comp-filter")
serializer.attribute(null, "name", "VCALENDAR")
serializer.startTag(XmlUtils.NS_CALDAV, "comp-filter")
serializer.attribute(null, "name", component)
if (start != null || end != null) {
serializer.startTag(XmlUtils.NS_CALDAV, "time-range")
if (start != null)
serializer.attribute(null, "start", timeFormatUTC.format(start))
if (end != null)
serializer.attribute(null, "end", timeFormatUTC.format(end))
serializer.endTag(XmlUtils.NS_CALDAV, "time-range")
serializer.insertTag(CALENDAR_QUERY) {
insertTag(PROP) {
insertTag(GetETag.NAME)
}
insertTag(FILTER) {
insertTag(COMP_FILTER) {
attribute(null, COMP_FILTER_NAME, "VCALENDAR")
insertTag(COMP_FILTER) {
attribute(null, COMP_FILTER_NAME, component)
if (start != null || end != null) {
insertTag(TIME_RANGE) {
if (start != null)
attribute(null, TIME_RANGE_START, timeFormatUTC.format(start))
if (end != null)
attribute(null, TIME_RANGE_END, timeFormatUTC.format(end))
}
}
}
serializer.endTag(XmlUtils.NS_CALDAV, "comp-filter")
serializer.endTag(XmlUtils.NS_CALDAV, "comp-filter")
serializer.endTag(XmlUtils.NS_CALDAV, "filter")
serializer.endTag(XmlUtils.NS_CALDAV, "calendar-query")
}
}
}
serializer.endDocument()
followRedirects {
......@@ -124,11 +134,6 @@ class DavCalendar @JvmOverloads constructor(
* @throws DavException on WebDAV error
*/
fun multiget(urls: List<HttpUrl>, callback: DavResponseCallback): List<Property> {
fun XmlSerializer.emptyTag(propertyName: Property.Name) {
startTag(propertyName.namespace, propertyName.name)
endTag(propertyName.namespace, propertyName.name)
}
/* <!ELEMENT calendar-multiget ((DAV:allprop |
DAV:propname |
DAV:prop)?, DAV:href+)>
......@@ -139,19 +144,18 @@ class DavCalendar @JvmOverloads constructor(
serializer.startDocument("UTF-8", null)
serializer.setPrefix("", XmlUtils.NS_WEBDAV)
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.startTag(XmlUtils.NS_CALDAV, "calendar-multiget")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
serializer.emptyTag(GetContentType.NAME) // to determine the character set
serializer.emptyTag(GetETag.NAME)
serializer.emptyTag(ScheduleTag.NAME)
serializer.emptyTag(CalendarData.NAME)
serializer.endTag(XmlUtils.NS_WEBDAV, "prop")
for (url in urls) {
serializer.startTag(XmlUtils.NS_WEBDAV, "href")
serializer.text(url.encodedPath)
serializer.endTag(XmlUtils.NS_WEBDAV, "href")
serializer.insertTag(CALENDAR_MULTIGET) {
insertTag(PROP) {
insertTag(GetContentType.NAME) // to determine the character set
insertTag(GetETag.NAME)
insertTag(ScheduleTag.NAME)
insertTag(CalendarData.NAME)
}
serializer.endTag(XmlUtils.NS_CALDAV, "calendar-multiget")
for (url in urls)
insertTag(HREF) {
serializer.text(url.encodedPath)
}
}
serializer.endDocument()
followRedirects {
......
......@@ -6,6 +6,7 @@
package at.bitfire.dav4jvm
import at.bitfire.dav4jvm.XmlUtils.insertTag
import at.bitfire.dav4jvm.exception.*
import at.bitfire.dav4jvm.property.SyncToken
import okhttp3.*
......@@ -41,7 +42,12 @@ open class DavResource @JvmOverloads constructor(
companion object {
const val MAX_REDIRECTS = 5
val MIME_XML = "application/xml; charset=utf-8".toMediaType()
val PROPFIND = Property.Name(XmlUtils.NS_WEBDAV, "propfind")
val PROP = Property.Name(XmlUtils.NS_WEBDAV, "prop")
val HREF = Property.Name(XmlUtils.NS_WEBDAV, "href")
}
/**
......@@ -314,14 +320,12 @@ open class DavResource @JvmOverloads constructor(
serializer.setPrefix("CAL", XmlUtils.NS_CALDAV)
serializer.setPrefix("CARD", XmlUtils.NS_CARDDAV)
serializer.startDocument("UTF-8", null)
serializer.startTag(XmlUtils.NS_WEBDAV, "propfind")
serializer.startTag(XmlUtils.NS_WEBDAV, "prop")
for (prop in reqProp) {
serializer.startTag(prop.namespace, prop.name)
serializer.endTag(prop.namespace, prop.name)
serializer.insertTag(PROPFIND) {
insertTag(PROP) {
for (prop in reqProp)
insertTag(prop)
}
}
serializer.endTag(XmlUtils.NS_WEBDAV, "prop")
serializer.endTag(XmlUtils.NS_WEBDAV, "propfind")
serializer.endDocument()
followRedirects {
......@@ -386,7 +390,7 @@ open class DavResource @JvmOverloads constructor(
for (attempt in 1..MAX_REDIRECTS) {
response = sendRequest()
if (response.isRedirect)
// handle 3xx Redirection
// handle 3xx Redirection
response.use {
val target = it.header("Location")?.let { location.resolve(it) }
if (target != null) {
......
......@@ -9,6 +9,7 @@ package at.bitfire.dav4jvm
import org.xmlpull.v1.XmlPullParser
import org.xmlpull.v1.XmlPullParserException
import org.xmlpull.v1.XmlPullParserFactory
import org.xmlpull.v1.XmlSerializer
import java.io.IOException
object XmlUtils {
......@@ -72,4 +73,11 @@ object XmlUtils {
}
}
fun XmlSerializer.insertTag(name: Property.Name, contentGenerator: XmlSerializer.() -> Unit = {}) {
startTag(name.namespace, name.name)
contentGenerator(this)
endTag(name.namespace, name.name)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment