]> git.mxchange.org Git - friendica.git/blobdiff - include/diaspora.php
account expiration structures
[friendica.git] / include / diaspora.php
index 2145ca56ccc8e54ed137d88c06d535d96afaaf09..313324a16a667f38424eb5b2d6bd523caf63e89a 100644 (file)
@@ -8,15 +8,18 @@ require_once('include/contact_selectors.php');
 
 function diaspora_dispatch_public($msg) {
 
-       $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `uid` FROM `contact` WHERE `network` = '%s' AND `addr` = '%s' ) ",
+       $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) ",
                dbesc(NETWORK_DIASPORA),
                dbesc($msg['author'])
        );
        if(count($r)) {
                foreach($r as $rr) {
+                       logger('diaspora_public: delivering to: ' . $rr['username']);
                        diaspora_dispatch($rr,$msg);
                }
        }
+       else
+               logger('diaspora_public: no subscribers');
 }
 
 
@@ -115,7 +118,7 @@ function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey) {
        $outer_iv = random_string(16);
        $b_outer_iv = base64_encode($outer_iv);
        
-       $handle = 'acct:' . $user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
+       $handle = $user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
 
        $padded_data = pkcs5_pad($msg,16);
        $inner_encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $padded_data, MCRYPT_MODE_CBC, $inner_iv);
@@ -126,7 +129,7 @@ function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey) {
        $b64url_data = base64url_encode($b64_data);
        $data = str_replace(array("\n","\r"," ","\t"),array('','','',''),$b64url_data);
 
-       $type = 'application/atom+xml';
+       $type = 'application/xml';
        $encoding = 'base64url';
        $alg = 'RSA-SHA256';
 
@@ -140,10 +143,7 @@ $decrypted_header = <<< EOT
 <decrypted_header>
   <iv>$b_inner_iv</iv>
   <aes_key>$b_inner_aes_key</aes_key>
-  <author>
-    <name>{$user['username']}</name>
-    <uri>$handle</uri>
-  </author>
+  <author_id>$handle</author_id>
 </decrypted_header>
 EOT;
 
@@ -168,15 +168,15 @@ EOT;
 
 $magic_env = <<< EOT
 <?xml version='1.0' encoding='UTF-8'?>
-<entry xmlns='http://www.w3.org/2005/Atom'>
+<diaspora xmlns="https://joindiaspora.org/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env" >
   $encrypted_header
-  <me:env xmlns:me="http://salmon-protocol.org/ns/magic-env">
+  <me:env>
     <me:encoding>base64url</me:encoding>
     <me:alg>RSA-SHA256</me:alg>
     <me:data type="application/xml">$data</me:data>
     <me:sig>$sig</me:sig>
   </me:env>
-</entry>
+</diaspora>
 EOT;
 
        logger('diaspora_msg_build: magic_env: ' . $magic_env, LOGGER_DATA);
@@ -204,11 +204,11 @@ function diaspora_decode($importer,$xml) {
        $public = false;
        $basedom = parse_xml_string($xml);
 
-       $children = $basedom->children(NAMESPACE_DIASPORA_PROTOCOL);
+       $children = $basedom->children('https://joindiaspora.com/protocol');
 
        if($children->header) {
                $public = true;
-               $author_link = str_replace('acct:','',$children->author_id);
+               $author_link = str_replace('acct:','',$children->header->author_id);
        }
        else {
 
@@ -288,16 +288,6 @@ function diaspora_decode($importer,$xml) {
        // strip whitespace so our data element will return to one big base64 blob
        $data = str_replace(array(" ","\t","\r","\n"),array("","","",""),$base->data);
 
-       // Add back the 60 char linefeeds
-
-       // This completely violates the entire principle of salmon magic signatures,
-       // which was to have a message signing format that was completely ambivalent to linefeeds 
-       // and transport whitespace mangling, and base64 wrapping rules. Guess what? PHP and Ruby 
-       // use different linelengths for base64 output. 
-
-//    $lines = str_split($data,60);
- //   $data = implode("\n",$lines);
-
 
        // stash away some other stuff for later
 
@@ -347,7 +337,7 @@ function diaspora_decode($importer,$xml) {
 
        if(! $verify) {
                logger('mod-diaspora: Message did not verify. Discarding.');
-               http_status_exit(400);
+//             http_status_exit(400);
        }
 
        logger('mod-diaspora: Message verified.');