+ $return_code = $a->get_curl_code();
+
+ // check for success, e.g. 2xx
+
+ if ($return_code > 299) {
+
+ logger('GNU Social salmon failed. Falling back to compliant mode');
+
+ // Now try the compliant mode that normally isn't used for GNU Social
+ $xmldata = array("me:env" => array("me:data" => $data,
+ "@attributes" => array("type" => $data_type),
+ "me:encoding" => $encoding,
+ "me:alg" => $algorithm,
+ "me:sig" => $signature2,
+ "@attributes2" => array("key_id" => $keyhash)));
+
+ $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
+
+ $salmon = xml::from_array($xmldata, $xml, false, $namespaces);
+
+ // slap them
+ post_url($url, $salmon, array(
+ 'Content-type: application/magic-envelope+xml',
+ 'Content-length: ' . strlen($salmon)
+ ));
+ $return_code = $a->get_curl_code();
+ }
+
+ if ($return_code > 299) {
+ logger('compliant salmon failed. Falling back to old status.net');
+
+ // Last try. This will most likely fail as well.
+ $xmldata = array("me:env" => array("me:data" => $data,
+ "@attributes" => array("type" => $data_type),
+ "me:encoding" => $encoding,
+ "me:alg" => $algorithm,
+ "me:sig" => $signature3,
+ "@attributes2" => array("key_id" => $keyhash)));
+
+ $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env");
+
+ $salmon = xml::from_array($xmldata, $xml, false, $namespaces);
+
+ // slap them
+ post_url($url, $salmon, array(
+ 'Content-type: application/magic-envelope+xml',
+ 'Content-length: ' . strlen($salmon)
+ ));
+ $return_code = $a->get_curl_code();
+ }
+
+ logger('slapper for '.$url.' returned ' . $return_code);
+
+ if (! $return_code) {
+ return -1;
+ }
+
+ if (($return_code == 503) && (stristr($a->get_curl_headers(), 'retry-after'))) {
+ return -1;
+ }
+
+ return ((($return_code >= 200) && ($return_code < 300)) ? 0 : 1);
+}