summaryrefslogtreecommitdiff
path: root/plugins/RSSCloud/RSSCloudNotifier.php
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-12-07 09:10:04 +0000
committerZach Copley <zach@status.net>2010-01-05 23:19:13 -0800
commit61804bb7bbd0cea92ba2bbcce15e37a35195341a (patch)
tree6e96d53f41463238549fec3cf99f456af1728f29 /plugins/RSSCloud/RSSCloudNotifier.php
parent4e07d9eeec0e2cc8f77dbd9d6e67c9ca03adc7ba (diff)
Plugin now checks notify handlers before registering subscriptions
Diffstat (limited to 'plugins/RSSCloud/RSSCloudNotifier.php')
-rw-r--r--plugins/RSSCloud/RSSCloudNotifier.php90
1 files changed, 54 insertions, 36 deletions
diff --git a/plugins/RSSCloud/RSSCloudNotifier.php b/plugins/RSSCloud/RSSCloudNotifier.php
index c2130b7b8..eb3198b5a 100644
--- a/plugins/RSSCloud/RSSCloudNotifier.php
+++ b/plugins/RSSCloud/RSSCloudNotifier.php
@@ -33,59 +33,77 @@ if (!defined('STATUSNET')) {
class RSSCloudNotifier {
- function postUpdate($endpoint, $feed) {
- common_debug("CloudNotifier->notify: $feed");
+ function challenge($endpoint, $feed)
+ {
+ $code = common_confirmation_code(128);
+ $params = array('url' => $feed, 'challenge' => $code);
+ $url = $endpoint . '?' . http_build_query($params);
+
+ try {
+ $client = new HTTPClient();
+ $response = $client->get($url);
+ } catch (HTTP_Request2_Exception $e) {
+ common_log(LOG_INFO, 'RSSCloud plugin - failure testing notify handler ' .
+ $endpoint . ' - ' . $e->getMessage());
+ return false;
+ }
- $params = 'url=' . urlencode($feed);
+ // Check response is betweet 200 and 299 and body contains challenge data
- $result = $this->httpPost($endpoint, $params);
+ $status = $response->getStatus();
+ $body = $response->getBody();
- // XXX: Make all this use CurlClient (lib/curlclient.php)
+ if ($status >= 200 && $status < 300) {
- if ($result) {
- common_debug('RSSCloud plugin - success notifying cloud endpoint!');
+ if (strpos($body, $code) !== false) {
+ common_log(LOG_INFO, 'RSSCloud plugin - ' .
+ "success testing notify handler: $endpoint");
+ return true;
+ } else {
+ common_log(LOG_INFO, 'RSSCloud plugin - ' .
+ 'challenge/repsonse failed for notify handler ' .
+ $endpoint);
+ common_debug('body = ' . var_export($body, true));
+ return false;
+ }
} else {
- common_debug('RSSClous plugin - failure notifying cloud endpoint!');
+ common_log(LOG_INFO, 'RSSCloud plugin - ' .
+ "failure testing notify handler: $endpoint " .
+ ' - got HTTP ' . $status);
+ common_debug('body = ' . var_export($body, true));
+ return false;
}
-
- return $result;
}
- function userAgent()
- {
- return 'rssCloudPlugin/' . RSSCLOUDPLUGIN_VERSION .
- ' StatusNet/' . STATUSNET_VERSION;
- }
-
- private function httpPost($url, $params) {
-
- $options = array(CURLOPT_URL => $url,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $params,
- CURLOPT_USERAGENT => $this->userAgent(),
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_FAILONERROR => true,
- CURLOPT_HEADER => false,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_CONNECTTIMEOUT => 5,
- CURLOPT_TIMEOUT => 5);
-
- $ch = curl_init();
- curl_setopt_array($ch, $options);
+ function postUpdate($endpoint, $feed) {
- $response = curl_exec($ch);
+ $headers = array();
+ $postdata = array('url' => $feed);
- $info = curl_getinfo($ch);
+ try {
+ $client = new HTTPClient();
+ $response = $client->post($endpoint, $headers, $postdata);
+ } catch (HTTP_Request2_Exception $e) {
+ common_log(LOG_INFO, 'RSSCloud plugin - failure notifying ' .
+ $endpoint . ' that feed ' . $feed .
+ ' has changed: ' . $e->getMessage());
+ return false;
+ }
- curl_close($ch);
+ $status = $response->getStatus();
- if ($info['http_code'] == 200) {
+ if ($status >= 200 && $status < 300) {
+ common_log(LOG_INFO, 'RSSCloud plugin - success notifying ' .
+ $endpoint . ' that feed ' . $feed . ' has changed.');
return true;
} else {
+ common_log(LOG_INFO, 'RSSCloud plugin - failure notifying ' .
+ $endpoint . ' that feed ' . $feed .
+ ' has changed: got HTTP ' . $status);
+ common_debug('body = ' . var_export($response->getBody(), true));
return false;
}
}
}
-