From e98446d5701b9467bc64003b0f08c7c915db1e61 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Fri, 8 Sep 2006 04:20:13 +0000 Subject: fixed missing password pass issue with the mpd controller --- docs/CHANGELOG | 3 +++ modules/localplay/mpd.controller.php | 2 +- modules/mpd/mpd.class.php | 49 +++++++++++++++++++----------------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 544c738f..496fd1ec 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,9 @@ -------------------------------------------------------------------------- v.3.3.2 + - Fixed an issue with the MPD Controller not passing the password + to the MPD class causing flames to shoot out if your MPD + had a password set - Fixed issue with transcoding not changing the mime type or the filename, currently hardcodes to mp3 and audio/mpeg - Updated Spanish Translation (Thx Bgordon) diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index cd07e92e..3c99e63f 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -373,7 +373,7 @@ class AmpacheMpd { */ function connect() { - $this->_mpd = new mpd(conf('localplay_mpd_hostname'),conf('localplay_mpd_port')); + $this->_mpd = new mpd(conf('localplay_mpd_hostname'),conf('localplay_mpd_port'),conf('localplay_mpd_password')); if ($this->_mpd->connected) { return true; } diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index 2fe297f6..1191f39a 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -72,9 +72,9 @@ define("MPD_TBL_ALBUM","album"); class mpd { // TCP/Connection variables - var $host; - var $port; - var $password; + var $host; + var $port; + var $password; var $mpd_sock = NULL; var $connected = FALSE; @@ -119,20 +119,23 @@ class mpd { function mpd($srv,$port,$pwd = NULL) { $this->host = $srv; $this->port = $port; - $this->password = $pwd; + $this->password = $pwd; - $resp = $this->Connect(); - if ( is_null($resp) ) { - $this->errStr = "Could not connect"; - return; - } else { - list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n"); - if ( ! is_null($pwd) ) { - if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) { - $this->connected = FALSE; - return; // bad password or command - } - if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! + $resp = $this->Connect(); + if ( is_null($resp) ) { + $this->errStr = "Could not connect"; + return; + } + else { list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n"); + + if ( ! is_null($pwd) ) { + if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) { + $this->connected = FALSE; + $this->errStr = "Password supplied is incorrect or Invalid Command"; + return; // bad password or command + } + + if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! $this->connected = FALSE; $this->errStr = "Password supplied does not have read access"; return; @@ -156,6 +159,7 @@ class mpd { function Connect() { if ( $this->debugging ) echo "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n"; $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,3); + /* Vollmerize this bizatch, if we've got php4.3+ we should * have these functions and we need them */ @@ -170,7 +174,6 @@ class mpd { stream_set_blocking($this->mpd_sock,TRUE); $status = socket_get_status($this->mpd_sock); } - if (!$this->mpd_sock) { $this->errStr = "Socket Error: $errStr ($errNo)"; return NULL; @@ -192,12 +195,12 @@ class mpd { } // end while - // Generic response - $this->errStr = "Connection not available"; - return NULL; - } - } - + // Generic response + $this->errStr = "Connection not available"; + return NULL; + } + } + /* SendCommand() * * Sends a generic command to the MPD server. Several command constants are pre-defined for -- cgit