X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FDiaspora.php;h=b5ecfcefcc9d16f1b934fdd7d8d87e735249e1b2;hb=3a74f3364d28297ba957544893d9c721d683dba1;hp=8decec0d024feeb5833f56dca94fe6363b679898;hpb=7f3fb34c24e30b79d8c25f63dbb2c3c3da79e599;p=friendica.git diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 8decec0d02..b5ecfcefcc 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -365,15 +365,16 @@ class Diaspora /** * @brief: Decodes incoming Diaspora message in the new format * - * @param array $importer Array of the importer user - * @param string $raw raw post message + * @param array $importer Array of the importer user + * @param string $raw raw post message + * @param boolean $no_exit Don't do an http exit on error * * @return array * 'message' -> decoded Diaspora XML message * 'author' -> author diaspora handle * 'key' -> author public key (converted to pkcs#8) */ - public static function decodeRaw(array $importer, $raw) + public static function decodeRaw(array $importer, $raw, $no_exit = false) { $data = json_decode($raw); @@ -388,7 +389,11 @@ class Diaspora if (!is_object($j_outer_key_bundle)) { logger('Outer Salmon did not verify. Discarding.'); - System::httpExit(400); + if ($no_exit) { + return false; + } else { + System::httpExit(400); + } } $outer_iv = base64_decode($j_outer_key_bundle->iv); @@ -403,7 +408,11 @@ class Diaspora if (!is_object($basedom)) { logger('Received data does not seem to be an XML. Discarding. '.$xml); - System::httpExit(400); + if ($no_exit) { + return false; + } else { + System::httpExit(400); + } } $base = $basedom->children(NAMESPACE_SALMON_ME); @@ -425,19 +434,31 @@ class Diaspora $author_addr = base64_decode($key_id); if ($author_addr == '') { logger('No author could be decoded. Discarding. Message: ' . $xml); - System::httpExit(400); + if ($no_exit) { + return false; + } else { + System::httpExit(400); + } } $key = self::key($author_addr); if ($key == '') { logger("Couldn't get a key for handle " . $author_addr . ". Discarding."); - System::httpExit(400); + if ($no_exit) { + return false; + } else { + System::httpExit(400); + } } $verify = Crypto::rsaVerify($signed_data, $signature, $key); if (!$verify) { logger('Message did not verify. Discarding.'); - System::httpExit(400); + if ($no_exit) { + return false; + } else { + System::httpExit(400); + } } return ['message' => (string)base64url_decode($base->data), @@ -1050,7 +1071,7 @@ class Diaspora return false; } - $contact = dba::selectFirst('contact', [], ['id' => $cid]); + $contact = DBA::selectFirst('contact', [], ['id' => $cid]); if (!DBA::isResult($contact)) { // This here shouldn't happen at all logger("Haven't found a contact for user " . $uid . " and handle " . $handle, LOGGER_DEBUG); @@ -1079,7 +1100,7 @@ class Diaspora // It is deactivated by now, due to side effects. See issue https://github.com/friendica/friendica/pull/4033 // It is not removed by now. Possibly the code is needed? //if (!$is_comment && $contact["rel"] == Contact::FOLLOWER && in_array($importer["page-flags"], array(Contact::PAGE_FREELOVE))) { - // dba::update( + // DBA::update( // 'contact', // array('rel' => Contact::FRIEND, 'writable' => true), // array('id' => $contact["id"], 'uid' => $contact["uid"]) @@ -1571,17 +1592,13 @@ class Diaspora if (DBA::isResult($item)) { return $item["uri"]; } elseif (!$onlyfound) { - $contact = Contact::getDetailsByAddr($author, 0); - if (!empty($contact['network'])) { - $prefix = 'urn:X-' . $contact['network'] . ':'; - } else { - // This fallback should happen most unlikely - $prefix = 'urn:X-dspr:'; - } + $person = self::personByHandle($author); - $author_parts = explode('@', $author); + $parts = parse_url($person['url']); + unset($parts['path']); + $host_url = Network::unparseURL($parts); - return $prefix . $author_parts[1] . ':' . $author_parts[0] . ':'. $guid; + return $host_url . '/objects/' . $guid; } return ""; @@ -1821,10 +1838,10 @@ class Diaspora "to_name" => $importer["username"], "to_email" => $importer["email"], "uid" =>$importer["uid"], - "item" => ["subject" => $subject, "body" => $body], + "item" => ["id" => $conversation["id"], "title" => $subject, "subject" => $subject, "body" => $body], "source_name" => $person["name"], "source_link" => $person["url"], - "source_photo" => $person["thumb"], + "source_photo" => $person["photo"], "verb" => ACTIVITY_POST, "otype" => "mail"] ); @@ -1952,11 +1969,8 @@ class Diaspora $datarray["contact-id"] = $author_contact["cid"]; $datarray["network"] = $author_contact["network"]; - $datarray["author-link"] = $person["url"]; - $datarray["author-id"] = Contact::getIdForURL($person["url"], 0); - - $datarray["owner-link"] = $contact["url"]; - $datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0); + $datarray["owner-link"] = $datarray["author-link"] = $person["url"]; + $datarray["owner-id"] = $datarray["author-id"] = Contact::getIdForURL($person["url"], 0); $datarray["guid"] = $guid; $datarray["uri"] = self::getUriFromGuid($author, $guid); @@ -2425,10 +2439,11 @@ class Diaspora Contact::updateAvatar($contact_record["photo"], $importer["uid"], $contact_record["id"]); - // technically they are sharing with us (Contact::SHARING), - // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX - // we are going to change the relationship and make them a follower. - + /* + * technically they are sharing with us (Contact::SHARING), + * but if our page-type is Profile::PAGE_COMMUNITY or Profile::PAGE_SOAPBOX + * we are going to change the relationship and make them a follower. + */ if (($importer["page-flags"] == Contact::PAGE_FREELOVE) && $sharing && $following) { $new_relation = Contact::FRIEND; } elseif (($importer["page-flags"] == Contact::PAGE_FREELOVE) && $sharing) { @@ -2755,7 +2770,7 @@ class Diaspora * * @return int The message id of the newly created item */ - private static function receiveStatusMessage(array $importer, $data, $xml) + private static function receiveStatusMessage(array $importer, SimpleXMLElement $data, $xml) { $author = notags(unxmlify($data->author)); $guid = notags(unxmlify($data->guid)); @@ -3075,7 +3090,7 @@ class Diaspora logger("transmit: ".$logid."-".$guid." to ".$dest_url." returns: ".$return_code); if (!$return_code || (($return_code == 503) && (stristr($a->get_curl_headers(), "retry-after")))) { - if (!$no_queue && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) { + if (!$no_queue && !empty($contact['contact-type']) && ($contact['contact-type'] != Contact::ACCOUNT_TYPE_RELAY)) { logger("queue message"); // queue message for redelivery Queue::add($contact["id"], Protocol::DIASPORA, $envelope, $public_batch, $guid); @@ -3182,7 +3197,7 @@ class Diaspora $author = self::myHandle($owner); $message = ["author" => $author, - "guid" => System::createGUID(32), + "guid" => System::createUUID(), "parent_type" => "Post", "parent_guid" => $item["guid"]]; @@ -3474,7 +3489,7 @@ class Diaspora $myaddr = self::myHandle($owner); - $public = (($item["private"]) ? "false" : "true"); + $public = ($item["private"] ? "false" : "true"); $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);