- 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())
return [];
}
- $fetched_contact = false;
+ $fetched_contact = [];
if (empty($update)) {
if (is_null($update)) {
if ($failed) {
self::markForArchival($fetched_contact ?: []);
- return $fetched_contact ?? [];
+ return $fetched_contact;
}
}
// 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'] = '';
// 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']);
}
}
- 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
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');
}
}
/**
- * 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);
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();
}
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();
}
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();
}
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();
}