]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/lib/salmonaction.php
Merge branch 'social-master' into rewrites-master/type-hints-asserts
[quix0rs-gnu-social.git] / plugins / OStatus / lib / salmonaction.php
index 6fb3d2f9fe20bf175437305ba3004d8e46836e63..58b531fa13c2726f2b36023e6d698ce019cf08f8 100644 (file)
@@ -41,13 +41,27 @@ class SalmonAction extends Action
 
         parent::prepare($args);
 
-        if (!isset($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') {
-            // TRANS: Client error. Do not translate "application/magic-envelope+xml".
-            $this->clientError(_m('Salmon requires "application/magic-envelope+xml".'));
+        if (!isset($_SERVER['CONTENT_TYPE'])) {
+            // TRANS: Client error. Do not translate "Content-type"
+            $this->clientError(_m('Salmon requires a Content-type header.'));
+        }
+        $envxml = null;
+        switch ($_SERVER['CONTENT_TYPE']) {
+        case 'application/magic-envelope+xml':
+            $envxml = file_get_contents('php://input');
+            break;
+        case 'application/x-www-form-urlencoded':
+            $envxml = Magicsig::base64_url_decode($this->trimmed('xml'));
+            break;
+        default:
+            // TRANS: Client error. Do not translate the quoted "application/[type]" strings.
+            $this->clientError(_m('Salmon requires "application/magic-envelope+xml". For Diaspora we also accept "application/x-www-form-urlencoded" with an "xml" parameter.', 415));
         }
 
         try {
-            $envxml = file_get_contents('php://input');
+            if (empty($envxml)) {
+                throw new ClientException('No magic envelope supplied in POST.');
+            }
             $magic_env = new MagicEnvelope($envxml);   // parse incoming XML as a MagicEnvelope
 
             $entry = $magic_env->getPayload();  // Not cryptographically verified yet!
@@ -67,7 +81,7 @@ class SalmonAction extends Action
 
         // Cryptographic verification test
         if (!$magic_env->verify($this->actor)) {
-            common_log(LOG_DEBUG, "Salmon signature verification failed.");
+            common_debug("Salmon signature verification failed.");
             // TRANS: Client error.
             $this->clientError(_m('Salmon signature verification failed.'));
         }
@@ -83,7 +97,7 @@ class SalmonAction extends Action
     {
         parent::handle();
 
-        common_log(LOG_DEBUG, "Got a " . $this->activity->verb);
+        common_debug("Got a " . $this->activity->verb);
         try {
             if (Event::handle('StartHandleSalmonTarget', array($this->activity, $this->target)) &&
                     Event::handle('StartHandleSalmon', array($this->activity))) {