author: revo
software: drupal
version: 6.15
description: ini_set-Warnungen unterdruecken, fsockopen durch curl ersetzen
lastchange: 2009-12-24

--- includes/bootstrap.inc	Di Dez 22 18:12:38 2009
+++ includes/bootstrap.inc	Di Dez 22 17:57:29 2009
@@ -387,7 +387,7 @@
   // Per RFC 2109, cookie domains must contain at least one dot other than the
   // first. For hosts such as 'localhost' or IP Addresses we don't set a cookie domain.
   if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) {
-    ini_set('session.cookie_domain', $cookie_domain);
+    @ini_set('session.cookie_domain', $cookie_domain);
   }
   session_name('SESS'. md5($session_name));
 }
--- includes/common.inc	Mi Dez 23 21:26:06 2009
+++ includes/common.inc	Mi Dez 23 21:24:44 2009
@@ -449,108 +449,94 @@
     $result->code = -1002;
     return $result;
   }
-
-  switch ($uri['scheme']) {
-    case 'http':
-      $port = isset($uri['port']) ? $uri['port'] : 80;
-      $host = $uri['host'] . ($port != 80 ? ':'. $port : '');
-      $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15);
-      break;
-    case 'https':
-      // Note: Only works for PHP 4.3 compiled with OpenSSL.
-      $port = isset($uri['port']) ? $uri['port'] : 443;
-      $host = $uri['host'] . ($port != 443 ? ':'. $port : '');
-      $fp = @fsockopen('ssl://'. $uri['host'], $port, $errno, $errstr, 20);
-      break;
-    default:
-      $result->error = 'invalid schema '. $uri['scheme'];
+  
+  // Anstatt des auf diesen Block folgenden switch Konstruktes, nur dieser Test
+  if(!in_array($uri['scheme'], array('http', 'https'))) {
+	  $result->error = 'invalid schema '. $uri['scheme'];
       $result->code = -1003;
       return $result;
   }
-
-  // Make sure the socket opened properly.
-  if (!$fp) {
-    // When a network error occurs, we use a negative number so it does not
-    // clash with the HTTP status codes.
-    $result->code = -$errno;
-    $result->error = trim($errstr);
-
-    // Mark that this request failed. This will trigger a check of the web
-    // server's ability to make outgoing HTTP requests the next time that
-    // requirements checking is performed.
-    // @see system_requirements()
-    variable_set('drupal_http_request_fails', TRUE);
-
-    return $result;
+  
+  // Curl-Anfrage erzeugen
+  $ch = curl_init();
+  curl_setopt($ch, CURLOPT_URL, $url);
+  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+  curl_setopt($ch, CURLOPT_HEADER, 1);
+  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
+  curl_setopt($ch, CURLOPT_TIMEOUT, 15);
+  
+  // Location-Headern folgen
+  // Edit:
+  // Wird doch wieder rekursiv gelöst, weil es Probleme mit curl und dem Safe-Mode
+  // auf Redio gibt.
+  /* if($retry) {
+    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+    curl_setopt($ch, CURLOPT_MAXREDIRS, $retry);
+  } */
+  
+  // HTTP-Anfragen Methode setzen
+  switch(strtolower($method)) {
+    case 'get':
+	  curl_setopt($ch, CURLOPT_HTTPGET, 1);
+	  break;
+	case 'post':
+	  curl_setopt($ch, CURLOPT_POST, 1);
+	  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+	  break;
+	case 'put':
+	  // Todo: Unterstützung für Put-Anfragen - oder ist die überhaupt nötig?
+	  $result->error = 'Fixme: HTTP-Put Anfragen werden vom Redio-Diff im Moment nicht unterstützt.';
+	  $result->code = -1003;
+	  curl_close($ch);
+	  return $result;
   }
 
-  // Construct the path to act on.
-  $path = isset($uri['path']) ? $uri['path'] : '/';
-  if (isset($uri['query'])) {
-    $path .= '?'. $uri['query'];
-  }
-
-  // Create HTTP request.
-  $defaults = array(
-    // RFC 2616: "non-standard ports MUST, default ports MAY be included".
-    // We don't add the port to prevent from breaking rewrite rules checking the
-    // host that do not take into account the port number.
-    'Host' => "Host: $host",
-    'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
-  );
-
-  // Only add Content-Length if we actually have any content or if it is a POST
-  // or PUT request. Some non-standard servers get confused by Content-Length in
-  // at least HEAD/GET requests, and Squid always requires Content-Length in
-  // POST/PUT requests.
-  $content_length = strlen($data);
-  if ($content_length > 0 || $method == 'POST' || $method == 'PUT') {
-    $defaults['Content-Length'] = 'Content-Length: '. $content_length;
-  }
-
-  // If the server url has a user then attempt to use basic authentication
+  // Basic Authentication?
   if (isset($uri['user'])) {
-    $defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
+    curl_setopt($ch, CURLOPT_USERPWD, $uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
   }
 
-  // If the database prefix is being used by SimpleTest to run the tests in a copied
-  // database then set the user-agent header to the database prefix so that any
-  // calls to other Drupal pages will run the SimpleTest prefixed database. The
-  // user-agent is used to ensure that multiple testing sessions running at the
-  // same time won't interfere with each other as they would if the database
-  // prefix were stored statically in a file or database variable.
+  // User-Agent Header  
   if (is_string($db_prefix) && preg_match("/^simpletest\d+$/", $db_prefix, $matches)) {
-    $defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
+    // If the database prefix is being used by SimpleTest to run the tests in a copied
+    // database then set the user-agent header to the database prefix so that any
+    // calls to other Drupal pages will run the SimpleTest prefixed database. The
+    // user-agent is used to ensure that multiple testing sessions running at the
+    // same time won't interfere with each other as they would if the database
+    // prefix were stored statically in a file or database variable.
+    curl_setopt($ch, CURLOPT_USERAGENT, $matches[0]);
+  } else {
+    curl_setopt($ch, CURLOPT_USERAGENT, 'Drupal (+http://drupal.org/)');
   }
 
-  foreach ($headers as $header => $value) {
-    $defaults[$header] = $header .': '. $value;
+  // Weitere Header
+  if(count($headers)) {
+    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   }
 
-  $request = $method .' '. $path ." HTTP/1.0\r\n";
-  $request .= implode("\r\n", $defaults);
-  $request .= "\r\n\r\n";
-  $request .= $data;
+  // In der nicht-Curl wurde hier die gesamte generierte HTTP-Anfrage eingefügt
+  // Ich hoffe es tut nicht weh? Fixme: Das prüfen!
+  $result->request = ''; 
 
-  $result->request = $request;
-
-  fwrite($fp, $request);
-
-  // Fetch response.
-  $response = '';
-  while (!feof($fp) && $chunk = fread($fp, 1024)) {
-    $response .= $chunk;
+  // Anfrage ausführen
+  $response = curl_exec($ch);
+  if(!$response) {
+    $result->code = curl_errno($ch);
+    $result->error = curl_error($ch);
+    curl_close($ch);
+    variable_set('drupal_http_request_fails', TRUE);
+    return $result;
   }
-  fclose($fp);
+  curl_close($ch);
 
-  // Parse response.
+  // Parse response
   list($split, $result->data) = explode("\r\n\r\n", $response, 2);
   $split = preg_split("/\r\n|\n|\r/", $split);
 
   list($protocol, $code, $text) = explode(' ', trim(array_shift($split)), 3);
   $result->headers = array();
 
-  // Parse headers.
+  // Parse headers
   while ($line = trim(array_shift($split))) {
     list($header, $value) = explode(':', $line, 2);
     if (isset($result->headers[$header]) && $header == 'Set-Cookie') {
@@ -584,14 +570,13 @@
     case 302: // Moved temporarily
     case 307: // Moved temporarily
       $location = $result->headers['Location'];
-
       if ($retry) {
         $result = drupal_http_request($result->headers['Location'], $headers, $method, $data, --$retry);
         $result->redirect_code = $result->code;
       }
       $result->redirect_url = $location;
-
       break;
+	  
     default:
       $result->error = $text;
   }
--- sites/default/default.settings.php	Di Dez 22 18:13:48 2009
+++ sites/default/default.settings.php	Di Dez 22 17:57:57 2009
@@ -134,18 +134,18 @@
  * settings are used there. Settings defined here should not be
  * duplicated there so as to avoid conflict issues.
  */
-ini_set('arg_separator.output',     '&amp;');
-ini_set('magic_quotes_runtime',     0);
-ini_set('magic_quotes_sybase',      0);
-ini_set('session.cache_expire',     200000);
-ini_set('session.cache_limiter',    'none');
-ini_set('session.cookie_lifetime',  2000000);
-ini_set('session.gc_maxlifetime',   200000);
-ini_set('session.save_handler',     'user');
-ini_set('session.use_cookies',      1);
-ini_set('session.use_only_cookies', 1);
-ini_set('session.use_trans_sid',    0);
-ini_set('url_rewriter.tags',        '');
+@ini_set('arg_separator.output',     '&amp;');
+@ini_set('magic_quotes_runtime',     0);
+@ini_set('magic_quotes_sybase',      0);
+@ini_set('session.cache_expire',     200000);
+@ini_set('session.cache_limiter',    'none');
+@ini_set('session.cookie_lifetime',  2000000);
+@ini_set('session.gc_maxlifetime',   200000);
+@ini_set('session.save_handler',     'user');
+@ini_set('session.use_cookies',      1);
+@ini_set('session.use_only_cookies', 1);
+@ini_set('session.use_trans_sid',    0);
+@ini_set('url_rewriter.tags',        '');
 
 /**
  * If you encounter a situation where users post a large amount of text, and
--- .htaccess	Mi Dez 23 21:08:16 2009
+++ .htaccess	Mi Dez 23 21:07:56 2009
@@ -77,7 +77,7 @@
 </IfModule>
 
 # Various rewrite rules.
-<IfModule mod_rewrite.c>
+#<IfModule mod_rewrite.c>
   RewriteEngine on
 
   # If your site can be accessed both with and without the 'www.' prefix, you
@@ -111,6 +111,6 @@
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_URI} !=/favicon.ico
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
-</IfModule>
+#</IfModule>
 
 # $Id: .htaccess,v 1.90.2.4 2009/12/07 12:00:40 goba Exp $
--- update.php	Mi Dez 23 21:09:12 2009
+++ update.php	Di Dez 22 21:50:00 2009
@@ -561,7 +561,7 @@
 
 // Some unavoidable errors happen because the database is not yet up-to-date.
 // Our custom error handler is not yet installed, so we just suppress them.
-ini_set('display_errors', FALSE);
+@ini_set('display_errors', FALSE);
 
 require_once './includes/bootstrap.inc';
 
@@ -613,7 +613,7 @@
 
 // Turn error reporting back on. From now on, only fatal errors (which are
 // not passed through the error handler) will cause a message to be printed.
-ini_set('display_errors', TRUE);
+@ini_set('display_errors', TRUE);
 
 // Access check:
 if (!empty($update_free_access) || $user->uid == 1) {

