]> granicus.if.org Git - php/commitdiff
* fix http auth bug
authorStig Bakken <ssb@php.net>
Tue, 19 Mar 2002 19:30:06 +0000 (19:30 +0000)
committerStig Bakken <ssb@php.net>
Tue, 19 Mar 2002 19:30:06 +0000 (19:30 +0000)
pear/PEAR/Remote.php

index 2b12c3b73a0b4eb0ee907811a73146d194b83974..aba4b24780e7789d74da2e8272b77ea539789123 100644 (file)
@@ -35,12 +35,9 @@ class PEAR_Remote extends PEAR
 
     // {{{ PEAR_Remote(config_object)
 
-    function PEAR_Remote($config = null)
+    function PEAR_Remote(&$config)
     {
         $this->PEAR();
-        if ($config === null) {
-            $config = &PEAR_Config::singleton();
-        }
         $this->config = $config;
     }
 
@@ -72,7 +69,7 @@ class PEAR_Remote extends PEAR
         $password = $this->config->get('password');
         if ($username && $password) {
             $tmp = base64_encode("$username:$password");
-            $req_headers .= "Authorization: Basic $auth\r\n";
+            $req_headers .= "Authorization: Basic $tmp\r\n";
         }
         fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n$req_headers\r\n$request"));
         $response = '';
@@ -84,9 +81,13 @@ class PEAR_Remote extends PEAR
             case "200":
                 break;
             case "401":
-                return $this->raiseError("PEAR_Remote: authorization required, please log in first");
+                if ($username && $password) {
+                    return $this->raiseError("PEAR_Remote: authorization failed", 401);
+                } else {
+                    return $this->raiseError("PEAR_Remote: authorization required, please log in first", 401);
+                }
             default:
-                return $this->raiseError("PEAR_Remote: unexpected HTTP response: $matches[1] $matches[2]");
+                return $this->raiseError("PEAR_Remote: unexpected HTTP response: $matches[1] $matches[2]", (int)$matches[1]);
         }
         while (trim(fgets($fp, 2048)) != ''); // skip rest of headers
         while ($chunk = fread($fp, 10240)) {
@@ -106,11 +107,11 @@ class PEAR_Remote extends PEAR
                 if ($ret['userinfo'] === '') $ret['userinfo'] = null;
                 if (strtolower($class) == 'db_error') {
                     $ret = $this->raiseError(DB::errorMessage($ret['code']),
-                                                $ret['code'], null, null,
-                                                $ret['userinfo']);
+                                             $ret['code'], null, null,
+                                             $ret['userinfo']);
                 } else {
                     $ret = $this->raiseError($ret['message'], $ret['code'],
-                                                null, null, $ret['userinfo']);
+                                             null, null, $ret['userinfo']);
                 }
             }
         }