aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/lib/CardDAV/Xml
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/lib/CardDAV/Xml')
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Filter/AddressData.php59
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Filter/ParamFilter.php89
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Filter/PropFilter.php98
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedAddressData.php83
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedCollationSet.php47
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php113
-rw-r--r--vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookQueryReport.php192
7 files changed, 681 insertions, 0 deletions
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Filter/AddressData.php b/vendor/sabre/dav/lib/CardDAV/Xml/Filter/AddressData.php
new file mode 100644
index 000000000..34028db85
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Filter/AddressData.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Filter;
+
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+
+/**
+ * AddressData parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}address-data XML
+ * element, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-10.4
+ *
+ * This element is used in two distinct places, but this one specifically
+ * encodes the address-data element as it appears in the addressbook-query
+ * adressbook-multiget REPORT requests.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class AddressData implements XmlDeserializable {
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $result = [
+ 'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard',
+ 'version' => $reader->getAttribute('version') ?: '3.0',
+ ];
+
+ $reader->next();
+ return $result;
+
+ }
+
+}
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Filter/ParamFilter.php b/vendor/sabre/dav/lib/CardDAV/Xml/Filter/ParamFilter.php
new file mode 100644
index 000000000..9646ae3e6
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Filter/ParamFilter.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Filter;
+
+use Sabre\Xml\Element;
+use Sabre\Xml\Reader;
+use Sabre\DAV\Exception\BadRequest;
+use Sabre\CardDAV\Plugin;
+
+/**
+ * ParamFilter parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}param-filter XML
+ * element, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-10.5.2
+ *
+ * The result will be spit out as an array.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+abstract class ParamFilter implements Element {
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $result = [
+ 'name' => null,
+ 'is-not-defined' => false,
+ 'text-match' => null,
+ ];
+
+ $att = $reader->parseAttributes();
+ $result['name'] = $att['name'];
+
+ $elems = $reader->parseInnerTree();
+
+ if (is_array($elems)) foreach ($elems as $elem) {
+
+ switch ($elem['name']) {
+
+ case '{' . Plugin::NS_CARDDAV . '}is-not-defined' :
+ $result['is-not-defined'] = true;
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}text-match' :
+ $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains';
+
+ if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) {
+ throw new BadRequest('Unknown match-type: ' . $matchType);
+ }
+ $result['text-match'] = [
+ 'negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition'] === 'yes',
+ 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap',
+ 'value' => $elem['value'],
+ 'match-type' => $matchType,
+ ];
+ break;
+
+ }
+
+ }
+
+ return $result;
+
+ }
+
+}
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Filter/PropFilter.php b/vendor/sabre/dav/lib/CardDAV/Xml/Filter/PropFilter.php
new file mode 100644
index 000000000..c162da160
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Filter/PropFilter.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Filter;
+
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+use Sabre\DAV\Exception\BadRequest;
+use Sabre\CardDAV\Plugin;
+
+/**
+ * PropFilter parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}prop-filter XML
+ * element, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-10.5.1
+ *
+ * The result will be spit out as an array.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class PropFilter implements XmlDeserializable {
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $result = [
+ 'name' => null,
+ 'test' => 'anyof',
+ 'is-not-defined' => false,
+ 'param-filters' => [],
+ 'text-matches' => [],
+ ];
+
+ $att = $reader->parseAttributes();
+ $result['name'] = $att['name'];
+
+ if (isset($att['test']) && $att['test'] === 'allof') {
+ $result['test'] = 'allof';
+ }
+
+ $elems = $reader->parseInnerTree();
+
+ if (is_array($elems)) foreach ($elems as $elem) {
+
+ switch ($elem['name']) {
+
+ case '{' . Plugin::NS_CARDDAV . '}param-filter' :
+ $result['param-filters'][] = $elem['value'];
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}is-not-defined' :
+ $result['is-not-defined'] = true;
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}text-match' :
+ $matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains';
+
+ if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) {
+ throw new BadRequest('Unknown match-type: ' . $matchType);
+ }
+ $result['text-matches'][] = [
+ 'negate-condition' => isset($elem['attributes']['negate-condition']) && $elem['attributes']['negate-condition'] === 'yes',
+ 'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap',
+ 'value' => $elem['value'],
+ 'match-type' => $matchType,
+ ];
+ break;
+
+ }
+
+ }
+
+ return $result;
+
+ }
+
+}
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedAddressData.php b/vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedAddressData.php
new file mode 100644
index 000000000..6ff57b6e3
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedAddressData.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Property;
+
+use Sabre\Xml\Writer;
+use Sabre\Xml\XmlSerializable;
+use Sabre\CardDAV\Plugin;
+
+/**
+ * Supported-address-data property
+ *
+ * This property is a representation of the supported-address-data property
+ * in the CardDAV namespace.
+ *
+ * This property is defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-6.2.2
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class SupportedAddressData implements XmlSerializable {
+
+ /**
+ * supported versions
+ *
+ * @var array
+ */
+ protected $supportedData = [];
+
+ /**
+ * Creates the property
+ *
+ * @param array|null $supportedData
+ */
+ function __construct(array $supportedData = null) {
+
+ if (is_null($supportedData)) {
+ $supportedData = [
+ ['contentType' => 'text/vcard', 'version' => '3.0'],
+ ['contentType' => 'text/vcard', 'version' => '4.0'],
+ ['contentType' => 'application/vcard+json', 'version' => '4.0'],
+ ];
+ }
+
+ $this->supportedData = $supportedData;
+
+ }
+
+ /**
+ * The xmlSerialize metod is called during xml writing.
+ *
+ * Use the $writer argument to write its own xml serialization.
+ *
+ * An important note: do _not_ create a parent element. Any element
+ * implementing XmlSerializble should only ever write what's considered
+ * its 'inner xml'.
+ *
+ * The parent of the current element is responsible for writing a
+ * containing element.
+ *
+ * This allows serializers to be re-used for different element names.
+ *
+ * If you are opening new elements, you must also close them again.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ function xmlSerialize(Writer $writer) {
+
+ foreach ($this->supportedData as $supported) {
+ $writer->startElement('{' . Plugin::NS_CARDDAV . '}address-data-type');
+ $writer->writeAttributes([
+ 'content-type' => $supported['contentType'],
+ 'version' => $supported['version']
+ ]);
+ $writer->endElement(); // address-data-type
+ }
+
+ }
+
+}
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedCollationSet.php b/vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedCollationSet.php
new file mode 100644
index 000000000..1fc064900
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Property/SupportedCollationSet.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Property;
+
+use Sabre\Xml\Writer;
+use Sabre\Xml\XmlSerializable;
+
+/**
+ * supported-collation-set property
+ *
+ * This property is a representation of the supported-collation-set property
+ * in the CardDAV namespace.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class SupportedCollationSet implements XmlSerializable {
+
+ /**
+ * The xmlSerialize metod is called during xml writing.
+ *
+ * Use the $writer argument to write its own xml serialization.
+ *
+ * An important note: do _not_ create a parent element. Any element
+ * implementing XmlSerializble should only ever write what's considered
+ * its 'inner xml'.
+ *
+ * The parent of the current element is responsible for writing a
+ * containing element.
+ *
+ * This allows serializers to be re-used for different element names.
+ *
+ * If you are opening new elements, you must also close them again.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ function xmlSerialize(Writer $writer) {
+
+ foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) {
+ $writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll);
+ }
+
+ }
+
+}
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php b/vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php
new file mode 100644
index 000000000..c97c5eb4f
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookMultiGetReport.php
@@ -0,0 +1,113 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Request;
+
+use Sabre\CardDAV\Plugin;
+use Sabre\Uri;
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+
+/**
+ * AddressBookMultiGetReport request parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}addressbook-multiget
+ * REPORT, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-8.7
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class AddressBookMultiGetReport implements XmlDeserializable {
+
+ /**
+ * An array with requested properties.
+ *
+ * @var array
+ */
+ public $properties;
+
+ /**
+ * This is an array with the urls that are being requested.
+ *
+ * @var array
+ */
+ public $hrefs;
+
+ /**
+ * The mimetype of the content that should be returend. Usually
+ * text/vcard.
+ *
+ * @var string
+ */
+ public $contentType = null;
+
+ /**
+ * The version of vcard data that should be returned. Usually 3.0,
+ * referring to vCard 3.0.
+ *
+ * @var string
+ */
+ public $version = null;
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $elems = $reader->parseInnerTree([
+ '{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData',
+ '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
+ ]);
+
+ $newProps = [
+ 'hrefs' => [],
+ 'properties' => []
+ ];
+
+ foreach ($elems as $elem) {
+
+ switch ($elem['name']) {
+
+ case '{DAV:}prop' :
+ $newProps['properties'] = array_keys($elem['value']);
+ if (isset($elem['value']['{' . Plugin::NS_CARDDAV . '}address-data'])) {
+ $newProps += $elem['value']['{' . Plugin::NS_CARDDAV . '}address-data'];
+ }
+ break;
+ case '{DAV:}href' :
+ $newProps['hrefs'][] = Uri\resolve($reader->contextUri, $elem['value']);
+ break;
+
+ }
+
+ }
+
+ $obj = new self();
+ foreach ($newProps as $key => $value) {
+ $obj->$key = $value;
+ }
+ return $obj;
+
+ }
+
+}
diff --git a/vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookQueryReport.php b/vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookQueryReport.php
new file mode 100644
index 000000000..a68ac5800
--- /dev/null
+++ b/vendor/sabre/dav/lib/CardDAV/Xml/Request/AddressBookQueryReport.php
@@ -0,0 +1,192 @@
+<?php
+
+namespace Sabre\CardDAV\Xml\Request;
+
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+use Sabre\DAV\Exception\BadRequest;
+use Sabre\CardDAV\Plugin;
+
+/**
+ * AddressBookQueryReport request parser.
+ *
+ * This class parses the {urn:ietf:params:xml:ns:carddav}addressbook-query
+ * REPORT, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc6352#section-8.6
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class AddressBookQueryReport implements XmlDeserializable {
+
+ /**
+ * An array with requested properties.
+ *
+ * @var array
+ */
+ public $properties;
+
+ /**
+ * List of property/component filters.
+ *
+ * This is an array with filters. Every item is a property filter. Every
+ * property filter has the following keys:
+ * * name - name of the component to filter on
+ * * test - anyof or allof
+ * * is-not-defined - Test for non-existence
+ * * param-filters - A list of parameter filters on the property
+ * * text-matches - A list of text values the filter needs to match
+ *
+ * Each param-filter has the following keys:
+ * * name - name of the parameter
+ * * is-not-defined - Test for non-existence
+ * * text-match - Match the parameter value
+ *
+ * Each text-match in property filters, and the single text-match in
+ * param-filters have the following keys:
+ *
+ * * value - value to match
+ * * match-type - contains, starts-with, ends-with, equals
+ * * negate-condition - Do the opposite match
+ * * collation - Usually i;unicode-casemap
+ *
+ * @var array
+ */
+ public $filters;
+
+ /**
+ * The number of results the client wants
+ *
+ * null means it wasn't specified, which in most cases means 'all results'.
+ *
+ * @var int|null
+ */
+ public $limit;
+
+ /**
+ * Either 'anyof' or 'allof'
+ *
+ * @var string
+ */
+ public $test;
+
+ /**
+ * The mimetype of the content that should be returend. Usually
+ * text/vcard.
+ *
+ * @var string
+ */
+ public $contentType = null;
+
+ /**
+ * The version of vcard data that should be returned. Usually 3.0,
+ * referring to vCard 3.0.
+ *
+ * @var string
+ */
+ public $version = null;
+
+
+ /**
+ * The deserialize method is called during xml parsing.
+ *
+ * This method is called statictly, this is because in theory this method
+ * may be used as a type of constructor, or factory method.
+ *
+ * Often you want to return an instance of the current class, but you are
+ * free to return other data as well.
+ *
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
+ *
+ * If you just want to skip parsing for this element altogether, you can
+ * just call $reader->next();
+ *
+ * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
+ * the next element.
+ *
+ * @param Reader $reader
+ * @return mixed
+ */
+ static function xmlDeserialize(Reader $reader) {
+
+ $elems = (array)$reader->parseInnerTree([
+ '{urn:ietf:params:xml:ns:carddav}prop-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\PropFilter',
+ '{urn:ietf:params:xml:ns:carddav}param-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\ParamFilter',
+ '{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData',
+ '{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
+ ]);
+
+ $newProps = [
+ 'filters' => null,
+ 'properties' => [],
+ 'test' => 'anyof',
+ 'limit' => null,
+ ];
+
+ if (!is_array($elems)) $elems = [];
+
+ foreach ($elems as $elem) {
+
+ switch ($elem['name']) {
+
+ case '{DAV:}prop' :
+ $newProps['properties'] = array_keys($elem['value']);
+ if (isset($elem['value']['{' . Plugin::NS_CARDDAV . '}address-data'])) {
+ $newProps += $elem['value']['{' . Plugin::NS_CARDDAV . '}address-data'];
+ }
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}filter' :
+
+ if (!is_null($newProps['filters'])) {
+ throw new BadRequest('You can only include 1 {' . Plugin::NS_CARDDAV . '}filter element');
+ }
+ if (isset($elem['attributes']['test'])) {
+ $newProps['test'] = $elem['attributes']['test'];
+ if ($newProps['test'] !== 'allof' && $newProps['test'] !== 'anyof') {
+ throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"');
+ }
+ }
+
+ $newProps['filters'] = [];
+ foreach ((array)$elem['value'] as $subElem) {
+ if ($subElem['name'] === '{' . Plugin::NS_CARDDAV . '}prop-filter') {
+ $newProps['filters'][] = $subElem['value'];
+ }
+ }
+ break;
+ case '{' . Plugin::NS_CARDDAV . '}limit' :
+ foreach ($elem['value'] as $child) {
+ if ($child['name'] === '{' . Plugin::NS_CARDDAV . '}nresults') {
+ $newProps['limit'] = (int)$child['value'];
+ }
+ }
+ break;
+
+ }
+
+ }
+
+ if (is_null($newProps['filters'])) {
+ /*
+ * We are supposed to throw this error, but KDE sometimes does not
+ * include the filter element, and we need to treat it as if no
+ * filters are supplied
+ */
+ //throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request');
+ $newProps['filters'] = [];
+
+ }
+
+ $obj = new self();
+ foreach ($newProps as $key => $value) {
+ $obj->$key = $value;
+ }
+
+ return $obj;
+
+ }
+
+}