From 8b974f8f74f6eefc5955a0f9e385f6460504fc42 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 7 Dec 2015 16:01:54 -0800 Subject: abstract the message handlers --- Zotlabs/Zot/IHandler.php | 22 ++++++++++++++++++++++ Zotlabs/Zot/Receiver.php | 19 +++++++++++-------- Zotlabs/Zot/ZotHandler.php | 38 ++++++++++++++++++++++++++++++++++++++ include/zot.php | 11 +++++------ mod/post.php | 3 ++- version.inc | 2 +- 6 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 Zotlabs/Zot/IHandler.php create mode 100644 Zotlabs/Zot/ZotHandler.php diff --git a/Zotlabs/Zot/IHandler.php b/Zotlabs/Zot/IHandler.php new file mode 100644 index 000000000..eeca1555c --- /dev/null +++ b/Zotlabs/Zot/IHandler.php @@ -0,0 +1,22 @@ +error = false; $this->validated = false; $this->messagetype = ''; $this->response = array('success' => false); + $this->handler = $handler; + if(! is_array($data)) $data = json_decode($data,true); @@ -76,11 +79,11 @@ class Receiver { switch($this->messagetype) { case 'ping': /* no validation needed */ - zot_reply_ping(); + $this->handler->Ping(); break; case 'pickup': /* perform site validation, as opposed to sender validation */ - zot_reply_pickup($this->data); + $this->handler->Pickup($this->data); break; default: @@ -96,24 +99,24 @@ class Receiver { switch($this->messagetype) { case 'auth_check': - zot_reply_auth_check($this->data,$this->encrypted); + $this->handler->AuthCheck($this->data,$this->encrypted); break; case 'request': - json_return_and_die(zot_process_message_request($this->data)); + $this->handler->Request($this->data); break; case 'purge': - zot_reply_purge($this->sender,$this->recipients); + $this->handler->Purge($this->sender,$this->recipients); break; case 'refresh': case 'force_refresh': - zot_reply_refresh($this->sender,$this->recipients); + $this->handler->Refresh($this->sender,$this->recipients); break; case 'notify': - zot_reply_notify($this->data); + $this->handler->Notify($this->data); break; default: diff --git a/Zotlabs/Zot/ZotHandler.php b/Zotlabs/Zot/ZotHandler.php new file mode 100644 index 000000000..20332074e --- /dev/null +++ b/Zotlabs/Zot/ZotHandler.php @@ -0,0 +1,38 @@ + false); if (! $data['message_id']) { $ret['message'] = 'no message_id'; logger('no message_id'); - return $ret; + json_return_and_die($ret); } $sender = $data['sender']; @@ -3518,7 +3518,7 @@ function zot_process_message_request($data) { if (! $c) { logger('recipient channel not found.'); $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) { logger('no hubs'); - return $ret; + json_return_and_die($ret); } $hubs = $r; @@ -3577,8 +3577,7 @@ function zot_process_message_request($data) { } } $ret['success'] = true; - - return $ret; + json_return_and_die($ret); } diff --git a/mod/post.php b/mod/post.php index 6885b0d69..d1a53e7a6 100644 --- a/mod/post.php +++ b/mod/post.php @@ -486,8 +486,9 @@ function post_init(&$a) { function post_post(&$a) { 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; diff --git a/version.inc b/version.inc index 8816dde5d..97ba9c359 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2015-12-06.1238 +2015-12-07.1239 -- cgit v1.2.3