]> git.mxchange.org Git - friendica.git/blobdiff - include/salmon.php
mail changes
[friendica.git] / include / salmon.php
index 85bda1c8f314afad412b2255ac8a61bf725b8edc..b5c21a87b5641f8636fca2f24d5d6c6ad0aa9ad0 100644 (file)
@@ -18,15 +18,13 @@ function salmon_key($pubkey) {
 }
 
 
-function base64url_encode($s) {
+function base64url_encode($s, $strip_padding = false) {
+
        $s = strtr(base64_encode($s),'+/','-_');
-/*
- *  // placeholder for un-padded base64url_encode 
- *  // per latest salmon rev
- *
- *  $s = str_replace('=','',$s);
- *
- */
+
+       if($strip_padding)
+               $s = str_replace('=','',$s);
+
        return $s;
 }
 
@@ -130,7 +128,8 @@ $namespaces = <<< EOT
       xmlns:dfrn="http://purl.org/macgirvin/dfrn/1.0" 
       xmlns:as="http://activitystrea.ms/spec/1.0/"
       xmlns:georss="http://www.georss.org/georss" 
-      xmlns:poco="http://portablecontacts.net/spec/1.0" >
+      xmlns:poco="http://portablecontacts.net/spec/1.0" 
+      xmlns:ostatus="http://ostatus.org/schema/1.0" >
 EOT;
 
        $slap = str_replace('<entry>',$namespaces,$slap);
@@ -178,11 +177,13 @@ EOT;
        ));
 
        $a = get_app();
-       $return_code = trim($a->get_curl_code());
+       $return_code = $a->get_curl_code();
 
        // check for success, e.g. 2xx
 
-       if(substr($return_code,0,1) !== '2') {
+       if($return_code > 299) {
+
+               logger('slapper: compliant salmon failed. Falling back to status.net hack');
 
                // Entirely likely that their salmon implementation is
                // non-compliant. Let's try once more, this time only signing
@@ -201,12 +202,12 @@ EOT;
                        'Content-type: application/magic-envelope+xml',
                        'Content-length: ' . strlen($salmon)
                ));
-               $return_code = trim($a->get_curl_code());
+               $return_code = $a->get_curl_code();
 
        }
        logger('slapper returned ' . $return_code); 
        if(! $return_code)
                return(-1);
-       return ((substr($return_code,0,1) === '2') ? 0 : 1);
+       return ((($return_code >= 200) && ($return_code < 300)) ? 0 : 1);
 }