@@ -27,58 +27,58 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class CalendarData implements XmlDeserializable { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * The deserialize method is called during xml parsing. |
|
| 32 | - * |
|
| 33 | - * This method is called statictly, this is because in theory this method |
|
| 34 | - * may be used as a type of constructor, or factory method. |
|
| 35 | - * |
|
| 36 | - * Often you want to return an instance of the current class, but you are |
|
| 37 | - * free to return other data as well. |
|
| 38 | - * |
|
| 39 | - * You are responsible for advancing the reader to the next element. Not |
|
| 40 | - * doing anything will result in a never-ending loop. |
|
| 41 | - * |
|
| 42 | - * If you just want to skip parsing for this element altogether, you can |
|
| 43 | - * just call $reader->next(); |
|
| 44 | - * |
|
| 45 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 46 | - * the next element. |
|
| 47 | - * |
|
| 48 | - * @param Reader $reader |
|
| 49 | - * @return mixed |
|
| 50 | - */ |
|
| 51 | - static function xmlDeserialize(Reader $reader) { |
|
| 30 | + /** |
|
| 31 | + * The deserialize method is called during xml parsing. |
|
| 32 | + * |
|
| 33 | + * This method is called statictly, this is because in theory this method |
|
| 34 | + * may be used as a type of constructor, or factory method. |
|
| 35 | + * |
|
| 36 | + * Often you want to return an instance of the current class, but you are |
|
| 37 | + * free to return other data as well. |
|
| 38 | + * |
|
| 39 | + * You are responsible for advancing the reader to the next element. Not |
|
| 40 | + * doing anything will result in a never-ending loop. |
|
| 41 | + * |
|
| 42 | + * If you just want to skip parsing for this element altogether, you can |
|
| 43 | + * just call $reader->next(); |
|
| 44 | + * |
|
| 45 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 46 | + * the next element. |
|
| 47 | + * |
|
| 48 | + * @param Reader $reader |
|
| 49 | + * @return mixed |
|
| 50 | + */ |
|
| 51 | + static function xmlDeserialize(Reader $reader) { |
|
| 52 | 52 | |
| 53 | - $result = [ |
|
| 54 | - 'contentType' => $reader->getAttribute('content-type') ?: 'text/calendar', |
|
| 55 | - 'version' => $reader->getAttribute('version') ?: '2.0', |
|
| 56 | - ]; |
|
| 53 | + $result = [ |
|
| 54 | + 'contentType' => $reader->getAttribute('content-type') ?: 'text/calendar', |
|
| 55 | + 'version' => $reader->getAttribute('version') ?: '2.0', |
|
| 56 | + ]; |
|
| 57 | 57 | |
| 58 | - $elems = (array)$reader->parseInnerTree(); |
|
| 59 | - foreach ($elems as $elem) { |
|
| 58 | + $elems = (array)$reader->parseInnerTree(); |
|
| 59 | + foreach ($elems as $elem) { |
|
| 60 | 60 | |
| 61 | - switch ($elem['name']) { |
|
| 62 | - case '{' . Plugin::NS_CALDAV . '}expand' : |
|
| 61 | + switch ($elem['name']) { |
|
| 62 | + case '{' . Plugin::NS_CALDAV . '}expand' : |
|
| 63 | 63 | |
| 64 | - $result['expand'] = [ |
|
| 65 | - 'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, |
|
| 66 | - 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null, |
|
| 67 | - ]; |
|
| 64 | + $result['expand'] = [ |
|
| 65 | + 'start' => isset($elem['attributes']['start']) ? DateTimeParser::parseDateTime($elem['attributes']['start']) : null, |
|
| 66 | + 'end' => isset($elem['attributes']['end']) ? DateTimeParser::parseDateTime($elem['attributes']['end']) : null, |
|
| 67 | + ]; |
|
| 68 | 68 | |
| 69 | - if (!$result['expand']['start'] || !$result['expand']['end']) { |
|
| 70 | - throw new BadRequest('The "start" and "end" attributes are required when expanding calendar-data'); |
|
| 71 | - } |
|
| 72 | - if ($result['expand']['end'] <= $result['expand']['start']) { |
|
| 73 | - throw new BadRequest('The end-date must be larger than the start-date when expanding calendar-data'); |
|
| 74 | - } |
|
| 75 | - break; |
|
| 76 | - } |
|
| 69 | + if (!$result['expand']['start'] || !$result['expand']['end']) { |
|
| 70 | + throw new BadRequest('The "start" and "end" attributes are required when expanding calendar-data'); |
|
| 71 | + } |
|
| 72 | + if ($result['expand']['end'] <= $result['expand']['start']) { |
|
| 73 | + throw new BadRequest('The end-date must be larger than the start-date when expanding calendar-data'); |
|
| 74 | + } |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return $result; |
|
| 80 | + return $result; |
|
| 81 | 81 | |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | 'version' => $reader->getAttribute('version') ?: '2.0', |
| 56 | 56 | ]; |
| 57 | 57 | |
| 58 | - $elems = (array)$reader->parseInnerTree(); |
|
| 58 | + $elems = (array) $reader->parseInnerTree(); |
|
| 59 | 59 | foreach ($elems as $elem) { |
| 60 | 60 | |
| 61 | 61 | switch ($elem['name']) { |
@@ -192,8 +192,9 @@ |
||
| 192 | 192 | |
| 193 | 193 | foreach ($reader->parseInnerTree() as $elem) { |
| 194 | 194 | |
| 195 | - if ($elem['name'] !== $cs . 'user') |
|
| 196 | - continue; |
|
| 195 | + if ($elem['name'] !== $cs . 'user') { |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 197 | 198 | |
| 198 | 199 | $user = [ |
| 199 | 200 | 'href' => null, |
@@ -22,231 +22,231 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Invite implements Element { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * The list of users a calendar has been shared to. |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $users; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * The organizer contains information about the person who shared the |
|
| 34 | - * object. |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $organizer; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Creates the property. |
|
| 42 | - * |
|
| 43 | - * Users is an array. Each element of the array has the following |
|
| 44 | - * properties: |
|
| 45 | - * |
|
| 46 | - * * href - Often a mailto: address |
|
| 47 | - * * commonName - Optional, for example a first and lastname for a user. |
|
| 48 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 49 | - * * readOnly - true or false |
|
| 50 | - * * summary - Optional, description of the share |
|
| 51 | - * |
|
| 52 | - * The organizer key is optional to specify. It's only useful when a |
|
| 53 | - * 'sharee' requests the sharing information. |
|
| 54 | - * |
|
| 55 | - * The organizer may have the following properties: |
|
| 56 | - * * href - Often a mailto: address. |
|
| 57 | - * * commonName - Optional human-readable name. |
|
| 58 | - * * firstName - Optional first name. |
|
| 59 | - * * lastName - Optional last name. |
|
| 60 | - * |
|
| 61 | - * If you wonder why these two structures are so different, I guess a |
|
| 62 | - * valid answer is that the current spec is still a draft. |
|
| 63 | - * |
|
| 64 | - * @param array $users |
|
| 65 | - */ |
|
| 66 | - public function __construct(array $users, array $organizer = null) { |
|
| 67 | - |
|
| 68 | - $this->users = $users; |
|
| 69 | - $this->organizer = $organizer; |
|
| 70 | - |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Returns the list of users, as it was passed to the constructor. |
|
| 75 | - * |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - public function getValue() { |
|
| 79 | - |
|
| 80 | - return $this->users; |
|
| 81 | - |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The xmlSerialize metod is called during xml writing. |
|
| 86 | - * |
|
| 87 | - * Use the $writer argument to write its own xml serialization. |
|
| 88 | - * |
|
| 89 | - * An important note: do _not_ create a parent element. Any element |
|
| 90 | - * implementing XmlSerializble should only ever write what's considered |
|
| 91 | - * its 'inner xml'. |
|
| 92 | - * |
|
| 93 | - * The parent of the current element is responsible for writing a |
|
| 94 | - * containing element. |
|
| 95 | - * |
|
| 96 | - * This allows serializers to be re-used for different element names. |
|
| 97 | - * |
|
| 98 | - * If you are opening new elements, you must also close them again. |
|
| 99 | - * |
|
| 100 | - * @param Writer $writer |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - public function xmlSerialize(Writer $writer) { |
|
| 104 | - |
|
| 105 | - $cs = '{' . Plugin::NS_CALENDARSERVER . '}'; |
|
| 106 | - |
|
| 107 | - if (!is_null($this->organizer)) { |
|
| 108 | - |
|
| 109 | - $writer->startElement($cs . 'organizer'); |
|
| 110 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 111 | - |
|
| 112 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 113 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 114 | - } |
|
| 115 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 116 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 117 | - } |
|
| 118 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 119 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 120 | - } |
|
| 121 | - $writer->endElement(); // organizer |
|
| 122 | - |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - foreach ($this->users as $user) { |
|
| 126 | - |
|
| 127 | - $writer->startElement($cs . 'user'); |
|
| 128 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
| 129 | - if (isset($user['commonName']) && $user['commonName']) { |
|
| 130 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 131 | - } |
|
| 132 | - switch ($user['status']) { |
|
| 133 | - |
|
| 134 | - case SharingPlugin::STATUS_ACCEPTED : |
|
| 135 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 136 | - break; |
|
| 137 | - case SharingPlugin::STATUS_DECLINED : |
|
| 138 | - $writer->writeElement($cs . 'invite-declined'); |
|
| 139 | - break; |
|
| 140 | - case SharingPlugin::STATUS_NORESPONSE : |
|
| 141 | - $writer->writeElement($cs . 'invite-noresponse'); |
|
| 142 | - break; |
|
| 143 | - case SharingPlugin::STATUS_INVALID : |
|
| 144 | - $writer->writeElement($cs . 'invite-invalid'); |
|
| 145 | - break; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $writer->startElement($cs . 'access'); |
|
| 149 | - if ($user['readOnly']) { |
|
| 150 | - $writer->writeElement($cs . 'read'); |
|
| 151 | - } else { |
|
| 152 | - $writer->writeElement($cs . 'read-write'); |
|
| 153 | - } |
|
| 154 | - $writer->endElement(); // access |
|
| 155 | - |
|
| 156 | - if (isset($user['summary']) && $user['summary']) { |
|
| 157 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $writer->endElement(); //user |
|
| 161 | - |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * The deserialize method is called during xml parsing. |
|
| 168 | - * |
|
| 169 | - * This method is called statictly, this is because in theory this method |
|
| 170 | - * may be used as a type of constructor, or factory method. |
|
| 171 | - * |
|
| 172 | - * Often you want to return an instance of the current class, but you are |
|
| 173 | - * free to return other data as well. |
|
| 174 | - * |
|
| 175 | - * You are responsible for advancing the reader to the next element. Not |
|
| 176 | - * doing anything will result in a never-ending loop. |
|
| 177 | - * |
|
| 178 | - * If you just want to skip parsing for this element altogether, you can |
|
| 179 | - * just call $reader->next(); |
|
| 180 | - * |
|
| 181 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 182 | - * the next element. |
|
| 183 | - * |
|
| 184 | - * @param Reader $reader |
|
| 185 | - * @return mixed |
|
| 186 | - */ |
|
| 187 | - static function xmlDeserialize(Reader $reader) { |
|
| 188 | - |
|
| 189 | - $cs = '{' . Plugin::NS_CALENDARSERVER . '}'; |
|
| 190 | - |
|
| 191 | - $users = []; |
|
| 192 | - |
|
| 193 | - foreach ($reader->parseInnerTree() as $elem) { |
|
| 194 | - |
|
| 195 | - if ($elem['name'] !== $cs . 'user') |
|
| 196 | - continue; |
|
| 197 | - |
|
| 198 | - $user = [ |
|
| 199 | - 'href' => null, |
|
| 200 | - 'commonName' => null, |
|
| 201 | - 'readOnly' => null, |
|
| 202 | - 'summary' => null, |
|
| 203 | - 'status' => null, |
|
| 204 | - ]; |
|
| 205 | - |
|
| 206 | - foreach ($elem['value'] as $userElem) { |
|
| 207 | - |
|
| 208 | - switch ($userElem['name']) { |
|
| 209 | - case $cs . 'invite-accepted' : |
|
| 210 | - $user['status'] = SharingPlugin::STATUS_ACCEPTED; |
|
| 211 | - break; |
|
| 212 | - case $cs . 'invite-declined' : |
|
| 213 | - $user['status'] = SharingPlugin::STATUS_DECLINED; |
|
| 214 | - break; |
|
| 215 | - case $cs . 'invite-noresponse' : |
|
| 216 | - $user['status'] = SharingPlugin::STATUS_NORESPONSE; |
|
| 217 | - break; |
|
| 218 | - case $cs . 'invite-invalid' : |
|
| 219 | - $user['status'] = SharingPlugin::STATUS_INVALID; |
|
| 220 | - break; |
|
| 221 | - case '{DAV:}href' : |
|
| 222 | - $user['href'] = $userElem['value']; |
|
| 223 | - break; |
|
| 224 | - case $cs . 'common-name' : |
|
| 225 | - $user['commonName'] = $userElem['value']; |
|
| 226 | - break; |
|
| 227 | - case $cs . 'access' : |
|
| 228 | - foreach ($userElem['value'] as $accessHref) { |
|
| 229 | - if ($accessHref['name'] === $cs . 'read') { |
|
| 230 | - $user['readOnly'] = true; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - break; |
|
| 234 | - case $cs . 'summary' : |
|
| 235 | - $user['summary'] = $userElem['value']; |
|
| 236 | - break; |
|
| 237 | - |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - if (!$user['status']) { |
|
| 242 | - throw new \InvalidArgumentException('Every user must have one of cs:invite-accepted, cs:invite-declined, cs:invite-noresponse or cs:invite-invalid'); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - $users[] = $user; |
|
| 246 | - |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return new self($users); |
|
| 250 | - |
|
| 251 | - } |
|
| 25 | + /** |
|
| 26 | + * The list of users a calendar has been shared to. |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $users; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * The organizer contains information about the person who shared the |
|
| 34 | + * object. |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $organizer; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Creates the property. |
|
| 42 | + * |
|
| 43 | + * Users is an array. Each element of the array has the following |
|
| 44 | + * properties: |
|
| 45 | + * |
|
| 46 | + * * href - Often a mailto: address |
|
| 47 | + * * commonName - Optional, for example a first and lastname for a user. |
|
| 48 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 49 | + * * readOnly - true or false |
|
| 50 | + * * summary - Optional, description of the share |
|
| 51 | + * |
|
| 52 | + * The organizer key is optional to specify. It's only useful when a |
|
| 53 | + * 'sharee' requests the sharing information. |
|
| 54 | + * |
|
| 55 | + * The organizer may have the following properties: |
|
| 56 | + * * href - Often a mailto: address. |
|
| 57 | + * * commonName - Optional human-readable name. |
|
| 58 | + * * firstName - Optional first name. |
|
| 59 | + * * lastName - Optional last name. |
|
| 60 | + * |
|
| 61 | + * If you wonder why these two structures are so different, I guess a |
|
| 62 | + * valid answer is that the current spec is still a draft. |
|
| 63 | + * |
|
| 64 | + * @param array $users |
|
| 65 | + */ |
|
| 66 | + public function __construct(array $users, array $organizer = null) { |
|
| 67 | + |
|
| 68 | + $this->users = $users; |
|
| 69 | + $this->organizer = $organizer; |
|
| 70 | + |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Returns the list of users, as it was passed to the constructor. |
|
| 75 | + * |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + public function getValue() { |
|
| 79 | + |
|
| 80 | + return $this->users; |
|
| 81 | + |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The xmlSerialize metod is called during xml writing. |
|
| 86 | + * |
|
| 87 | + * Use the $writer argument to write its own xml serialization. |
|
| 88 | + * |
|
| 89 | + * An important note: do _not_ create a parent element. Any element |
|
| 90 | + * implementing XmlSerializble should only ever write what's considered |
|
| 91 | + * its 'inner xml'. |
|
| 92 | + * |
|
| 93 | + * The parent of the current element is responsible for writing a |
|
| 94 | + * containing element. |
|
| 95 | + * |
|
| 96 | + * This allows serializers to be re-used for different element names. |
|
| 97 | + * |
|
| 98 | + * If you are opening new elements, you must also close them again. |
|
| 99 | + * |
|
| 100 | + * @param Writer $writer |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + public function xmlSerialize(Writer $writer) { |
|
| 104 | + |
|
| 105 | + $cs = '{' . Plugin::NS_CALENDARSERVER . '}'; |
|
| 106 | + |
|
| 107 | + if (!is_null($this->organizer)) { |
|
| 108 | + |
|
| 109 | + $writer->startElement($cs . 'organizer'); |
|
| 110 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 111 | + |
|
| 112 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 113 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 114 | + } |
|
| 115 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 116 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 117 | + } |
|
| 118 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 119 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 120 | + } |
|
| 121 | + $writer->endElement(); // organizer |
|
| 122 | + |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + foreach ($this->users as $user) { |
|
| 126 | + |
|
| 127 | + $writer->startElement($cs . 'user'); |
|
| 128 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
| 129 | + if (isset($user['commonName']) && $user['commonName']) { |
|
| 130 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 131 | + } |
|
| 132 | + switch ($user['status']) { |
|
| 133 | + |
|
| 134 | + case SharingPlugin::STATUS_ACCEPTED : |
|
| 135 | + $writer->writeElement($cs . 'invite-accepted'); |
|
| 136 | + break; |
|
| 137 | + case SharingPlugin::STATUS_DECLINED : |
|
| 138 | + $writer->writeElement($cs . 'invite-declined'); |
|
| 139 | + break; |
|
| 140 | + case SharingPlugin::STATUS_NORESPONSE : |
|
| 141 | + $writer->writeElement($cs . 'invite-noresponse'); |
|
| 142 | + break; |
|
| 143 | + case SharingPlugin::STATUS_INVALID : |
|
| 144 | + $writer->writeElement($cs . 'invite-invalid'); |
|
| 145 | + break; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $writer->startElement($cs . 'access'); |
|
| 149 | + if ($user['readOnly']) { |
|
| 150 | + $writer->writeElement($cs . 'read'); |
|
| 151 | + } else { |
|
| 152 | + $writer->writeElement($cs . 'read-write'); |
|
| 153 | + } |
|
| 154 | + $writer->endElement(); // access |
|
| 155 | + |
|
| 156 | + if (isset($user['summary']) && $user['summary']) { |
|
| 157 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $writer->endElement(); //user |
|
| 161 | + |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * The deserialize method is called during xml parsing. |
|
| 168 | + * |
|
| 169 | + * This method is called statictly, this is because in theory this method |
|
| 170 | + * may be used as a type of constructor, or factory method. |
|
| 171 | + * |
|
| 172 | + * Often you want to return an instance of the current class, but you are |
|
| 173 | + * free to return other data as well. |
|
| 174 | + * |
|
| 175 | + * You are responsible for advancing the reader to the next element. Not |
|
| 176 | + * doing anything will result in a never-ending loop. |
|
| 177 | + * |
|
| 178 | + * If you just want to skip parsing for this element altogether, you can |
|
| 179 | + * just call $reader->next(); |
|
| 180 | + * |
|
| 181 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 182 | + * the next element. |
|
| 183 | + * |
|
| 184 | + * @param Reader $reader |
|
| 185 | + * @return mixed |
|
| 186 | + */ |
|
| 187 | + static function xmlDeserialize(Reader $reader) { |
|
| 188 | + |
|
| 189 | + $cs = '{' . Plugin::NS_CALENDARSERVER . '}'; |
|
| 190 | + |
|
| 191 | + $users = []; |
|
| 192 | + |
|
| 193 | + foreach ($reader->parseInnerTree() as $elem) { |
|
| 194 | + |
|
| 195 | + if ($elem['name'] !== $cs . 'user') |
|
| 196 | + continue; |
|
| 197 | + |
|
| 198 | + $user = [ |
|
| 199 | + 'href' => null, |
|
| 200 | + 'commonName' => null, |
|
| 201 | + 'readOnly' => null, |
|
| 202 | + 'summary' => null, |
|
| 203 | + 'status' => null, |
|
| 204 | + ]; |
|
| 205 | + |
|
| 206 | + foreach ($elem['value'] as $userElem) { |
|
| 207 | + |
|
| 208 | + switch ($userElem['name']) { |
|
| 209 | + case $cs . 'invite-accepted' : |
|
| 210 | + $user['status'] = SharingPlugin::STATUS_ACCEPTED; |
|
| 211 | + break; |
|
| 212 | + case $cs . 'invite-declined' : |
|
| 213 | + $user['status'] = SharingPlugin::STATUS_DECLINED; |
|
| 214 | + break; |
|
| 215 | + case $cs . 'invite-noresponse' : |
|
| 216 | + $user['status'] = SharingPlugin::STATUS_NORESPONSE; |
|
| 217 | + break; |
|
| 218 | + case $cs . 'invite-invalid' : |
|
| 219 | + $user['status'] = SharingPlugin::STATUS_INVALID; |
|
| 220 | + break; |
|
| 221 | + case '{DAV:}href' : |
|
| 222 | + $user['href'] = $userElem['value']; |
|
| 223 | + break; |
|
| 224 | + case $cs . 'common-name' : |
|
| 225 | + $user['commonName'] = $userElem['value']; |
|
| 226 | + break; |
|
| 227 | + case $cs . 'access' : |
|
| 228 | + foreach ($userElem['value'] as $accessHref) { |
|
| 229 | + if ($accessHref['name'] === $cs . 'read') { |
|
| 230 | + $user['readOnly'] = true; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + break; |
|
| 234 | + case $cs . 'summary' : |
|
| 235 | + $user['summary'] = $userElem['value']; |
|
| 236 | + break; |
|
| 237 | + |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + if (!$user['status']) { |
|
| 242 | + throw new \InvalidArgumentException('Every user must have one of cs:invite-accepted, cs:invite-declined, cs:invite-noresponse or cs:invite-invalid'); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + $users[] = $user; |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return new self($users); |
|
| 250 | + |
|
| 251 | + } |
|
| 252 | 252 | } |
@@ -112,7 +112,7 @@ |
||
| 112 | 112 | |
| 113 | 113 | $components = []; |
| 114 | 114 | |
| 115 | - foreach ((array)$elems as $elem) { |
|
| 115 | + foreach ((array) $elems as $elem) { |
|
| 116 | 116 | if ($elem['name'] === '{' . Plugin::NS_CALDAV . '}comp') { |
| 117 | 117 | $components[] = $elem['attributes']['name']; |
| 118 | 118 | } |
@@ -23,107 +23,107 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class SupportedCalendarComponentSet implements Element { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * List of supported components. |
|
| 28 | - * |
|
| 29 | - * This array will contain values such as VEVENT, VTODO and VJOURNAL. |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $components = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Creates the property. |
|
| 37 | - * |
|
| 38 | - * @param array $components |
|
| 39 | - */ |
|
| 40 | - public function __construct(array $components) { |
|
| 41 | - |
|
| 42 | - $this->components = $components; |
|
| 43 | - |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Returns the list of supported components |
|
| 48 | - * |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function getValue() { |
|
| 52 | - |
|
| 53 | - return $this->components; |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * The xmlSerialize metod is called during xml writing. |
|
| 59 | - * |
|
| 60 | - * Use the $writer argument to write its own xml serialization. |
|
| 61 | - * |
|
| 62 | - * An important note: do _not_ create a parent element. Any element |
|
| 63 | - * implementing XmlSerializble should only ever write what's considered |
|
| 64 | - * its 'inner xml'. |
|
| 65 | - * |
|
| 66 | - * The parent of the current element is responsible for writing a |
|
| 67 | - * containing element. |
|
| 68 | - * |
|
| 69 | - * This allows serializers to be re-used for different element names. |
|
| 70 | - * |
|
| 71 | - * If you are opening new elements, you must also close them again. |
|
| 72 | - * |
|
| 73 | - * @param Writer $writer |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public function xmlSerialize(Writer $writer) { |
|
| 77 | - |
|
| 78 | - foreach ($this->components as $component) { |
|
| 79 | - |
|
| 80 | - $writer->startElement('{' . Plugin::NS_CALDAV . '}comp'); |
|
| 81 | - $writer->writeAttributes(['name' => $component]); |
|
| 82 | - $writer->endElement(); |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * The deserialize method is called during xml parsing. |
|
| 90 | - * |
|
| 91 | - * This method is called statictly, this is because in theory this method |
|
| 92 | - * may be used as a type of constructor, or factory method. |
|
| 93 | - * |
|
| 94 | - * Often you want to return an instance of the current class, but you are |
|
| 95 | - * free to return other data as well. |
|
| 96 | - * |
|
| 97 | - * You are responsible for advancing the reader to the next element. Not |
|
| 98 | - * doing anything will result in a never-ending loop. |
|
| 99 | - * |
|
| 100 | - * If you just want to skip parsing for this element altogether, you can |
|
| 101 | - * just call $reader->next(); |
|
| 102 | - * |
|
| 103 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 104 | - * the next element. |
|
| 105 | - * |
|
| 106 | - * @param Reader $reader |
|
| 107 | - * @return mixed |
|
| 108 | - */ |
|
| 109 | - static function xmlDeserialize(Reader $reader) { |
|
| 110 | - |
|
| 111 | - $elems = $reader->parseInnerTree(); |
|
| 112 | - |
|
| 113 | - $components = []; |
|
| 114 | - |
|
| 115 | - foreach ((array)$elems as $elem) { |
|
| 116 | - if ($elem['name'] === '{' . Plugin::NS_CALDAV . '}comp') { |
|
| 117 | - $components[] = $elem['attributes']['name']; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if (!$components) { |
|
| 122 | - throw new ParseException('supported-calendar-component-set must have at least one CALDAV:comp element'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return new self($components); |
|
| 126 | - |
|
| 127 | - } |
|
| 26 | + /** |
|
| 27 | + * List of supported components. |
|
| 28 | + * |
|
| 29 | + * This array will contain values such as VEVENT, VTODO and VJOURNAL. |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $components = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Creates the property. |
|
| 37 | + * |
|
| 38 | + * @param array $components |
|
| 39 | + */ |
|
| 40 | + public function __construct(array $components) { |
|
| 41 | + |
|
| 42 | + $this->components = $components; |
|
| 43 | + |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Returns the list of supported components |
|
| 48 | + * |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function getValue() { |
|
| 52 | + |
|
| 53 | + return $this->components; |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * The xmlSerialize metod is called during xml writing. |
|
| 59 | + * |
|
| 60 | + * Use the $writer argument to write its own xml serialization. |
|
| 61 | + * |
|
| 62 | + * An important note: do _not_ create a parent element. Any element |
|
| 63 | + * implementing XmlSerializble should only ever write what's considered |
|
| 64 | + * its 'inner xml'. |
|
| 65 | + * |
|
| 66 | + * The parent of the current element is responsible for writing a |
|
| 67 | + * containing element. |
|
| 68 | + * |
|
| 69 | + * This allows serializers to be re-used for different element names. |
|
| 70 | + * |
|
| 71 | + * If you are opening new elements, you must also close them again. |
|
| 72 | + * |
|
| 73 | + * @param Writer $writer |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public function xmlSerialize(Writer $writer) { |
|
| 77 | + |
|
| 78 | + foreach ($this->components as $component) { |
|
| 79 | + |
|
| 80 | + $writer->startElement('{' . Plugin::NS_CALDAV . '}comp'); |
|
| 81 | + $writer->writeAttributes(['name' => $component]); |
|
| 82 | + $writer->endElement(); |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * The deserialize method is called during xml parsing. |
|
| 90 | + * |
|
| 91 | + * This method is called statictly, this is because in theory this method |
|
| 92 | + * may be used as a type of constructor, or factory method. |
|
| 93 | + * |
|
| 94 | + * Often you want to return an instance of the current class, but you are |
|
| 95 | + * free to return other data as well. |
|
| 96 | + * |
|
| 97 | + * You are responsible for advancing the reader to the next element. Not |
|
| 98 | + * doing anything will result in a never-ending loop. |
|
| 99 | + * |
|
| 100 | + * If you just want to skip parsing for this element altogether, you can |
|
| 101 | + * just call $reader->next(); |
|
| 102 | + * |
|
| 103 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 104 | + * the next element. |
|
| 105 | + * |
|
| 106 | + * @param Reader $reader |
|
| 107 | + * @return mixed |
|
| 108 | + */ |
|
| 109 | + static function xmlDeserialize(Reader $reader) { |
|
| 110 | + |
|
| 111 | + $elems = $reader->parseInnerTree(); |
|
| 112 | + |
|
| 113 | + $components = []; |
|
| 114 | + |
|
| 115 | + foreach ((array)$elems as $elem) { |
|
| 116 | + if ($elem['name'] === '{' . Plugin::NS_CALDAV . '}comp') { |
|
| 117 | + $components[] = $elem['attributes']['name']; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (!$components) { |
|
| 122 | + throw new ParseException('supported-calendar-component-set must have at least one CALDAV:comp element'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return new self($components); |
|
| 126 | + |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | } |
@@ -130,8 +130,9 @@ |
||
| 130 | 130 | break; |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | - if (is_null($value)) |
|
| 134 | - return null; |
|
| 133 | + if (is_null($value)) { |
|
| 134 | + return null; |
|
| 135 | + } |
|
| 135 | 136 | |
| 136 | 137 | return new self($value); |
| 137 | 138 | |
@@ -26,115 +26,115 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class ScheduleCalendarTransp implements Element { |
| 28 | 28 | |
| 29 | - const TRANSPARENT = 'transparent'; |
|
| 30 | - const OPAQUE = 'opaque'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * value |
|
| 34 | - * |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - protected $value; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Creates the property |
|
| 41 | - * |
|
| 42 | - * @param string $value |
|
| 43 | - */ |
|
| 44 | - public function __construct($value) { |
|
| 45 | - |
|
| 46 | - if ($value !== self::TRANSPARENT && $value !== self::OPAQUE) { |
|
| 47 | - throw new \InvalidArgumentException('The value must either be specified as "transparent" or "opaque"'); |
|
| 48 | - } |
|
| 49 | - $this->value = $value; |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Returns the current value |
|
| 55 | - * |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function getValue() { |
|
| 59 | - |
|
| 60 | - return $this->value; |
|
| 61 | - |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * The xmlSerialize metod is called during xml writing. |
|
| 66 | - * |
|
| 67 | - * Use the $writer argument to write its own xml serialization. |
|
| 68 | - * |
|
| 69 | - * An important note: do _not_ create a parent element. Any element |
|
| 70 | - * implementing XmlSerializble should only ever write what's considered |
|
| 71 | - * its 'inner xml'. |
|
| 72 | - * |
|
| 73 | - * The parent of the current element is responsible for writing a |
|
| 74 | - * containing element. |
|
| 75 | - * |
|
| 76 | - * This allows serializers to be re-used for different element names. |
|
| 77 | - * |
|
| 78 | - * If you are opening new elements, you must also close them again. |
|
| 79 | - * |
|
| 80 | - * @param Writer $writer |
|
| 81 | - * @return void |
|
| 82 | - */ |
|
| 83 | - public function xmlSerialize(Writer $writer) { |
|
| 84 | - |
|
| 85 | - switch ($this->value) { |
|
| 86 | - case self::TRANSPARENT : |
|
| 87 | - $writer->writeElement('{' . Plugin::NS_CALDAV . '}transparent'); |
|
| 88 | - break; |
|
| 89 | - case self::OPAQUE : |
|
| 90 | - $writer->writeElement('{' . Plugin::NS_CALDAV . '}opaque'); |
|
| 91 | - break; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * The deserialize method is called during xml parsing. |
|
| 98 | - * |
|
| 99 | - * This method is called statictly, this is because in theory this method |
|
| 100 | - * may be used as a type of constructor, or factory method. |
|
| 101 | - * |
|
| 102 | - * Often you want to return an instance of the current class, but you are |
|
| 103 | - * free to return other data as well. |
|
| 104 | - * |
|
| 105 | - * You are responsible for advancing the reader to the next element. Not |
|
| 106 | - * doing anything will result in a never-ending loop. |
|
| 107 | - * |
|
| 108 | - * If you just want to skip parsing for this element altogether, you can |
|
| 109 | - * just call $reader->next(); |
|
| 110 | - * |
|
| 111 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 112 | - * the next element. |
|
| 113 | - * |
|
| 114 | - * @param Reader $reader |
|
| 115 | - * @return mixed |
|
| 116 | - */ |
|
| 117 | - static function xmlDeserialize(Reader $reader) { |
|
| 118 | - |
|
| 119 | - $elems = Elements::xmlDeserialize($reader); |
|
| 120 | - |
|
| 121 | - $value = null; |
|
| 122 | - |
|
| 123 | - foreach ($elems as $elem) { |
|
| 124 | - switch ($elem) { |
|
| 125 | - case '{' . Plugin::NS_CALDAV . '}opaque' : |
|
| 126 | - $value = self::OPAQUE; |
|
| 127 | - break; |
|
| 128 | - case '{' . Plugin::NS_CALDAV . '}transparent' : |
|
| 129 | - $value = self::TRANSPARENT; |
|
| 130 | - break; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if (is_null($value)) |
|
| 134 | - return null; |
|
| 135 | - |
|
| 136 | - return new self($value); |
|
| 137 | - |
|
| 138 | - } |
|
| 29 | + const TRANSPARENT = 'transparent'; |
|
| 30 | + const OPAQUE = 'opaque'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * value |
|
| 34 | + * |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + protected $value; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Creates the property |
|
| 41 | + * |
|
| 42 | + * @param string $value |
|
| 43 | + */ |
|
| 44 | + public function __construct($value) { |
|
| 45 | + |
|
| 46 | + if ($value !== self::TRANSPARENT && $value !== self::OPAQUE) { |
|
| 47 | + throw new \InvalidArgumentException('The value must either be specified as "transparent" or "opaque"'); |
|
| 48 | + } |
|
| 49 | + $this->value = $value; |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Returns the current value |
|
| 55 | + * |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function getValue() { |
|
| 59 | + |
|
| 60 | + return $this->value; |
|
| 61 | + |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * The xmlSerialize metod is called during xml writing. |
|
| 66 | + * |
|
| 67 | + * Use the $writer argument to write its own xml serialization. |
|
| 68 | + * |
|
| 69 | + * An important note: do _not_ create a parent element. Any element |
|
| 70 | + * implementing XmlSerializble should only ever write what's considered |
|
| 71 | + * its 'inner xml'. |
|
| 72 | + * |
|
| 73 | + * The parent of the current element is responsible for writing a |
|
| 74 | + * containing element. |
|
| 75 | + * |
|
| 76 | + * This allows serializers to be re-used for different element names. |
|
| 77 | + * |
|
| 78 | + * If you are opening new elements, you must also close them again. |
|
| 79 | + * |
|
| 80 | + * @param Writer $writer |
|
| 81 | + * @return void |
|
| 82 | + */ |
|
| 83 | + public function xmlSerialize(Writer $writer) { |
|
| 84 | + |
|
| 85 | + switch ($this->value) { |
|
| 86 | + case self::TRANSPARENT : |
|
| 87 | + $writer->writeElement('{' . Plugin::NS_CALDAV . '}transparent'); |
|
| 88 | + break; |
|
| 89 | + case self::OPAQUE : |
|
| 90 | + $writer->writeElement('{' . Plugin::NS_CALDAV . '}opaque'); |
|
| 91 | + break; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * The deserialize method is called during xml parsing. |
|
| 98 | + * |
|
| 99 | + * This method is called statictly, this is because in theory this method |
|
| 100 | + * may be used as a type of constructor, or factory method. |
|
| 101 | + * |
|
| 102 | + * Often you want to return an instance of the current class, but you are |
|
| 103 | + * free to return other data as well. |
|
| 104 | + * |
|
| 105 | + * You are responsible for advancing the reader to the next element. Not |
|
| 106 | + * doing anything will result in a never-ending loop. |
|
| 107 | + * |
|
| 108 | + * If you just want to skip parsing for this element altogether, you can |
|
| 109 | + * just call $reader->next(); |
|
| 110 | + * |
|
| 111 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
| 112 | + * the next element. |
|
| 113 | + * |
|
| 114 | + * @param Reader $reader |
|
| 115 | + * @return mixed |
|
| 116 | + */ |
|
| 117 | + static function xmlDeserialize(Reader $reader) { |
|
| 118 | + |
|
| 119 | + $elems = Elements::xmlDeserialize($reader); |
|
| 120 | + |
|
| 121 | + $value = null; |
|
| 122 | + |
|
| 123 | + foreach ($elems as $elem) { |
|
| 124 | + switch ($elem) { |
|
| 125 | + case '{' . Plugin::NS_CALDAV . '}opaque' : |
|
| 126 | + $value = self::OPAQUE; |
|
| 127 | + break; |
|
| 128 | + case '{' . Plugin::NS_CALDAV . '}transparent' : |
|
| 129 | + $value = self::TRANSPARENT; |
|
| 130 | + break; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if (is_null($value)) |
|
| 134 | + return null; |
|
| 135 | + |
|
| 136 | + return new self($value); |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
@@ -99,11 +99,13 @@ |
||
| 99 | 99 | |
| 100 | 100 | $summary = $iTipMessage->message->VEVENT->SUMMARY; |
| 101 | 101 | |
| 102 | - if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') |
|
| 103 | - return; |
|
| 102 | + if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
| 103 | + return; |
|
| 104 | + } |
|
| 104 | 105 | |
| 105 | - if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') |
|
| 106 | - return; |
|
| 106 | + if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 107 | 109 | |
| 108 | 110 | $sender = substr($iTipMessage->sender, 7); |
| 109 | 111 | $recipient = substr($iTipMessage->recipient, 7); |
@@ -21,35 +21,35 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class IMipPlugin extends DAV\ServerPlugin { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Email address used in From: header. |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $senderEmail; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * ITipMessage |
|
| 33 | - * |
|
| 34 | - * @var ITip\Message |
|
| 35 | - */ |
|
| 36 | - protected $itipMessage; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Creates the email handler. |
|
| 40 | - * |
|
| 41 | - * @param string $senderEmail. The 'senderEmail' is the email that shows up |
|
| 42 | - * in the 'From:' address. This should |
|
| 43 | - * generally be some kind of no-reply email |
|
| 44 | - * address you own. |
|
| 45 | - */ |
|
| 46 | - public function __construct($senderEmail) { |
|
| 47 | - |
|
| 48 | - $this->senderEmail = $senderEmail; |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /* |
|
| 24 | + /** |
|
| 25 | + * Email address used in From: header. |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $senderEmail; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * ITipMessage |
|
| 33 | + * |
|
| 34 | + * @var ITip\Message |
|
| 35 | + */ |
|
| 36 | + protected $itipMessage; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Creates the email handler. |
|
| 40 | + * |
|
| 41 | + * @param string $senderEmail. The 'senderEmail' is the email that shows up |
|
| 42 | + * in the 'From:' address. This should |
|
| 43 | + * generally be some kind of no-reply email |
|
| 44 | + * address you own. |
|
| 45 | + */ |
|
| 46 | + public function __construct($senderEmail) { |
|
| 47 | + |
|
| 48 | + $this->senderEmail = $senderEmail; |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /* |
|
| 53 | 53 | * This initializes the plugin. |
| 54 | 54 | * |
| 55 | 55 | * This function is called by Sabre\DAV\Server, after |
@@ -60,131 +60,131 @@ discard block |
||
| 60 | 60 | * @param DAV\Server $server |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - public function initialize(DAV\Server $server) { |
|
| 64 | - |
|
| 65 | - $server->on('schedule', [$this, 'schedule'], 120); |
|
| 66 | - |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Returns a plugin name. |
|
| 71 | - * |
|
| 72 | - * Using this name other plugins will be able to access other plugins |
|
| 73 | - * using \Sabre\DAV\Server::getPlugin |
|
| 74 | - * |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function getPluginName() { |
|
| 78 | - |
|
| 79 | - return 'imip'; |
|
| 80 | - |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Event handler for the 'schedule' event. |
|
| 85 | - * |
|
| 86 | - * @param ITip\Message $iTipMessage |
|
| 87 | - * @return void |
|
| 88 | - */ |
|
| 89 | - public function schedule(ITip\Message $iTipMessage) { |
|
| 90 | - |
|
| 91 | - // Not sending any emails if the system considers the update |
|
| 92 | - // insignificant. |
|
| 93 | - if (!$iTipMessage->significantChange) { |
|
| 94 | - if (!$iTipMessage->scheduleStatus) { |
|
| 95 | - $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
| 96 | - } |
|
| 97 | - return; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
| 101 | - |
|
| 102 | - if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') |
|
| 103 | - return; |
|
| 104 | - |
|
| 105 | - if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') |
|
| 106 | - return; |
|
| 107 | - |
|
| 108 | - $sender = substr($iTipMessage->sender, 7); |
|
| 109 | - $recipient = substr($iTipMessage->recipient, 7); |
|
| 110 | - |
|
| 111 | - if ($iTipMessage->senderName) { |
|
| 112 | - $sender = $iTipMessage->senderName . ' <' . $sender . '>'; |
|
| 113 | - } |
|
| 114 | - if ($iTipMessage->recipientName) { |
|
| 115 | - $recipient = $iTipMessage->recipientName . ' <' . $recipient . '>'; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $subject = 'SabreDAV iTIP message'; |
|
| 119 | - switch (strtoupper($iTipMessage->method)) { |
|
| 120 | - case 'REPLY' : |
|
| 121 | - $subject = 'Re: ' . $summary; |
|
| 122 | - break; |
|
| 123 | - case 'REQUEST' : |
|
| 124 | - $subject = $summary; |
|
| 125 | - break; |
|
| 126 | - case 'CANCEL' : |
|
| 127 | - $subject = 'Cancelled: ' . $summary; |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $headers = [ |
|
| 132 | - 'Reply-To: ' . $sender, |
|
| 133 | - 'From: ' . $this->senderEmail, |
|
| 134 | - 'Content-Type: text/calendar; charset=UTF-8; method=' . $iTipMessage->method, |
|
| 135 | - ]; |
|
| 136 | - if (DAV\Server::$exposeVersion) { |
|
| 137 | - $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION; |
|
| 138 | - } |
|
| 139 | - $this->mail( |
|
| 140 | - $recipient, |
|
| 141 | - $subject, |
|
| 142 | - $iTipMessage->message->serialize(), |
|
| 143 | - $headers |
|
| 144 | - ); |
|
| 145 | - $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
| 146 | - |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // @codeCoverageIgnoreStart |
|
| 150 | - // This is deemed untestable in a reasonable manner |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * This function is responsible for sending the actual email. |
|
| 154 | - * |
|
| 155 | - * @param string $to Recipient email address |
|
| 156 | - * @param string $subject Subject of the email |
|
| 157 | - * @param string $body iCalendar body |
|
| 158 | - * @param array $headers List of headers |
|
| 159 | - * @return void |
|
| 160 | - */ |
|
| 161 | - protected function mail($to, $subject, $body, array $headers) { |
|
| 162 | - |
|
| 163 | - mail($to, $subject, $body, implode("\r\n", $headers)); |
|
| 164 | - |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // @codeCoverageIgnoreEnd |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Returns a bunch of meta-data about the plugin. |
|
| 171 | - * |
|
| 172 | - * Providing this information is optional, and is mainly displayed by the |
|
| 173 | - * Browser plugin. |
|
| 174 | - * |
|
| 175 | - * The description key in the returned array may contain html and will not |
|
| 176 | - * be sanitized. |
|
| 177 | - * |
|
| 178 | - * @return array |
|
| 179 | - */ |
|
| 180 | - public function getPluginInfo() { |
|
| 181 | - |
|
| 182 | - return [ |
|
| 183 | - 'name' => $this->getPluginName(), |
|
| 184 | - 'description' => 'Email delivery (rfc6037) for CalDAV scheduling', |
|
| 185 | - 'link' => 'http://sabre.io/dav/scheduling/', |
|
| 186 | - ]; |
|
| 187 | - |
|
| 188 | - } |
|
| 63 | + public function initialize(DAV\Server $server) { |
|
| 64 | + |
|
| 65 | + $server->on('schedule', [$this, 'schedule'], 120); |
|
| 66 | + |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Returns a plugin name. |
|
| 71 | + * |
|
| 72 | + * Using this name other plugins will be able to access other plugins |
|
| 73 | + * using \Sabre\DAV\Server::getPlugin |
|
| 74 | + * |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function getPluginName() { |
|
| 78 | + |
|
| 79 | + return 'imip'; |
|
| 80 | + |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Event handler for the 'schedule' event. |
|
| 85 | + * |
|
| 86 | + * @param ITip\Message $iTipMessage |
|
| 87 | + * @return void |
|
| 88 | + */ |
|
| 89 | + public function schedule(ITip\Message $iTipMessage) { |
|
| 90 | + |
|
| 91 | + // Not sending any emails if the system considers the update |
|
| 92 | + // insignificant. |
|
| 93 | + if (!$iTipMessage->significantChange) { |
|
| 94 | + if (!$iTipMessage->scheduleStatus) { |
|
| 95 | + $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
| 96 | + } |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
| 101 | + |
|
| 102 | + if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') |
|
| 103 | + return; |
|
| 104 | + |
|
| 105 | + if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') |
|
| 106 | + return; |
|
| 107 | + |
|
| 108 | + $sender = substr($iTipMessage->sender, 7); |
|
| 109 | + $recipient = substr($iTipMessage->recipient, 7); |
|
| 110 | + |
|
| 111 | + if ($iTipMessage->senderName) { |
|
| 112 | + $sender = $iTipMessage->senderName . ' <' . $sender . '>'; |
|
| 113 | + } |
|
| 114 | + if ($iTipMessage->recipientName) { |
|
| 115 | + $recipient = $iTipMessage->recipientName . ' <' . $recipient . '>'; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $subject = 'SabreDAV iTIP message'; |
|
| 119 | + switch (strtoupper($iTipMessage->method)) { |
|
| 120 | + case 'REPLY' : |
|
| 121 | + $subject = 'Re: ' . $summary; |
|
| 122 | + break; |
|
| 123 | + case 'REQUEST' : |
|
| 124 | + $subject = $summary; |
|
| 125 | + break; |
|
| 126 | + case 'CANCEL' : |
|
| 127 | + $subject = 'Cancelled: ' . $summary; |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $headers = [ |
|
| 132 | + 'Reply-To: ' . $sender, |
|
| 133 | + 'From: ' . $this->senderEmail, |
|
| 134 | + 'Content-Type: text/calendar; charset=UTF-8; method=' . $iTipMessage->method, |
|
| 135 | + ]; |
|
| 136 | + if (DAV\Server::$exposeVersion) { |
|
| 137 | + $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION; |
|
| 138 | + } |
|
| 139 | + $this->mail( |
|
| 140 | + $recipient, |
|
| 141 | + $subject, |
|
| 142 | + $iTipMessage->message->serialize(), |
|
| 143 | + $headers |
|
| 144 | + ); |
|
| 145 | + $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
| 146 | + |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // @codeCoverageIgnoreStart |
|
| 150 | + // This is deemed untestable in a reasonable manner |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * This function is responsible for sending the actual email. |
|
| 154 | + * |
|
| 155 | + * @param string $to Recipient email address |
|
| 156 | + * @param string $subject Subject of the email |
|
| 157 | + * @param string $body iCalendar body |
|
| 158 | + * @param array $headers List of headers |
|
| 159 | + * @return void |
|
| 160 | + */ |
|
| 161 | + protected function mail($to, $subject, $body, array $headers) { |
|
| 162 | + |
|
| 163 | + mail($to, $subject, $body, implode("\r\n", $headers)); |
|
| 164 | + |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // @codeCoverageIgnoreEnd |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Returns a bunch of meta-data about the plugin. |
|
| 171 | + * |
|
| 172 | + * Providing this information is optional, and is mainly displayed by the |
|
| 173 | + * Browser plugin. |
|
| 174 | + * |
|
| 175 | + * The description key in the returned array may contain html and will not |
|
| 176 | + * be sanitized. |
|
| 177 | + * |
|
| 178 | + * @return array |
|
| 179 | + */ |
|
| 180 | + public function getPluginInfo() { |
|
| 181 | + |
|
| 182 | + return [ |
|
| 183 | + 'name' => $this->getPluginName(), |
|
| 184 | + 'description' => 'Email delivery (rfc6037) for CalDAV scheduling', |
|
| 185 | + 'link' => 'http://sabre.io/dav/scheduling/', |
|
| 186 | + ]; |
|
| 187 | + |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | } |
@@ -101,11 +101,13 @@ |
||
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if (!$requestDate = $this->request->getHeader('x-amz-date')) |
|
| 105 | - $requestDate = $this->request->getHeader('Date'); |
|
| 104 | + if (!$requestDate = $this->request->getHeader('x-amz-date')) { |
|
| 105 | + $requestDate = $this->request->getHeader('Date'); |
|
| 106 | + } |
|
| 106 | 107 | |
| 107 | - if (!$this->validateRFC2616Date($requestDate)) |
|
| 108 | - return false; |
|
| 108 | + if (!$this->validateRFC2616Date($requestDate)) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | $amzHeaders = $this->getAmzHeaders(); |
| 111 | 113 | |
@@ -15,220 +15,220 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class AWS extends AbstractAuth { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The signature supplied by the HTTP client |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - private $signature = null; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The accesskey supplied by the HTTP client |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - private $accessKey = null; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * An error code, if any |
|
| 34 | - * |
|
| 35 | - * This value will be filled with one of the ERR_* constants |
|
| 36 | - * |
|
| 37 | - * @var int |
|
| 38 | - */ |
|
| 39 | - public $errorCode = 0; |
|
| 40 | - |
|
| 41 | - const ERR_NOAWSHEADER = 1; |
|
| 42 | - const ERR_MD5CHECKSUMWRONG = 2; |
|
| 43 | - const ERR_INVALIDDATEFORMAT = 3; |
|
| 44 | - const ERR_REQUESTTIMESKEWED = 4; |
|
| 45 | - const ERR_INVALIDSIGNATURE = 5; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Gathers all information from the headers |
|
| 49 | - * |
|
| 50 | - * This method needs to be called prior to anything else. |
|
| 51 | - * |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function init() { |
|
| 55 | - |
|
| 56 | - $authHeader = $this->request->getHeader('Authorization'); |
|
| 57 | - $authHeader = explode(' ', $authHeader); |
|
| 58 | - |
|
| 59 | - if ($authHeader[0] != 'AWS' || !isset($authHeader[1])) { |
|
| 60 | - $this->errorCode = self::ERR_NOAWSHEADER; |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - list($this->accessKey, $this->signature) = explode(':', $authHeader[1]); |
|
| 65 | - |
|
| 66 | - return true; |
|
| 67 | - |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Returns the username for the request |
|
| 72 | - * |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public function getAccessKey() { |
|
| 76 | - |
|
| 77 | - return $this->accessKey; |
|
| 78 | - |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Validates the signature based on the secretKey |
|
| 83 | - * |
|
| 84 | - * @param string $secretKey |
|
| 85 | - * @return bool |
|
| 86 | - */ |
|
| 87 | - public function validate($secretKey) { |
|
| 88 | - |
|
| 89 | - $contentMD5 = $this->request->getHeader('Content-MD5'); |
|
| 90 | - |
|
| 91 | - if ($contentMD5) { |
|
| 92 | - // We need to validate the integrity of the request |
|
| 93 | - $body = $this->request->getBody(); |
|
| 94 | - $this->request->setBody($body); |
|
| 95 | - |
|
| 96 | - if ($contentMD5 != base64_encode(md5($body, true))) { |
|
| 97 | - // content-md5 header did not match md5 signature of body |
|
| 98 | - $this->errorCode = self::ERR_MD5CHECKSUMWRONG; |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (!$requestDate = $this->request->getHeader('x-amz-date')) |
|
| 105 | - $requestDate = $this->request->getHeader('Date'); |
|
| 106 | - |
|
| 107 | - if (!$this->validateRFC2616Date($requestDate)) |
|
| 108 | - return false; |
|
| 109 | - |
|
| 110 | - $amzHeaders = $this->getAmzHeaders(); |
|
| 111 | - |
|
| 112 | - $signature = base64_encode( |
|
| 113 | - $this->hmacsha1($secretKey, |
|
| 114 | - $this->request->getMethod() . "\n" . |
|
| 115 | - $contentMD5 . "\n" . |
|
| 116 | - $this->request->getHeader('Content-type') . "\n" . |
|
| 117 | - $requestDate . "\n" . |
|
| 118 | - $amzHeaders . |
|
| 119 | - $this->request->getUrl() |
|
| 120 | - ) |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - if ($this->signature != $signature) { |
|
| 124 | - |
|
| 125 | - $this->errorCode = self::ERR_INVALIDSIGNATURE; |
|
| 126 | - return false; |
|
| 127 | - |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return true; |
|
| 131 | - |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Returns an HTTP 401 header, forcing login |
|
| 137 | - * |
|
| 138 | - * This should be called when username and password are incorrect, or not supplied at all |
|
| 139 | - * |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - public function requireLogin() { |
|
| 143 | - |
|
| 144 | - $this->response->addHeader('WWW-Authenticate', 'AWS'); |
|
| 145 | - $this->response->setStatus(401); |
|
| 146 | - |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Makes sure the supplied value is a valid RFC2616 date. |
|
| 151 | - * |
|
| 152 | - * If we would just use strtotime to get a valid timestamp, we have no way of checking if a |
|
| 153 | - * user just supplied the word 'now' for the date header. |
|
| 154 | - * |
|
| 155 | - * This function also makes sure the Date header is within 15 minutes of the operating |
|
| 156 | - * system date, to prevent replay attacks. |
|
| 157 | - * |
|
| 158 | - * @param string $dateHeader |
|
| 159 | - * @return bool |
|
| 160 | - */ |
|
| 161 | - protected function validateRFC2616Date($dateHeader) { |
|
| 162 | - |
|
| 163 | - $date = Util::parseHTTPDate($dateHeader); |
|
| 164 | - |
|
| 165 | - // Unknown format |
|
| 166 | - if (!$date) { |
|
| 167 | - $this->errorCode = self::ERR_INVALIDDATEFORMAT; |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $min = new \DateTime('-15 minutes'); |
|
| 172 | - $max = new \DateTime('+15 minutes'); |
|
| 173 | - |
|
| 174 | - // We allow 15 minutes around the current date/time |
|
| 175 | - if ($date > $max || $date < $min) { |
|
| 176 | - $this->errorCode = self::ERR_REQUESTTIMESKEWED; |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $date; |
|
| 181 | - |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Returns a list of AMZ headers |
|
| 186 | - * |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - protected function getAmzHeaders() { |
|
| 190 | - |
|
| 191 | - $amzHeaders = []; |
|
| 192 | - $headers = $this->request->getHeaders(); |
|
| 193 | - foreach ($headers as $headerName => $headerValue) { |
|
| 194 | - if (strpos(strtolower($headerName), 'x-amz-') === 0) { |
|
| 195 | - $amzHeaders[strtolower($headerName)] = str_replace(["\r\n"], [' '], $headerValue[0]) . "\n"; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - ksort($amzHeaders); |
|
| 199 | - |
|
| 200 | - $headerStr = ''; |
|
| 201 | - foreach ($amzHeaders as $h => $v) { |
|
| 202 | - $headerStr .= $h . ':' . $v; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return $headerStr; |
|
| 206 | - |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Generates an HMAC-SHA1 signature |
|
| 211 | - * |
|
| 212 | - * @param string $key |
|
| 213 | - * @param string $message |
|
| 214 | - * @return string |
|
| 215 | - */ |
|
| 216 | - private function hmacsha1($key, $message) { |
|
| 217 | - |
|
| 218 | - if (function_exists('hash_hmac')) { |
|
| 219 | - return hash_hmac('sha1', $message, $key, true); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $blocksize = 64; |
|
| 223 | - if (strlen($key) > $blocksize) { |
|
| 224 | - $key = pack('H*', sha1($key)); |
|
| 225 | - } |
|
| 226 | - $key = str_pad($key, $blocksize, chr(0x00)); |
|
| 227 | - $ipad = str_repeat(chr(0x36), $blocksize); |
|
| 228 | - $opad = str_repeat(chr(0x5c), $blocksize); |
|
| 229 | - $hmac = pack('H*', sha1(($key ^ $opad) . pack('H*', sha1(($key ^ $ipad) . $message)))); |
|
| 230 | - return $hmac; |
|
| 231 | - |
|
| 232 | - } |
|
| 18 | + /** |
|
| 19 | + * The signature supplied by the HTTP client |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + private $signature = null; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The accesskey supplied by the HTTP client |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + private $accessKey = null; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * An error code, if any |
|
| 34 | + * |
|
| 35 | + * This value will be filled with one of the ERR_* constants |
|
| 36 | + * |
|
| 37 | + * @var int |
|
| 38 | + */ |
|
| 39 | + public $errorCode = 0; |
|
| 40 | + |
|
| 41 | + const ERR_NOAWSHEADER = 1; |
|
| 42 | + const ERR_MD5CHECKSUMWRONG = 2; |
|
| 43 | + const ERR_INVALIDDATEFORMAT = 3; |
|
| 44 | + const ERR_REQUESTTIMESKEWED = 4; |
|
| 45 | + const ERR_INVALIDSIGNATURE = 5; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Gathers all information from the headers |
|
| 49 | + * |
|
| 50 | + * This method needs to be called prior to anything else. |
|
| 51 | + * |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function init() { |
|
| 55 | + |
|
| 56 | + $authHeader = $this->request->getHeader('Authorization'); |
|
| 57 | + $authHeader = explode(' ', $authHeader); |
|
| 58 | + |
|
| 59 | + if ($authHeader[0] != 'AWS' || !isset($authHeader[1])) { |
|
| 60 | + $this->errorCode = self::ERR_NOAWSHEADER; |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + list($this->accessKey, $this->signature) = explode(':', $authHeader[1]); |
|
| 65 | + |
|
| 66 | + return true; |
|
| 67 | + |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Returns the username for the request |
|
| 72 | + * |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public function getAccessKey() { |
|
| 76 | + |
|
| 77 | + return $this->accessKey; |
|
| 78 | + |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Validates the signature based on the secretKey |
|
| 83 | + * |
|
| 84 | + * @param string $secretKey |
|
| 85 | + * @return bool |
|
| 86 | + */ |
|
| 87 | + public function validate($secretKey) { |
|
| 88 | + |
|
| 89 | + $contentMD5 = $this->request->getHeader('Content-MD5'); |
|
| 90 | + |
|
| 91 | + if ($contentMD5) { |
|
| 92 | + // We need to validate the integrity of the request |
|
| 93 | + $body = $this->request->getBody(); |
|
| 94 | + $this->request->setBody($body); |
|
| 95 | + |
|
| 96 | + if ($contentMD5 != base64_encode(md5($body, true))) { |
|
| 97 | + // content-md5 header did not match md5 signature of body |
|
| 98 | + $this->errorCode = self::ERR_MD5CHECKSUMWRONG; |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (!$requestDate = $this->request->getHeader('x-amz-date')) |
|
| 105 | + $requestDate = $this->request->getHeader('Date'); |
|
| 106 | + |
|
| 107 | + if (!$this->validateRFC2616Date($requestDate)) |
|
| 108 | + return false; |
|
| 109 | + |
|
| 110 | + $amzHeaders = $this->getAmzHeaders(); |
|
| 111 | + |
|
| 112 | + $signature = base64_encode( |
|
| 113 | + $this->hmacsha1($secretKey, |
|
| 114 | + $this->request->getMethod() . "\n" . |
|
| 115 | + $contentMD5 . "\n" . |
|
| 116 | + $this->request->getHeader('Content-type') . "\n" . |
|
| 117 | + $requestDate . "\n" . |
|
| 118 | + $amzHeaders . |
|
| 119 | + $this->request->getUrl() |
|
| 120 | + ) |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + if ($this->signature != $signature) { |
|
| 124 | + |
|
| 125 | + $this->errorCode = self::ERR_INVALIDSIGNATURE; |
|
| 126 | + return false; |
|
| 127 | + |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return true; |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Returns an HTTP 401 header, forcing login |
|
| 137 | + * |
|
| 138 | + * This should be called when username and password are incorrect, or not supplied at all |
|
| 139 | + * |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + public function requireLogin() { |
|
| 143 | + |
|
| 144 | + $this->response->addHeader('WWW-Authenticate', 'AWS'); |
|
| 145 | + $this->response->setStatus(401); |
|
| 146 | + |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Makes sure the supplied value is a valid RFC2616 date. |
|
| 151 | + * |
|
| 152 | + * If we would just use strtotime to get a valid timestamp, we have no way of checking if a |
|
| 153 | + * user just supplied the word 'now' for the date header. |
|
| 154 | + * |
|
| 155 | + * This function also makes sure the Date header is within 15 minutes of the operating |
|
| 156 | + * system date, to prevent replay attacks. |
|
| 157 | + * |
|
| 158 | + * @param string $dateHeader |
|
| 159 | + * @return bool |
|
| 160 | + */ |
|
| 161 | + protected function validateRFC2616Date($dateHeader) { |
|
| 162 | + |
|
| 163 | + $date = Util::parseHTTPDate($dateHeader); |
|
| 164 | + |
|
| 165 | + // Unknown format |
|
| 166 | + if (!$date) { |
|
| 167 | + $this->errorCode = self::ERR_INVALIDDATEFORMAT; |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $min = new \DateTime('-15 minutes'); |
|
| 172 | + $max = new \DateTime('+15 minutes'); |
|
| 173 | + |
|
| 174 | + // We allow 15 minutes around the current date/time |
|
| 175 | + if ($date > $max || $date < $min) { |
|
| 176 | + $this->errorCode = self::ERR_REQUESTTIMESKEWED; |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $date; |
|
| 181 | + |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Returns a list of AMZ headers |
|
| 186 | + * |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + protected function getAmzHeaders() { |
|
| 190 | + |
|
| 191 | + $amzHeaders = []; |
|
| 192 | + $headers = $this->request->getHeaders(); |
|
| 193 | + foreach ($headers as $headerName => $headerValue) { |
|
| 194 | + if (strpos(strtolower($headerName), 'x-amz-') === 0) { |
|
| 195 | + $amzHeaders[strtolower($headerName)] = str_replace(["\r\n"], [' '], $headerValue[0]) . "\n"; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + ksort($amzHeaders); |
|
| 199 | + |
|
| 200 | + $headerStr = ''; |
|
| 201 | + foreach ($amzHeaders as $h => $v) { |
|
| 202 | + $headerStr .= $h . ':' . $v; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return $headerStr; |
|
| 206 | + |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Generates an HMAC-SHA1 signature |
|
| 211 | + * |
|
| 212 | + * @param string $key |
|
| 213 | + * @param string $message |
|
| 214 | + * @return string |
|
| 215 | + */ |
|
| 216 | + private function hmacsha1($key, $message) { |
|
| 217 | + |
|
| 218 | + if (function_exists('hash_hmac')) { |
|
| 219 | + return hash_hmac('sha1', $message, $key, true); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $blocksize = 64; |
|
| 223 | + if (strlen($key) > $blocksize) { |
|
| 224 | + $key = pack('H*', sha1($key)); |
|
| 225 | + } |
|
| 226 | + $key = str_pad($key, $blocksize, chr(0x00)); |
|
| 227 | + $ipad = str_repeat(chr(0x36), $blocksize); |
|
| 228 | + $opad = str_repeat(chr(0x5c), $blocksize); |
|
| 229 | + $hmac = pack('H*', sha1(($key ^ $opad) . pack('H*', sha1(($key ^ $ipad) . $message)))); |
|
| 230 | + return $hmac; |
|
| 231 | + |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | } |
@@ -139,7 +139,9 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | if ($this->digestParts['qop'] == 'auth-int') { |
| 141 | 141 | // Making sure we support this qop value |
| 142 | - if (!($this->qop & self::QOP_AUTHINT)) return false; |
|
| 142 | + if (!($this->qop & self::QOP_AUTHINT)) { |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 143 | 145 | // We need to add an md5 of the entire request body to the A2 part of the hash |
| 144 | 146 | $body = $this->request->getBody($asString = true); |
| 145 | 147 | $this->request->setBody($body); |
@@ -147,7 +149,9 @@ discard block |
||
| 147 | 149 | } else { |
| 148 | 150 | |
| 149 | 151 | // We need to make sure we support this qop value |
| 150 | - if (!($this->qop & self::QOP_AUTH)) return false; |
|
| 152 | + if (!($this->qop & self::QOP_AUTH)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 151 | 155 | } |
| 152 | 156 | |
| 153 | 157 | $A2 = md5($A2); |
@@ -29,203 +29,203 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Digest extends AbstractAuth { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * These constants are used in setQOP(); |
|
| 34 | - */ |
|
| 35 | - const QOP_AUTH = 1; |
|
| 36 | - const QOP_AUTHINT = 2; |
|
| 37 | - |
|
| 38 | - protected $nonce; |
|
| 39 | - protected $opaque; |
|
| 40 | - protected $digestParts; |
|
| 41 | - protected $A1; |
|
| 42 | - protected $qop = self::QOP_AUTH; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Initializes the object |
|
| 46 | - */ |
|
| 47 | - public function __construct($realm = 'SabreTooth', RequestInterface $request, ResponseInterface $response) { |
|
| 48 | - |
|
| 49 | - $this->nonce = uniqid(); |
|
| 50 | - $this->opaque = md5($realm); |
|
| 51 | - parent::__construct($realm, $request, $response); |
|
| 52 | - |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Gathers all information from the headers |
|
| 57 | - * |
|
| 58 | - * This method needs to be called prior to anything else. |
|
| 59 | - * |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public function init() { |
|
| 63 | - |
|
| 64 | - $digest = $this->getDigest(); |
|
| 65 | - $this->digestParts = $this->parseDigest($digest); |
|
| 66 | - |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Sets the quality of protection value. |
|
| 71 | - * |
|
| 72 | - * Possible values are: |
|
| 73 | - * Sabre\HTTP\DigestAuth::QOP_AUTH |
|
| 74 | - * Sabre\HTTP\DigestAuth::QOP_AUTHINT |
|
| 75 | - * |
|
| 76 | - * Multiple values can be specified using logical OR. |
|
| 77 | - * |
|
| 78 | - * QOP_AUTHINT ensures integrity of the request body, but this is not |
|
| 79 | - * supported by most HTTP clients. QOP_AUTHINT also requires the entire |
|
| 80 | - * request body to be md5'ed, which can put strains on CPU and memory. |
|
| 81 | - * |
|
| 82 | - * @param int $qop |
|
| 83 | - * @return void |
|
| 84 | - */ |
|
| 85 | - public function setQOP($qop) { |
|
| 86 | - |
|
| 87 | - $this->qop = $qop; |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Validates the user. |
|
| 93 | - * |
|
| 94 | - * The A1 parameter should be md5($username . ':' . $realm . ':' . $password); |
|
| 95 | - * |
|
| 96 | - * @param string $A1 |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 99 | - public function validateA1($A1) { |
|
| 100 | - |
|
| 101 | - $this->A1 = $A1; |
|
| 102 | - return $this->validate(); |
|
| 103 | - |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Validates authentication through a password. The actual password must be provided here. |
|
| 108 | - * It is strongly recommended not store the password in plain-text and use validateA1 instead. |
|
| 109 | - * |
|
| 110 | - * @param string $password |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function validatePassword($password) { |
|
| 114 | - |
|
| 115 | - $this->A1 = md5($this->digestParts['username'] . ':' . $this->realm . ':' . $password); |
|
| 116 | - return $this->validate(); |
|
| 117 | - |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Returns the username for the request |
|
| 122 | - * |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public function getUsername() { |
|
| 126 | - |
|
| 127 | - return $this->digestParts['username']; |
|
| 128 | - |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Validates the digest challenge |
|
| 133 | - * |
|
| 134 | - * @return bool |
|
| 135 | - */ |
|
| 136 | - protected function validate() { |
|
| 137 | - |
|
| 138 | - $A2 = $this->request->getMethod() . ':' . $this->digestParts['uri']; |
|
| 139 | - |
|
| 140 | - if ($this->digestParts['qop'] == 'auth-int') { |
|
| 141 | - // Making sure we support this qop value |
|
| 142 | - if (!($this->qop & self::QOP_AUTHINT)) return false; |
|
| 143 | - // We need to add an md5 of the entire request body to the A2 part of the hash |
|
| 144 | - $body = $this->request->getBody($asString = true); |
|
| 145 | - $this->request->setBody($body); |
|
| 146 | - $A2 .= ':' . md5($body); |
|
| 147 | - } else { |
|
| 148 | - |
|
| 149 | - // We need to make sure we support this qop value |
|
| 150 | - if (!($this->qop & self::QOP_AUTH)) return false; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $A2 = md5($A2); |
|
| 154 | - |
|
| 155 | - $validResponse = md5("{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}"); |
|
| 156 | - |
|
| 157 | - return $this->digestParts['response'] == $validResponse; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Returns an HTTP 401 header, forcing login |
|
| 164 | - * |
|
| 165 | - * This should be called when username and password are incorrect, or not supplied at all |
|
| 166 | - * |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - public function requireLogin() { |
|
| 170 | - |
|
| 171 | - $qop = ''; |
|
| 172 | - switch ($this->qop) { |
|
| 173 | - case self::QOP_AUTH : |
|
| 174 | - $qop = 'auth'; |
|
| 175 | - break; |
|
| 176 | - case self::QOP_AUTHINT : |
|
| 177 | - $qop = 'auth-int'; |
|
| 178 | - break; |
|
| 179 | - case self::QOP_AUTH | self::QOP_AUTHINT : |
|
| 180 | - $qop = 'auth,auth-int'; |
|
| 181 | - break; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $this->response->addHeader('WWW-Authenticate', 'Digest realm="' . $this->realm . '",qop="' . $qop . '",nonce="' . $this->nonce . '",opaque="' . $this->opaque . '"'); |
|
| 185 | - $this->response->setStatus(401); |
|
| 186 | - |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * This method returns the full digest string. |
|
| 192 | - * |
|
| 193 | - * It should be compatibile with mod_php format and other webservers. |
|
| 194 | - * |
|
| 195 | - * If the header could not be found, null will be returned |
|
| 196 | - * |
|
| 197 | - * @return mixed |
|
| 198 | - */ |
|
| 199 | - public function getDigest() { |
|
| 32 | + /** |
|
| 33 | + * These constants are used in setQOP(); |
|
| 34 | + */ |
|
| 35 | + const QOP_AUTH = 1; |
|
| 36 | + const QOP_AUTHINT = 2; |
|
| 37 | + |
|
| 38 | + protected $nonce; |
|
| 39 | + protected $opaque; |
|
| 40 | + protected $digestParts; |
|
| 41 | + protected $A1; |
|
| 42 | + protected $qop = self::QOP_AUTH; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Initializes the object |
|
| 46 | + */ |
|
| 47 | + public function __construct($realm = 'SabreTooth', RequestInterface $request, ResponseInterface $response) { |
|
| 48 | + |
|
| 49 | + $this->nonce = uniqid(); |
|
| 50 | + $this->opaque = md5($realm); |
|
| 51 | + parent::__construct($realm, $request, $response); |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Gathers all information from the headers |
|
| 57 | + * |
|
| 58 | + * This method needs to be called prior to anything else. |
|
| 59 | + * |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public function init() { |
|
| 63 | + |
|
| 64 | + $digest = $this->getDigest(); |
|
| 65 | + $this->digestParts = $this->parseDigest($digest); |
|
| 66 | + |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Sets the quality of protection value. |
|
| 71 | + * |
|
| 72 | + * Possible values are: |
|
| 73 | + * Sabre\HTTP\DigestAuth::QOP_AUTH |
|
| 74 | + * Sabre\HTTP\DigestAuth::QOP_AUTHINT |
|
| 75 | + * |
|
| 76 | + * Multiple values can be specified using logical OR. |
|
| 77 | + * |
|
| 78 | + * QOP_AUTHINT ensures integrity of the request body, but this is not |
|
| 79 | + * supported by most HTTP clients. QOP_AUTHINT also requires the entire |
|
| 80 | + * request body to be md5'ed, which can put strains on CPU and memory. |
|
| 81 | + * |
|
| 82 | + * @param int $qop |
|
| 83 | + * @return void |
|
| 84 | + */ |
|
| 85 | + public function setQOP($qop) { |
|
| 86 | + |
|
| 87 | + $this->qop = $qop; |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Validates the user. |
|
| 93 | + * |
|
| 94 | + * The A1 parameter should be md5($username . ':' . $realm . ':' . $password); |
|
| 95 | + * |
|
| 96 | + * @param string $A1 |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | + public function validateA1($A1) { |
|
| 100 | + |
|
| 101 | + $this->A1 = $A1; |
|
| 102 | + return $this->validate(); |
|
| 103 | + |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Validates authentication through a password. The actual password must be provided here. |
|
| 108 | + * It is strongly recommended not store the password in plain-text and use validateA1 instead. |
|
| 109 | + * |
|
| 110 | + * @param string $password |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function validatePassword($password) { |
|
| 114 | + |
|
| 115 | + $this->A1 = md5($this->digestParts['username'] . ':' . $this->realm . ':' . $password); |
|
| 116 | + return $this->validate(); |
|
| 117 | + |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Returns the username for the request |
|
| 122 | + * |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public function getUsername() { |
|
| 126 | + |
|
| 127 | + return $this->digestParts['username']; |
|
| 128 | + |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Validates the digest challenge |
|
| 133 | + * |
|
| 134 | + * @return bool |
|
| 135 | + */ |
|
| 136 | + protected function validate() { |
|
| 137 | + |
|
| 138 | + $A2 = $this->request->getMethod() . ':' . $this->digestParts['uri']; |
|
| 139 | + |
|
| 140 | + if ($this->digestParts['qop'] == 'auth-int') { |
|
| 141 | + // Making sure we support this qop value |
|
| 142 | + if (!($this->qop & self::QOP_AUTHINT)) return false; |
|
| 143 | + // We need to add an md5 of the entire request body to the A2 part of the hash |
|
| 144 | + $body = $this->request->getBody($asString = true); |
|
| 145 | + $this->request->setBody($body); |
|
| 146 | + $A2 .= ':' . md5($body); |
|
| 147 | + } else { |
|
| 148 | + |
|
| 149 | + // We need to make sure we support this qop value |
|
| 150 | + if (!($this->qop & self::QOP_AUTH)) return false; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $A2 = md5($A2); |
|
| 154 | + |
|
| 155 | + $validResponse = md5("{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}"); |
|
| 156 | + |
|
| 157 | + return $this->digestParts['response'] == $validResponse; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Returns an HTTP 401 header, forcing login |
|
| 164 | + * |
|
| 165 | + * This should be called when username and password are incorrect, or not supplied at all |
|
| 166 | + * |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + public function requireLogin() { |
|
| 170 | + |
|
| 171 | + $qop = ''; |
|
| 172 | + switch ($this->qop) { |
|
| 173 | + case self::QOP_AUTH : |
|
| 174 | + $qop = 'auth'; |
|
| 175 | + break; |
|
| 176 | + case self::QOP_AUTHINT : |
|
| 177 | + $qop = 'auth-int'; |
|
| 178 | + break; |
|
| 179 | + case self::QOP_AUTH | self::QOP_AUTHINT : |
|
| 180 | + $qop = 'auth,auth-int'; |
|
| 181 | + break; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $this->response->addHeader('WWW-Authenticate', 'Digest realm="' . $this->realm . '",qop="' . $qop . '",nonce="' . $this->nonce . '",opaque="' . $this->opaque . '"'); |
|
| 185 | + $this->response->setStatus(401); |
|
| 186 | + |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * This method returns the full digest string. |
|
| 192 | + * |
|
| 193 | + * It should be compatibile with mod_php format and other webservers. |
|
| 194 | + * |
|
| 195 | + * If the header could not be found, null will be returned |
|
| 196 | + * |
|
| 197 | + * @return mixed |
|
| 198 | + */ |
|
| 199 | + public function getDigest() { |
|
| 200 | 200 | |
| 201 | - return $this->request->getHeader('Authorization'); |
|
| 202 | - |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Parses the different pieces of the digest string into an array. |
|
| 208 | - * |
|
| 209 | - * This method returns false if an incomplete digest was supplied |
|
| 210 | - * |
|
| 211 | - * @param string $digest |
|
| 212 | - * @return mixed |
|
| 213 | - */ |
|
| 214 | - protected function parseDigest($digest) { |
|
| 201 | + return $this->request->getHeader('Authorization'); |
|
| 202 | + |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Parses the different pieces of the digest string into an array. |
|
| 208 | + * |
|
| 209 | + * This method returns false if an incomplete digest was supplied |
|
| 210 | + * |
|
| 211 | + * @param string $digest |
|
| 212 | + * @return mixed |
|
| 213 | + */ |
|
| 214 | + protected function parseDigest($digest) { |
|
| 215 | 215 | |
| 216 | - // protect against missing data |
|
| 217 | - $needed_parts = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1]; |
|
| 218 | - $data = []; |
|
| 216 | + // protect against missing data |
|
| 217 | + $needed_parts = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1]; |
|
| 218 | + $data = []; |
|
| 219 | 219 | |
| 220 | - preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $digest, $matches, PREG_SET_ORDER); |
|
| 221 | - |
|
| 222 | - foreach ($matches as $m) { |
|
| 223 | - $data[$m[1]] = $m[2] ? $m[2] : $m[3]; |
|
| 224 | - unset($needed_parts[$m[1]]); |
|
| 225 | - } |
|
| 220 | + preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $digest, $matches, PREG_SET_ORDER); |
|
| 221 | + |
|
| 222 | + foreach ($matches as $m) { |
|
| 223 | + $data[$m[1]] = $m[2] ? $m[2] : $m[3]; |
|
| 224 | + unset($needed_parts[$m[1]]); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - return $needed_parts ? false : $data; |
|
| 227 | + return $needed_parts ? false : $data; |
|
| 228 | 228 | |
| 229 | - } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | 231 | } |
@@ -11,9 +11,9 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Version { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Full version number |
|
| 16 | - */ |
|
| 17 | - const VERSION = '4.2.1'; |
|
| 14 | + /** |
|
| 15 | + * Full version number |
|
| 16 | + */ |
|
| 17 | + const VERSION = '4.2.1'; |
|
| 18 | 18 | |
| 19 | 19 | } |
@@ -13,62 +13,62 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Util { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Content negotiation |
|
| 18 | - * |
|
| 19 | - * @deprecated Use \Sabre\HTTP\negotiateContentType |
|
| 20 | - * @param string|null $acceptHeaderValue |
|
| 21 | - * @param array $availableOptions |
|
| 22 | - * @return string|null |
|
| 23 | - */ |
|
| 24 | - static function negotiateContentType($acceptHeaderValue, array $availableOptions) { |
|
| 16 | + /** |
|
| 17 | + * Content negotiation |
|
| 18 | + * |
|
| 19 | + * @deprecated Use \Sabre\HTTP\negotiateContentType |
|
| 20 | + * @param string|null $acceptHeaderValue |
|
| 21 | + * @param array $availableOptions |
|
| 22 | + * @return string|null |
|
| 23 | + */ |
|
| 24 | + static function negotiateContentType($acceptHeaderValue, array $availableOptions) { |
|
| 25 | 25 | |
| 26 | - return negotiateContentType($acceptHeaderValue, $availableOptions); |
|
| 26 | + return negotiateContentType($acceptHeaderValue, $availableOptions); |
|
| 27 | 27 | |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Deprecated! Use negotiateContentType. |
|
| 32 | - * |
|
| 33 | - * @deprecated Use \Sabre\HTTP\NegotiateContentType |
|
| 34 | - * @param string|null $acceptHeader |
|
| 35 | - * @param array $availableOptions |
|
| 36 | - * @return string|null |
|
| 37 | - */ |
|
| 38 | - static function negotiate($acceptHeaderValue, array $availableOptions) { |
|
| 30 | + /** |
|
| 31 | + * Deprecated! Use negotiateContentType. |
|
| 32 | + * |
|
| 33 | + * @deprecated Use \Sabre\HTTP\NegotiateContentType |
|
| 34 | + * @param string|null $acceptHeader |
|
| 35 | + * @param array $availableOptions |
|
| 36 | + * @return string|null |
|
| 37 | + */ |
|
| 38 | + static function negotiate($acceptHeaderValue, array $availableOptions) { |
|
| 39 | 39 | |
| 40 | - return negotiateContentType($acceptHeaderValue, $availableOptions); |
|
| 40 | + return negotiateContentType($acceptHeaderValue, $availableOptions); |
|
| 41 | 41 | |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Parses a RFC2616-compatible date string |
|
| 46 | - * |
|
| 47 | - * This method returns false if the date is invalid |
|
| 48 | - * |
|
| 49 | - * @deprecated Use parseDate |
|
| 50 | - * @param string $dateHeader |
|
| 51 | - * @return bool|DateTime |
|
| 52 | - */ |
|
| 53 | - static function parseHTTPDate($dateHeader) { |
|
| 44 | + /** |
|
| 45 | + * Parses a RFC2616-compatible date string |
|
| 46 | + * |
|
| 47 | + * This method returns false if the date is invalid |
|
| 48 | + * |
|
| 49 | + * @deprecated Use parseDate |
|
| 50 | + * @param string $dateHeader |
|
| 51 | + * @return bool|DateTime |
|
| 52 | + */ |
|
| 53 | + static function parseHTTPDate($dateHeader) { |
|
| 54 | 54 | |
| 55 | - return parseDate($dateHeader); |
|
| 55 | + return parseDate($dateHeader); |
|
| 56 | 56 | |
| 57 | - } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Transforms a DateTime object to HTTP's most common date format. |
|
| 61 | - * |
|
| 62 | - * We're serializing it as the RFC 1123 date, which, for HTTP must be |
|
| 63 | - * specified as GMT. |
|
| 64 | - * |
|
| 65 | - * @deprecated Use toDate |
|
| 66 | - * @param \DateTime $dateTime |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - static function toHTTPDate(\DateTime $dateTime) { |
|
| 59 | + /** |
|
| 60 | + * Transforms a DateTime object to HTTP's most common date format. |
|
| 61 | + * |
|
| 62 | + * We're serializing it as the RFC 1123 date, which, for HTTP must be |
|
| 63 | + * specified as GMT. |
|
| 64 | + * |
|
| 65 | + * @deprecated Use toDate |
|
| 66 | + * @param \DateTime $dateTime |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + static function toHTTPDate(\DateTime $dateTime) { |
|
| 70 | 70 | |
| 71 | - return toDate($dateTime); |
|
| 71 | + return toDate($dateTime); |
|
| 72 | 72 | |
| 73 | - } |
|
| 73 | + } |
|
| 74 | 74 | } |