use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\System;
+use Friendica\Database\dba;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Protocol\DFRN;
$data = json_decode($postdata);
if (is_object($data)) {
$nick = defaults($a->argv, 1, '');
- $public = empty($nick);
- if (!$public) {
- $user = dba::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]);
- if (!DBM::is_result($user)) {
- System::httpExit(500);
- }
- } else {
- // We don't need the user with public posts
- $user = [];
- }
- $msg = Diaspora::decodeRaw($user, $postdata);
- if ($public) {
- dfrn_dispatch_public($msg);
- } else {
- dfrn_dispatch_private($user, $msg);
+ $user = dba::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]);
+ if (!DBM::is_result($user)) {
+ System::httpExit(500);
}
- } else {
+ dfrn_dispatch_private($user, $postdata);
+ } elseif (!dfrn_dispatch_public($postdata)) {
require_once 'mod/salmon.php';
salmon_post($a, $postdata);
}
// NOTREACHED
}
-function dfrn_dispatch_public($msg)
+function dfrn_dispatch_public($postdata)
{
+ $msg = Diaspora::decodeRaw([], $postdata);
+ if (!$msg) {
+ // We have to fail silently to be able to hand it over to the salmon parser
+ return false;
+ }
+
// Fetch the corresponding public contact
- $contact = getDetailsByAddr($msg['author'], 0);
+ $contact = Contact::getDetailsByAddr($msg['author'], 0);
if (!$contact) {
logger('Contact not found for address ' . $msg['author']);
- System::xmlExit(3, 'Contact not found');
+ System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
}
// We now have some contact, so we fetch it
$importer = dba::fetch_first("SELECT *, `name` as `senderName`
FROM `contact`
WHERE NOT `blocked` AND `id` = ? LIMIT 1",
- $cid);
+ $contact['id']);
+
+ $importer['importer_uid'] = 0;
// This should never fail
if (!DBM::is_result($importer)) {
logger('Contact not found for address ' . $msg['author']);
- System::xmlExit(3, 'Contact not found');
+ System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
}
logger('Importing post from ' . $msg['author'] . ' with the public envelope.', LOGGER_DEBUG);
System::xmlExit($ret, 'Done');
}
-function dfrn_dispatch_private($user, $msg)
+function dfrn_dispatch_private($user, $postdata)
{
+ $msg = Diaspora::decodeRaw($user, $postdata);
+ if (!$msg) {
+ System::xmlExit(4, 'Unable to parse message');
+ }
+
// Check if the user has got this contact
$cid = Contact::getIdForURL($msg['author'], $user['uid']);
if (!$cid) {
$cid = Contact::getIdForURL($msg['author']);
if (!$cid) {
logger('Contact not found for address ' . $msg['author']);
- System::xmlExit(3, 'Contact not found');
+ System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
}
}
// This should never fail
if (!DBM::is_result($importer)) {
logger('Contact not found for address ' . $msg['author']);
- System::xmlExit(3, 'Contact not found');
+ System::xmlExit(3, 'Contact ' . $msg['author'] . ' not found');
}
// Set the user id. This is important if this is a public contact
$importer['importer_uid'] = $user['uid'];
+ $importer = array_merge($importer, $user);
+
logger('Importing post from ' . $msg['author'] . ' to ' . $user['nickname'] . ' with the private envelope.', LOGGER_DEBUG);
// Now we should be able to import it
);
if (!DBM::is_result($r)) {
- $status = 1;
+ logger('No user data found for ' . $a->argv[1] . ' - SQL: ' . $sql_extra);
+ killme();
}
logger("Remote rino version: ".$rino_remote." for ".$r[0]["url"], LOGGER_DATA);