From: garvinhicking Date: Fri, 31 Mar 2006 08:25:08 +0000 (+0000) Subject: Write session data before we request any longer lasting HTTP things, to prevent clien... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7f784e5e6508d472bc6d65c383a9fa1d58bafcef;p=s9y.git Write session data before we request any longer lasting HTTP things, to prevent client connection being unresponsive. --- diff --git a/bundled-libs/Onyx/RSS.php b/bundled-libs/Onyx/RSS.php index 2db05c7..1bd838f 100644 --- a/bundled-libs/Onyx/RSS.php +++ b/bundled-libs/Onyx/RSS.php @@ -129,16 +129,19 @@ class ONYX_RSS clearstatcache(); require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; + serendipity_request_start(); $req = &new HTTP_Request($uri, array('allowRedirects' => true, 'maxRedirects' => 5)); $res = $req->sendRequest(); if (PEAR::isError($res) || $req->getResponseCode() != '200') { + serendipity_request_end(); $this->raiseError((__LINE__-2), ONYX_ERR_INVALID_URI . ' (#' . $req->getResponseCode() . ')'); return false; } $fContent = $req->getResponseBody(); + serendipity_request_end(); if (@preg_match('@]*encoding="([^"]+)"@i', $fContent, $xml_encoding)) { $this->rss['encoding'] = strtolower($xml_encoding[1]); } @@ -345,15 +348,19 @@ class ONYX_RSS if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') >= 0) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; + serendipity_request_start(); $req = &new HTTP_Request($uri); - if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') + if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { + serendipity_request_end(); return false; + } $fHeader = $req->getResponseHeader(); if (isset($fHeader['last-modified'])) { $modtime = $fHeader['last-modified']; } + serendipity_request_end(); } else { diff --git a/docs/NEWS b/docs/NEWS index 809495f..0207532 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,9 @@ Version 1.1-alpha1() ------------------------------------------------------------------------ + * Fix blocking site during file requests by writing session data to + disk. Thanks to jgoerzen! (garvinhicking) + * Make categories sidebar plugin able to only show categories readable for logged in user (garvinhicking) diff --git a/include/admin/images.inc.php b/include/admin/images.inc.php index ab1b6f3..23efa34 100644 --- a/include/admin/images.inc.php +++ b/include/admin/images.inc.php @@ -176,6 +176,7 @@ switch ($serendipity['GET']['adminAction']) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $options = array(); serendipity_plugin_api::hook_event('backend_http_request', $options, 'image'); + serendipity_request_start(); $req = &new HTTP_Request($serendipity['POST']['imageurl'], $options); // Try to get the URL @@ -219,6 +220,7 @@ switch ($serendipity['GET']['adminAction']) { serendipity_plugin_api::hook_event('backend_image_add', $target); } } + serendipity_request_end(); } } else { if (!is_array($serendipity['POST']['target_filename'])) { diff --git a/include/functions.inc.php b/include/functions.inc.php index 14cb074..1d0529a 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -981,6 +981,22 @@ function serendipity_updateCategory($cid, $name, $desc, $authorid, $icon, $paren } +/** + * Ends a session, so that while a file requests happens, Serendipity can work on in that session + */ +function serendipity_request_start() { + @session_write_close(); + return true; +} + +/** + * Continues a session after a file request + */ +function serendipity_request_end() { + @session_start(); + return true; +} + if (!function_exists('microtime_float')) { /** * Get current timestamp as microseconds diff --git a/include/functions_trackbacks.inc.php b/include/functions_trackbacks.inc.php index c14081b..17cdc14 100644 --- a/include/functions_trackbacks.inc.php +++ b/include/functions_trackbacks.inc.php @@ -86,15 +86,19 @@ function _serendipity_send($loc, $data) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'POST'); serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_send'); + serendipity_request_start(); + $req = &new HTTP_Request($uri, $options); $req->addRawPostData($data, true); $res = $req->sendRequest(); if (PEAR::isError($res)) { + serendipity_request_end(); return false; } $fContent = $req->getResponseBody(); + serendipity_request_end(); return $fContent; } @@ -199,15 +203,18 @@ global $serendipity; require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $options = array('allowRedirects' => true, 'maxRedirects' => 5, 'method' => 'GET'); serendipity_plugin_api::hook_event('backend_http_request', $options, 'trackback_detect'); + serendipity_request_start(); $req = &new HTTP_Request($parsed_loc, $options); $res = $req->sendRequest(); if (PEAR::isError($res)) { echo '
• ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'
'; + serendipity_request_end(); return; } $fContent = $req->getResponseBody(); + serendipity_request_end(); if (strlen($fContent) != 0) { serendipity_trackback_autodiscover($fContent, $parsed_loc, $url, $author, $title, $text, $loc); diff --git a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php index 019ed86..192f396 100644 --- a/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php +++ b/plugins/serendipity_event_spamblock/serendipity_event_spamblock.php @@ -280,6 +280,8 @@ var $filter_defaults; } else { $data = ''; require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; + serendipity_request_start(); + $req = &new HTTP_Request('http://spam.blogg.de/blacklist.txt'); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { @@ -296,6 +298,7 @@ var $filter_defaults; fclose($fp); } } + serendipity_request_end(); } $blacklist = explode("\n", $data); @@ -474,6 +477,7 @@ var $filter_defaults; if ($addData['type'] == 'TRACKBACK' && serendipity_db_bool($this->get_config('trackback_check_url'))) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; + serendipity_request_start(); $req = &new HTTP_Request($addData['url'], array('allowRedirects' => true, 'maxRedirects' => 5)); $is_valid = false; if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { @@ -488,6 +492,7 @@ var $filter_defaults; $is_valid = false; } } + serendipity_request_end(); if ($is_valid === false) { $this->log($logfile, $eventData['id'], 'REJECTED', PLUGIN_EVENT_SPAMBLOCK_REASON_TRACKBACKURL, $addData); diff --git a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php index f077f01..467dffc 100644 --- a/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php +++ b/plugins/serendipity_event_spartacus/serendipity_event_spartacus.php @@ -256,6 +256,7 @@ class serendipity_event_spartacus extends serendipity_event require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; $options = array(); serendipity_plugin_api::hook_event('backend_http_request', $options, 'spartacus'); + serendipity_request_start(); $req = &new HTTP_Request($url, $options); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { @@ -300,6 +301,7 @@ class serendipity_event_spartacus extends serendipity_event echo '
'; $this->purgeCache = true; } + serendipity_request_end(); } return $data; diff --git a/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php b/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php index 2c66bc8..8451a85 100644 --- a/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php +++ b/plugins/serendipity_event_weblogping/serendipity_event_weblogping.php @@ -203,6 +203,8 @@ class serendipity_event_weblogping extends serendipity_event $message->createPayload(); $options = array(); serendipity_plugin_api::hook_event('backend_http_request', $options, 'weblogping'); + serendipity_request_start(); + $req = new HTTP_Request("http://".$service['host'].$service['path'], $options); $req->setMethod(HTTP_REQUEST_METHOD_POST); $req->addHeader("Content-Type", "text/xml"); @@ -220,6 +222,7 @@ class serendipity_event_weblogping extends serendipity_event } else { $out = PLUGIN_EVENT_WEBLOGPING_SEND_SUCCESS . "
"; } + serendipity_request_end(); if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) { echo $out; diff --git a/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php b/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php index efd028f..eb8d976 100644 --- a/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php +++ b/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php @@ -47,6 +47,7 @@ class s9y_remoterss_XMLTree { function GetXMLTree($file) { require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; + serendipity_request_start(); $req = &new HTTP_Request($file); if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') { @@ -55,6 +56,7 @@ class s9y_remoterss_XMLTree { // Fetch file $data = $req->getResponseBody(); } + serendipity_request_end(); // Global replacements // by: waldo@wh-e.com - trim space around tags not within @@ -376,11 +378,14 @@ class serendipity_plugin_remoterss extends serendipity_plugin { // Disabled by now. May get enabled in the future, but for now the extra HTTP call isn't worth trying. return true; require_once S9Y_PEAR_PATH . 'HTTP/Request.php'; + serendipity_request_start(); $req = &new HTTP_Request($uri); if (PEAR::isError($req->sendRequest()) || !preg_match('@^[23]..@', $req->getResponseCode())) { + serendipity_request_end(); return false; } else { + serendipity_request_end(); return true; } }