Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Downloader, the PEAR Installer's download utility class
3
 * PEAR_Downloader, the PEAR Installer's download utility class
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Greg Beaver <cellog@php.net>
9
 * @author     Greg Beaver <cellog@php.net>
16
 * @author     Stig Bakken <ssb@php.net>
10
 * @author     Stig Bakken <ssb@php.net>
17
 * @author     Tomas V. V. Cox <cox@idecnet.com>
11
 * @author     Tomas V. V. Cox <cox@idecnet.com>
18
 * @author     Martin Jansen <mj@php.net>
12
 * @author     Martin Jansen <mj@php.net>
19
 * @copyright  1997-2006 The PHP Group
13
 * @copyright  1997-2009 The Authors
20
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
14
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
21
 * @version    CVS: $Id: Downloader.php,v 1.123 2007/02/20 00:16:12 cellog Exp $
-
 
22
 * @link       http://pear.php.net/package/PEAR
15
 * @link       http://pear.php.net/package/PEAR
23
 * @since      File available since Release 1.3.0
16
 * @since      File available since Release 1.3.0
24
 */
17
 */
Line 25... Line 18...
25
 
18
 
Line 41... Line 34...
41
 * @package    PEAR
34
 * @package    PEAR
42
 * @author     Greg Beaver <cellog@php.net>
35
 * @author     Greg Beaver <cellog@php.net>
43
 * @author     Stig Bakken <ssb@php.net>
36
 * @author     Stig Bakken <ssb@php.net>
44
 * @author     Tomas V. V. Cox <cox@idecnet.com>
37
 * @author     Tomas V. V. Cox <cox@idecnet.com>
45
 * @author     Martin Jansen <mj@php.net>
38
 * @author     Martin Jansen <mj@php.net>
46
 * @copyright  1997-2006 The PHP Group
39
 * @copyright  1997-2009 The Authors
47
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
40
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
48
 * @version    Release: 1.5.1
41
 * @version    Release: 1.10.1
49
 * @link       http://pear.php.net/package/PEAR
42
 * @link       http://pear.php.net/package/PEAR
50
 * @since      Class available since Release 1.3.0
43
 * @since      Class available since Release 1.3.0
51
 */
44
 */
52
class PEAR_Downloader extends PEAR_Common
45
class PEAR_Downloader extends PEAR_Common
53
{
46
{
Line 56... Line 49...
56
     * @access private
49
     * @access private
57
     */
50
     */
58
    var $_registry;
51
    var $_registry;
Line 59... Line 52...
59
 
52
 
60
    /**
-
 
61
     * @var PEAR_Remote
-
 
62
     * @access private
-
 
63
     */
-
 
64
    var $_remote;
-
 
65
 
-
 
66
    /**
53
    /**
67
     * Preferred Installation State (snapshot, devel, alpha, beta, stable)
54
     * Preferred Installation State (snapshot, devel, alpha, beta, stable)
68
     * @var string|null
55
     * @var string|null
69
     * @access private
56
     * @access private
70
     */
57
     */
Line 130... Line 117...
130
    /**
117
    /**
131
     * @var array
118
     * @var array
132
     * @access private
119
     * @access private
133
     */
120
     */
134
    var $_errorStack = array();
121
    var $_errorStack = array();
135
    
122
 
136
    /**
123
    /**
137
     * @var boolean
124
     * @var boolean
138
     * @access private
125
     * @access private
139
     */
126
     */
140
    var $_internalDownload = false;
127
    var $_internalDownload = false;
Line 149... Line 136...
149
    /**
136
    /**
150
     * Temporary directory, or configuration value where downloads will occur
137
     * Temporary directory, or configuration value where downloads will occur
151
     * @var string
138
     * @var string
152
     */
139
     */
153
    var $_downloadDir;
140
    var $_downloadDir;
-
 
141
 
-
 
142
    /**
-
 
143
     * List of methods that can be called both statically and non-statically.
-
 
144
     * @var array
-
 
145
     */
-
 
146
    protected static $bivalentMethods = array(
-
 
147
        'setErrorHandling' => true,
154
    // {{{ PEAR_Downloader()
148
        'raiseError' => true,
-
 
149
        'throwError' => true,
-
 
150
        'pushErrorHandling' => true,
-
 
151
        'popErrorHandling' => true,
-
 
152
        'downloadHttp' => true,
-
 
153
    );
Line 155... Line 154...
155
 
154
 
156
    /**
155
    /**
157
     * @param PEAR_Frontend_*
156
     * @param PEAR_Frontend_*
158
     * @param array
157
     * @param array
159
     * @param PEAR_Config
158
     * @param PEAR_Config
160
     */
159
     */
161
    function PEAR_Downloader(&$ui, $options, &$config)
160
    function __construct($ui = null, $options = array(), $config = null)
162
    {
161
    {
163
        parent::PEAR_Common();
162
        parent::__construct();
-
 
163
        $this->_options = $options;
164
        $this->_options = $options;
164
        if ($config !== null) {
165
        $this->config = &$config;
165
            $this->config = &$config;
-
 
166
            $this->_preferredState = $this->config->get('preferred_state');
166
        $this->_preferredState = $this->config->get('preferred_state');
167
        }
167
        $this->ui = &$ui;
168
        $this->ui = &$ui;
168
        if (!$this->_preferredState) {
169
        if (!$this->_preferredState) {
169
            // don't inadvertantly use a non-set preferred_state
170
            // don't inadvertantly use a non-set preferred_state
170
            $this->_preferredState = null;
171
            $this->_preferredState = null;
Line -... Line 172...
-
 
172
        }
171
        }
173
 
172
 
174
        if ($config !== null) {
-
 
175
            if (isset($this->_options['installroot'])) {
-
 
176
                $this->config->setInstallRoot($this->_options['installroot']);
173
        if (isset($this->_options['installroot'])) {
177
            }
174
            $this->config->setInstallRoot($this->_options['installroot']);
-
 
175
        }
-
 
Line 176... Line 178...
176
        $this->_registry = &$config->getRegistry();
178
            $this->_registry = &$config->getRegistry();
177
        $this->_remote = &$config->getRemote();
179
        }
178
 
180
 
179
        if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
181
        if (isset($this->_options['alldeps']) || isset($this->_options['onlyreqdeps'])) {
Line 200... Line 202...
200
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
202
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
201
        $callback = $this->ui ? array(&$this, '_downloadCallback') : null;
203
        $callback = $this->ui ? array(&$this, '_downloadCallback') : null;
202
        if (!class_exists('System')) {
204
        if (!class_exists('System')) {
203
            require_once 'System.php';
205
            require_once 'System.php';
204
        }
206
        }
-
 
207
 
205
        $a = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui,
208
        $tmpdir = $this->config->get('temp_dir');
206
            System::mktemp(array('-d')), $callback, false);
209
        $tmp = System::mktemp('-d -t "' . $tmpdir . '"');
-
 
210
        $a   = $this->downloadHttp('http://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
207
        PEAR::popErrorHandling();
211
        PEAR::popErrorHandling();
208
        if (PEAR::isError($a)) {
212
        if (PEAR::isError($a)) {
-
 
213
            // Attempt to fallback to https automatically.
-
 
214
            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
-
 
215
            $this->log(1, 'Attempting fallback to https instead of http on channel "' . $channel . '"...');
-
 
216
            $a = $this->downloadHttp('https://' . $channel . '/channel.xml', $this->ui, $tmp, $callback, false);
-
 
217
            PEAR::popErrorHandling();
-
 
218
            if (PEAR::isError($a)) {
209
            return false;
219
                return false;
-
 
220
            }
210
        }
221
        }
-
 
222
 
211
        list($a, $lastmodified) = $a;
223
        list($a, $lastmodified) = $a;
212
        if (!class_exists('PEAR/ChannelFile.php')) {
224
        if (!class_exists('PEAR_ChannelFile')) {
213
            require_once 'PEAR/ChannelFile.php';
225
            require_once 'PEAR/ChannelFile.php';
214
        }
226
        }
-
 
227
 
215
        $b = new PEAR_ChannelFile;
228
        $b = new PEAR_ChannelFile;
216
        if ($b->fromXmlFile($a)) {
229
        if ($b->fromXmlFile($a)) {
217
            unlink($a);
230
            unlink($a);
218
            if ($this->config->get('auto_discover')) {
231
            if ($this->config->get('auto_discover')) {
219
                $this->_registry->addChannel($b, $lastmodified);
232
                $this->_registry->addChannel($b, $lastmodified);
220
                $alias = $b->getName();
233
                $alias = $b->getName();
221
                if ($b->getName() == $this->_registry->channelName($b->getAlias())) {
234
                if ($b->getName() == $this->_registry->channelName($b->getAlias())) {
222
                    $alias = $b->getAlias();
235
                    $alias = $b->getAlias();
223
                }
236
                }
-
 
237
 
224
                $this->log(1, 'Auto-discovered channel "' . $channel .
238
                $this->log(1, 'Auto-discovered channel "' . $channel .
225
                    '", alias "' . $alias . '", adding to registry');
239
                    '", alias "' . $alias . '", adding to registry');
226
            }
240
            }
-
 
241
 
227
            return true;
242
            return true;
228
        }
243
        }
-
 
244
 
229
        unlink($a);
245
        unlink($a);
230
        return false;
246
        return false;
231
    }
247
    }
Line 232... Line 248...
232
 
248
 
233
    /**
249
    /**
234
     * For simpler unit-testing
250
     * For simpler unit-testing
235
     * @param PEAR_Downloader
251
     * @param PEAR_Downloader
236
     * @return PEAR_Downloader_Package
252
     * @return PEAR_Downloader_Package
237
     */
253
     */
238
    function &newDownloaderPackage(&$t)
254
    function newDownloaderPackage(&$t)
239
    {
255
    {
240
        if (!class_exists('PEAR_Downloader_Package')) {
256
        if (!class_exists('PEAR_Downloader_Package')) {
241
            require_once 'PEAR/Downloader/Package.php';
257
            require_once 'PEAR/Downloader/Package.php';
242
        }
258
        }
243
        $a = &new PEAR_Downloader_Package($t);
259
        $a = new PEAR_Downloader_Package($t);
244
        return $a;
260
        return $a;
Line 245... Line 261...
245
    }
261
    }
246
 
262
 
Line 251... Line 267...
251
     * @param array
267
     * @param array
252
     * @param int
268
     * @param int
253
     */
269
     */
254
    function &getDependency2Object(&$c, $i, $p, $s)
270
    function &getDependency2Object(&$c, $i, $p, $s)
255
    {
271
    {
256
        if (!class_exists('PEAR/Dependency2.php')) {
272
        if (!class_exists('PEAR_Dependency2')) {
257
            require_once 'PEAR/Dependency2.php';
273
            require_once 'PEAR/Dependency2.php';
258
        }
274
        }
259
        $z = &new PEAR_Dependency2($c, $i, $p, $s);
275
        $z = new PEAR_Dependency2($c, $i, $p, $s);
260
        return $z;
276
        return $z;
261
    }
277
    }
Line 262... Line 278...
262
 
278
 
263
    function &download($params)
279
    function &download($params)
264
    {
280
    {
265
        if (!count($params)) {
281
        if (!count($params)) {
266
            $a = array();
282
            $a = array();
267
            return $a;
283
            return $a;
-
 
284
        }
268
        }
285
 
269
        if (!isset($this->_registry)) {
286
        if (!isset($this->_registry)) {
270
            $this->_registry = &$this->config->getRegistry();
287
            $this->_registry = &$this->config->getRegistry();
271
        }
-
 
272
        if (!isset($this->_remote)) {
-
 
273
            $this->_remote = &$this->config->getRemote();
288
        }
274
        }
289
 
275
        $channelschecked = array();
290
        $channelschecked = array();
276
        // convert all parameters into PEAR_Downloader_Package objects
291
        // convert all parameters into PEAR_Downloader_Package objects
277
        foreach ($params as $i => $param) {
292
        foreach ($params as $i => $param) {
278
            $params[$i] = &$this->newDownloaderPackage($this);
293
            $params[$i] = $this->newDownloaderPackage($this);
279
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
294
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
280
            $err = $params[$i]->initialize($param);
295
            $err = $params[$i]->initialize($param);
281
            PEAR::staticPopErrorHandling();
296
            PEAR::staticPopErrorHandling();
282
            if (!$err) {
297
            if (!$err) {
283
                // skip parameters that were missed by preferred_state
298
                // skip parameters that were missed by preferred_state
284
                continue;
299
                continue;
-
 
300
            }
285
            }
301
 
286
            if (PEAR::isError($err)) {
302
            if (PEAR::isError($err)) {
287
                if (!isset($this->_options['soft'])) {
303
                if (!isset($this->_options['soft']) && $err->getMessage() !== '') {
288
                    $this->log(0, $err->getMessage());
304
                    $this->log(0, $err->getMessage());
-
 
305
                }
289
                }
306
 
290
                $params[$i] = false;
307
                $params[$i] = false;
291
                if (is_object($param)) {
308
                if (is_object($param)) {
292
                    $param = $param->getChannel() . '/' . $param->getPackage();
309
                    $param = $param->getChannel() . '/' . $param->getPackage();
-
 
310
                }
-
 
311
 
293
                }
312
                if (!isset($this->_options['soft'])) {
-
 
313
                    $this->log(2, 'Package "' . $param . '" is not valid');
-
 
314
                }
-
 
315
 
294
                $this->pushError('Package "' . $param . '" is not valid',
316
                // Message logged above in a specific verbose mode, passing null to not show up on CLI
295
                    PEAR_INSTALLER_SKIPPED);
317
                $this->pushError(null, PEAR_INSTALLER_SKIPPED);
296
            } else {
318
            } else {
297
                do {
319
                do {
298
                    if ($params[$i] && $params[$i]->getType() == 'local') {
-
 
299
                        // bug #7090
320
                    if ($params[$i] && $params[$i]->getType() == 'local') {
300
                        // skip channel.xml check for local packages
321
                        // bug #7090 skip channel.xml check for local packages
301
                        break;
322
                        break;
-
 
323
                    }
302
                    }
324
 
303
                    if ($params[$i] && !isset($channelschecked[$params[$i]->getChannel()]) &&
325
                    if ($params[$i] && !isset($channelschecked[$params[$i]->getChannel()]) &&
-
 
326
                          !isset($this->_options['offline'])
304
                          !isset($this->_options['offline'])) {
327
                    ) {
305
                        $channelschecked[$params[$i]->getChannel()] = true;
328
                        $channelschecked[$params[$i]->getChannel()] = true;
306
                        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
329
                        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
307
                        if (!class_exists('System')) {
330
                        if (!class_exists('System')) {
308
                            require_once 'System.php';
331
                            require_once 'System.php';
-
 
332
                        }
309
                        }
333
 
310
                        $curchannel = &$this->_registry->getChannel($params[$i]->getChannel());
334
                        $curchannel = $this->_registry->getChannel($params[$i]->getChannel());
311
                        if (PEAR::isError($curchannel)) {
335
                        if (PEAR::isError($curchannel)) {
312
                            PEAR::staticPopErrorHandling();
336
                            PEAR::staticPopErrorHandling();
313
                            return $this->raiseError($curchannel);
337
                            return $this->raiseError($curchannel);
-
 
338
                        }
314
                        }
339
 
315
                        if (PEAR::isError($dir = $this->getDownloadDir())) {
340
                        if (PEAR::isError($dir = $this->getDownloadDir())) {
316
                            PEAR::staticPopErrorHandling();
341
                            PEAR::staticPopErrorHandling();
317
                            break;
342
                            break;
-
 
343
                        }
318
                        }
344
 
-
 
345
                        $mirror = $this->config->get('preferred_mirror', null, $params[$i]->getChannel());
319
                        $a = $this->downloadHttp('http://' . $params[$i]->getChannel() .
346
                        $url    = 'http://' . $mirror . '/channel.xml';
Line 320... Line 347...
320
                            '/channel.xml', $this->ui, $dir, null, $curchannel->lastModified());
347
                        $a = $this->downloadHttp($url, $this->ui, $dir, null, $curchannel->lastModified());
321
 
348
 
-
 
349
                        PEAR::staticPopErrorHandling();
322
                        PEAR::staticPopErrorHandling();
350
                        if ($a === false) {
-
 
351
                            //channel.xml not modified
-
 
352
                            break;
-
 
353
                        } else if (PEAR::isError($a)) {
-
 
354
                            // Attempt fallback to https automatically
-
 
355
                            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
-
 
356
                            $a = $this->downloadHttp('https://' . $mirror .
-
 
357
                                '/channel.xml', $this->ui, $dir, null, $curchannel->lastModified());
-
 
358
 
-
 
359
                            PEAR::staticPopErrorHandling();
-
 
360
                            if (PEAR::isError($a) || !$a) {
323
                        if (PEAR::isError($a) || !$a) {
361
                                break;
324
                            break;
362
                            }
325
                        }
363
                        }
326
                        $this->log(0, 'WARNING: channel "' . $params[$i]->getChannel() . '" has ' .
364
                        $this->log(0, 'WARNING: channel "' . $params[$i]->getChannel() . '" has ' .
327
                            'updated its protocols, use "channel-update ' . $params[$i]->getChannel() .
365
                            'updated its protocols, use "' . PEAR_RUNTYPE . ' channel-update ' . $params[$i]->getChannel() .
328
                            '" to update');
366
                            '" to update');
-
 
367
                    }
329
                    }
368
                } while (false);
330
                } while (false);
369
 
331
                if ($params[$i] && !isset($this->_options['downloadonly'])) {
370
                if ($params[$i] && !isset($this->_options['downloadonly'])) {
332
                    if (isset($this->_options['packagingroot'])) {
371
                    if (isset($this->_options['packagingroot'])) {
333
                        $checkdir = $this->_prependPath(
372
                        $checkdir = $this->_prependPath(
334
                            $this->config->get('php_dir', null, $params[$i]->getChannel()),
373
                            $this->config->get('php_dir', null, $params[$i]->getChannel()),
335
                            $this->_options['packagingroot']);
374
                            $this->_options['packagingroot']);
336
                    } else {
375
                    } else {
337
                        $checkdir = $this->config->get('php_dir',
376
                        $checkdir = $this->config->get('php_dir',
-
 
377
                            null, $params[$i]->getChannel());
338
                            null, $params[$i]->getChannel());
378
                    }
339
                    }
379
 
340
                    while ($checkdir && $checkdir != '/' && !file_exists($checkdir)) {
380
                    while ($checkdir && $checkdir != '/' && !file_exists($checkdir)) {
-
 
381
                        $checkdir = dirname($checkdir);
341
                        $checkdir = dirname($checkdir);
382
                    }
342
                    }
383
 
343
                    if ($checkdir == '.') {
384
                    if ($checkdir == '.') {
-
 
385
                        $checkdir = '/';
344
                        $checkdir = '/';
386
                    }
345
                    }
387
 
346
                    if (!is_writeable($checkdir)) {
388
                    if (!is_writeable($checkdir)) {
347
                        return PEAR::raiseError('Cannot install, php_dir for channel "' .
389
                        return PEAR::raiseError('Cannot install, php_dir for channel "' .
348
                            $params[$i]->getChannel() . '" is not writeable by the current user');
390
                            $params[$i]->getChannel() . '" is not writeable by the current user');
349
                    }
391
                    }
350
                }
392
                }
-
 
393
            }
351
            }
394
        }
352
        }
395
 
353
        unset($channelschecked);
396
        unset($channelschecked);
354
        PEAR_Downloader_Package::removeDuplicates($params);
397
        PEAR_Downloader_Package::removeDuplicates($params);
355
        if (!count($params)) {
398
        if (!count($params)) {
356
            $a = array();
399
            $a = array();
-
 
400
            return $a;
357
            return $a;
401
        }
358
        }
402
 
359
        if (!isset($this->_options['nodeps']) && !isset($this->_options['offline'])) {
403
        if (!isset($this->_options['nodeps']) && !isset($this->_options['offline'])) {
360
            $reverify = true;
404
            $reverify = true;
361
            while ($reverify) {
405
            while ($reverify) {
-
 
406
                $reverify = false;
-
 
407
                foreach ($params as $i => $param) {
-
 
408
                    //PHP Bug 40768 / PEAR Bug #10944
362
                $reverify = false;
409
                    //Nested foreaches fail in PHP 5.2.1
363
                foreach ($params as $i => $param) {
410
                    key($params);
364
                    $ret = $params[$i]->detectDependencies($params);
411
                    $ret = $params[$i]->detectDependencies($params);
365
                    if (PEAR::isError($ret)) {
412
                    if (PEAR::isError($ret)) {
366
                        $reverify = true;
413
                        $reverify = true;
Line 372... Line 419...
372
                        continue 2;
419
                        continue 2;
373
                    }
420
                    }
374
                }
421
                }
375
            }
422
            }
376
        }
423
        }
-
 
424
 
377
        if (isset($this->_options['offline'])) {
425
        if (isset($this->_options['offline'])) {
378
            $this->log(3, 'Skipping dependency download check, --offline specified');
426
            $this->log(3, 'Skipping dependency download check, --offline specified');
379
        }
427
        }
-
 
428
 
380
        if (!count($params)) {
429
        if (!count($params)) {
381
            $a = array();
430
            $a = array();
382
            return $a;
431
            return $a;
383
        }
432
        }
-
 
433
 
384
        while (PEAR_Downloader_Package::mergeDependencies($params));
434
        while (PEAR_Downloader_Package::mergeDependencies($params));
385
        PEAR_Downloader_Package::removeDuplicates($params, true);
435
        PEAR_Downloader_Package::removeDuplicates($params, true);
-
 
436
        $errorparams = array();
-
 
437
        if (PEAR_Downloader_Package::detectStupidDuplicates($params, $errorparams)) {
-
 
438
            if (count($errorparams)) {
-
 
439
                foreach ($errorparams as $param) {
-
 
440
                    $name = $this->_registry->parsedPackageNameToString($param->getParsedPackage());
-
 
441
                    $this->pushError('Duplicate package ' . $name . ' found', PEAR_INSTALLER_FAILED);
-
 
442
                }
-
 
443
                $a = array();
-
 
444
                return $a;
-
 
445
            }
-
 
446
        }
-
 
447
 
386
        PEAR_Downloader_Package::removeInstalled($params);
448
        PEAR_Downloader_Package::removeInstalled($params);
387
        if (!count($params)) {
449
        if (!count($params)) {
388
            $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
450
            $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
389
            $a = array();
451
            $a = array();
390
            return $a;
452
            return $a;
391
        }
453
        }
-
 
454
 
392
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
455
        PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
393
        $err = $this->analyzeDependencies($params);
456
        $err = $this->analyzeDependencies($params);
394
        PEAR::popErrorHandling();
457
        PEAR::popErrorHandling();
395
        if (!count($params)) {
458
        if (!count($params)) {
396
            $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
459
            $this->pushError('No valid packages found', PEAR_INSTALLER_FAILED);
397
            $a = array();
460
            $a = array();
398
            return $a;
461
            return $a;
399
        }
462
        }
-
 
463
 
400
        $ret = array();
464
        $ret = array();
401
        $newparams = array();
465
        $newparams = array();
402
        if (isset($this->_options['pretend'])) {
466
        if (isset($this->_options['pretend'])) {
403
            return $params;
467
            return $params;
404
        }
468
        }
-
 
469
 
-
 
470
        $somefailed = false;
405
        foreach ($params as $i => $package) {
471
        foreach ($params as $i => $package) {
406
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
472
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
407
            $pf = &$params[$i]->download();
473
            $pf = &$params[$i]->download();
408
            PEAR::staticPopErrorHandling();
474
            PEAR::staticPopErrorHandling();
409
            if (PEAR::isError($pf)) {
475
            if (PEAR::isError($pf)) {
Line 412... Line 478...
412
                    $this->log(0, 'Error: cannot download "' .
478
                    $this->log(0, 'Error: cannot download "' .
413
                        $this->_registry->parsedPackageNameToString($package->getParsedPackage(),
479
                        $this->_registry->parsedPackageNameToString($package->getParsedPackage(),
414
                            true) .
480
                            true) .
415
                        '"');
481
                        '"');
416
                }
482
                }
-
 
483
                $somefailed = true;
417
                continue;
484
                continue;
418
            }
485
            }
-
 
486
 
419
            $newparams[] = &$params[$i];
487
            $newparams[] = &$params[$i];
-
 
488
            $ret[] = array(
420
            $ret[] = array('file' => $pf->getArchiveFile(),
489
                'file' => $pf->getArchiveFile(),
421
                                   'info' => &$pf,
490
                'info' => &$pf,
422
                                   'pkg' => $pf->getPackage());
491
                'pkg'  => $pf->getPackage()
-
 
492
            );
-
 
493
        }
-
 
494
 
-
 
495
        if ($somefailed) {
-
 
496
            // remove params that did not download successfully
-
 
497
            PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
-
 
498
            $err = $this->analyzeDependencies($newparams, true);
-
 
499
            PEAR::popErrorHandling();
-
 
500
            if (!count($newparams)) {
-
 
501
                $this->pushError('Download failed', PEAR_INSTALLER_FAILED);
-
 
502
                $a = array();
-
 
503
                return $a;
-
 
504
            }
423
        }
505
        }
-
 
506
 
424
        $this->_downloadedPackages = $ret;
507
        $this->_downloadedPackages = $ret;
425
        return $newparams;
508
        return $newparams;
426
    }
509
    }
Line 427... Line 510...
427
 
510
 
428
    /**
511
    /**
429
     * @param array all packages to be installed
512
     * @param array all packages to be installed
430
     */
513
     */
431
    function analyzeDependencies(&$params)
514
    function analyzeDependencies(&$params, $force = false)
432
    {
-
 
433
        $hasfailed = $failed = false;
515
    {
434
        if (isset($this->_options['downloadonly'])) {
516
        if (isset($this->_options['downloadonly'])) {
435
            return;
517
            return;
-
 
518
        }
436
        }
519
 
437
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
520
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
438
        $redo = true;
521
        $redo  = true;
439
        $reset = false;
522
        $reset = $hasfailed = $failed = false;
440
        while ($redo) {
523
        while ($redo) {
441
            $redo = false;
524
            $redo = false;
442
            foreach ($params as $i => $param) {
525
            foreach ($params as $i => $param) {
443
                $deps = $param->getDeps();
526
                $deps = $param->getDeps();
444
                if (!$deps) {
527
                if (!$deps) {
445
                    $depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
528
                    $depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
446
                        $param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
-
 
447
                    if ($param->getType() == 'xmlrpc') {
-
 
448
                        $send = $param->getDownloadURL();
-
 
449
                    } else {
529
                        $param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
450
                        $send = $param->getPackageFile();
-
 
-
 
530
                    $send = $param->getPackageFile();
451
                    }
531
 
452
                    $installcheck = $depchecker->validatePackage($send, $this, $params);
532
                    $installcheck = $depchecker->validatePackage($send, $this, $params);
453
                    if (PEAR::isError($installcheck)) {
533
                    if (PEAR::isError($installcheck)) {
454
                        if (!isset($this->_options['soft'])) {
534
                        if (!isset($this->_options['soft'])) {
455
                            $this->log(0, $installcheck->getMessage());
535
                            $this->log(0, $installcheck->getMessage());
456
                        }
536
                        }
457
                        $hasfailed = true;
537
                        $hasfailed  = true;
458
                        $params[$i] = false;
538
                        $params[$i] = false;
459
                        $reset = true;
539
                        $reset      = true;
460
                        $redo = true;
540
                        $redo       = true;
461
                        $failed = false;
541
                        $failed     = false;
462
                        PEAR_Downloader_Package::removeDuplicates($params);
542
                        PEAR_Downloader_Package::removeDuplicates($params);
463
                        continue 2;
543
                        continue 2;
464
                    }
544
                    }
465
                    continue;
545
                    continue;
-
 
546
                }
466
                }
547
 
467
                if (!$reset && $param->alreadyValidated()) {
548
                if (!$reset && $param->alreadyValidated() && !$force) {
468
                    continue;
549
                    continue;
-
 
550
                }
469
                }
551
 
470
                if (count($deps)) {
552
                if (count($deps)) {
471
                    $depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
553
                    $depchecker = &$this->getDependency2Object($this->config, $this->getOptions(),
-
 
554
                        $param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
472
                        $param->getParsedPackage(), PEAR_VALIDATE_DOWNLOADING);
555
                    $send = $param->getPackageFile();
473
                    if ($param->getType() == 'xmlrpc') {
556
                    if ($send === null) {
474
                        $send = $param->getDownloadURL();
-
 
475
                    } else {
-
 
476
                        $send = $param->getPackageFile();
557
                        $send = $param->getDownloadURL();
-
 
558
                    }
477
                    }
559
 
478
                    $installcheck = $depchecker->validatePackage($send, $this, $params);
560
                    $installcheck = $depchecker->validatePackage($send, $this, $params);
479
                    if (PEAR::isError($installcheck)) {
561
                    if (PEAR::isError($installcheck)) {
480
                        if (!isset($this->_options['soft'])) {
562
                        if (!isset($this->_options['soft'])) {
481
                            $this->log(0, $installcheck->getMessage());
563
                            $this->log(0, $installcheck->getMessage());
482
                        }
564
                        }
483
                        $hasfailed = true;
565
                        $hasfailed  = true;
484
                        $params[$i] = false;
566
                        $params[$i] = false;
485
                        $reset = true;
567
                        $reset      = true;
486
                        $redo = true;
568
                        $redo       = true;
487
                        $failed = false;
569
                        $failed     = false;
488
                        PEAR_Downloader_Package::removeDuplicates($params);
570
                        PEAR_Downloader_Package::removeDuplicates($params);
489
                        continue 2;
571
                        continue 2;
-
 
572
                    }
490
                    }
573
 
491
                    $failed = false;
574
                    $failed = false;
492
                    if (isset($deps['required'])) {
575
                    if (isset($deps['required']) && is_array($deps['required'])) {
493
                        foreach ($deps['required'] as $type => $dep) {
576
                        foreach ($deps['required'] as $type => $dep) {
494
                            // note: Dependency2 will never return a PEAR_Error if ignore-errors
577
                            // note: Dependency2 will never return a PEAR_Error if ignore-errors
495
                            // is specified, so soft is needed to turn off logging
578
                            // is specified, so soft is needed to turn off logging
496
                            if (!isset($dep[0])) {
579
                            if (!isset($dep[0])) {
Line 520... Line 603...
520
                                        }
603
                                        }
521
                                    }
604
                                    }
522
                                }
605
                                }
523
                            }
606
                            }
524
                        }
607
                        }
-
 
608
 
525
                        if (isset($deps['optional'])) {
609
                        if (isset($deps['optional']) && is_array($deps['optional'])) {
526
                            foreach ($deps['optional'] as $type => $dep) {
610
                            foreach ($deps['optional'] as $type => $dep) {
527
                                if (!isset($dep[0])) {
611
                                if (!isset($dep[0])) {
528
                                    if (PEAR::isError($e =
612
                                    if (PEAR::isError($e =
529
                                          $depchecker->{"validate{$type}Dependency"}($dep,
613
                                          $depchecker->{"validate{$type}Dependency"}($dep,
530
                                          false, $params))) {
614
                                          false, $params))) {
Line 553... Line 637...
553
                                        }
637
                                        }
554
                                    }
638
                                    }
555
                                }
639
                                }
556
                            }
640
                            }
557
                        }
641
                        }
-
 
642
 
558
                        $groupname = $param->getGroup();
643
                        $groupname = $param->getGroup();
559
                        if (isset($deps['group']) && $groupname) {
644
                        if (isset($deps['group']) && $groupname) {
560
                            if (!isset($deps['group'][0])) {
645
                            if (!isset($deps['group'][0])) {
561
                                $deps['group'] = array($deps['group']);
646
                                $deps['group'] = array($deps['group']);
562
                            }
647
                            }
-
 
648
 
563
                            $found = false;
649
                            $found = false;
564
                            foreach ($deps['group'] as $group) {
650
                            foreach ($deps['group'] as $group) {
565
                                if ($group['attribs']['name'] == $groupname) {
651
                                if ($group['attribs']['name'] == $groupname) {
566
                                    $found = true;
652
                                    $found = true;
567
                                    break;
653
                                    break;
568
                                }
654
                                }
569
                            }
655
                            }
-
 
656
 
570
                            if ($found) {
657
                            if ($found) {
571
                                unset($group['attribs']);
658
                                unset($group['attribs']);
572
                                foreach ($group as $type => $dep) {
659
                                foreach ($group as $type => $dep) {
573
                                    if (!isset($dep[0])) {
660
                                    if (!isset($dep[0])) {
574
                                        if (PEAR::isError($e =
661
                                        if (PEAR::isError($e =
Line 616... Line 703...
616
                            }
703
                            }
617
                        }
704
                        }
618
                    }
705
                    }
619
                    $params[$i]->setValidated();
706
                    $params[$i]->setValidated();
620
                }
707
                }
-
 
708
 
621
                if ($failed) {
709
                if ($failed) {
622
                    $hasfailed = true;
710
                    $hasfailed  = true;
623
                    $params[$i] = false;
711
                    $params[$i] = false;
624
                    $reset = true;
712
                    $reset      = true;
625
                    $redo = true;
713
                    $redo       = true;
626
                    $failed = false;
714
                    $failed     = false;
627
                    PEAR_Downloader_Package::removeDuplicates($params);
715
                    PEAR_Downloader_Package::removeDuplicates($params);
628
                    continue 2;
716
                    continue 2;
629
                }
717
                }
630
            }
718
            }
631
        }
719
        }
-
 
720
 
632
        PEAR::staticPopErrorHandling();
721
        PEAR::staticPopErrorHandling();
633
        if ($hasfailed && (isset($this->_options['ignore-errors']) ||
722
        if ($hasfailed && (isset($this->_options['ignore-errors']) ||
634
              isset($this->_options['nodeps']))) {
723
              isset($this->_options['nodeps']))) {
635
            // this is probably not needed, but just in case
724
            // this is probably not needed, but just in case
636
            if (!isset($this->_options['soft'])) {
725
            if (!isset($this->_options['soft'])) {
Line 647... Line 736...
647
    function getDownloadDir()
736
    function getDownloadDir()
648
    {
737
    {
649
        if (isset($this->_downloadDir)) {
738
        if (isset($this->_downloadDir)) {
650
            return $this->_downloadDir;
739
            return $this->_downloadDir;
651
        }
740
        }
-
 
741
 
652
        $downloaddir = $this->config->get('download_dir');
742
        $downloaddir = $this->config->get('download_dir');
-
 
743
        if (empty($downloaddir) || (is_dir($downloaddir) && !is_writable($downloaddir))) {
653
        if (empty($downloaddir)) {
744
            if  (is_dir($downloaddir) && !is_writable($downloaddir)) {
-
 
745
                $this->log(0, 'WARNING: configuration download directory "' . $downloaddir .
-
 
746
                    '" is not writeable.  Change download_dir config variable to ' .
-
 
747
                    'a writeable dir to avoid this warning');
-
 
748
            }
-
 
749
 
654
            if (!class_exists('System')) {
750
            if (!class_exists('System')) {
655
                require_once 'System.php';
751
                require_once 'System.php';
656
            }
752
            }
-
 
753
 
657
            if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
754
            if (PEAR::isError($downloaddir = System::mktemp('-d'))) {
658
                return $downloaddir;
755
                return $downloaddir;
659
            }
756
            }
660
            $this->log(3, '+ tmp dir created at ' . $downloaddir);
757
            $this->log(3, '+ tmp dir created at ' . $downloaddir);
661
        }
758
        }
-
 
759
 
662
        if (!is_writable($downloaddir)) {
760
        if (!is_writable($downloaddir)) {
663
            if (PEAR::isError(System::mkdir(array('-p', $downloaddir)))) {
761
            if (PEAR::isError(System::mkdir(array('-p', $downloaddir))) ||
-
 
762
                  !is_writable($downloaddir)) {
664
                return PEAR::raiseError('download directory "' . $downloaddir .
763
                return PEAR::raiseError('download directory "' . $downloaddir .
665
                    '" is not writeable.  Change download_dir config variable to ' .
764
                    '" is not writeable.  Change download_dir config variable to ' .
666
                    'a writeable dir');
765
                    'a writeable dir');
667
            }
766
            }
668
        }
767
        }
-
 
768
 
669
        return $this->_downloadDir = $downloaddir;
769
        return $this->_downloadDir = $downloaddir;
670
    }
770
    }
Line 671... Line 771...
671
 
771
 
672
    function setDownloadDir($dir)
772
    function setDownloadDir($dir)
-
 
773
    {
-
 
774
        if (!@is_writable($dir)) {
-
 
775
            if (PEAR::isError(System::mkdir(array('-p', $dir)))) {
-
 
776
                return PEAR::raiseError('download directory "' . $dir .
-
 
777
                    '" is not writeable.  Change download_dir config variable to ' .
-
 
778
                    'a writeable dir');
-
 
779
            }
673
    {
780
        }
674
        $this->_downloadDir = $dir;
781
        $this->_downloadDir = $dir;
Line 675... Line -...
675
    }
-
 
676
 
-
 
677
    // }}}
782
    }
678
    // {{{ configSet()
783
 
679
    function configSet($key, $value, $layer = 'user', $channel = false)
784
    function configSet($key, $value, $layer = 'user', $channel = false)
680
    {
785
    {
681
        $this->config->set($key, $value, $layer, $channel);
786
        $this->config->set($key, $value, $layer, $channel);
682
        $this->_preferredState = $this->config->get('preferred_state', null, $channel);
787
        $this->_preferredState = $this->config->get('preferred_state', null, $channel);
683
        if (!$this->_preferredState) {
788
        if (!$this->_preferredState) {
684
            // don't inadvertantly use a non-set preferred_state
789
            // don't inadvertantly use a non-set preferred_state
685
            $this->_preferredState = null;
790
            $this->_preferredState = null;
Line 686... Line -...
686
        }
-
 
687
    }
-
 
688
 
791
        }
689
    // }}}
792
    }
690
    // {{{ setOptions()
793
 
691
    function setOptions($options)
794
    function setOptions($options)
Line 692... Line -...
692
    {
-
 
693
        $this->_options = $options;
-
 
694
    }
795
    {
695
 
796
        $this->_options = $options;
696
    // }}}
797
    }
697
    // {{{ setOptions()
798
 
Line 698... Line -...
698
    function getOptions()
-
 
699
    {
-
 
700
        return $this->_options;
-
 
701
    }
-
 
702
 
-
 
703
    // }}}
-
 
704
 
-
 
705
    /**
-
 
706
     * For simpler unit-testing
-
 
707
     * @param PEAR_Config
-
 
708
     * @param int
-
 
709
     * @param string
-
 
710
     */
-
 
711
    function &getPackagefileObject(&$c, $d, $t = false)
-
 
712
    {
-
 
713
        if (!class_exists('PEAR_PackageFile')) {
-
 
714
            require_once 'PEAR/PackageFile.php';
-
 
715
        }
-
 
Line 716... Line 799...
716
        $a = &new PEAR_PackageFile($c, $d, $t);
799
    function getOptions()
717
        return $a;
800
    {
718
    }
801
        return $this->_options;
719
 
802
    }
Line 731... Line 814...
731
        // on the latest release as array(version, info).  On success it contains
814
        // on the latest release as array(version, info).  On success it contains
732
        // array(version, info, download url string)
815
        // array(version, info, download url string)
733
        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
816
        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
734
        if (!$this->_registry->channelExists($parr['channel'])) {
817
        if (!$this->_registry->channelExists($parr['channel'])) {
735
            do {
818
            do {
736
                if ($this->config->get('auto_discover')) {
819
                if ($this->config->get('auto_discover') && $this->discover($parr['channel'])) {
737
                    if ($this->discover($parr['channel'])) {
-
 
738
                        break;
820
                    break;
739
                    }
-
 
740
                }
821
                }
-
 
822
 
741
                $this->configSet('default_channel', $curchannel);
823
                $this->configSet('default_channel', $curchannel);
742
                return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
824
                return PEAR::raiseError('Unknown remote channel: ' . $parr['channel']);
743
            } while (false);
825
            } while (false);
744
        }
826
        }
-
 
827
 
745
        $chan = &$this->_registry->getChannel($parr['channel']);
828
        $chan = $this->_registry->getChannel($parr['channel']);
746
        if (PEAR::isError($chan)) {
829
        if (PEAR::isError($chan)) {
747
            return $chan;
830
            return $chan;
748
        }
831
        }
749
        $version = $this->_registry->packageInfo($parr['package'], 'version',
-
 
750
            $parr['channel']);
-
 
751
        if ($chan->supportsREST($this->config->get('preferred_mirror')) &&
-
 
752
              $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
-
 
-
 
832
 
753
            $rest = &$this->config->getREST('1.0', $this->_options);
833
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
754
            if (!isset($parr['version']) && !isset($parr['state']) && $version
834
        $version   = $this->_registry->packageInfo($parr['package'], 'version', $parr['channel']);
755
                  && !isset($this->_options['downloadonly'])) {
-
 
756
                $url = $rest->getDownloadURL($base, $parr, $state, $version);
835
        $stability = $this->_registry->packageInfo($parr['package'], 'stability', $parr['channel']);
757
            } else {
-
 
758
                $url = $rest->getDownloadURL($base, $parr, $state, false);
836
        // package is installed - use the installed release stability level
759
            }
-
 
760
            if (PEAR::isError($url)) {
-
 
761
                $this->configSet('default_channel', $curchannel);
-
 
762
                return $url;
-
 
763
            }
-
 
764
            if ($parr['channel'] != $curchannel) {
837
        if (!isset($parr['state']) && $stability !== null) {
765
                $this->configSet('default_channel', $curchannel);
-
 
766
            }
-
 
767
            if (!is_array($url)) {
-
 
768
                return $url;
-
 
769
            }
-
 
770
            $url['raw'] = false; // no checking is necessary for REST
-
 
771
            if (!is_array($url['info'])) {
-
 
772
                return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
-
 
773
                    'this should never happen');
838
            $state = $stability['release'];
774
            }
839
        }
775
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
776
            $testversion = $this->_registry->packageInfo($url['package'], 'version',
-
 
777
                $parr['channel']);
-
 
778
            PEAR::staticPopErrorHandling();
840
        PEAR::staticPopErrorHandling();
779
            if (!isset($this->_options['force']) &&
841
        $base2 = false;
-
 
842
 
780
                  !isset($this->_options['downloadonly']) &&
843
        $preferred_mirror = $this->config->get('preferred_mirror');
781
                  !PEAR::isError($testversion) &&
844
        if (!$chan->supportsREST($preferred_mirror) ||
782
                  !isset($parr['group'])) {
-
 
783
                if (version_compare($testversion, $url['version'], '>=')) {
-
 
784
                    return PEAR::raiseError($this->_registry->parsedPackageNameToString(
-
 
785
                        $parr, true) . ' is already installed and is newer than detected ' .
-
 
786
                        'release version ' . $url['version'], -976);
-
 
787
                }
845
              (
788
            }
-
 
789
            if (isset($url['info']['required']) || $url['compatible']) {
-
 
790
                require_once 'PEAR/PackageFile/v2.php';
-
 
791
                $pf = new PEAR_PackageFile_v2;
-
 
792
                $pf->setRawChannel($parr['channel']);
-
 
793
                if ($url['compatible']) {
-
 
794
                    $pf->setRawCompatible($url['compatible']);
846
               !($base2 = $chan->getBaseURL('REST1.3', $preferred_mirror))
795
                }
847
               &&
796
            } else {
-
 
797
                require_once 'PEAR/PackageFile/v1.php';
848
               !($base = $chan->getBaseURL('REST1.0', $preferred_mirror))
798
                $pf = new PEAR_PackageFile_v1;
-
 
799
            }
849
              )
800
            $pf->setRawPackage($url['package']);
-
 
801
            $pf->setDeps($url['info']);
-
 
802
            if ($url['compatible']) {
-
 
803
                $pf->setCompatible($url['compatible']);
-
 
804
            }
850
        ) {
805
            $pf->setRawState($url['stability']);
-
 
806
            $url['info'] = &$pf;
-
 
807
            if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
851
            return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
808
                $ext = '.tar';
-
 
809
            } else {
-
 
810
                $ext = '.tgz';
-
 
811
            }
852
        }
812
            if (is_array($url)) {
-
 
813
                if (isset($url['url'])) {
-
 
814
                    $url['url'] .= $ext;
-
 
-
 
853
 
815
                }
854
        if ($base2) {
816
            }
-
 
817
            return $url;
-
 
818
        } elseif ($chan->supports('xmlrpc', 'package.getDownloadURL', false, '1.1')) {
-
 
819
            // don't install with the old version information unless we're doing a plain
-
 
820
            // vanilla simple installation.  If the user says to install a particular
-
 
821
            // version or state, ignore the current installed version
-
 
822
            if (!isset($parr['version']) && !isset($parr['state']) && $version
-
 
823
                  && !isset($this->_options['downloadonly'])) {
855
            $rest = &$this->config->getREST('1.3', $this->_options);
824
                $url = $this->_remote->call('package.getDownloadURL', $parr, $state, $version);
-
 
825
            } else {
856
            $base = $base2;
826
                $url = $this->_remote->call('package.getDownloadURL', $parr, $state);
-
 
827
            }
-
 
828
        } else {
857
        } else {
829
            $url = $this->_remote->call('package.getDownloadURL', $parr, $state);
858
            $rest = &$this->config->getREST('1.0', $this->_options);
830
        }
859
        }
-
 
860
 
-
 
861
        $downloadVersion = false;
-
 
862
        if (!isset($parr['version']) && !isset($parr['state']) && $version
-
 
863
              && !PEAR::isError($version)
-
 
864
              && !isset($this->_options['downloadonly'])
-
 
865
        ) {
-
 
866
            $downloadVersion = $version;
-
 
867
        }
-
 
868
 
-
 
869
        $url = $rest->getDownloadURL($base, $parr, $state, $downloadVersion, $chan->getName());
831
        if (PEAR::isError($url)) {
870
        if (PEAR::isError($url)) {
-
 
871
            $this->configSet('default_channel', $curchannel);
832
            return $url;
872
            return $url;
833
        }
873
        }
-
 
874
 
834
        if ($parr['channel'] != $curchannel) {
875
        if ($parr['channel'] != $curchannel) {
835
            $this->configSet('default_channel', $curchannel);
876
            $this->configSet('default_channel', $curchannel);
836
        }
877
        }
837
        if (isset($url['__PEAR_ERROR_CLASS__'])) {
-
 
838
            return PEAR::raiseError($url['message']);
-
 
839
        }
878
 
840
        if (!is_array($url)) {
879
        if (!is_array($url)) {
841
            return $url;
880
            return $url;
842
        }
881
        }
-
 
882
 
-
 
883
        $url['raw'] = false; // no checking is necessary for REST
843
        $url['raw'] = $url['info'];
884
        if (!is_array($url['info'])) {
-
 
885
            return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
-
 
886
                'this should never happen');
-
 
887
        }
-
 
888
 
-
 
889
        if (!isset($this->_options['force']) &&
844
        if (isset($this->_options['downloadonly'])) {
890
              !isset($this->_options['downloadonly']) &&
-
 
891
              $version &&
845
            $pkg = &$this->getPackagefileObject($this->config, $this->debug);
892
              !PEAR::isError($version) &&
-
 
893
              !isset($parr['group'])
846
        } else {
894
        ) {
847
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
895
            if (version_compare($version, $url['version'], '=')) {
848
            if (PEAR::isError($dir = $this->getDownloadDir())) {
896
                return PEAR::raiseError($this->_registry->parsedPackageNameToString(
-
 
897
                    $parr, true) . ' is already installed and is the same as the ' .
849
                PEAR::staticPopErrorHandling();
898
                    'released version ' . $url['version'], -976);
850
                return $dir;
899
            }
-
 
900
 
-
 
901
            if (version_compare($version, $url['version'], '>')) {
-
 
902
                return PEAR::raiseError($this->_registry->parsedPackageNameToString(
-
 
903
                    $parr, true) . ' is already installed and is newer than detected ' .
-
 
904
                    'released version ' . $url['version'], -976);
851
            }
905
            }
852
            PEAR::staticPopErrorHandling();
-
 
853
            $pkg = &$this->getPackagefileObject($this->config, $this->debug, $dir);
-
 
854
        }
906
        }
-
 
907
 
855
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
908
        if (isset($url['info']['required']) || $url['compatible']) {
856
        $pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote');
909
            require_once 'PEAR/PackageFile/v2.php';
857
        PEAR::staticPopErrorHandling();
910
            $pf = new PEAR_PackageFile_v2;
858
        if (PEAR::isError($pinfo)) {
911
            $pf->setRawChannel($parr['channel']);
859
            if (!isset($this->_options['soft'])) {
912
            if ($url['compatible']) {
860
                $this->log(0, $pinfo->getMessage());
913
                $pf->setRawCompatible($url['compatible']);
861
            }
914
            }
-
 
915
        } else {
862
            return PEAR::raiseError('Remote package.xml is not valid - this should never happen');
916
            require_once 'PEAR/PackageFile/v1.php';
-
 
917
            $pf = new PEAR_PackageFile_v1;
-
 
918
        }
-
 
919
 
-
 
920
        $pf->setRawPackage($url['package']);
-
 
921
        $pf->setDeps($url['info']);
-
 
922
        if ($url['compatible']) {
-
 
923
            $pf->setCompatible($url['compatible']);
863
        }
924
        }
-
 
925
 
-
 
926
        $pf->setRawState($url['stability']);
864
        $url['info'] = &$pinfo;
927
        $url['info'] = &$pf;
865
        if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
928
        if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
866
            $ext = '.tar';
929
            $ext = '.tar';
867
        } else {
930
        } else {
868
            $ext = '.tgz';
931
            $ext = '.tgz';
869
        }
932
        }
870
        if (is_array($url)) {
-
 
-
 
933
 
871
            if (isset($url['url'])) {
934
        if (is_array($url) && isset($url['url'])) {
872
                $url['url'] .= $ext;
935
            $url['url'] .= $ext;
873
            }
-
 
874
        }
936
        }
-
 
937
 
875
        return $url;
938
        return $url;
876
    }
939
    }
877
    // }}}
-
 
878
    // {{{ getDepPackageDownloadUrl()
-
 
Line 879... Line 940...
879
 
940
 
880
    /**
941
    /**
881
     * @param array dependency array
942
     * @param array dependency array
882
     * @access private
943
     * @access private
Line 885... Line 946...
885
    {
946
    {
886
        $xsdversion = isset($dep['rel']) ? '1.0' : '2.0';
947
        $xsdversion = isset($dep['rel']) ? '1.0' : '2.0';
887
        $curchannel = $this->config->get('default_channel');
948
        $curchannel = $this->config->get('default_channel');
888
        if (isset($dep['uri'])) {
949
        if (isset($dep['uri'])) {
889
            $xsdversion = '2.0';
950
            $xsdversion = '2.0';
890
            $chan = &$this->_registry->getChannel('__uri');
951
            $chan = $this->_registry->getChannel('__uri');
891
            if (PEAR::isError($chan)) {
952
            if (PEAR::isError($chan)) {
892
                return $chan;
953
                return $chan;
893
            }
954
            }
-
 
955
 
894
            $version = $this->_registry->packageInfo($dep['name'], 'version', '__uri');
956
            $version = $this->_registry->packageInfo($dep['name'], 'version', '__uri');
895
            $this->configSet('default_channel', '__uri');
957
            $this->configSet('default_channel', '__uri');
896
        } else {
958
        } else {
897
            if (isset($dep['channel'])) {
959
            if (isset($dep['channel'])) {
898
                $remotechannel = $dep['channel'];
960
                $remotechannel = $dep['channel'];
899
            } else {
961
            } else {
900
                $remotechannel = 'pear.php.net';
962
                $remotechannel = 'pear.php.net';
901
            }
963
            }
-
 
964
 
902
            if (!$this->_registry->channelExists($remotechannel)) {
965
            if (!$this->_registry->channelExists($remotechannel)) {
903
                do {
966
                do {
904
                    if ($this->config->get('auto_discover')) {
967
                    if ($this->config->get('auto_discover')) {
905
                        if ($this->discover($remotechannel)) {
968
                        if ($this->discover($remotechannel)) {
906
                            break;
969
                            break;
907
                        }
970
                        }
908
                    }
971
                    }
909
                    return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
972
                    return PEAR::raiseError('Unknown remote channel: ' . $remotechannel);
910
                } while (false);
973
                } while (false);
911
            }
974
            }
-
 
975
 
912
            $chan = &$this->_registry->getChannel($remotechannel);
976
            $chan = $this->_registry->getChannel($remotechannel);
913
            if (PEAR::isError($chan)) {
977
            if (PEAR::isError($chan)) {
914
                return $chan;
978
                return $chan;
915
            }
979
            }
-
 
980
 
916
            $version = $this->_registry->packageInfo($dep['name'], 'version',
981
            $version = $this->_registry->packageInfo($dep['name'], 'version', $remotechannel);
917
                $remotechannel);
-
 
918
            $this->configSet('default_channel', $remotechannel);
982
            $this->configSet('default_channel', $remotechannel);
919
        }
983
        }
-
 
984
 
920
        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
985
        $state = isset($parr['state']) ? $parr['state'] : $this->config->get('preferred_state');
921
        if (isset($parr['state']) && isset($parr['version'])) {
986
        if (isset($parr['state']) && isset($parr['version'])) {
922
            unset($parr['state']);
987
            unset($parr['state']);
923
        }
988
        }
-
 
989
 
924
        if (isset($dep['uri'])) {
990
        if (isset($dep['uri'])) {
925
            $info = &$this->newDownloaderPackage($this);
991
            $info = $this->newDownloaderPackage($this);
926
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
992
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
927
            $err = $info->initialize($dep);
993
            $err = $info->initialize($dep);
928
            PEAR::staticPopErrorHandling();
994
            PEAR::staticPopErrorHandling();
929
            if (!$err) {
995
            if (!$err) {
930
                // skip parameters that were missed by preferred_state
996
                // skip parameters that were missed by preferred_state
931
                return PEAR::raiseError('Cannot initialize dependency');
997
                return PEAR::raiseError('Cannot initialize dependency');
932
            }
998
            }
-
 
999
 
933
            if (PEAR::isError($err)) {
1000
            if (PEAR::isError($err)) {
934
                if (!isset($this->_options['soft'])) {
1001
                if (!isset($this->_options['soft'])) {
935
                    $this->log(0, $err->getMessage());
1002
                    $this->log(0, $err->getMessage());
936
                }
1003
                }
-
 
1004
 
937
                if (is_object($info)) {
1005
                if (is_object($info)) {
938
                    $param = $info->getChannel() . '/' . $info->getPackage();
1006
                    $param = $info->getChannel() . '/' . $info->getPackage();
939
                }
1007
                }
940
                return PEAR::raiseError('Package "' . $param . '" is not valid');
1008
                return PEAR::raiseError('Package "' . $param . '" is not valid');
941
            }
1009
            }
942
            return $info;
1010
            return $info;
943
        } elseif ($chan->supportsREST($this->config->get('preferred_mirror')) &&
1011
        } elseif ($chan->supportsREST($this->config->get('preferred_mirror'))
-
 
1012
              &&
-
 
1013
                (
-
 
1014
                  ($base2 = $chan->getBaseURL('REST1.3', $this->config->get('preferred_mirror')))
-
 
1015
                    ||
944
              $base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror'))) {
1016
                  ($base = $chan->getBaseURL('REST1.0', $this->config->get('preferred_mirror')))
-
 
1017
                )
-
 
1018
        ) {
-
 
1019
            if ($base2) {
-
 
1020
                $base = $base2;
-
 
1021
                $rest = &$this->config->getREST('1.3', $this->_options);
-
 
1022
            } else {
945
            $rest = &$this->config->getREST('1.0', $this->_options);
1023
                $rest = &$this->config->getREST('1.0', $this->_options);
-
 
1024
            }
-
 
1025
 
946
            $url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr,
1026
            $url = $rest->getDepDownloadURL($base, $xsdversion, $dep, $parr,
947
                    $state, $version);
1027
                    $state, $version, $chan->getName());
948
            if (PEAR::isError($url)) {
1028
            if (PEAR::isError($url)) {
949
                return $url;
1029
                return $url;
950
            }
1030
            }
-
 
1031
 
951
            if ($parr['channel'] != $curchannel) {
1032
            if ($parr['channel'] != $curchannel) {
952
                $this->configSet('default_channel', $curchannel);
1033
                $this->configSet('default_channel', $curchannel);
953
            }
1034
            }
-
 
1035
 
954
            if (!is_array($url)) {
1036
            if (!is_array($url)) {
955
                return $url;
1037
                return $url;
956
            }
1038
            }
-
 
1039
 
957
            $url['raw'] = false; // no checking is necessary for REST
1040
            $url['raw'] = false; // no checking is necessary for REST
958
            if (!is_array($url['info'])) {
1041
            if (!is_array($url['info'])) {
959
                return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
1042
                return PEAR::raiseError('Invalid remote dependencies retrieved from REST - ' .
960
                    'this should never happen');
1043
                    'this should never happen');
961
            }
1044
            }
-
 
1045
 
962
            if (isset($url['info']['required'])) {
1046
            if (isset($url['info']['required'])) {
963
                if (!class_exists('PEAR_PackageFile_v2')) {
1047
                if (!class_exists('PEAR_PackageFile_v2')) {
964
                    require_once 'PEAR/PackageFile/v2.php';
1048
                    require_once 'PEAR/PackageFile/v2.php';
965
                }
1049
                }
966
                $pf = new PEAR_PackageFile_v2;
1050
                $pf = new PEAR_PackageFile_v2;
Line 968... Line 1052...
968
            } else {
1052
            } else {
969
                if (!class_exists('PEAR_PackageFile_v1')) {
1053
                if (!class_exists('PEAR_PackageFile_v1')) {
970
                    require_once 'PEAR/PackageFile/v1.php';
1054
                    require_once 'PEAR/PackageFile/v1.php';
971
                }
1055
                }
972
                $pf = new PEAR_PackageFile_v1;
1056
                $pf = new PEAR_PackageFile_v1;
-
 
1057
 
973
            }
1058
            }
974
            $pf->setRawPackage($url['package']);
1059
            $pf->setRawPackage($url['package']);
975
            $pf->setDeps($url['info']);
1060
            $pf->setDeps($url['info']);
976
            if ($url['compatible']) {
1061
            if ($url['compatible']) {
977
                $pf->setCompatible($url['compatible']);
1062
                $pf->setCompatible($url['compatible']);
978
            }
1063
            }
-
 
1064
 
979
            $pf->setRawState($url['stability']);
1065
            $pf->setRawState($url['stability']);
980
            $url['info'] = &$pf;
1066
            $url['info'] = &$pf;
981
            if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
1067
            if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
982
                $ext = '.tar';
1068
                $ext = '.tar';
983
            } else {
1069
            } else {
984
                $ext = '.tgz';
1070
                $ext = '.tgz';
985
            }
1071
            }
986
            if (is_array($url)) {
-
 
987
                if (isset($url['url'])) {
-
 
988
                    $url['url'] .= $ext;
-
 
989
                }
-
 
990
            }
-
 
991
            return $url;
-
 
992
        } elseif ($chan->supports('xmlrpc', 'package.getDepDownloadURL', false, '1.1')) {
-
 
993
            if ($version) {
-
 
994
                $url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr,
-
 
995
                    $state, $version);
-
 
996
            } else {
-
 
997
                $url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr,
-
 
998
                    $state);
-
 
999
            }
-
 
1000
        } else {
-
 
1001
            $url = $this->_remote->call('package.getDepDownloadURL', $xsdversion, $dep, $parr, $state);
-
 
1002
        }
-
 
1003
        if ($this->config->get('default_channel') != $curchannel) {
-
 
1004
            $this->configSet('default_channel', $curchannel);
-
 
1005
        }
1072
 
1006
        if (!is_array($url)) {
-
 
1007
            return $url;
-
 
1008
        }
-
 
1009
        if (isset($url['__PEAR_ERROR_CLASS__'])) {
-
 
1010
            return PEAR::raiseError($url['message']);
-
 
1011
        }
-
 
1012
        $url['raw'] = $url['info'];
-
 
1013
        $pkg = &$this->getPackagefileObject($this->config, $this->debug);
-
 
1014
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
1015
        $pinfo = &$pkg->fromXmlString($url['info'], PEAR_VALIDATE_DOWNLOADING, 'remote');
-
 
1016
        PEAR::staticPopErrorHandling();
-
 
1017
        if (PEAR::isError($pinfo)) {
-
 
1018
            if (!isset($this->_options['soft'])) {
-
 
1019
                $this->log(0, $pinfo->getMessage());
-
 
1020
            }
-
 
1021
            return PEAR::raiseError('Remote package.xml is not valid - this should never happen');
-
 
1022
        }
-
 
1023
        $url['info'] = &$pinfo;
-
 
1024
        if (is_array($url)) {
-
 
1025
            if (!extension_loaded("zlib") || isset($this->_options['nocompress'])) {
-
 
1026
                $ext = '.tar';
-
 
1027
            } else {
-
 
1028
                $ext = '.tgz';
-
 
1029
            }
-
 
1030
            if (isset($url['url'])) {
1073
            if (is_array($url) && isset($url['url'])) {
1031
                $url['url'] .= $ext;
1074
                $url['url'] .= $ext;
1032
            }
1075
            }
-
 
1076
 
-
 
1077
            return $url;
1033
        }
1078
        }
-
 
1079
 
1034
        return $url;
1080
        return $this->raiseError($parr['channel'] . ' is using a unsupported protocol - This should never happen.');
1035
    }
1081
    }
1036
    // }}}
-
 
1037
    // {{{ getPackageDownloadUrl()
-
 
Line 1038... Line 1082...
1038
 
1082
 
1039
    /**
1083
    /**
1040
     * @deprecated in favor of _getPackageDownloadUrl
1084
     * @deprecated in favor of _getPackageDownloadUrl
1041
     */
1085
     */
Line 1057... Line 1101...
1057
            $package .= '?uncompress=yes';
1101
            $package .= '?uncompress=yes';
1058
        }
1102
        }
1059
        return $package;
1103
        return $package;
1060
    }
1104
    }
Line 1061... Line -...
1061
 
-
 
1062
    // }}}
-
 
1063
    // {{{ getDownloadedPackages()
-
 
1064
 
1105
 
1065
    /**
1106
    /**
1066
     * Retrieve a list of downloaded packages after a call to {@link download()}.
1107
     * Retrieve a list of downloaded packages after a call to {@link download()}.
1067
     *
1108
     *
1068
     * Also resets the list of downloaded packages.
1109
     * Also resets the list of downloaded packages.
Line 1074... Line 1115...
1074
        $this->_downloadedPackages = array();
1115
        $this->_downloadedPackages = array();
1075
        $this->_toDownload = array();
1116
        $this->_toDownload = array();
1076
        return $ret;
1117
        return $ret;
1077
    }
1118
    }
Line 1078... Line -...
1078
 
-
 
1079
    // }}}
-
 
1080
    // {{{ _downloadCallback()
-
 
1081
 
1119
 
1082
    function _downloadCallback($msg, $params = null)
1120
    function _downloadCallback($msg, $params = null)
1083
    {
1121
    {
1084
        switch ($msg) {
1122
        switch ($msg) {
1085
            case 'saveas':
1123
            case 'saveas':
Line 1109... Line 1147...
1109
        }
1147
        }
1110
        if (method_exists($this->ui, '_downloadCallback'))
1148
        if (method_exists($this->ui, '_downloadCallback'))
1111
            $this->ui->_downloadCallback($msg, $params);
1149
            $this->ui->_downloadCallback($msg, $params);
1112
    }
1150
    }
Line 1113... Line -...
1113
 
-
 
1114
    // }}}
-
 
1115
    // {{{ _prependPath($path, $prepend)
-
 
1116
 
1151
 
1117
    function _prependPath($path, $prepend)
1152
    function _prependPath($path, $prepend)
1118
    {
1153
    {
1119
        if (strlen($prepend) > 0) {
1154
        if (strlen($prepend) > 0) {
1120
            if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
1155
            if (OS_WINDOWS && preg_match('/^[a-z]:/i', $path)) {
Line 1128... Line 1163...
1128
                $path = $prepend . $path;
1163
                $path = $prepend . $path;
1129
            }
1164
            }
1130
        }
1165
        }
1131
        return $path;
1166
        return $path;
1132
    }
1167
    }
1133
    // }}}
-
 
1134
    // {{{ pushError($errmsg, $code)
-
 
Line 1135... Line 1168...
1135
 
1168
 
1136
    /**
1169
    /**
1137
     * @param string
1170
     * @param string
1138
     * @param integer
1171
     * @param integer
1139
     */
1172
     */
1140
    function pushError($errmsg, $code = -1)
1173
    function pushError($errmsg, $code = -1)
1141
    {
1174
    {
1142
        array_push($this->_errorStack, array($errmsg, $code));
1175
        array_push($this->_errorStack, array($errmsg, $code));
Line 1143... Line -...
1143
    }
-
 
1144
 
-
 
1145
    // }}}
-
 
1146
    // {{{ getErrorMsgs()
1176
    }
1147
 
1177
 
1148
    function getErrorMsgs()
1178
    function getErrorMsgs()
1149
    {
1179
    {
1150
        $msgs = array();
1180
        $msgs = array();
Line 1154... Line 1184...
1154
        }
1184
        }
1155
        $this->_errorStack = array();
1185
        $this->_errorStack = array();
1156
        return $msgs;
1186
        return $msgs;
1157
    }
1187
    }
Line 1158... Line -...
1158
 
-
 
1159
    // }}}
-
 
1160
 
1188
 
1161
    /**
1189
    /**
-
 
1190
     * for BC
-
 
1191
     *
1162
     * for BC
1192
     * @deprecated
1163
     */
1193
     */
1164
    function sortPkgDeps(&$packages, $uninstall = false)
1194
    function sortPkgDeps(&$packages, $uninstall = false)
1165
    {
1195
    {
1166
        $uninstall ? 
1196
        $uninstall ?
1167
            $this->sortPackagesForUninstall($packages) :
1197
            $this->sortPackagesForUninstall($packages) :
1168
            $this->sortPackagesForInstall($packages);
1198
            $this->sortPackagesForInstall($packages);
Line 1169... Line 1199...
1169
    }
1199
    }
Line 1192... Line 1222...
1192
                ));
1222
                ));
1193
            $nodes[$pname] = new Structures_Graph_Node;
1223
            $nodes[$pname] = new Structures_Graph_Node;
1194
            $nodes[$pname]->setData($packages[$i]);
1224
            $nodes[$pname]->setData($packages[$i]);
1195
            $depgraph->addNode($nodes[$pname]);
1225
            $depgraph->addNode($nodes[$pname]);
1196
        }
1226
        }
-
 
1227
 
1197
        $deplinks = array();
1228
        $deplinks = array();
1198
        foreach ($nodes as $package => $node) {
1229
        foreach ($nodes as $package => $node) {
1199
            $pf = &$node->getData();
1230
            $pf = &$node->getData();
1200
            $pdeps = $pf->getDeps(true);
1231
            $pdeps = $pf->getDeps(true);
1201
            if (!$pdeps) {
1232
            if (!$pdeps) {
1202
                continue;
1233
                continue;
1203
            }
1234
            }
-
 
1235
 
1204
            if ($pf->getPackagexmlVersion() == '1.0') {
1236
            if ($pf->getPackagexmlVersion() == '1.0') {
1205
                foreach ($pdeps as $dep) {
1237
                foreach ($pdeps as $dep) {
1206
                    if ($dep['type'] != 'pkg' ||
1238
                    if ($dep['type'] != 'pkg' ||
1207
                          (isset($dep['optional']) && $dep['optional'] == 'yes')) {
1239
                          (isset($dep['optional']) && $dep['optional'] == 'yes')) {
1208
                        continue;
1240
                        continue;
1209
                    }
1241
                    }
-
 
1242
 
1210
                    $dname = $reg->parsedPackageNameToString(
1243
                    $dname = $reg->parsedPackageNameToString(
1211
                          array(
1244
                          array(
1212
                              'channel' => 'pear.php.net',
1245
                              'channel' => 'pear.php.net',
1213
                              'package' => strtolower($dep['name']),
1246
                              'package' => strtolower($dep['name']),
1214
                          ));
1247
                          ));
-
 
1248
 
1215
                    if (isset($nodes[$dname]))
1249
                    if (isset($nodes[$dname])) {
1216
                    {
-
 
1217
                        if (!isset($deplinks[$dname])) {
1250
                        if (!isset($deplinks[$dname])) {
1218
                            $deplinks[$dname] = array();
1251
                            $deplinks[$dname] = array();
1219
                        }
1252
                        }
-
 
1253
 
1220
                        $deplinks[$dname][$package] = 1;
1254
                        $deplinks[$dname][$package] = 1;
1221
                        // dependency is in installed packages
1255
                        // dependency is in installed packages
1222
                        continue;
1256
                        continue;
1223
                    }
1257
                    }
-
 
1258
 
1224
                    $dname = $reg->parsedPackageNameToString(
1259
                    $dname = $reg->parsedPackageNameToString(
1225
                          array(
1260
                          array(
1226
                              'channel' => 'pecl.php.net',
1261
                              'channel' => 'pecl.php.net',
1227
                              'package' => strtolower($dep['name']),
1262
                              'package' => strtolower($dep['name']),
1228
                          ));
1263
                          ));
-
 
1264
 
1229
                    if (isset($nodes[$dname]))
1265
                    if (isset($nodes[$dname])) {
1230
                    {
-
 
1231
                        if (!isset($deplinks[$dname])) {
1266
                        if (!isset($deplinks[$dname])) {
1232
                            $deplinks[$dname] = array();
1267
                            $deplinks[$dname] = array();
1233
                        }
1268
                        }
-
 
1269
 
1234
                        $deplinks[$dname][$package] = 1;
1270
                        $deplinks[$dname][$package] = 1;
1235
                        // dependency is in installed packages
1271
                        // dependency is in installed packages
1236
                        continue;
1272
                        continue;
1237
                    }
1273
                    }
1238
                }
1274
                }
Line 1243... Line 1279...
1243
                if (isset($pdeps['required']['subpackage'])) {
1279
                if (isset($pdeps['required']['subpackage'])) {
1244
                    $t = $pdeps['required']['subpackage'];
1280
                    $t = $pdeps['required']['subpackage'];
1245
                    if (!isset($t[0])) {
1281
                    if (!isset($t[0])) {
1246
                        $t = array($t);
1282
                        $t = array($t);
1247
                    }
1283
                    }
-
 
1284
 
1248
                    $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1285
                    $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1249
                }
1286
                }
-
 
1287
 
1250
                if (isset($pdeps['group'])) {
1288
                if (isset($pdeps['group'])) {
1251
                    if (!isset($pdeps['group'][0])) {
1289
                    if (!isset($pdeps['group'][0])) {
1252
                        $pdeps['group'] = array($pdeps['group']);
1290
                        $pdeps['group'] = array($pdeps['group']);
1253
                    }
1291
                    }
-
 
1292
 
1254
                    foreach ($pdeps['group'] as $group) {
1293
                    foreach ($pdeps['group'] as $group) {
1255
                        if (isset($group['subpackage'])) {
1294
                        if (isset($group['subpackage'])) {
1256
                            $t = $group['subpackage'];
1295
                            $t = $group['subpackage'];
1257
                            if (!isset($t[0])) {
1296
                            if (!isset($t[0])) {
1258
                                $t = array($t);
1297
                                $t = array($t);
1259
                            }
1298
                            }
-
 
1299
 
1260
                            $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1300
                            $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1261
                        }
1301
                        }
1262
                    }
1302
                    }
1263
                }
1303
                }
-
 
1304
 
1264
                if (isset($pdeps['optional']['subpackage'])) {
1305
                if (isset($pdeps['optional']['subpackage'])) {
1265
                    $t = $pdeps['optional']['subpackage'];
1306
                    $t = $pdeps['optional']['subpackage'];
1266
                    if (!isset($t[0])) {
1307
                    if (!isset($t[0])) {
1267
                        $t = array($t);
1308
                        $t = array($t);
1268
                    }
1309
                    }
-
 
1310
 
1269
                    $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1311
                    $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1270
                }
1312
                }
-
 
1313
 
1271
                if (isset($pdeps['required']['package'])) {
1314
                if (isset($pdeps['required']['package'])) {
1272
                    $t = $pdeps['required']['package'];
1315
                    $t = $pdeps['required']['package'];
1273
                    if (!isset($t[0])) {
1316
                    if (!isset($t[0])) {
1274
                        $t = array($t);
1317
                        $t = array($t);
1275
                    }
1318
                    }
-
 
1319
 
1276
                    $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1320
                    $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1277
                }
1321
                }
-
 
1322
 
1278
                if (isset($pdeps['group'])) {
1323
                if (isset($pdeps['group'])) {
1279
                    if (!isset($pdeps['group'][0])) {
1324
                    if (!isset($pdeps['group'][0])) {
1280
                        $pdeps['group'] = array($pdeps['group']);
1325
                        $pdeps['group'] = array($pdeps['group']);
1281
                    }
1326
                    }
-
 
1327
 
1282
                    foreach ($pdeps['group'] as $group) {
1328
                    foreach ($pdeps['group'] as $group) {
1283
                        if (isset($group['package'])) {
1329
                        if (isset($group['package'])) {
1284
                            $t = $group['package'];
1330
                            $t = $group['package'];
1285
                            if (!isset($t[0])) {
1331
                            if (!isset($t[0])) {
1286
                                $t = array($t);
1332
                                $t = array($t);
1287
                            }
1333
                            }
-
 
1334
 
1288
                            $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1335
                            $this->_setupGraph($t, $reg, $deplinks, $nodes, $package);
1289
                        }
1336
                        }
1290
                    }
1337
                    }
1291
                }
1338
                }
1292
            }
1339
            }
1293
        }
1340
        }
-
 
1341
 
1294
        $this->_detectDepCycle($deplinks);
1342
        $this->_detectDepCycle($deplinks);
1295
        foreach ($deplinks as $dependent => $parents) {
1343
        foreach ($deplinks as $dependent => $parents) {
1296
            foreach ($parents as $parent => $unused) {
1344
            foreach ($parents as $parent => $unused) {
1297
                $nodes[$dependent]->connectTo($nodes[$parent]);
1345
                $nodes[$dependent]->connectTo($nodes[$parent]);
1298
            }
1346
            }
1299
        }
1347
        }
-
 
1348
 
1300
        $installOrder = Structures_Graph_Manipulator_TopologicalSorter::sort($depgraph);
1349
        $installOrder = Structures_Graph_Manipulator_TopologicalSorter::sort($depgraph);
1301
        $ret = array();
1350
        $ret = array();
1302
        for ($i = 0; $i < count($installOrder); $i++) {
1351
        for ($i = 0, $count = count($installOrder); $i < $count; $i++) {
1303
            foreach ($installOrder[$i] as $index => $sortedpackage) {
1352
            foreach ($installOrder[$i] as $index => $sortedpackage) {
1304
                $data = &$installOrder[$i][$index]->getData();
1353
                $data = &$installOrder[$i][$index]->getData();
1305
                $ret[] = &$nodes[$reg->parsedPackageNameToString(
1354
                $ret[] = &$nodes[$reg->parsedPackageNameToString(
1306
                          array(
1355
                          array(
1307
                              'channel' => $data->getChannel(),
1356
                              'channel' => $data->getChannel(),
1308
                              'package' => strtolower($data->getPackage()),
1357
                              'package' => strtolower($data->getPackage()),
1309
                          ))]->getData();
1358
                          ))]->getData();
1310
            }
1359
            }
1311
        }
1360
        }
-
 
1361
 
1312
        $packages = $ret;
1362
        $packages = $ret;
1313
        return;
1363
        return;
1314
    }
1364
    }
Line 1315... Line 1365...
1315
 
1365
 
Line 1331... Line 1381...
1331
                        $keepgoing = true;
1381
                        $keepgoing = true;
1332
                        unset($deplinks[$dep][$parent]);
1382
                        unset($deplinks[$dep][$parent]);
1333
                        if (count($deplinks[$dep]) == 0) {
1383
                        if (count($deplinks[$dep]) == 0) {
1334
                            unset($deplinks[$dep]);
1384
                            unset($deplinks[$dep]);
1335
                        }
1385
                        }
-
 
1386
 
1336
                        continue 3;
1387
                        continue 3;
1337
                    }
1388
                    }
1338
                }
1389
                }
1339
            }
1390
            }
1340
        } while ($keepgoing);
1391
        } while ($keepgoing);
Line 1345... Line 1396...
1345
        static $visited = array();
1396
        static $visited = array();
1346
        if ($test === null) {
1397
        if ($test === null) {
1347
            $visited = array();
1398
            $visited = array();
1348
            return;
1399
            return;
1349
        }
1400
        }
-
 
1401
 
1350
        // this happens when a parent has a dep cycle on another dependency
1402
        // this happens when a parent has a dep cycle on another dependency
1351
        // but the child is not part of the cycle
1403
        // but the child is not part of the cycle
1352
        if (isset($visited[$dep])) {
1404
        if (isset($visited[$dep])) {
1353
            return false;
1405
            return false;
1354
        }
1406
        }
-
 
1407
 
1355
        $visited[$dep] = 1;
1408
        $visited[$dep] = 1;
1356
        if ($test == $dep) {
1409
        if ($test == $dep) {
1357
            return true;
1410
            return true;
1358
        }
1411
        }
-
 
1412
 
1359
        if (isset($deplinks[$dep])) {
1413
        if (isset($deplinks[$dep])) {
1360
            if (in_array($test, array_keys($deplinks[$dep]), true)) {
1414
            if (in_array($test, array_keys($deplinks[$dep]), true)) {
1361
                return true;
1415
                return true;
1362
            }
1416
            }
-
 
1417
 
1363
            foreach ($deplinks[$dep] as $parent => $unused) {
1418
            foreach ($deplinks[$dep] as $parent => $unused) {
1364
                if ($this->_testCycle($test, $deplinks, $parent)) {
1419
                if ($this->_testCycle($test, $deplinks, $parent)) {
1365
                    return true;
1420
                    return true;
1366
                }
1421
                }
1367
            }
1422
            }
1368
        }
1423
        }
-
 
1424
 
1369
        return false;
1425
        return false;
1370
    }
1426
    }
Line 1371... Line 1427...
1371
 
1427
 
1372
    /**
1428
    /**
Line 1380... Line 1436...
1380
     * @access private
1436
     * @access private
1381
     */
1437
     */
1382
    function _setupGraph($t, $reg, &$deplinks, &$nodes, $package)
1438
    function _setupGraph($t, $reg, &$deplinks, &$nodes, $package)
1383
    {
1439
    {
1384
        foreach ($t as $dep) {
1440
        foreach ($t as $dep) {
1385
            $depchannel = !isset($dep['channel']) ?
1441
            $depchannel = !isset($dep['channel']) ? '__uri': $dep['channel'];
1386
                '__uri': $dep['channel'];
-
 
1387
            $dname = $reg->parsedPackageNameToString(
1442
            $dname = $reg->parsedPackageNameToString(
1388
                  array(
1443
                  array(
1389
                      'channel' => $depchannel,
1444
                      'channel' => $depchannel,
1390
                      'package' => strtolower($dep['name']),
1445
                      'package' => strtolower($dep['name']),
1391
                  ));
1446
                  ));
-
 
1447
 
1392
            if (isset($nodes[$dname]))
1448
            if (isset($nodes[$dname])) {
1393
            {
-
 
1394
                if (!isset($deplinks[$dname])) {
1449
                if (!isset($deplinks[$dname])) {
1395
                    $deplinks[$dname] = array();
1450
                    $deplinks[$dname] = array();
1396
                }
1451
                }
1397
                $deplinks[$dname][$package] = 1;
1452
                $deplinks[$dname][$package] = 1;
1398
            }
1453
            }
1399
        }
1454
        }
1400
    }
1455
    }
Line 1401... Line 1456...
1401
 
1456
 
1402
    function _dependsOn($a, $b)
1457
    function _dependsOn($a, $b)
1403
    {
1458
    {
1404
        return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()),
-
 
1405
            $b);
1459
        return $this->_checkDepTree(strtolower($a->getChannel()), strtolower($a->getPackage()), $b);
Line 1406... Line 1460...
1406
    }
1460
    }
1407
 
1461
 
1408
    function _checkDepTree($channel, $package, $b, $checked = array())
1462
    function _checkDepTree($channel, $package, $b, $checked = array())
1409
    {
1463
    {
1410
        $checked[$channel][$package] = true;
1464
        $checked[$channel][$package] = true;
1411
        if (!isset($this->_depTree[$channel][$package])) {
1465
        if (!isset($this->_depTree[$channel][$package])) {
-
 
1466
            return false;
1412
            return false;
1467
        }
1413
        }
1468
 
1414
        if (isset($this->_depTree[$channel][$package][strtolower($b->getChannel())]
1469
        if (isset($this->_depTree[$channel][$package][strtolower($b->getChannel())]
1415
              [strtolower($b->getPackage())])) {
1470
              [strtolower($b->getPackage())])) {
-
 
1471
            return true;
1416
            return true;
1472
        }
1417
        }
1473
 
1418
        foreach ($this->_depTree[$channel][$package] as $ch => $packages) {
1474
        foreach ($this->_depTree[$channel][$package] as $ch => $packages) {
1419
            foreach ($packages as $pa => $true) {
1475
            foreach ($packages as $pa => $true) {
1420
                if ($this->_checkDepTree($ch, $pa, $b, $checked)) {
1476
                if ($this->_checkDepTree($ch, $pa, $b, $checked)) {
1421
                    return true;
1477
                    return true;
1422
                }
1478
                }
-
 
1479
            }
1423
            }
1480
        }
1424
        }
1481
 
Line 1425... Line 1482...
1425
        return false;
1482
        return false;
1426
    }
1483
    }
Line 1482... Line 1539...
1482
     * @param mixed   $callback  function/method to call for status
1539
     * @param mixed   $callback  function/method to call for status
1483
     *                           updates
1540
     *                           updates
1484
     * @param false|string|array $lastmodified header values to check against for caching
1541
     * @param false|string|array $lastmodified header values to check against for caching
1485
     *                           use false to return the header values from this download
1542
     *                           use false to return the header values from this download
1486
     * @param false|array $accept Accept headers to send
1543
     * @param false|array $accept Accept headers to send
-
 
1544
     * @param false|string $channel Channel to use for retrieving authentication
1487
     * @return string|array  Returns the full path of the downloaded file or a PEAR
1545
     * @return mixed  Returns the full path of the downloaded file or a PEAR
1488
     *                       error on failure.  If the error is caused by
1546
     *                error on failure.  If the error is caused by
1489
     *                       socket-related errors, the error object will
1547
     *                socket-related errors, the error object will
1490
     *                       have the fsockopen error code available through
1548
     *                have the fsockopen error code available through
1491
     *                       getCode().  If caching is requested, then return the header
1549
     *                getCode().  If caching is requested, then return the header
1492
     *                       values.
1550
     *                values.
-
 
1551
     *                If $lastmodified was given and the there are no changes,
-
 
1552
     *                boolean false is returned.
1493
     *
1553
     *
1494
     * @access public
1554
     * @access public
1495
     */
1555
     */
-
 
1556
    public static function _downloadHttp(
1496
    function downloadHttp($url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
1557
        $object, $url, &$ui, $save_dir = '.', $callback = null, $lastmodified = null,
1497
                          $accept = false)
1558
        $accept = false, $channel = false
1498
    {
1559
    ) {
1499
        static $redirect = 0;
1560
        static $redirect = 0;
1500
        // allways reset , so we are clean case of error
1561
        // always reset , so we are clean case of error
1501
        $wasredirect = $redirect;
1562
        $wasredirect = $redirect;
1502
        $redirect = 0;
1563
        $redirect = 0;
1503
        if ($callback) {
1564
        if ($callback) {
1504
            call_user_func($callback, 'setup', array(&$ui));
1565
            call_user_func($callback, 'setup', array(&$ui));
1505
        }
1566
        }
-
 
1567
 
1506
        $info = parse_url($url);
1568
        $info = parse_url($url);
1507
        if (!isset($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) {
1569
        if (!isset($info['scheme']) || !in_array($info['scheme'], array('http', 'https'))) {
1508
            return PEAR::raiseError('Cannot download non-http URL "' . $url . '"');
1570
            return PEAR::raiseError('Cannot download non-http URL "' . $url . '"');
1509
        }
1571
        }
-
 
1572
 
1510
        if (!isset($info['host'])) {
1573
        if (!isset($info['host'])) {
1511
            return PEAR::raiseError('Cannot download from non-URL "' . $url . '"');
1574
            return PEAR::raiseError('Cannot download from non-URL "' . $url . '"');
1512
        } else {
-
 
1513
            $host = isset($info['host']) ? $info['host'] : null;
-
 
1514
            $port = isset($info['port']) ? $info['port'] : null;
-
 
1515
            $path = isset($info['path']) ? $info['path'] : null;
-
 
1516
        }
1575
        }
-
 
1576
 
-
 
1577
        $host = isset($info['host']) ? $info['host'] : null;
-
 
1578
        $port = isset($info['port']) ? $info['port'] : null;
-
 
1579
        $path = isset($info['path']) ? $info['path'] : null;
-
 
1580
 
1517
        if (isset($this)) {
1581
        if ($object !== null) {
1518
            $config = &$this->config;
1582
            $config = $object->config;
1519
        } else {
1583
        } else {
1520
            $config = &PEAR_Config::singleton();
1584
            $config = &PEAR_Config::singleton();
1521
        }
1585
        }
-
 
1586
 
1522
        $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
1587
        $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
1523
        if ($config->get('http_proxy') && 
1588
        if ($config->get('http_proxy') &&
1524
              $proxy = parse_url($config->get('http_proxy'))) {
1589
              $proxy = parse_url($config->get('http_proxy'))) {
1525
            $proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
1590
            $proxy_host = isset($proxy['host']) ? $proxy['host'] : null;
1526
            if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
1591
            if (isset($proxy['scheme']) && $proxy['scheme'] == 'https') {
1527
                $proxy_host = 'ssl://' . $proxy_host;
1592
                $proxy_host = 'ssl://' . $proxy_host;
1528
            }
1593
            }
Line 1532... Line 1597...
1532
 
1597
 
1533
            if ($callback) {
1598
            if ($callback) {
1534
                call_user_func($callback, 'message', "Using HTTP proxy $host:$port");
1599
                call_user_func($callback, 'message', "Using HTTP proxy $host:$port");
1535
            }
1600
            }
-
 
1601
        }
1536
        }
1602
 
1537
        if (empty($port)) {
1603
        if (empty($port)) {
1538
            if (isset($info['scheme']) && $info['scheme'] == 'https') {
-
 
1539
                $port = 443;
-
 
1540
            } else {
-
 
1541
                $port = 80;
-
 
1542
            }
1604
            $port = (isset($info['scheme']) && $info['scheme'] == 'https') ? 443 : 80;
-
 
1605
        }
-
 
1606
 
-
 
1607
        $scheme = (isset($info['scheme']) && $info['scheme'] == 'https') ? 'https' : 'http';
1543
        }
1608
 
1544
        if ($proxy_host != '') {
1609
        if ($proxy_host != '') {
1545
            $fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr);
1610
            $fp = @fsockopen($proxy_host, $proxy_port, $errno, $errstr);
1546
            if (!$fp) {
1611
            if (!$fp) {
1547
                if ($callback) {
1612
                if ($callback) {
1548
                    call_user_func($callback, 'connfailed', array($proxy_host, $proxy_port,
1613
                    call_user_func($callback, 'connfailed', array($proxy_host, $proxy_port,
1549
                                                                  $errno, $errstr));
1614
                                                                  $errno, $errstr));
1550
                }
1615
                }
1551
                return PEAR::raiseError("Connection to `$proxy_host:$proxy_port' failed: $errstr", $errno);
1616
                return PEAR::raiseError("Connection to `$proxy_host:$proxy_port' failed: $errstr", $errno);
-
 
1617
            }
1552
            }
1618
 
1553
            if ($lastmodified === false || $lastmodified) {
1619
            if ($lastmodified === false || $lastmodified) {
-
 
1620
                $request  = "GET $url HTTP/1.1\r\n";
1554
                $request = "GET $url HTTP/1.1\r\n";
1621
                $request .= "Host: $host\r\n";
1555
            } else {
1622
            } else {
-
 
1623
                $request  = "GET $url HTTP/1.0\r\n";
1556
                $request = "GET $url HTTP/1.0\r\n";
1624
                $request .= "Host: $host\r\n";
1557
            }
1625
            }
-
 
1626
        } else {
1558
        } else {
1627
            $network_host = $host;
1559
            if (isset($info['scheme']) && $info['scheme'] == 'https') {
1628
            if (isset($info['scheme']) && $info['scheme'] == 'https') {
1560
                $host = 'ssl://' . $host;
1629
                $network_host = 'ssl://' . $host;
-
 
1630
            }
1561
            }
1631
 
1562
            $fp = @fsockopen($host, $port, $errno, $errstr);
1632
            $fp = @fsockopen($network_host, $port, $errno, $errstr);
1563
            if (!$fp) {
1633
            if (!$fp) {
1564
                if ($callback) {
1634
                if ($callback) {
1565
                    call_user_func($callback, 'connfailed', array($host, $port,
1635
                    call_user_func($callback, 'connfailed', array($host, $port,
1566
                                                                  $errno, $errstr));
1636
                                                                  $errno, $errstr));
1567
                }
1637
                }
1568
                return PEAR::raiseError("Connection to `$host:$port' failed: $errstr", $errno);
1638
                return PEAR::raiseError("Connection to `$host:$port' failed: $errstr", $errno);
-
 
1639
            }
1569
            }
1640
 
1570
            if ($lastmodified === false || $lastmodified) {
1641
            if ($lastmodified === false || $lastmodified) {
1571
                $request = "GET $path HTTP/1.1\r\n";
1642
                $request = "GET $path HTTP/1.1\r\n";
1572
                $request .= "Host: $host:$port\r\n";
1643
                $request .= "Host: $host\r\n";
1573
            } else {
1644
            } else {
1574
                $request = "GET $path HTTP/1.0\r\n";
1645
                $request = "GET $path HTTP/1.0\r\n";
1575
                $request .= "Host: $host\r\n";
1646
                $request .= "Host: $host\r\n";
1576
            }
1647
            }
-
 
1648
        }
1577
        }
1649
 
1578
        $ifmodifiedsince = '';
1650
        $ifmodifiedsince = '';
1579
        if (is_array($lastmodified)) {
1651
        if (is_array($lastmodified)) {
1580
            if (isset($lastmodified['Last-Modified'])) {
1652
            if (isset($lastmodified['Last-Modified'])) {
1581
                $ifmodifiedsince = 'If-Modified-Since: ' . $lastmodified['Last-Modified'] . "\r\n";
1653
                $ifmodifiedsince = 'If-Modified-Since: ' . $lastmodified['Last-Modified'] . "\r\n";
-
 
1654
            }
1582
            }
1655
 
1583
            if (isset($lastmodified['ETag'])) {
1656
            if (isset($lastmodified['ETag'])) {
1584
                $ifmodifiedsince .= "If-None-Match: $lastmodified[ETag]\r\n";
1657
                $ifmodifiedsince .= "If-None-Match: $lastmodified[ETag]\r\n";
1585
            }
1658
            }
1586
        } else {
1659
        } else {
1587
            $ifmodifiedsince = ($lastmodified ? "If-Modified-Since: $lastmodified\r\n" : '');
1660
            $ifmodifiedsince = ($lastmodified ? "If-Modified-Since: $lastmodified\r\n" : '');
-
 
1661
        }
1588
        }
1662
 
1589
        $request .= $ifmodifiedsince . "User-Agent: PEAR/1.5.1/PHP/" .
1663
        $request .= $ifmodifiedsince .
-
 
1664
            "User-Agent: PEAR/1.10.1/PHP/" . PHP_VERSION . "\r\n";
1590
            PHP_VERSION . "\r\n";
1665
 
1591
        if (isset($this)) { // only pass in authentication for non-static calls
1666
        if ($object !== null) { // only pass in authentication for non-static calls
1592
            $username = $config->get('username');
1667
            $username = $config->get('username', null, $channel);
1593
            $password = $config->get('password');
1668
            $password = $config->get('password', null, $channel);
1594
            if ($username && $password) {
1669
            if ($username && $password) {
1595
                $tmp = base64_encode("$username:$password");
1670
                $tmp = base64_encode("$username:$password");
1596
                $request .= "Authorization: Basic $tmp\r\n";
1671
                $request .= "Authorization: Basic $tmp\r\n";
1597
            }
1672
            }
-
 
1673
        }
1598
        }
1674
 
1599
        if ($proxy_host != '' && $proxy_user != '') {
1675
        if ($proxy_host != '' && $proxy_user != '') {
1600
            $request .= 'Proxy-Authorization: Basic ' .
1676
            $request .= 'Proxy-Authorization: Basic ' .
1601
                base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
1677
                base64_encode($proxy_user . ':' . $proxy_pass) . "\r\n";
-
 
1678
        }
1602
        }
1679
 
1603
        if ($accept) {
1680
        if ($accept) {
1604
            $request .= 'Accept: ' . implode(', ', $accept) . "\r\n";
1681
            $request .= 'Accept: ' . implode(', ', $accept) . "\r\n";
-
 
1682
        }
1605
        }
1683
 
1606
        $request .= "Connection: close\r\n";
1684
        $request .= "Connection: close\r\n";
1607
        $request .= "\r\n";
1685
        $request .= "\r\n";
1608
        fwrite($fp, $request);
1686
        fwrite($fp, $request);
1609
        $headers = array();
1687
        $headers = array();
1610
        $reply = 0;
1688
        $reply = 0;
1611
        while (trim($line = fgets($fp, 1024))) {
1689
        while (trim($line = fgets($fp, 1024))) {
1612
            if (preg_match('/^([^:]+):\s+(.*)\s*$/', $line, $matches)) {
1690
            if (preg_match('/^([^:]+):\s+(.*)\s*\\z/', $line, $matches)) {
1613
                $headers[strtolower($matches[1])] = trim($matches[2]);
1691
                $headers[strtolower($matches[1])] = trim($matches[2]);
1614
            } elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
1692
            } elseif (preg_match('|^HTTP/1.[01] ([0-9]{3}) |', $line, $matches)) {
1615
                $reply = (int) $matches[1];
1693
                $reply = (int)$matches[1];
1616
                if ($reply == 304 && ($lastmodified || ($lastmodified === false))) {
1694
                if ($reply == 304 && ($lastmodified || ($lastmodified === false))) {
1617
                    return false;
1695
                    return false;
-
 
1696
                }
1618
                }
1697
 
1619
                if (! in_array($reply, array(200, 301, 302, 303, 305, 307))) {
1698
                if (!in_array($reply, array(200, 301, 302, 303, 305, 307))) {
1620
                    return PEAR::raiseError("File http://$host:$port$path not valid (received: $line)");
1699
                    return PEAR::raiseError("File $scheme://$host:$port$path not valid (received: $line)");
1621
                }
1700
                }
1622
            }
1701
            }
-
 
1702
        }
1623
        }
1703
 
1624
        if ($reply != 200) {
1704
        if ($reply != 200) {
1625
            if (isset($headers['location'])) {
-
 
1626
                if ($wasredirect < 5) {
-
 
1627
                    $redirect = $wasredirect + 1;
-
 
1628
                    return $this->downloadHttp($headers['location'],
-
 
1629
                            $ui, $save_dir, $callback, $lastmodified, $accept);
-
 
1630
                } else {
-
 
1631
                    return PEAR::raiseError("File http://$host:$port$path not valid (redirection looped more than 5 times)");
-
 
1632
                }
-
 
1633
            } else {
1705
            if (!isset($headers['location'])) {
1634
                return PEAR::raiseError("File http://$host:$port$path not valid (redirected but no location)");
1706
                return PEAR::raiseError("File $scheme://$host:$port$path not valid (redirected but no location)");
-
 
1707
            }
-
 
1708
 
-
 
1709
            if ($wasredirect > 4) {
-
 
1710
                return PEAR::raiseError("File $scheme://$host:$port$path not valid (redirection looped more than 5 times)");
-
 
1711
            }
-
 
1712
 
-
 
1713
            $redirect = $wasredirect + 1;
-
 
1714
            return static::_downloadHttp($object, $headers['location'],
1635
            }
1715
                    $ui, $save_dir, $callback, $lastmodified, $accept);
-
 
1716
        }
1636
        }
1717
 
1637
        if (isset($headers['content-disposition']) &&
1718
        if (isset($headers['content-disposition']) &&
1638
            preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|$)/', $headers['content-disposition'], $matches)) {
1719
            preg_match('/\sfilename=\"([^;]*\S)\"\s*(;|\\z)/', $headers['content-disposition'], $matches)) {
1639
            $save_as = basename($matches[1]);
1720
            $save_as = basename($matches[1]);
1640
        } else {
1721
        } else {
1641
            $save_as = basename($url);
1722
            $save_as = basename($url);
-
 
1723
        }
1642
        }
1724
 
1643
        if ($callback) {
1725
        if ($callback) {
1644
            $tmp = call_user_func($callback, 'saveas', $save_as);
1726
            $tmp = call_user_func($callback, 'saveas', $save_as);
1645
            if ($tmp) {
1727
            if ($tmp) {
1646
                $save_as = $tmp;
1728
                $save_as = $tmp;
1647
            }
1729
            }
-
 
1730
        }
1648
        }
1731
 
-
 
1732
        $dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as;
-
 
1733
        if (is_link($dest_file)) {
-
 
1734
            return PEAR::raiseError('SECURITY ERROR: Will not write to ' . $dest_file . ' as it is symlinked to ' . readlink($dest_file) . ' - Possible symlink attack');
-
 
1735
        }
1649
        $dest_file = $save_dir . DIRECTORY_SEPARATOR . $save_as;
1736
 
1650
        if (!$wp = @fopen($dest_file, 'wb')) {
1737
        if (!$wp = @fopen($dest_file, 'wb')) {
1651
            fclose($fp);
1738
            fclose($fp);
1652
            if ($callback) {
1739
            if ($callback) {
1653
                call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
1740
                call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
1654
            }
1741
            }
1655
            return PEAR::raiseError("could not open $dest_file for writing");
1742
            return PEAR::raiseError("could not open $dest_file for writing");
1656
        }
-
 
-
 
1743
        }
1657
        if (isset($headers['content-length'])) {
1744
 
1658
            $length = $headers['content-length'];
-
 
1659
        } else {
-
 
1660
            $length = -1;
1745
        $length = isset($headers['content-length']) ? $headers['content-length'] : -1;
1661
        }
1746
 
1662
        $bytes = 0;
1747
        $bytes = 0;
1663
        if ($callback) {
1748
        if ($callback) {
1664
            call_user_func($callback, 'start', array(basename($dest_file), $length));
1749
            call_user_func($callback, 'start', array(basename($dest_file), $length));
-
 
1750
        }
1665
        }
1751
 
1666
        while ($data = fread($fp, 1024)) {
1752
        while ($data = fread($fp, 1024)) {
1667
            $bytes += strlen($data);
1753
            $bytes += strlen($data);
1668
            if ($callback) {
1754
            if ($callback) {
1669
                call_user_func($callback, 'bytesread', $bytes);
1755
                call_user_func($callback, 'bytesread', $bytes);
Line 1674... Line 1760...
1674
                    call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
1760
                    call_user_func($callback, 'writefailed', array($dest_file, $php_errormsg));
1675
                }
1761
                }
1676
                return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
1762
                return PEAR::raiseError("$dest_file: write failed ($php_errormsg)");
1677
            }
1763
            }
1678
        }
1764
        }
-
 
1765
 
1679
        fclose($fp);
1766
        fclose($fp);
1680
        fclose($wp);
1767
        fclose($wp);
1681
        if ($callback) {
1768
        if ($callback) {
1682
            call_user_func($callback, 'done', $bytes);
1769
            call_user_func($callback, 'done', $bytes);
1683
        }
1770
        }
-
 
1771
 
1684
        if ($lastmodified === false || $lastmodified) {
1772
        if ($lastmodified === false || $lastmodified) {
1685
            if (isset($headers['etag'])) {
1773
            if (isset($headers['etag'])) {
1686
                $lastmodified = array('ETag' => $headers['etag']);
1774
                $lastmodified = array('ETag' => $headers['etag']);
1687
            }
1775
            }
-
 
1776
 
1688
            if (isset($headers['last-modified'])) {
1777
            if (isset($headers['last-modified'])) {
1689
                if (is_array($lastmodified)) {
1778
                if (is_array($lastmodified)) {
1690
                    $lastmodified['Last-Modified'] = $headers['last-modified'];
1779
                    $lastmodified['Last-Modified'] = $headers['last-modified'];
1691
                } else {
1780
                } else {
1692
                    $lastmodified = $headers['last-modified'];
1781
                    $lastmodified = $headers['last-modified'];
Line 1695... Line 1784...
1695
            return array($dest_file, $lastmodified, $headers);
1784
            return array($dest_file, $lastmodified, $headers);
1696
        }
1785
        }
1697
        return $dest_file;
1786
        return $dest_file;
1698
    }
1787
    }
1699
}
1788
}
1700
// }}}
-
 
1701
 
-
 
1702
?>
-