abstract the message handlers
This commit is contained in:
parent
53627c89a7
commit
8b974f8f74
22
Zotlabs/Zot/IHandler.php
Normal file
22
Zotlabs/Zot/IHandler.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Zot;
|
||||||
|
|
||||||
|
interface IHandler {
|
||||||
|
|
||||||
|
function Ping();
|
||||||
|
|
||||||
|
function Pickup($data);
|
||||||
|
|
||||||
|
function Notify($data);
|
||||||
|
|
||||||
|
function Request($data);
|
||||||
|
|
||||||
|
function AuthCheck($data,$encrypted);
|
||||||
|
|
||||||
|
function Purge($sender,$recipients);
|
||||||
|
|
||||||
|
function Refresh($sender,$recipients);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -12,14 +12,17 @@ class Receiver {
|
|||||||
protected $validated;
|
protected $validated;
|
||||||
protected $recipients;
|
protected $recipients;
|
||||||
protected $response;
|
protected $response;
|
||||||
|
protected $handler;
|
||||||
|
|
||||||
function __construct($data,$prvkey) {
|
function __construct($data,$prvkey,$handler) {
|
||||||
|
|
||||||
$this->error = false;
|
$this->error = false;
|
||||||
$this->validated = false;
|
$this->validated = false;
|
||||||
$this->messagetype = '';
|
$this->messagetype = '';
|
||||||
$this->response = array('success' => false);
|
$this->response = array('success' => false);
|
||||||
|
|
||||||
|
$this->handler = $handler;
|
||||||
|
|
||||||
if(! is_array($data))
|
if(! is_array($data))
|
||||||
$data = json_decode($data,true);
|
$data = json_decode($data,true);
|
||||||
|
|
||||||
@ -76,11 +79,11 @@ class Receiver {
|
|||||||
switch($this->messagetype) {
|
switch($this->messagetype) {
|
||||||
case 'ping':
|
case 'ping':
|
||||||
/* no validation needed */
|
/* no validation needed */
|
||||||
zot_reply_ping();
|
$this->handler->Ping();
|
||||||
break;
|
break;
|
||||||
case 'pickup':
|
case 'pickup':
|
||||||
/* perform site validation, as opposed to sender validation */
|
/* perform site validation, as opposed to sender validation */
|
||||||
zot_reply_pickup($this->data);
|
$this->handler->Pickup($this->data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -96,24 +99,24 @@ class Receiver {
|
|||||||
switch($this->messagetype) {
|
switch($this->messagetype) {
|
||||||
|
|
||||||
case 'auth_check':
|
case 'auth_check':
|
||||||
zot_reply_auth_check($this->data,$this->encrypted);
|
$this->handler->AuthCheck($this->data,$this->encrypted);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'request':
|
case 'request':
|
||||||
json_return_and_die(zot_process_message_request($this->data));
|
$this->handler->Request($this->data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'purge':
|
case 'purge':
|
||||||
zot_reply_purge($this->sender,$this->recipients);
|
$this->handler->Purge($this->sender,$this->recipients);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'refresh':
|
case 'refresh':
|
||||||
case 'force_refresh':
|
case 'force_refresh':
|
||||||
zot_reply_refresh($this->sender,$this->recipients);
|
$this->handler->Refresh($this->sender,$this->recipients);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'notify':
|
case 'notify':
|
||||||
zot_reply_notify($this->data);
|
$this->handler->Notify($this->data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
38
Zotlabs/Zot/ZotHandler.php
Normal file
38
Zotlabs/Zot/ZotHandler.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Zot;
|
||||||
|
|
||||||
|
require_once('Zotlabs/Zot/IHandler.php');
|
||||||
|
|
||||||
|
|
||||||
|
class ZotHandler implements IHandler {
|
||||||
|
|
||||||
|
function Ping() {
|
||||||
|
zot_reply_ping();
|
||||||
|
}
|
||||||
|
|
||||||
|
function Pickup($data) {
|
||||||
|
zot_reply_pickup($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Notify($data) {
|
||||||
|
zot_reply_notify($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Request($data) {
|
||||||
|
zot_reply_message_request($data));
|
||||||
|
}
|
||||||
|
|
||||||
|
function AuthCheck($data,$encrypted) {
|
||||||
|
zot_reply_auth_check($data,$encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Purge($sender,$recipients) {
|
||||||
|
zot_reply_purge($sender,$recipients);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Refresh($sender,$recipients) {
|
||||||
|
zot_reply_refresh($sender,$recipients);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3494,13 +3494,13 @@ function import_author_zot($x) {
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function zot_process_message_request($data) {
|
function zot_reply_message_request($data) {
|
||||||
$ret = array('success' => false);
|
$ret = array('success' => false);
|
||||||
|
|
||||||
if (! $data['message_id']) {
|
if (! $data['message_id']) {
|
||||||
$ret['message'] = 'no message_id';
|
$ret['message'] = 'no message_id';
|
||||||
logger('no message_id');
|
logger('no message_id');
|
||||||
return $ret;
|
json_return_and_die($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sender = $data['sender'];
|
$sender = $data['sender'];
|
||||||
@ -3518,7 +3518,7 @@ function zot_process_message_request($data) {
|
|||||||
if (! $c) {
|
if (! $c) {
|
||||||
logger('recipient channel not found.');
|
logger('recipient channel not found.');
|
||||||
$ret['message'] .= 'recipient not found.' . EOL;
|
$ret['message'] .= 'recipient not found.' . EOL;
|
||||||
return $ret;
|
json_return_and_die($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3536,7 +3536,7 @@ function zot_process_message_request($data) {
|
|||||||
);
|
);
|
||||||
if (! $r) {
|
if (! $r) {
|
||||||
logger('no hubs');
|
logger('no hubs');
|
||||||
return $ret;
|
json_return_and_die($ret);
|
||||||
}
|
}
|
||||||
$hubs = $r;
|
$hubs = $r;
|
||||||
|
|
||||||
@ -3577,8 +3577,7 @@ function zot_process_message_request($data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$ret['success'] = true;
|
$ret['success'] = true;
|
||||||
|
json_return_and_die($ret);
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -486,8 +486,9 @@ function post_init(&$a) {
|
|||||||
function post_post(&$a) {
|
function post_post(&$a) {
|
||||||
|
|
||||||
require_once('Zotlabs/Zot/Receiver.php');
|
require_once('Zotlabs/Zot/Receiver.php');
|
||||||
|
require_once('Zotlabs/Zot/ZotHandler.php');
|
||||||
|
|
||||||
$z = new Zotlabs\Zot\Receiver($_REQUEST['data'],get_config('system','prvkey'));
|
$z = new Zotlabs\Zot\Receiver($_REQUEST['data'],get_config('system','prvkey'), new Zotlabs\Zot\ZotHandler());
|
||||||
|
|
||||||
// notreached;
|
// notreached;
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
2015-12-06.1238
|
2015-12-07.1239
|
||||||
|
Reference in New Issue
Block a user