add proper mpd password handling
This commit is contained in:
@@ -52,11 +52,10 @@ bool MPDConnection::Connect()
|
|||||||
{
|
{
|
||||||
itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT);
|
itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT);
|
||||||
isConnected = 1;
|
isConnected = 1;
|
||||||
if (!CheckForErrors())
|
|
||||||
return isConnected;
|
|
||||||
SendPassword();
|
|
||||||
CheckForErrors();
|
CheckForErrors();
|
||||||
return isConnected;
|
if (!MPD_PASSWORD.empty())
|
||||||
|
SendPassword();
|
||||||
|
return !CheckForErrors();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
@@ -93,7 +92,6 @@ void MPDConnection::SendPassword()
|
|||||||
{
|
{
|
||||||
mpd_sendPasswordCommand(itsConnection, MPD_PASSWORD.c_str());
|
mpd_sendPasswordCommand(itsConnection, MPD_PASSWORD.c_str());
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
CheckForErrors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::SetStatusUpdater(StatusUpdater updater, void *data)
|
void MPDConnection::SetStatusUpdater(StatusUpdater updater, void *data)
|
||||||
@@ -121,9 +119,7 @@ void MPDConnection::UpdateStatus()
|
|||||||
if (!itsMaxPlaylistLength)
|
if (!itsMaxPlaylistLength)
|
||||||
itsMaxPlaylistLength = GetPlaylistLength();
|
itsMaxPlaylistLength = GetPlaylistLength();
|
||||||
|
|
||||||
CheckForErrors();
|
if (CheckForErrors())
|
||||||
|
|
||||||
if (!isConnected)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MPDStatusChanges changes;
|
MPDStatusChanges changes;
|
||||||
@@ -632,7 +628,7 @@ int MPDConnection::CheckForErrors()
|
|||||||
isConnected = 0; // the rest of errors are fatal to connection
|
isConnected = 0; // the rest of errors are fatal to connection
|
||||||
if (itsErrorHandler)
|
if (itsErrorHandler)
|
||||||
itsErrorHandler(this, itsConnection->error, itsConnection->errorStr, itsErrorHandlerUserdata);
|
itsErrorHandler(this, itsConnection->error, itsConnection->errorStr, itsErrorHandlerUserdata);
|
||||||
errid = itsConnection->errorCode;
|
errid = itsConnection->error;
|
||||||
}
|
}
|
||||||
itsLastErrorMessage = itsConnection->errorStr;
|
itsLastErrorMessage = itsConnection->errorStr;
|
||||||
mpd_clearError(itsConnection);
|
mpd_clearError(itsConnection);
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class MPDConnection
|
|||||||
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
|
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
|
||||||
|
|
||||||
unsigned int GetMaxPlaylistLength() { return itsMaxPlaylistLength; }
|
unsigned int GetMaxPlaylistLength() { return itsMaxPlaylistLength; }
|
||||||
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : -1; }
|
int GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
|
||||||
void GetPlaylistChanges(long long, SongList &) const;
|
void GetPlaylistChanges(long long, SongList &) const;
|
||||||
|
|
||||||
string GetLastErrorMessage() const { return itsLastErrorMessage; }
|
string GetLastErrorMessage() const { return itsLastErrorMessage; }
|
||||||
|
|||||||
@@ -121,6 +121,15 @@ void TraceMpdStatus()
|
|||||||
|
|
||||||
void NcmpcppErrorCallback(MPDConnection *Mpd, int errorid, string msg, void *data)
|
void NcmpcppErrorCallback(MPDConnection *Mpd, int errorid, string msg, void *data)
|
||||||
{
|
{
|
||||||
|
if (errorid == MPD_ACK_ERROR_PERMISSION)
|
||||||
|
{
|
||||||
|
wFooter->WriteXY(0, Config.statusbar_visibility, "Password: ", 1);
|
||||||
|
string password = wFooter->GetString("");
|
||||||
|
Mpd->SetPassword(password);
|
||||||
|
Mpd->SendPassword();
|
||||||
|
Mpd->UpdateStatus();
|
||||||
|
}
|
||||||
|
else
|
||||||
ShowMessage(msg);
|
ShowMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user