diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-05-16 07:13:45 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-05-16 07:13:45 +0000 |
commit | cebb21facc2e2219f1d498def8ee19bbb4b72f7e (patch) | |
tree | 17c779f616c63ab8bc552ea2e4ce8a66a6f7e460 | |
parent | 8046e377bcb7a83b8966e7a2809b905071f7f08a (diff) | |
download | ampache-cebb21facc2e2219f1d498def8ee19bbb4b72f7e.tar.gz ampache-cebb21facc2e2219f1d498def8ee19bbb4b72f7e.tar.bz2 ampache-cebb21facc2e2219f1d498def8ee19bbb4b72f7e.zip |
fixed mpd timeout issues and a stupid little theme config load issue
-rwxr-xr-x | docs/CHANGELOG | 5 | ||||
-rw-r--r-- | lib/general.lib.php | 2 | ||||
-rw-r--r-- | lib/localplay.lib.php | 1 | ||||
-rw-r--r-- | lib/themes.php | 4 | ||||
-rw-r--r-- | modules/localplay/mpd.controller.php | 2 | ||||
-rw-r--r-- | modules/mpd/mpd.class.php | 82 |
6 files changed, 61 insertions, 35 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 84bb3868..480a7606 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,11 @@ -------------------------------------------------------------------------- v.3.3.2-Beta3 + - Fixed error on /login.php when theme isn't set which caused + a fopen failure to show up in the logs + - Improved MPD class to use PHP 4.3+ socket timeout settings so + that if your MPD server goes down while in MPD mode it + doesn't hard-lock ampache. - Supressed deprecated var warnings in PHP5 - Fixed link to playlist import - Fixed playlist add on every catalog add (I'm not kidding this diff --git a/lib/general.lib.php b/lib/general.lib.php index cd7757c4..1ad4a908 100644 --- a/lib/general.lib.php +++ b/lib/general.lib.php @@ -81,7 +81,7 @@ function int2ip($i) { @param $template Name of Template */ function show_template($template) { -global $myMpd, $user; + global $user; /* Check for a 'Theme' template */ if (is_readable(conf('prefix') . conf('theme_path') . "/templates/$template".".inc")) { diff --git a/lib/localplay.lib.php b/lib/localplay.lib.php index 2aa42772..523a5548 100644 --- a/lib/localplay.lib.php +++ b/lib/localplay.lib.php @@ -178,7 +178,6 @@ function get_localplay_controllers() { function init_localplay($reload=0) { static $localplay; - if ($GLOBALS['user']->prefs['localplay_level'] == '0') { return false; } if ($GLOBALS['user']->prefs['localplay_level'] == '1' AND !is_object($localplay)) { diff --git a/lib/themes.php b/lib/themes.php index 3c89a00a..5b1101b2 100644 --- a/lib/themes.php +++ b/lib/themes.php @@ -32,7 +32,7 @@ function get_themes() { $handle = @opendir(conf('prefix') . "/themes"); if (!is_resource($handle)) { - if (conf('debug')) { log_event($_SESSION['userdata']['username'],'theme',"Error unable to open Themes Directory"); } + debug_event('theme',"Error unable to open Themes Directory",'2'); } $results = array(); @@ -62,6 +62,8 @@ function get_themes() { */ function get_theme($name) { + if (strlen($name) < 1) { return false; } + $config_file = conf('prefix') . "/themes/" . $name . "/theme.cfg.php"; $results = read_config($config_file); $results['path'] = $name; diff --git a/modules/localplay/mpd.controller.php b/modules/localplay/mpd.controller.php index cd2f686c..ac595b26 100644 --- a/modules/localplay/mpd.controller.php +++ b/modules/localplay/mpd.controller.php @@ -330,7 +330,7 @@ class AmpacheMpd { * is stored in this class */ function connect() { - + $this->_mpd = new mpd(conf('localplay_mpd_hostname'),conf('localplay_mpd_port')); if ($this->_mpd->connected) { return true; } diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index 2556f01b..2fe297f6 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -120,7 +120,7 @@ class mpd { $this->host = $srv;
$this->port = $port;
$this->password = $pwd;
-
+ $resp = $this->Connect();
if ( is_null($resp) ) {
$this->errStr = "Could not connect";
@@ -142,36 +142,56 @@ class mpd { $this->connected = FALSE;
$this->errStr = "Password required to access server";
return;
- }
- }
- }
- }
-
- /* Connect()
- *
- * Connects to the MPD server.
- *
- * NOTE: This is called automatically upon object instantiation; you should not need to call this directly.
- */
- 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,10);
- if (!$this->mpd_sock) {
- $this->errStr = "Socket Error: $errStr ($errNo)";
- return NULL;
- } else {
- while(!feof($this->mpd_sock)) {
- $response = fgets($this->mpd_sock,1024);
- if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
- $this->connected = TRUE;
- return $response;
- break;
- }
- if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
- $this->errStr = "Server responded with: $response";
- return NULL;
- }
- }
+ } + } + } + } + + /* Connect() + * + * Connects to the MPD server. + * + * NOTE: This is called automatically upon object instantiation; you should not need to call this directly. + */ + 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 + */ + if (function_exists('stream_set_timeout')) { + + /* Set the timeout on the connection */ + stream_set_timeout($this->mpd_sock,2); + + /* We want blocking, cause otherwise it doesn't + * timeout, and feof just keeps on spinning + */ + 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; + } else { + while(!feof($this->mpd_sock) && !$status['timed_out']) { + $response = fgets($this->mpd_sock,1024); + if (function_exists('socket_get_status')) { + $status = socket_get_status($this->mpd_sock); + } + if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) { + $this->connected = TRUE; + return $response; + break; + } + if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) { + $this->errStr = "Server responded with: $response"; + return NULL; + } + + + } // end while // Generic response
$this->errStr = "Connection not available";
return NULL;
|