Skip to content

Commit 2c3ad43

Browse files
committed
Log failure on parsing
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
1 parent f46993e commit 2c3ad43

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

apps/dav/appinfo/v1/carddav.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@
8484

8585
$server->addPlugin(new \Sabre\DAV\Sync\Plugin());
8686
$server->addPlugin(new \Sabre\CardDAV\VCFExportPlugin());
87-
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
87+
$server->addPlugin(new \OCA\DAV\CardDAV\ImageExportPlugin(new \OCA\DAV\CardDAV\PhotoCache(
88+
\OC::$server->getAppDataDir('dav-photocache'),
89+
\OC::$server->getLogger()
90+
)));
8891
$server->addPlugin(new ExceptionLoggerPlugin('carddav', \OC::$server->getLogger()));
8992

9093
// And off we go!

apps/dav/lib/AppInfo/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function __construct() {
5454

5555
$container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) {
5656
return new PhotoCache(
57-
$server->getAppDataDir('dav-photocache')
57+
$server->getAppDataDir('dav-photocache'),
58+
$server->getLogger()
5859
);
5960
});
6061

apps/dav/lib/CardDAV/ImageExportPlugin.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
108108

109109
$response->setBody($file->getContent());
110110
} catch (NotFoundException $e) {
111-
var_dump($e);
112111
$response->setStatus(404);
113112
}
114113

apps/dav/lib/CardDAV/PhotoCache.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,32 @@
2424
namespace OCA\DAV\CardDAV;
2525

2626
use OCP\Files\IAppData;
27+
use OCP\ILogger;
2728
use OCP\Files\NotFoundException;
2829
use OCP\Files\NotPermittedException;
2930
use OCP\Files\SimpleFS\ISimpleFile;
3031
use OCP\Files\SimpleFS\ISimpleFolder;
3132
use Sabre\CardDAV\Card;
3233
use Sabre\VObject\Property\Binary;
33-
use Sabre\VObject\Property\Uri;
3434
use Sabre\VObject\Reader;
3535

3636
class PhotoCache {
3737

38-
/** @var IAppData $appData */
38+
/** @var IAppData */
3939
protected $appData;
4040

41+
/** @var ILogger */
42+
protected $logger;
43+
4144
/**
4245
* PhotoCache constructor.
4346
*
4447
* @param IAppData $appData
48+
* @param ILogger $logger
4549
*/
46-
public function __construct(IAppData $appData) {
50+
public function __construct(IAppData $appData, ILogger $logger) {
4751
$this->appData = $appData;
52+
$this->logger = $logger;
4853
}
4954

5055
/**
@@ -135,13 +140,14 @@ private function getFile(ISimpleFolder $folder, $size) {
135140

136141
$ratio = $photo->width() / $photo->height();
137142
if ($ratio < 1) {
138-
$ratio = 1/$ratio;
143+
$ratio = 1 / $ratio;
139144
}
140-
$size = (int)($size * $ratio);
141145

146+
$size = (int) ($size * $ratio);
142147
if ($size !== -1) {
143148
$photo->resize($size);
144149
}
150+
145151
try {
146152
$file = $folder->newFile($path);
147153
$file->putContent($photo->data());
@@ -153,7 +159,6 @@ private function getFile(ISimpleFolder $folder, $size) {
153159
return $file;
154160
}
155161

156-
157162
/**
158163
* @param int $addressBookId
159164
* @param string $cardUri
@@ -194,7 +199,6 @@ private function getPhoto(Card $node) {
194199
}
195200

196201
$photo = $vObject->PHOTO;
197-
$val = $photo->getValue();
198202

199203
// handle data URI. e.g PHOTO;VALUE=URI:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE
200204
if ($photo->getValueType() === 'URI') {
@@ -205,12 +209,13 @@ private function getPhoto(Card $node) {
205209
return false;
206210
}
207211
if (substr_count($parsed['path'], ';') === 1) {
208-
list($type,) = explode(';', $parsed['path']);
212+
list($type) = explode(';', $parsed['path']);
209213
}
210214
$val = file_get_contents($val);
211215
} else {
212216
// get type if binary data
213217
$type = $this->getBinaryType($photo);
218+
$val = $photo->getValue();
214219
}
215220

216221
$allowedContentTypes = [
@@ -219,16 +224,18 @@ private function getPhoto(Card $node) {
219224
'image/gif',
220225
];
221226

222-
if(!in_array($type, $allowedContentTypes, true)) {
227+
if (!in_array($type, $allowedContentTypes, true)) {
223228
$type = 'application/octet-stream';
224229
}
225230

226231
return [
227232
'Content-Type' => $type,
228-
'body' => $val
233+
'body' => $val
229234
];
230-
} catch(\Exception $ex) {
231-
235+
} catch (\Exception $e) {
236+
$this->logger->logException($ex, [
237+
'message' => 'Exception during vcard photo parsing'
238+
]);
232239
}
233240
return false;
234241
}

apps/dav/lib/Server.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ public function __construct(IRequest $request, $baseUri) {
167167
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
168168
$this->server->addPlugin(new VCFExportPlugin());
169169
$this->server->addPlugin(new MultiGetExportPlugin());
170-
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache'))));
170+
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
171+
\OC::$server->getAppDataDir('dav-photocache'),
172+
\OC::$server->getLogger())
173+
));
171174
}
172175

173176
// system tags plugins

0 commit comments

Comments
 (0)