]> git.mjollnir.org Git - s9y.git/commitdiff
Write session data before we request any longer lasting HTTP things, to prevent clien...
authorgarvinhicking <garvinhicking>
Fri, 31 Mar 2006 08:25:08 +0000 (08:25 +0000)
committergarvinhicking <garvinhicking>
Fri, 31 Mar 2006 08:25:08 +0000 (08:25 +0000)
bundled-libs/Onyx/RSS.php
docs/NEWS
include/admin/images.inc.php
include/functions.inc.php
include/functions_trackbacks.inc.php
plugins/serendipity_event_spamblock/serendipity_event_spamblock.php
plugins/serendipity_event_spartacus/serendipity_event_spartacus.php
plugins/serendipity_event_weblogping/serendipity_event_weblogping.php
plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php

index 2db05c724d77662b5fbf6b95a4c99aae1c958cf5..1bd838f784adb3e095826599587bbadea3b53041 100644 (file)
@@ -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('@<?xml[^>]*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
       {
index 809495fcc72c8594d40416486ad58353565c304e..020753247d6d6515904e1efdfac7d57f85c86667 100644 (file)
--- 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)
 
index ab1b6f3bab3b8fb4b9c64508e1dff89be29d87b9..23efa34c1e9f38a4f83cb9885dc90f44dd07368f 100644 (file)
@@ -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'])) {
index 14cb074287706cddce73a099e71d136415a3ab30..1d0529a58ee0088adc72f434ddf889deeabaf2c0 100644 (file)
@@ -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
index c14081b14ccf663fe91b2ba8a0eae63983df61ee..17cdc14a9f828371da75d6169800d65ee19064d1 100644 (file)
@@ -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 '<div>&#8226; ' . sprintf(TRACKBACK_COULD_NOT_CONNECT, $u['host'], $u['port']) .'</div>';
+        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);
index 019ed864d9fe3f006daa6a909dae127c91f51161..192f396afca35a95bdab5b8cebe567f58458f92a 100644 (file)
@@ -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);
index f077f01da23134176a6f0cb79344006dc06ef78f..467dffcf5ccfb14d3e5e6c516ed24249c305b8bd 100644 (file)
@@ -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 '<br />';
                 $this->purgeCache = true;
             }
+            serendipity_request_end();
         }
 
         return $data;
index 2c66bc8d8bf6002f58ed14d6e153b1827f62aa98..8451a855f70f2db7931528f4c3d4ba103768e012 100644 (file)
@@ -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 . "<br />";
                             }
+                            serendipity_request_end();
 
                             if (!defined('SERENDIPITY_IS_XMLRPC') || defined('SERENDIPITY_XMLRPC_VERBOSE')) {
                                 echo $out;
index efd028fc58a84cedb5b60954044d2bc7bea9f945..eb8d976dd25b7f757329ab91706a16766a78c033 100644 (file)
@@ -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;
         }
     }