tools/. download.inc.php

Jeremy Newman jnewman at wine.codeweavers.com
Mon Dec 11 09:48:40 CST 2006


ChangeSet ID:	30473
CVSROOT:	/opt/cvs-commit
Module name:	tools
Changes by:	jnewman at winehq.org	2006/12/11 09:48:40

Modified files:
	.              : download.inc.php 

Log message:
	Jonathan Ernst <jonathan at ernstfamily.ch>
	avoid infinite loop in Wine downloader scripts

Patch: http://cvs.winehq.org/patch.py?id=30473

Old revision  New revision  Changes     Path
 1.1           1.2           +24 -11     tools/download.inc.php

Index: tools/download.inc.php
diff -u -p tools/download.inc.php:1.1 tools/download.inc.php:1.2
--- tools/download.inc.php:1.1	11 Dec 2006 15:48:40 -0000
+++ tools/download.inc.php	11 Dec 2006 15:48:40 -0000
@@ -31,17 +31,20 @@ $aList += array("http://switch.dl.source
                );
               
 
-function is_downloadable($sUrl){
+function is_downloadable($sUrl)
+{
     global $iFileSize;
     $parse = parse_url($sUrl);
     // open a socket connection
-    if($fp = @fsockopen($parse['host'], 80, $errno, $errstr, 10)){
+    if($fp = @fsockopen($parse['host'], 80, $errno, $errstr, 10))
+    {
         // set request
         $get = "HEAD ".$parse['path']." HTTP/1.1\r\n".
                "Host: ".$parse['host']."\r\n".
                "Connection: close\r\n\r\n";
         fputs($fp, $get);
-        while(!feof($fp)){
+        while(!feof($fp))
+        {
             // get ONLY header informations
             $header .= fgets($fp, 128);
         }
@@ -55,20 +58,30 @@ function is_downloadable($sUrl){
 }
 
 
-if($_REQUEST['action']=="showlist") {
+if($_REQUEST['action']=="showlist")
+{
     echo "<h2>List of mirrors available for file ".$sFileName." (".$iFileSize." bytes)</h2>";
-    foreach($aList as $sLocation) {
+    foreach($aList as $sLocation)
+    {
         echo $sLocation.": ";
-        if(is_downloadable($sLocation.$sFileName)) {
+        if(is_downloadable($sLocation.$sFileName))
             echo "<font color=\"green\">online</font>";
-        } else {
+        else
             echo "<font color=\"red\">offline</font>";
-        }
         echo "\n<br />";
+        flush();
     }
-} else {
-    while(!is_downloadable($sUrl)) {
-        $iRand = rand(0, (sizeof($aList)-1));
+} else
+{
+    $iRand = rand(0, (sizeof($aList)-1));
+    $sUrl = $aList[$iRand].$sFileName;
+    // we continue as long as we didn't find a working mirror and we didn't tried all the mirrors
+    while(!is_downloadable($sUrl) && sizeof($aAlreadyTried)<sizeof($aList))
+    {
+        $aAlreadyTried[$iRand] = true;
+        // we loop until we take a random mirror that we didn't already tried ; of course if we have already tried all mirrors we stop
+        while($aAlreadyTried[$iRand] == true && sizeof($aAlreadyTried)<sizeof($aList))
+            $iRand = rand(0, (sizeof($aList)-1));
         $sUrl = $aList[$iRand].$sFileName;
     }
     header("Location: ".$sUrl);



More information about the wine-cvs mailing list