Continued:
- changed back to 'return false;' as other methods heavily rely on false instead of an empty array as pointed out by @heluecht@pirati.ca - $fetched_contact should be initialized as an empty array, let's not make this code more crazier than it already is (see APContact::getByURL())
This commit is contained in:
parent
c467bff79f
commit
36d56a4041
|
@ -124,7 +124,7 @@ class APContact
|
|||
return [];
|
||||
}
|
||||
|
||||
$fetched_contact = false;
|
||||
$fetched_contact = [];
|
||||
|
||||
if (empty($update)) {
|
||||
if (is_null($update)) {
|
||||
|
@ -206,7 +206,7 @@ class APContact
|
|||
|
||||
if ($failed) {
|
||||
self::markForArchival($fetched_contact ?: []);
|
||||
return $fetched_contact ?? [];
|
||||
return $fetched_contact;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ class APContact
|
|||
|
||||
// Quit if none of the basic values are set
|
||||
if (empty($apcontact['url']) || empty($apcontact['type']) || (($apcontact['type'] != 'Tombstone') && empty($apcontact['inbox']))) {
|
||||
return $fetched_contact ?? [];
|
||||
return $fetched_contact;
|
||||
} elseif ($apcontact['type'] == 'Tombstone') {
|
||||
// The "inbox" field must have a content
|
||||
$apcontact['inbox'] = '';
|
||||
|
@ -283,7 +283,7 @@ class APContact
|
|||
|
||||
// Quit if this doesn't seem to be an account at all
|
||||
if (!in_array($apcontact['type'], ActivityPub::ACCOUNT_TYPES)) {
|
||||
return $fetched_contact ?? [];
|
||||
return $fetched_contact;
|
||||
}
|
||||
|
||||
$parts = parse_url($apcontact['url']);
|
||||
|
|
|
@ -59,12 +59,13 @@ class Notify extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
private static function dispatchPublic($postdata)
|
||||
private static function dispatchPublic(array $postdata)
|
||||
{
|
||||
$msg = Diaspora::decodeRaw($postdata, '', true);
|
||||
if (!$msg) {
|
||||
if (!is_array($msg)) {
|
||||
// We have to fail silently to be able to hand it over to the salmon parser
|
||||
return false;
|
||||
Logger::warning('Diaspora::decodeRaw() has failed for some reason.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the corresponding public contact
|
||||
|
@ -88,10 +89,10 @@ class Notify extends BaseModule
|
|||
System::xmlExit($ret, 'Done');
|
||||
}
|
||||
|
||||
private static function dispatchPrivate($user, $postdata)
|
||||
private static function dispatchPrivate(array $user, array $postdata)
|
||||
{
|
||||
$msg = Diaspora::decodeRaw($postdata, $user['prvkey'] ?? '');
|
||||
if (!$msg) {
|
||||
if (!is_array($msg)) {
|
||||
System::xmlExit(4, 'Unable to parse message');
|
||||
}
|
||||
|
||||
|
|
|
@ -203,20 +203,20 @@ class Diaspora
|
|||
}
|
||||
|
||||
/**
|
||||
* Decodes incoming Diaspora message in the new format
|
||||
* Decodes incoming Diaspora message in the new format. This method returns false on an error.
|
||||
*
|
||||
* @param string $raw raw post message
|
||||
* @param string $privKey The private key of the importer
|
||||
* @param boolean $no_exit Don't do an http exit on error
|
||||
*
|
||||
* @return array
|
||||
* @return bool|array
|
||||
* 'message' -> decoded Diaspora XML message
|
||||
* 'author' -> author diaspora handle
|
||||
* 'key' -> author public key (converted to pkcs#8)
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function decodeRaw(string $raw, string $privKey = '', bool $no_exit = false): array
|
||||
public static function decodeRaw(string $raw, string $privKey = '', bool $no_exit = false)
|
||||
{
|
||||
$data = json_decode($raw);
|
||||
|
||||
|
@ -232,7 +232,7 @@ class Diaspora
|
|||
if (!is_object($j_outer_key_bundle)) {
|
||||
Logger::notice('Outer Salmon did not verify. Discarding.');
|
||||
if ($no_exit) {
|
||||
return [];
|
||||
return false;
|
||||
} else {
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ class Diaspora
|
|||
if (!is_object($basedom)) {
|
||||
Logger::notice('Received data does not seem to be an XML. Discarding. '.$xml);
|
||||
if ($no_exit) {
|
||||
return [];
|
||||
return false;
|
||||
} else {
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ class Diaspora
|
|||
if ($author_addr == '') {
|
||||
Logger::notice('No author could be decoded. Discarding. Message: ' . $xml);
|
||||
if ($no_exit) {
|
||||
return [];
|
||||
return false;
|
||||
} else {
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ class Diaspora
|
|||
if ($key == '') {
|
||||
Logger::notice("Couldn't get a key for handle " . $author_addr . ". Discarding.");
|
||||
if ($no_exit) {
|
||||
return [];
|
||||
return false;
|
||||
} else {
|
||||
throw new \Friendica\Network\HTTPException\BadRequestException();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user