From 0594f13c35d53363fc36b31b23867331c1a9c35c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 2 Apr 2018 12:53:48 +0000 Subject: [PATCH] Receiving was tested, sending is implemented and tested as well, currently unused --- mod/dfrn_notify.php | 6 +++--- src/Protocol/DFRN.php | 38 ++++++++++++++++++++++++++++++++++++++ src/Protocol/Diaspora.php | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index a43c316b0c..7eddd4f3d5 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -32,10 +32,10 @@ function dfrn_notify_post(App $a) { $msg = Diaspora::decodeRaw($user, $postdata); // Check if the user has got this contact - $cid = getIdForURL($msg['author'], $user['uid']); + $cid = Contact::getIdForURL($msg['author'], $user['uid']); if (!$cid) { // Otherwise there should be a public contact - $cid = getIdForURL($msg['author']); + $cid = Contact::getIdForURL($msg['author']); if (!$cid) { logger('Contact not found for address ' . $msg['author']); System::xmlExit(3, 'Contact not found'); @@ -59,7 +59,7 @@ function dfrn_notify_post(App $a) { // Now we should be able to import it $ret = DFRN::import($msg['message'], $importer); - System::xmlExit($ret, 'Processed'); + System::xmlExit($ret, 'Done'); } else { require_once 'mod/salmon.php'; salmon_post($a, $postdata); diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index cb23c4bf12..43fe16c317 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -31,6 +31,7 @@ use Friendica\Util\Crypto; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\XML; +use Friendica\Protocol\Diaspora; use dba; use DOMDocument; use DOMXPath; @@ -1368,6 +1369,43 @@ class DFRN return intval($res->status); } + /** + * @brief Delivers items to the contacts via the Diaspora transport layer + * + * @param array $owner Owner record + * @param array $contact Contact record of the receiver + * @param array $items Items that will be transmitted + * + * @return int HTTP Deliver status + */ + public static function buildAndTransmit($owner, $contact, $items) + { + $a = get_app(); + + // Currently disabled, at first we will not use the batch delivery + // $public_batch = !$items[0]['private']; + $public_batch = false; + + $msg = DFRN::entries($items, $owner); + + $fcontact = Diaspora::personByHandle($contact['addr']); + if (empty($fcontact)) { + logger("unable to find contact details"); + return; + } + + $envelope = Diaspora::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $fcontact['pubkey'], $public_batch); + + $dest_url = ($public_batch ? $fcontact["batch"] : $contact["notify"]); + + $content_type = ($public_batch ? "application/magic-envelope+xml" : "application/json"); + + $ret = Network::post($dest_url, $envelope, ["Content-Type: ".$content_type]); + + /// @ToDo: Add better treating of return codes + return $a->get_curl_code(); + } + /** * @brief Add new birthday event for this person * diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 23bc575dd0..4b8ae21102 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3205,7 +3205,7 @@ class Diaspora * * @return string The message that will be transmitted to other servers */ - private static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false) + public static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false) { // The message is put into an envelope with the sender's signature $envelope = self::buildMagicEnvelope($msg, $user); -- 2.39.5