]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OStatus/actions/pushhub.php
Debugging log fix.
[quix0rs-gnu-social.git] / plugins / OStatus / actions / pushhub.php
index 5ab1fc23d833d435787eda24144c363ee15dcc93..6dc22706c3e55746d58df09b0aea01123b9c1567 100644 (file)
@@ -49,7 +49,7 @@ class PushHubAction extends Action
 
     protected function prepare(array $args=array())
     {
-        StatusNet::setApi(true); // reduce exception reports to aid in debugging
+        GNUsocial::setApi(true); // reduce exception reports to aid in debugging
         return parent::prepare($args);
     }
 
@@ -83,20 +83,24 @@ class PushHubAction extends Action
     {
         $callback = $this->argUrl('hub.callback');
 
+        common_debug('New PuSH hub request ('._ve($mode).') for callback '._ve($callback));
         $topic = $this->argUrl('hub.topic');
         if (!$this->recognizedFeed($topic)) {
+            common_debug('PuSH hub request had unrecognized feed topic=='._ve($topic));
             // TRANS: Client exception. %s is a topic.
             throw new ClientException(sprintf(_m('Unsupported hub.topic %s this hub only serves local user and group Atom feeds.'),$topic));
         }
 
         $lease = $this->arg('hub.lease_seconds', null);
         if ($mode == 'subscribe' && $lease != '' && !preg_match('/^\d+$/', $lease)) {
+            common_debug('PuSH hub request had invalid lease_seconds=='._ve($lease));
             // TRANS: Client exception. %s is the invalid lease value.
             throw new ClientException(sprintf(_m('Invalid hub.lease "%s". It must be empty or positive integer.'),$lease));
         }
 
         $secret = $this->arg('hub.secret', null);
         if ($secret != '' && strlen($secret) >= 200) {
+            common_debug('PuSH hub request had invalid secret=='._ve($secret));
             // TRANS: Client exception. %s is the invalid hub secret.
             throw new ClientException(sprintf(_m('Invalid hub.secret "%s". It must be under 200 bytes.'),$secret));
         }
@@ -104,6 +108,7 @@ class PushHubAction extends Action
         $sub = HubSub::getByHashkey($topic, $callback);
         if (!$sub instanceof HubSub) {
             // Creating a new one!
+            common_debug('PuSH creating new HubSub entry for topic=='._ve($topic).' to remote callback '._ve($callback));
             $sub = new HubSub();
             $sub->topic = $topic;
             $sub->callback = $callback;
@@ -116,6 +121,7 @@ class PushHubAction extends Action
                 $sub->setLease(intval($lease));
             }
         }
+        common_debug('PuSH hub request is now:'._ve($sub));
 
         $verify = $this->arg('hub.verify'); // TODO: deprecated
         $token = $this->arg('hub.verify_token', null);  // TODO: deprecated
@@ -193,21 +199,22 @@ class PushHubAction extends Action
 
     /**
      * Grab and validate a URL from POST parameters.
-     * @throws ClientException for malformed or non-http/https URLs
+     * @throws ClientException for malformed or non-http/https or blacklisted URLs
      */
     protected function argUrl($arg)
     {
         $url = $this->arg($arg);
         $params = array('domain_check' => false, // otherwise breaks my local tests :P
                         'allowed_schemes' => array('http', 'https'));
-        $validate = new Validate;
-        if ($validate->uri($url, $params)) {
-            return $url;
-        } else {
+        $validate = new Validate();
+        if (!$validate->uri($url, $params)) {
             // TRANS: Client exception.
             // TRANS: %1$s is this argument to the method this exception occurs in, %2$s is a URL.
             throw new ClientException(sprintf(_m('Invalid URL passed for %1$s: "%2$s"'),$arg,$url));
         }
+
+        Event::handle('UrlBlacklistTest', array($url));
+        return $url;
     }
 
     /**