]> git.mxchange.org Git - friendica.git/blobdiff - mod/salmon.php
Issue 7285: Perform duplicate check for item URI also with AP
[friendica.git] / mod / salmon.php
index 536a4516ceb7948651a16f3768f6d203ba180662..67e467a73fea89ceb7c9aa1dd03c50997f386129 100644 (file)
@@ -13,11 +13,12 @@ use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
 use Friendica\Util\Crypto;
 use Friendica\Util\Strings;
+use Friendica\Util\Network;
 
 function salmon_post(App $a, $xml = '') {
 
        if (empty($xml)) {
-               $xml = file_get_contents('php://input');
+               $xml = Network::postdata();
        }
 
        Logger::log('new salmon ' . $xml, Logger::DATA);
@@ -28,7 +29,7 @@ function salmon_post(App $a, $xml = '') {
                DBA::escape($nick)
        );
        if (! DBA::isResult($r)) {
-               System::httpExit(500);
+               throw new \Friendica\Network\HTTPException\InternalServerErrorException();
        }
 
        $importer = $r[0];
@@ -49,7 +50,7 @@ function salmon_post(App $a, $xml = '') {
 
        if (empty($base)) {
                Logger::log('unable to locate salmon data in xml ');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        // Stash the signature away for now. We have to find their key or it won't be good for anything.
@@ -87,7 +88,7 @@ function salmon_post(App $a, $xml = '') {
 
        if(! $author_link) {
                Logger::log('Could not retrieve author URI.');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        // Once we have the author URI, go to the web and try to find their public key
@@ -98,7 +99,7 @@ function salmon_post(App $a, $xml = '') {
 
        if(! $key) {
                Logger::log('Could not retrieve author key.');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        $key_info = explode('.',$key);
@@ -130,7 +131,7 @@ function salmon_post(App $a, $xml = '') {
 
        if (! $verify) {
                Logger::log('Message did not verify. Discarding.');
-               System::httpExit(400);
+               throw new \Friendica\Network\HTTPException\BadRequestException();
        }
 
        Logger::log('Message verified with mode '.$mode);
@@ -177,16 +178,15 @@ function salmon_post(App $a, $xml = '') {
        //if((DBA::isResult($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == Contact::FOLLOWER) || ($r[0]['blocked']))) {
        if (DBA::isResult($r) && $r[0]['blocked']) {
                Logger::log('Ignoring this author.');
-               System::httpExit(202);
-               // NOTREACHED
+               throw new \Friendica\Network\HTTPException\AcceptedException();
        }
 
        // Placeholder for hub discovery.
        $hub = '';
 
-       $contact_rec = ((DBA::isResult($r)) ? $r[0] : null);
+       $contact_rec = ((DBA::isResult($r)) ? $r[0] : []);
 
        OStatus::import($data, $importer, $contact_rec, $hub);
 
-       System::httpExit(200);
+       throw new \Friendica\Network\HTTPException\OKException();
 }