From b68417a643ac97834dea518ee79dc2c4a697a93f Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Mon, 12 Apr 2004 01:44:52 +0000 Subject: 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 --- src/command.c | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'src/command.c') 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 #include @@ -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); +} -- cgit v1.2.3