diff options
author | Eric Wong <normalperson@yhbt.net> | 2006-07-29 18:55:00 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2006-07-29 18:55:00 +0000 |
commit | f08342c11fb7f31b168902b4d89d8e543e03125a (patch) | |
tree | e56ebfd5f0b4376d10e4f02dba17f3dfef82b999 /src/command.c | |
parent | f05166a6a0f39e6c6f8ce9675d7f6f6f58300577 (diff) | |
download | mpd-f08342c11fb7f31b168902b4d89d8e543e03125a.tar.gz mpd-f08342c11fb7f31b168902b4d89d8e543e03125a.tar.xz mpd-f08342c11fb7f31b168902b4d89d8e543e03125a.zip |
replace buffer2array() with cstrtok() from mpd-ke
This modifies the string in place, and does not allocate any memory from
the heap. This is considerably smaller than the function it replaces,
and will be instrumental in getting the commands/conf malloc reductions
done.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4481 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/command.c')
-rw-r--r-- | src/command.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/command.c b/src/command.c index 8158032a6..cf4a37ae7 100644 --- a/src/command.c +++ b/src/command.c @@ -104,6 +104,11 @@ #define COMMAND_STATUS_AUDIO "audio" #define COMMAND_STATUS_UPDATING_DB "updating_db" +/* the most we ever use is argv[2], so argv[] has (at most) + * 3 usable elements. This means we tokenize up to 4 elements to + * detect errors clients may send us */ +#define COMMAND_ARGV_MAX 4 + typedef struct _CommandEntry CommandEntry; typedef int (*CommandHandlerFunction) (FILE *, int *, int, char **); @@ -1138,16 +1143,14 @@ static CommandEntry *getCommandEntryAndCheckArgcAndPermission(FILE * fp, static CommandEntry *getCommandEntryFromString(char *string, int *permission) { CommandEntry *cmd = NULL; - char **argv; - int argc = buffer2array(string, &argv); + char *argv[COMMAND_ARGV_MAX] = { 0 }; + int argc = cstrtok(string, argv, COMMAND_ARGV_MAX); if (0 == argc) return NULL; cmd = getCommandEntryAndCheckArgcAndPermission(NULL, permission, - argc, - argv); - freeArgArray(argv, argc); + argc, argv); return cmd; } @@ -1156,29 +1159,25 @@ static int processCommandInternal(FILE * fp, int *permission, char *commandString, ListNode * commandNode) { int argc; - char **argv; + char *argv[COMMAND_ARGV_MAX] = { 0 }; CommandEntry *cmd; int ret = -1; - argc = buffer2array(commandString, &argv); + argc = cstrtok(commandString, argv, COMMAND_ARGV_MAX); if (argc == 0) return 0; if ((cmd = getCommandEntryAndCheckArgcAndPermission(fp, permission, - argc, - argv))) { + argc, argv))) { if (NULL == commandNode || NULL == cmd->listHandler) { - ret = cmd->handler(fp, permission, argc, - argv); + ret = cmd->handler(fp, permission, argc, argv); } else { - ret = cmd->listHandler(fp, permission, argc, - argv, commandNode, cmd); + ret = cmd->listHandler(fp, permission, argc, argv, + commandNode, cmd); } } - freeArgArray(argv, argc); - current_command = NULL; return ret; |