work on ACK error codes
git-svn-id: https://svn.musicpd.org/mpd/trunk@1324 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
@ -106,6 +106,9 @@ struct _CommandEntry {
|
|||||||
CommandListHandlerFunction listHandler;
|
CommandListHandlerFunction listHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
char * current_command = NULL;
|
||||||
|
int command_listNum = 0;
|
||||||
|
|
||||||
CommandEntry * getCommandEntryFromString(char * string, int * permission);
|
CommandEntry * getCommandEntryFromString(char * string, int * permission);
|
||||||
|
|
||||||
List * commandList;
|
List * commandList;
|
||||||
@ -679,8 +682,11 @@ int checkArgcAndPermission(CommandEntry * cmd, FILE *fp,
|
|||||||
CommandEntry * getCommandEntryAndCheckArgcAndPermission(FILE * fp,
|
CommandEntry * getCommandEntryAndCheckArgcAndPermission(FILE * fp,
|
||||||
unsigned int * permission, int argArrayLength, char ** argArray)
|
unsigned int * permission, int argArrayLength, char ** argArray)
|
||||||
{
|
{
|
||||||
|
static char unknown[] = "";
|
||||||
CommandEntry * cmd;
|
CommandEntry * cmd;
|
||||||
|
|
||||||
|
current_command = unknown;
|
||||||
|
|
||||||
if(argArrayLength == 0) return NULL;
|
if(argArrayLength == 0) return NULL;
|
||||||
|
|
||||||
if(!findInList(commandList, argArray[0],(void *)&cmd)) {
|
if(!findInList(commandList, argArray[0],(void *)&cmd)) {
|
||||||
@ -688,6 +694,8 @@ CommandEntry * getCommandEntryAndCheckArgcAndPermission(FILE * fp,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current_command = cmd->cmd;
|
||||||
|
|
||||||
if(checkArgcAndPermission(cmd, fp, *permission, argArrayLength,
|
if(checkArgcAndPermission(cmd, fp, *permission, argArrayLength,
|
||||||
argArray) < 0)
|
argArray) < 0)
|
||||||
{
|
{
|
||||||
@ -739,6 +747,8 @@ int processCommandInternal(FILE * fp, unsigned int * permission,
|
|||||||
|
|
||||||
freeArgArray(argArray,argArrayLength);
|
freeArgArray(argArray,argArrayLength);
|
||||||
|
|
||||||
|
current_command = NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -749,6 +759,8 @@ int proccessListOfCommands(FILE * fp, int * permission, int * expired,
|
|||||||
ListNode * tempNode;
|
ListNode * tempNode;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
command_listNum = 0;
|
||||||
|
|
||||||
while(node!=NULL) {
|
while(node!=NULL) {
|
||||||
DEBUG("proccesListOfCommands: process command \"%s\"\n",
|
DEBUG("proccesListOfCommands: process command \"%s\"\n",
|
||||||
node->data);
|
node->data);
|
||||||
@ -759,7 +771,10 @@ int proccessListOfCommands(FILE * fp, int * permission, int * expired,
|
|||||||
deleteNodeFromList(list,node);
|
deleteNodeFromList(list,node);
|
||||||
node = tempNode;
|
node = tempNode;
|
||||||
if(ret!=0 || (*expired)!=0) node = NULL;
|
if(ret!=0 || (*expired)!=0) node = NULL;
|
||||||
|
command_listNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
command_listNum = 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -767,4 +782,3 @@ int proccessListOfCommands(FILE * fp, int * permission, int * expired,
|
|||||||
int processCommand(FILE * fp, unsigned int * permission, char * commandString) {
|
int processCommand(FILE * fp, unsigned int * permission, char * commandString) {
|
||||||
return processCommandInternal(fp,permission,commandString,NULL);
|
return processCommandInternal(fp,permission,commandString,NULL);
|
||||||
}
|
}
|
||||||
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
|
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
#define COMMAND_RETURN_KILL 10
|
#define COMMAND_RETURN_KILL 10
|
||||||
#define COMMAND_RETURN_CLOSE 20
|
#define COMMAND_RETURN_CLOSE 20
|
||||||
|
|
||||||
|
extern char * current_command;
|
||||||
|
extern int command_listNum;
|
||||||
|
|
||||||
int proccessListOfCommands(FILE * fp, int * permission, int * expired,
|
int proccessListOfCommands(FILE * fp, int * permission, int * expired,
|
||||||
List * list);
|
List * list);
|
||||||
|
|
||||||
@ -40,6 +43,18 @@ void finishCommands();
|
|||||||
|
|
||||||
#define commandSuccess(fp) myfprintf(fp, "OK\n")
|
#define commandSuccess(fp) myfprintf(fp, "OK\n")
|
||||||
|
|
||||||
#define commandError(fp, format, ... ) myfprintf(fp, "ACK " format "\n", ##__VA_ARGS__)
|
#define commandError(fp, format, ... ) \
|
||||||
|
{\
|
||||||
|
if(current_command) { \
|
||||||
|
myfprintf(fp, "ACK [%s:%i] " format "\n", \
|
||||||
|
current_command, command_listNum, \
|
||||||
|
##__VA_ARGS__); \
|
||||||
|
current_command = NULL; \
|
||||||
|
} \
|
||||||
|
else { \
|
||||||
|
myfprintf(fp, "ACK [:%i] " format "\n", \
|
||||||
|
command_listNum, ##__VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -375,7 +375,7 @@ int playlistInfo(FILE * fp,int song) {
|
|||||||
end = song+1;
|
end = song+1;
|
||||||
}
|
}
|
||||||
if(song>=playlist.length) {
|
if(song>=playlist.length) {
|
||||||
commandError(fp, "song doesn't exist");
|
commandError(fp, "song doesn't exist: \"%i\"", song);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,11 +535,11 @@ int swapSongsInPlaylist(FILE * fp, int song1, int song2) {
|
|||||||
int currentSong = -1;
|
int currentSong = -1;
|
||||||
|
|
||||||
if(song1<0 || song1>=playlist.length) {
|
if(song1<0 || song1>=playlist.length) {
|
||||||
commandError(fp,"\"%i\" is not in the playlist", song1);
|
commandError(fp, "song doesn't exist: \"%i\"", song1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(song2<0 || song2>=playlist.length) {
|
if(song2<0 || song2>=playlist.length) {
|
||||||
commandError(fp, "\"%i\" is not in the playlist", song2);
|
commandError(fp, "song doesn't exist: \"%i\"", song2);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,12 +585,8 @@ int deleteFromPlaylist(FILE * fp, int song) {
|
|||||||
int i;
|
int i;
|
||||||
int songOrder;
|
int songOrder;
|
||||||
|
|
||||||
if(song<0) {
|
if(song<0 || song>=playlist.length) {
|
||||||
commandError(fp, "need a positive integer");
|
commandError(fp, "song doesn't exist: \"%i\"", song);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(song>=playlist.length) {
|
|
||||||
commandError(fp, "song doesn't exist");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,18 +709,8 @@ int playPlaylist(FILE * fp, int song, int stopOnError) {
|
|||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(song<0) {
|
else if(song<0 || song>=playlist.length) {
|
||||||
commandError(fp, "need integer >= -1");
|
commandError(fp, "song doesn't exist: \"%i\"", song);
|
||||||
playlist_state = PLAYLIST_STATE_STOP;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!playlist.length) {
|
|
||||||
commandError(fp, "playlist is empty");
|
|
||||||
playlist_state = PLAYLIST_STATE_STOP;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if(song>=playlist.length) {
|
|
||||||
commandError(fp, "song doesn't exist");
|
|
||||||
playlist_state = PLAYLIST_STATE_STOP;
|
playlist_state = PLAYLIST_STATE_STOP;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -869,12 +855,12 @@ int moveSongInPlaylist(FILE * fp, int from, int to) {
|
|||||||
int currentSong = -1;
|
int currentSong = -1;
|
||||||
|
|
||||||
if(from<0 || from>=playlist.length) {
|
if(from<0 || from>=playlist.length) {
|
||||||
commandError(fp, "\"%i\" is not a song in the playlist", from);
|
commandError(fp, "song doesn't exist: \"%i\"", from);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(to<0 || to>=playlist.length) {
|
if(to<0 || to>=playlist.length) {
|
||||||
commandError(fp, "\"%i\" is not a song in the playlist", to);
|
commandError(fp, "song doesn't exist: \"%i\"", to);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,16 +1239,8 @@ int getPlaylistLength() {
|
|||||||
int seekSongInPlaylist(FILE * fp, int song, float time) {
|
int seekSongInPlaylist(FILE * fp, int song, float time) {
|
||||||
int i = song;
|
int i = song;
|
||||||
|
|
||||||
if(song<0) {
|
if(song<0 || song>=playlist.length) {
|
||||||
commandError(fp, "need integer >= -1");
|
commandError(fp, "song doesn't exist: \"%i\"", song);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(!playlist.length) {
|
|
||||||
commandError(fp, "playlist is empty");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if(song>=playlist.length) {
|
|
||||||
commandError(fp, "song doesn't exist");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,8 +192,7 @@ int printAllKeysOfTable(FILE * fp, char * table, char * arg1) {
|
|||||||
return printAllAlbums(fp,arg1);
|
return printAllAlbums(fp,arg1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
commandError(fp, "table \"%s\" does not exist or not available "
|
commandError(fp, "table \"%s\" does not exist", table);
|
||||||
"for listing", table);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user