]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/Diaspora.php
Fix spaces in Cache\Memcachedriver
[friendica.git] / src / Protocol / Diaspora.php
index a7f34b7a6dc8b43496fd6b1c2b3534a98b829fce..27cfdccd853af83b89d026ddaf6fb5e741e25605 100644 (file)
@@ -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),
@@ -2425,10 +2446,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 +2777,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));
@@ -3474,7 +3496,7 @@ class Diaspora
 
                $myaddr = self::myHandle($owner);
 
-               $public = (($item["private"]) ? "false" : "true");
+               $public = ($item["private"] ? "false" : "true");
 
                $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);