<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Register;
-use Friendica\Network\CurlResult;
+use Friendica\Network\IHTTPResult;
use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
if (($now - $contact_time) < (60 * 60 * 24)) {
return DateTimeFormat::utc('now +1 day');
}
-
+
// If the last contact was less than a week before then try again in a week
if (($now - $contact_time) < (60 * 60 * 24 * 7)) {
return DateTimeFormat::utc('now +1 week');
/**
* Detect server type by using the nodeinfo data
*
- * @param string $url address of the server
- * @param CurlResult $curlResult
+ * @param string $url address of the server
+ * @param IHTTPResult $httpResult
+ *
* @return array Server data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function fetchNodeinfo(string $url, CurlResult $curlResult)
+ private static function fetchNodeinfo(string $url, IHTTPResult $httpResult)
{
- if (!$curlResult->isSuccess()) {
+ if (!$httpResult->isSuccess()) {
return [];
}
- $nodeinfo = json_decode($curlResult->getBody(), true);
+ $nodeinfo = json_decode($httpResult->getBody(), true);
if (!is_array($nodeinfo) || empty($nodeinfo['links'])) {
return [];
/**
* Parses Nodeinfo 2
*
+ * @see https://git.feneas.org/jaywink/nodeinfo2
* @param string $nodeinfo_url address of the nodeinfo path
* @return array Server data
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
if (!empty($nodeinfo['protocols'])) {
$protocols = [];
foreach ($nodeinfo['protocols'] as $protocol) {
- $protocols[$protocol] = true;
+ if (is_string($protocol)) {
+ $protocols[$protocol] = true;
+ }
}
if (!empty($protocols['dfrn'])) {
*/
private static function analyseRootBody($curlResult, array $serverdata, string $url)
{
+ if (empty($curlResult->getBody())) {
+ return $serverdata;
+ }
+
$doc = new DOMDocument();
@$doc->loadHTML($curlResult->getBody());
$xpath = new DOMXPath($doc);
*
* @param int $gsid Server id
* @param int $protocol Protocol id
- * @return void
- * @throws Exception
+ * @return void
+ * @throws Exception
*/
public static function setProtocol(int $gsid, int $protocol)
{
}
}
- Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url']]);
+ Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url'], 'callstack' => System::callstack(20)]);
DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
}
* Fetch the protocol of the given server
*
* @param int $gsid Server id
- * @return int
- * @throws Exception
+ * @return int
+ * @throws Exception
*/
public static function getProtocol(int $gsid)
{