summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2020-11-30 23:58:32 -0100
committerMaxence Lange <maxence@artificial-owl.com>2020-11-30 23:58:32 -0100
commit68660884319e2bb03ebcbe7cdd26434b3473c50b (patch)
treeac00c2137fb19bac684201a361fe4636a8b2ec9f
parentda20d5901368e7a78be3926f827c6199f285aff1 (diff)
using TNC20Request
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--composer.json2
-rw-r--r--composer.lock122
-rw-r--r--lib/Controller/ActivityPubController.php5
-rw-r--r--lib/Controller/OAuthController.php1
-rw-r--r--lib/Search/UnifiedSearchProvider.php5
-rw-r--r--lib/Service/ActivityService.php9
-rw-r--r--lib/Service/CacheActorService.php18
-rw-r--r--lib/Service/CacheDocumentService.php11
-rw-r--r--lib/Service/ConfigService.php20
-rw-r--r--lib/Service/CurlService.php112
-rw-r--r--lib/Service/SearchService.php9
-rw-r--r--lib/Service/SignatureService.php28
-rw-r--r--lib/Service/TestService.php8
13 files changed, 197 insertions, 153 deletions
diff --git a/composer.json b/composer.json
index 2a6532ba..bc4315ce 100644
--- a/composer.json
+++ b/composer.json
@@ -23,7 +23,7 @@
}
},
"require": {
- "daita/my-small-php-tools": "dev-master#ca9c257dd640576c072cb50282e15ae51147cfc2",
+ "daita/my-small-php-tools": "dev-master",
"gumlet/php-image-resize": "2.0.*",
"friendica/json-ld": "^1.0"
},
diff --git a/composer.lock b/composer.lock
index c951dbec..302f8fc2 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "a5fe26ce64e01c6e8e2687e75ff674fb",
+ "content-hash": "773474981fdf7ef0b2f1bcf58cf1b2ec",
"packages": [
{
"name": "daita/my-small-php-tools",
@@ -12,12 +12,12 @@
"source": {
"type": "git",
"url": "https://github.com/daita/my-small-php-tools.git",
- "reference": "ca9c257dd640576c072cb50282e15ae51147cfc2"
+ "reference": "aeed155a9c0cf79153bc9703d1792b0361162dd3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/ca9c257dd640576c072cb50282e15ae51147cfc2",
- "reference": "ca9c257dd640576c072cb50282e15ae51147cfc2",
+ "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/aeed155a9c0cf79153bc9703d1792b0361162dd3",
+ "reference": "aeed155a9c0cf79153bc9703d1792b0361162dd3",
"shasum": ""
},
"require": {
@@ -40,7 +40,7 @@
}
],
"description": "My small PHP Tools",
- "time": "2020-09-29T15:30:16+00:00"
+ "time": "2020-12-01T00:47:38+00:00"
},
{
"name": "friendica/json-ld",
@@ -1003,23 +1003,23 @@
},
{
"name": "sebastian/code-unit-reverse-lookup",
- "version": "1.0.1",
+ "version": "1.0.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git",
- "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18"
+ "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18",
- "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18",
+ "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619",
+ "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619",
"shasum": ""
},
"require": {
- "php": "^5.6 || ^7.0"
+ "php": ">=5.6"
},
"require-dev": {
- "phpunit/phpunit": "^5.7 || ^6.0"
+ "phpunit/phpunit": "^8.5"
},
"type": "library",
"extra": {
@@ -1044,7 +1044,13 @@
],
"description": "Looks up which function or method a line of code belongs to",
"homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/",
- "time": "2017-03-04T06:30:41+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
+ "time": "2020-11-30T08:15:22+00:00"
},
{
"name": "sebastian/comparator",
@@ -1214,20 +1220,20 @@
},
{
"name": "sebastian/exporter",
- "version": "3.1.2",
+ "version": "3.1.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e"
+ "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e",
- "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/6b853149eab67d4da22291d36f5b0631c0fd856e",
+ "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e",
"shasum": ""
},
"require": {
- "php": "^7.0",
+ "php": ">=7.0",
"sebastian/recursion-context": "^3.0"
},
"require-dev": {
@@ -1277,7 +1283,13 @@
"export",
"exporter"
],
- "time": "2019-09-14T09:02:43+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
+ "time": "2020-11-30T07:47:53+00:00"
},
{
"name": "sebastian/global-state",
@@ -1332,20 +1344,20 @@
},
{
"name": "sebastian/object-enumerator",
- "version": "3.0.3",
+ "version": "3.0.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-enumerator.git",
- "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5"
+ "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5",
- "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5",
+ "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2",
+ "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2",
"shasum": ""
},
"require": {
- "php": "^7.0",
+ "php": ">=7.0",
"sebastian/object-reflector": "^1.1.1",
"sebastian/recursion-context": "^3.0"
},
@@ -1375,24 +1387,30 @@
],
"description": "Traverses array structures and object graphs to enumerate all referenced objects",
"homepage": "https://github.com/sebastianbergmann/object-enumerator/",
- "time": "2017-08-03T12:35:26+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
+ "time": "2020-11-30T07:40:27+00:00"
},
{
"name": "sebastian/object-reflector",
- "version": "1.1.1",
+ "version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/object-reflector.git",
- "reference": "773f97c67f28de00d397be301821b06708fca0be"
+ "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be",
- "reference": "773f97c67f28de00d397be301821b06708fca0be",
+ "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d",
+ "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d",
"shasum": ""
},
"require": {
- "php": "^7.0"
+ "php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
@@ -1420,24 +1438,30 @@
],
"description": "Allows reflection of object attributes, including inherited and non-public ones",
"homepage": "https://github.com/sebastianbergmann/object-reflector/",
- "time": "2017-03-29T09:07:27+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
+ "time": "2020-11-30T07:37:18+00:00"
},
{
"name": "sebastian/recursion-context",
- "version": "3.0.0",
+ "version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8"
+ "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8",
- "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb",
+ "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb",
"shasum": ""
},
"require": {
- "php": "^7.0"
+ "php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
@@ -1459,21 +1483,27 @@
],
"authors": [
{
- "name": "Jeff Welch",
- "email": "whatthejeff@gmail.com"
- },
- {
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
+ "name": "Jeff Welch",
+ "email": "whatthejeff@gmail.com"
+ },
+ {
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
- "time": "2017-03-03T06:23:57+00:00"
+ "funding": [
+ {
+ "url": "https://github.com/sebastianbergmann",
+ "type": "github"
+ }
+ ],
+ "time": "2020-11-30T07:34:24+00:00"
},
{
"name": "sebastian/resource-operations",
@@ -1562,16 +1592,16 @@
},
{
"name": "symfony/polyfill-ctype",
- "version": "v1.18.1",
+ "version": "v1.19.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
- "reference": "1c302646f6efc070cd46856e600e5e0684d6b454"
+ "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454",
- "reference": "1c302646f6efc070cd46856e600e5e0684d6b454",
+ "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/aed596913b70fae57be53d86faa2e9ef85a2297b",
+ "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b",
"shasum": ""
},
"require": {
@@ -1583,7 +1613,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.18-dev"
+ "dev-main": "1.19-dev"
},
"thanks": {
"name": "symfony/polyfill",
@@ -1634,7 +1664,7 @@
"type": "tidelift"
}
],
- "time": "2020-07-14T12:35:20+00:00"
+ "time": "2020-10-23T09:01:57+00:00"
},
{
"name": "theseer/tokenizer",
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php
index 1138bc64..0462b3da 100644
--- a/lib/Controller/ActivityPubController.php
+++ b/lib/Controller/ActivityPubController.php
@@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Controller;
+use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use daita\MySmallPhpTools\Traits\TAsync;
use daita\MySmallPhpTools\Traits\TStringTools;
@@ -65,6 +66,7 @@ class ActivityPubController extends Controller {
use TNCDataResponse;
use TStringTools;
use TAsync;
+use TNC20Logger;
/** @var SocialPubController */
@@ -246,10 +248,9 @@ class ActivityPubController extends Controller {
* @return Response
*/
public function inbox(string $username): Response {
-
try {
$body = file_get_contents('php://input');
- $this->miscService->log('[<<] inbox: ' . $body, 1);
+ $this->debug('[<<] inbox', ['body' => $body]);
$requestTime = 0;
$origin = $this->signatureService->checkRequest($this->request, $body, $requestTime);
diff --git a/lib/Controller/OAuthController.php b/lib/Controller/OAuthController.php
index 3f46cdc9..23a22c88 100644
--- a/lib/Controller/OAuthController.php
+++ b/lib/Controller/OAuthController.php
@@ -268,6 +268,7 @@ class OAuthController extends Controller {
], Http::STATUS_OK
);
} catch (Exception $e) {
+ $this->miscService->log($e->getMessage() . ' ' . get_class($e));
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_UNAUTHORIZED);
}
}
diff --git a/lib/Search/UnifiedSearchProvider.php b/lib/Search/UnifiedSearchProvider.php
index 9ef522cc..13eae127 100644
--- a/lib/Search/UnifiedSearchProvider.php
+++ b/lib/Search/UnifiedSearchProvider.php
@@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Search;
+use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Exceptions\AccountDoesNotExistException;
@@ -62,6 +63,7 @@ class UnifiedSearchProvider implements IProvider {
use TArrayTools;
+ use TNC20Logger;
/** @var IL10N */
@@ -217,7 +219,8 @@ class UnifiedSearchProvider implements IProvider {
private function convertAccounts(array $accounts): array {
$result = [];
foreach ($accounts as $account) {
- $icon = ($account->hasIcon()) ? $account->getIcon()->getUrl() : '';
+ $icon = ($account->hasIcon()) ? $account->getIcon()
+ ->getUrl() : '';
$result[] = new UnifiedSearchResult(
$icon,
$account->getPreferredUsername(),
diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php
index 41372d98..9e2d5f38 100644
--- a/lib/Service/ActivityService.php
+++ b/lib/Service/ActivityService.php
@@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
+use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
@@ -365,9 +366,9 @@ class ActivityService {
/**
* @param RequestQueue $queue
*
- * @return Request
+ * @return NC20Request
*/
- private function generateRequestFromQueue(RequestQueue $queue): Request {
+ private function generateRequestFromQueue(RequestQueue $queue): NC20Request {
$path = $queue->getInstance();
$requestType = Request::TYPE_GET;
@@ -377,10 +378,10 @@ class ActivityService {
$requestType = Request::TYPE_POST;
}
- $request = new Request($path->getPath(), $requestType);
+ $request = new NC20Request($path->getPath(), $requestType);
$request->setTimeout($queue->getTimeout());
$request->setDataJson($queue->getActivity());
- $request->setAddress($path->getAddress());
+ $request->setHost($path->getAddress());
$request->setProtocol($path->getProtocol());
return $request;
diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php
index b448a682..bfb594e8 100644
--- a/lib/Service/CacheActorService.php
+++ b/lib/Service/CacheActorService.php
@@ -36,6 +36,7 @@ use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
+use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\AP;
@@ -53,10 +54,16 @@ use OCA\Social\Model\ActivityPub\Actor\Person;
use OCP\IURLGenerator;
+/**
+ * Class CacheActorService
+ *
+ * @package OCA\Social\Service
+ */
class CacheActorService {
use TArrayTools;
+ use TNC20Logger;
/** @var IURLGenerator */
@@ -129,7 +136,6 @@ class CacheActorService {
* @throws UnauthorizedFediverseException
*/
public function getFromId(string $id, bool $refresh = false): Person {
-
$posAnchor = strpos($id, '#');
if ($posAnchor !== false) {
$id = substr($id, 0, $posAnchor);
@@ -144,6 +150,8 @@ class CacheActorService {
} catch (CacheActorDoesNotExistException $e) {
$object = $this->curlService->retrieveObject($id);
+ $this->debug('object retrieved', ['id' => $id, 'object' => $object]);
+
/** @var Person $actor */
$actor = AP::$activityPub->getItemFromData($object);
if (!AP::$activityPub->isActor($actor)) {
@@ -220,9 +228,15 @@ class CacheActorService {
} catch (CacheActorDoesNotExistException $e) {
}
+ $this->debug('getFromAccount', ['account' => $account, 'retrieve' => $retrieve]);
+
try {
$actor = $this->cacheActorsRequest->getFromAccount($account);
+
+ $this->debug('Found Actor', ['account' => $account, 'actor' => $actor]);
} catch (CacheActorDoesNotExistException $e) {
+ $this->debug('Actor not found', ['account' => $account]);
+
if (!$retrieve) {
throw new CacheActorDoesNotExistException();
}
@@ -230,6 +244,8 @@ class CacheActorService {
$actor = $this->curlService->retrieveAccount($account);
$actor->setAccount($account);
try {
+ $this->warning('Saving Actor', false, ['actor' => $actor]);
+
$this->save($actor);
} catch (Exception $e) {
throw new InvalidResourceException($e->getMessage());
diff --git a/lib/Service/CacheDocumentService.php b/lib/Service/CacheDocumentService.php
index 22fb640d..358cc81b 100644
--- a/lib/Service/CacheDocumentService.php
+++ b/lib/Service/CacheDocumentService.php
@@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Exceptions\RequestContentException;
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
+use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TStringTools;
@@ -270,16 +271,14 @@ class CacheDocumentService {
* @throws SocialAppConfigException
* @throws UnauthorizedFediverseException
*/
- public function retrieveContent(string $url) {
+ public function retrieveContent(string $url): string {
$url = parse_url($url);
$this->mustContains(['path', 'host', 'scheme'], $url);
- $request = new Request($url['path'], Request::TYPE_GET, true);
- $request->setAddress($url['host']);
+ $request = new NC20Request($url['path'], Request::TYPE_GET, true);
+ $request->setHost($url['host']);
$request->setProtocol($url['scheme']);
- $content = $this->curlService->doRequest($request);
-
- return $content;
+ return $this->curlService->doRequest($request);
}
}
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
index b77fda3e..38cac425 100644
--- a/lib/Service/ConfigService.php
+++ b/lib/Service/ConfigService.php
@@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Service;
+use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TPathTools;
@@ -436,10 +437,25 @@ class ConfigService {
/**
- * @param Request $request
+ * @param NC20Request $request
*/
- public function configureRequest(Request $request) {
+ public function configureRequest(NC20Request $request) {
$request->setVerifyPeer($this->getAppValue(ConfigService::SOCIAL_SELF_SIGNED) !== '1');
+
+ if ($request->getType() === Request::TYPE_GET) {
+ $request->addHeader(
+ 'Accept', 'application/json; profile="https://www.w3.org/ns/activitystreams"'
+ );
+ }
+
+ if ($request->getType() === Request::TYPE_POST) {
+ $request->addHeader(
+ 'Content-Type', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
+ );
+ }
+
+ $request->setLocalAddressAllowed(true);
+ $request->setFollowLocation(true);
}
diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php
index 2da6f0cf..a3b3b45a 100644
--- a/lib/Service/CurlService.php
+++ b/lib/Service/CurlService.php
@@ -37,10 +37,11 @@ use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
use daita\MySmallPhpTools\Exceptions\RequestServerException;
+use daita\MySmallPhpTools\Model\Nextcloud\nc20\NC20Request;
use daita\MySmallPhpTools\Model\Request;
+use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TPathTools;
-use daita\MySmallPhpTools\Traits\TRequest;
use Exception;
use OCA\Social\AP;
use OCA\Social\Exceptions\HostMetaException;
@@ -58,14 +59,11 @@ class CurlService {
use TArrayTools;
use TPathTools;
- use TRequest {
- initRequestPost as initRequestPostOrig;
- initRequestGet as initRequestGetOrig;
+ use TNC20Request {
retrieveJson as retrieveJsonOrig;
doRequest as doRequestOrig;
}
-
const ASYNC_REQUEST_TOKEN = '/async/request/{token}';
const USER_AGENT = 'Nextcloud Social';
@@ -96,6 +94,7 @@ class CurlService {
$maxDlSize = $this->configService->getAppValue(ConfigService::SOCIAL_MAX_SIZE) * (1024 * 1024);
$this->setMaxDownloadSize($maxDlSize);
+ $this->setup('app', 'social');
}
@@ -113,6 +112,7 @@ class CurlService {
* @throws UnauthorizedFediverseException
*/
public function webfingerAccount(string &$account): array {
+ $this->debug('webfingerAccount', ['account' => $account]);
$account = $this->withoutBeginAt($account);
// we consider an account is like an email
@@ -132,12 +132,14 @@ class CurlService {
$path = '/.well-known/webfinger';
}
- $request = new Request($path);
- $request->addData('resource', 'acct:' . $account);
- $request->setAddress($host);
+ $request = new NC20Request($path);
+ $request->addParam('resource', 'acct:' . $account);
+ $request->setHost($host);
$request->setProtocols($protocols);
$result = $this->retrieveJson($request);
+ $this->notice('webfingerAccount, request result', false, ['request' => $request]);
+
$subject = $this->get('subject', $result, '');
list($type, $temp) = explode(':', $subject, 2);
if ($type === 'acct') {
@@ -156,14 +158,17 @@ class CurlService {
* @throws HostMetaException
*/
public function hostMeta(string &$host, array &$protocols): string {
- $request = new Request('/.well-known/host-meta');
- $request->setAddress($host);
+ $request = new NC20Request('/.well-known/host-meta');
+ $request->setHost($host);
$request->setProtocols($protocols);
+ $this->debug('hostMeta', ['host' => $host, 'protocols' => $protocols]);
+
try {
$result = $this->retrieveJson($request);
} catch (Exception $e) {
- $this->miscService->log('hostMeta Exception - ' . get_class($e) . ' - ' . $e->getMessage(), 0);
+ $this->exception($e, self::$NOTICE, ['request' => $request]);
+
throw new HostMetaException(get_class($e) . ' - ' . $e->getMessage());
}
@@ -194,6 +199,7 @@ class CurlService {
* @throws UnauthorizedFediverseException
*/
public function retrieveAccount(string &$account): Person {
+ $this->debug('retrieveAccount', ['account' => $account]);
$result = $this->webfingerAccount($account);
try {
@@ -205,10 +211,12 @@ class CurlService {
$id = $this->get('href', $link, '');
$data = $this->retrieveObject($id);
+ $this->debug('retrieveAccount, details', ['link' => $link, 'data' => $data, 'account' => $account]);
+
/** @var Person $actor */
$actor = AP::$activityPub->getItemFromData($data);
if (!AP::$activityPub->isActor($actor)) {
- throw new ItemUnknownException();
+ throw new ItemUnknownException(json_encode($actor) . ' is not an Actor');
}
if (strtolower($actor->getId()) !== strtolower($id)) {
@@ -235,15 +243,20 @@ class CurlService {
* @throws UnauthorizedFediverseException
*/
public function retrieveObject($id): array {
+ $this->debug('retrieveObject', ['id' => $id]);
$url = parse_url($id);
$this->mustContains(['path', 'host', 'scheme'], $url);
- $request = new Request($url['path'], Request::TYPE_GET);
- $request->setAddress($url['host']);
+ $request = new NC20Request($url['path'], Request::TYPE_GET);
+ $request->setHost($url['host']);
$request->setProtocol($url['scheme']);
+ $this->debug('retrieveObject', ['request' => $request]);
+
$result = $this->retrieveJson($request);
+ $this->notice('retrieveObject, request result', false, ['request' => $request]);
+
if (is_array($result)) {
- $result['_host'] = $request->getAddress();
+ $result['_host'] = $request->getHost();
}
return $result;
@@ -251,35 +264,24 @@ class CurlService {
/**
- * @param Request $request
+ * @param NC20Request $request
*
* @return array
* @throws RequestContentException
* @throws RequestNetworkException
- * @throws RequestResultNotJsonException
- * @throws RequestResultSizeException
- * @throws RequestServerException
*/
- public function retrieveJson(Request $request): array {
- $this->configService->configureRequest($request);
- $this->assignUserAgent($request);
-
+ public function retrieveJson(NC20Request $request): array {
try {
- $result = $this->retrieveJsonOrig($request);
- } catch (RequestResultSizeException | RequestResultNotJsonException $e) {
- $this->miscService->log(
- '[!!] request: ' . json_encode($request) . ' - content-type: '
- . $request->getContentType() . ' - ' . $e->getMessage(), 1
- );
+ return $this->retrieveJsonOrig($request);
+ } catch (RequestNetworkException | RequestContentException $e) {
+ $this->exception($e, self::$NOTICE, ['request' => $request]);
throw $e;
}
-
- return $result;
}
/**
- * @param Request $request
+ * @param NC20Request $request
*
* @return mixed
* @throws SocialAppConfigException
@@ -289,7 +291,8 @@ class CurlService {
* @throws RequestResultSizeException
* @throws RequestServerException
*/
- public function doRequest(Request $request) {
+ // migration ?
+ public function doRequest(NC20Request $request) {
$this->fediverseService->authorized($request->getAddress());
$this->configService->configureRequest($request);
$this->assignUserAgent($request);
@@ -299,9 +302,9 @@ class CurlService {
/**
- * @param Request $request
+ * @param NC20Request $request
*/
- public function assignUserAgent(Request $request) {
+ public func