player_control: allocate getPlayerErrorStr() result
This lets us eliminate the static fixed-size buffer.
This commit is contained in:
parent
a5960c20cc
commit
128a5fa4a5
@ -454,6 +454,7 @@ handle_status(struct client *client,
|
|||||||
{
|
{
|
||||||
const char *state = NULL;
|
const char *state = NULL;
|
||||||
int updateJobId;
|
int updateJobId;
|
||||||
|
char *error;
|
||||||
int song;
|
int song;
|
||||||
|
|
||||||
switch (getPlayerState()) {
|
switch (getPlayerState()) {
|
||||||
@ -515,10 +516,12 @@ handle_status(struct client *client,
|
|||||||
updateJobId);
|
updateJobId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getPlayerError() != PLAYER_ERROR_NOERROR) {
|
error = getPlayerErrorStr();
|
||||||
|
if (error != NULL) {
|
||||||
client_printf(client,
|
client_printf(client,
|
||||||
COMMAND_STATUS_ERROR ": %s\n",
|
COMMAND_STATUS_ERROR ": %s\n",
|
||||||
getPlayerErrorStr());
|
error);
|
||||||
|
g_free(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
song = playlist_get_next_song(&g_playlist);
|
song = playlist_get_next_song(&g_playlist);
|
||||||
|
@ -167,46 +167,40 @@ pc_errored_song_uri(void)
|
|||||||
|
|
||||||
char *getPlayerErrorStr(void)
|
char *getPlayerErrorStr(void)
|
||||||
{
|
{
|
||||||
/* static OK here, only one user in main task */
|
char *error;
|
||||||
static char error[MPD_PATH_MAX + 64]; /* still too much */
|
|
||||||
static const size_t errorlen = sizeof(error);
|
|
||||||
char *uri;
|
char *uri;
|
||||||
|
|
||||||
*error = '\0'; /* likely */
|
|
||||||
|
|
||||||
switch (pc.error) {
|
switch (pc.error) {
|
||||||
case PLAYER_ERROR_NOERROR:
|
case PLAYER_ERROR_NOERROR:
|
||||||
break;
|
return NULL;
|
||||||
|
|
||||||
case PLAYER_ERROR_FILENOTFOUND:
|
case PLAYER_ERROR_FILENOTFOUND:
|
||||||
uri = pc_errored_song_uri();
|
uri = pc_errored_song_uri();
|
||||||
snprintf(error, errorlen,
|
error = g_strdup_printf("file \"%s\" does not exist or is inaccessible", uri);
|
||||||
"file \"%s\" does not exist or is inaccessible", uri);
|
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
break;
|
return error;
|
||||||
|
|
||||||
case PLAYER_ERROR_FILE:
|
case PLAYER_ERROR_FILE:
|
||||||
uri = pc_errored_song_uri();
|
uri = pc_errored_song_uri();
|
||||||
snprintf(error, errorlen, "problems decoding \"%s\"", uri);
|
error = g_strdup_printf("problems decoding \"%s\"", uri);
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
break;
|
return error;
|
||||||
|
|
||||||
case PLAYER_ERROR_AUDIO:
|
case PLAYER_ERROR_AUDIO:
|
||||||
strcpy(error, "problems opening audio device");
|
return g_strdup("problems opening audio device");
|
||||||
break;
|
|
||||||
|
|
||||||
case PLAYER_ERROR_SYSTEM:
|
case PLAYER_ERROR_SYSTEM:
|
||||||
strcpy(error, "system error occured");
|
return g_strdup("system error occured");
|
||||||
break;
|
|
||||||
|
|
||||||
case PLAYER_ERROR_UNKTYPE:
|
case PLAYER_ERROR_UNKTYPE:
|
||||||
uri = pc_errored_song_uri();
|
uri = pc_errored_song_uri();
|
||||||
snprintf(error, errorlen,
|
error = g_strdup_printf("file type of \"%s\" is unknown", uri);
|
||||||
"file type of \"%s\" is unknown", uri);
|
|
||||||
g_free(uri);
|
g_free(uri);
|
||||||
break;
|
return error;
|
||||||
}
|
}
|
||||||
return *error ? error : NULL;
|
|
||||||
|
assert(false);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -122,6 +122,11 @@ enum player_state getPlayerState(void);
|
|||||||
|
|
||||||
void clearPlayerError(void);
|
void clearPlayerError(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the human-readable message describing the last error during
|
||||||
|
* playback, NULL if no error occurred. The caller has to free the
|
||||||
|
* returned string.
|
||||||
|
*/
|
||||||
char *getPlayerErrorStr(void);
|
char *getPlayerErrorStr(void);
|
||||||
|
|
||||||
enum player_error getPlayerError(void);
|
enum player_error getPlayerError(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user