aboutsummaryrefslogtreecommitdiffstats
path: root/src/command.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-04-12 01:44:52 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-04-12 01:44:52 +0000
commitb68417a643ac97834dea518ee79dc2c4a697a93f (patch)
treef8bc0d7faa42c57145e7195671fc5583ff219b23 /src/command.c
parentf74991b9fdd50310c3984d69bc5ddcf327d16c07 (diff)
downloadmpd-b68417a643ac97834dea518ee79dc2c4a697a93f.tar.gz
mpd-b68417a643ac97834dea518ee79dc2c4a697a93f.tar.xz
mpd-b68417a643ac97834dea518ee79dc2c4a697a93f.zip
cleanup interface between interface.[ch] and command.[ch]
primarily move all buffer2array stuff from interface.c to command.c and write a new command function explicitly for dealing with commandLists git-svn-id: https://svn.musicpd.org/mpd/trunk@701 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/command.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/command.c b/src/command.c
index 5f2ad6eef..90686b7e3 100644
--- a/src/command.c
+++ b/src/command.c
@@ -31,6 +31,7 @@
#include "permission.h"
#include "audio.h"
#include "buffer2array.h"
+#include "log.h"
#include <stdlib.h>
#include <string.h>
@@ -708,25 +709,59 @@ CommandEntry * getCommandEntryFromString(char * string, int * permission) {
return cmd;
}
-int processCommand(FILE * fp, unsigned int * permission, int argArrayLength,
- char ** argArray, ListNode * commandNode)
+int processCommandInternal(FILE * fp, unsigned int * permission,
+ char * commandString,
+ ListNode * commandNode)
{
+ int argArrayLength;
+ char ** argArray;
CommandEntry * cmd;
+ int ret = -1;
+
+ argArrayLength = buffer2array(commandString,&argArray);
if(argArrayLength == 0) return 0;
- if(NULL==(cmd = getCommandEntryAndCheckArgcAndPermission(fp,permission,
+ if((cmd = getCommandEntryAndCheckArgcAndPermission(fp,permission,
argArrayLength,argArray)))
{
- return -1;
+ if(NULL==commandNode || NULL==cmd->listHandler) {
+ ret = cmd->handler(fp, permission, argArrayLength,
+ argArray);
+ }
+ else {
+ ret = cmd->listHandler(fp, permission, argArrayLength,
+ argArray, commandNode, cmd);
+ }
}
- if(NULL==commandNode || NULL==cmd->listHandler) {
- return cmd->handler(fp, permission, argArrayLength, argArray);
- }
- else {
- return cmd->listHandler(fp, permission, argArrayLength,
- argArray, commandNode, cmd);
+ freeArgArray(argArray,argArrayLength);
+
+ return ret;
+}
+
+int proccessListOfCommands(FILE * fp, int * permission, int * expired,
+ List * list)
+{
+ ListNode * node = list->firstNode;
+ ListNode * tempNode;
+ int ret = 0;
+
+ while(node!=NULL) {
+ DEBUG("proccesListOfCommands: process command \"%s\"\n",
+ node->data);
+ ret = processCommandInternal(fp,permission,(char *)node->data,
+ node);
+ DEBUG("proccessListOfCommands: command returned %i\n",ret);
+ tempNode = node->nextNode;
+ deleteNodeFromList(list,node);
+ node = tempNode;
+ if(ret!=0 || (*expired)!=0) node = NULL;
}
+
+ return ret;
}
+int processCommand(FILE * fp, unsigned int * permission, char * commandString) {
+ return processCommandInternal(fp,permission,commandString,NULL);
+}