ping handler returns proper boolean response
The ping queue handler wasn't returning a true value -- filling up the queue with ping requests. It now returns a true value.
This commit is contained in:
parent
f1041a3b4e
commit
e7c57b4307
77
lib/ping.php
77
lib/ping.php
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* Laconica - a distributed open-source microblogging tool
|
* Laconica - a distributed open-source microblogging tool
|
||||||
* Copyright (C) 2008, Controlez-Vous, Inc.
|
* Copyright (C) 2009, Control Yourself, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -20,49 +20,84 @@
|
||||||
if (!defined('LACONICA')) { exit(1); }
|
if (!defined('LACONICA')) { exit(1); }
|
||||||
|
|
||||||
function ping_broadcast_notice($notice) {
|
function ping_broadcast_notice($notice) {
|
||||||
|
|
||||||
if (!$notice->is_local) {
|
if (!$notice->is_local) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Array of servers, URL => type
|
# Array of servers, URL => type
|
||||||
$notify = common_config('ping', 'notify');
|
$notify = common_config('ping', 'notify');
|
||||||
$profile = $notice->getProfile();
|
$profile = $notice->getProfile();
|
||||||
$tags = ping_notice_tags($notice);
|
$tags = ping_notice_tags($notice);
|
||||||
|
|
||||||
foreach ($notify as $notify_url => $type) {
|
foreach ($notify as $notify_url => $type) {
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'xmlrpc':
|
case 'xmlrpc':
|
||||||
case 'extended':
|
case 'extended':
|
||||||
$req = xmlrpc_encode_request('weblogUpdates.ping',
|
$req = xmlrpc_encode_request('weblogUpdates.ping',
|
||||||
array($profile->nickname, # site name
|
array($profile->nickname, # site name
|
||||||
common_local_url('showstream',
|
common_local_url('showstream',
|
||||||
array('nickname' => $profile->nickname)),
|
array('nickname' => $profile->nickname)),
|
||||||
common_local_url('shownotice',
|
common_local_url('shownotice',
|
||||||
array('notice' => $notice->id)),
|
array('notice' => $notice->id)),
|
||||||
common_local_url('userrss',
|
common_local_url('userrss',
|
||||||
array('nickname' => $profile->nickname)),
|
array('nickname' => $profile->nickname)),
|
||||||
$tags));
|
$tags));
|
||||||
|
|
||||||
# We re-use this tool's fetcher, since it's pretty good
|
|
||||||
|
|
||||||
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
|
||||||
|
|
||||||
if (!$fetcher) {
|
$context = stream_context_create(array('http' => array('method' => "POST",
|
||||||
common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
|
'header' =>
|
||||||
return false;
|
"Content-Type: text/xml\r\n".
|
||||||
}
|
"User-Agent: Laconica/".LACONICA_VERSION."\r\n",
|
||||||
|
'content' => $request)));
|
||||||
$result = $fetcher->post($notify_url,
|
$file = file_get_contents($notify_url, false, $context);
|
||||||
$req);
|
$response = xmlrpc_decode($file);
|
||||||
|
if (xmlrpc_is_fault($response)) {
|
||||||
|
common_log(LOG_WARNING,
|
||||||
|
"XML-RPC error for ping ($notify_url, $notice->id) ".
|
||||||
|
"$response[faultString] ($response[faultCode])");
|
||||||
|
} else {
|
||||||
|
common_log(LOG_INFO,
|
||||||
|
"Ping success for $notify_url $notice->id");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'get':
|
case 'get':
|
||||||
case 'post':
|
case 'post':
|
||||||
|
$args = array('name' => $profile->nickname,
|
||||||
|
'url' => common_local_url('showstream',
|
||||||
|
array('nickname' => $profile->nickname)),
|
||||||
|
'changesURL' => common_local_url('userrss',
|
||||||
|
array('nickname' => $profile->nickname)));
|
||||||
|
|
||||||
|
$fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
|
||||||
|
|
||||||
|
if ($type === 'get') {
|
||||||
|
$result = $fetcher->get($notify_url . '?' . http_build_query($args),
|
||||||
|
array('User-Agent: Laconica/'.LACONICA_VERSION));
|
||||||
|
} else {
|
||||||
|
$result = $fetcher->post($notify_url,
|
||||||
|
http_build_query($args),
|
||||||
|
array('User-Agent: Laconica/'.LACONICA_VERSION));
|
||||||
|
}
|
||||||
|
if ($result->status != '200') {
|
||||||
|
common_log(LOG_WARNING,
|
||||||
|
"Ping error for '$notify_url' ($notice->id): ".
|
||||||
|
"$result->body");
|
||||||
|
} else {
|
||||||
|
common_log(LOG_INFO,
|
||||||
|
"Ping success for '$notify_url' ($notice->id): ".
|
||||||
|
"'$result->body'");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
|
common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ping_notice_tags($notice) {
|
function ping_notice_tags($notice) {
|
||||||
$tag = new Notice_tag();
|
$tag = new Notice_tag();
|
||||||
$tag->notice_id = $notice->id;
|
$tag->notice_id = $notice->id;
|
||||||
|
|
|
@ -34,7 +34,7 @@ require_once(INSTALLDIR . '/lib/queuehandler.php');
|
||||||
set_error_handler('common_error_handler');
|
set_error_handler('common_error_handler');
|
||||||
|
|
||||||
class PingQueueHandler extends QueueHandler {
|
class PingQueueHandler extends QueueHandler {
|
||||||
|
|
||||||
function transport() {
|
function transport() {
|
||||||
return 'ping';
|
return 'ping';
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class PingQueueHandler extends QueueHandler {
|
||||||
function handle_notice($notice) {
|
function handle_notice($notice) {
|
||||||
return ping_broadcast_notice($notice);
|
return ping_broadcast_notice($notice);
|
||||||
}
|
}
|
||||||
|
|
||||||
function finish() {
|
function finish() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user