Move mod/receive to src/Module/Diaspora/receive
- Added routes - Make Diaspora::decode(Raw) more explicit - Add new User::getByGuid() method
This commit is contained in:
parent
49c05036ae
commit
7716374593
6 changed files with 182 additions and 103 deletions
|
@ -15,8 +15,8 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\User;
|
||||
use Friendica\Protocol\DFRN;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
function dfrn_notify_post(App $a) {
|
||||
Logger::log(__function__, Logger::TRACE);
|
||||
|
@ -184,7 +184,7 @@ function dfrn_notify_post(App $a) {
|
|||
|
||||
function dfrn_dispatch_public($postdata)
|
||||
{
|
||||
$msg = Diaspora::decodeRaw([], $postdata, true);
|
||||
$msg = Diaspora::decodeRaw($postdata, '', true);
|
||||
if (!$msg) {
|
||||
// We have to fail silently to be able to hand it over to the salmon parser
|
||||
return false;
|
||||
|
@ -214,7 +214,7 @@ function dfrn_dispatch_public($postdata)
|
|||
|
||||
function dfrn_dispatch_private($user, $postdata)
|
||||
{
|
||||
$msg = Diaspora::decodeRaw($user, $postdata);
|
||||
$msg = Diaspora::decodeRaw($postdata, $user);
|
||||
if (!$msg) {
|
||||
System::xmlExit(4, 'Unable to parse message');
|
||||
}
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file mod/receive.php
|
||||
* @brief Diaspora endpoint
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
/**
|
||||
* @param App $a App
|
||||
* @return void
|
||||
* @throws ImagickException
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
function receive_post(App $a)
|
||||
{
|
||||
$enabled = intval(Config::get('system', 'diaspora_enabled'));
|
||||
if (!$enabled) {
|
||||
Logger::log('mod-diaspora: disabled');
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
}
|
||||
|
||||
if (($a->argc == 2) && ($a->argv[1] === 'public')) {
|
||||
$public = true;
|
||||
$importer = [];
|
||||
} else {
|
||||
$public = false;
|
||||
|
||||
if ($a->argc != 3 || $a->argv[1] !== 'users') {
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
}
|
||||
$guid = $a->argv[2];
|
||||
|
||||
$importer = DBA::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]);
|
||||
if (!DBA::isResult($importer)) {
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
}
|
||||
}
|
||||
|
||||
// It is an application/x-www-form-urlencoded
|
||||
|
||||
Logger::log('mod-diaspora: receiving post', Logger::DEBUG);
|
||||
|
||||
if (empty($_POST['xml'])) {
|
||||
$postdata = Network::postdata();
|
||||
if ($postdata == '') {
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
}
|
||||
|
||||
Logger::log('mod-diaspora: message is in the new format', Logger::DEBUG);
|
||||
$msg = Diaspora::decodeRaw($importer, $postdata);
|
||||
} else {
|
||||
$xml = urldecode($_POST['xml']);
|
||||
|
||||
Logger::log('mod-diaspora: decode message in the old format', Logger::DEBUG);
|
||||
$msg = Diaspora::decode($importer, $xml);
|
||||
|
||||
if ($public && !$msg) {
|
||||
Logger::log('mod-diaspora: decode message in the new format', Logger::DEBUG);
|
||||
$msg = Diaspora::decodeRaw($importer, $xml);
|
||||
}
|
||||
}
|
||||
|
||||
Logger::log('mod-diaspora: decoded', Logger::DEBUG);
|
||||
|
||||
Logger::log('mod-diaspora: decoded msg: ' . print_r($msg, true), Logger::DATA);
|
||||
|
||||
if (!is_array($msg)) {
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
}
|
||||
|
||||
Logger::log('mod-diaspora: dispatching', Logger::DEBUG);
|
||||
|
||||
$ret = true;
|
||||
if ($public) {
|
||||
Diaspora::dispatchPublic($msg);
|
||||
} else {
|
||||
$ret = Diaspora::dispatch($importer, $msg);
|
||||
}
|
||||
|
||||
if ($ret) {
|
||||
throw new \Friendica\Network\HTTPException\OKException();
|
||||
} else {
|
||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue