command: pass struct client to getCommandEntryAnd...()
Instead of passing the file descriptor, pass the client struct to getCommandEntryAndCheckArgcAndPermission().
This commit is contained in:
parent
54371add13
commit
d2543f03f5
@ -1385,18 +1385,17 @@ void finishCommands(void)
|
|||||||
freeList(commandList);
|
freeList(commandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int checkArgcAndPermission(CommandEntry * cmd, int fd,
|
static int checkArgcAndPermission(CommandEntry * cmd, struct client *client,
|
||||||
int permission, int argc, char *argv[])
|
int permission, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int min = cmd->min + 1;
|
int min = cmd->min + 1;
|
||||||
int max = cmd->max + 1;
|
int max = cmd->max + 1;
|
||||||
|
|
||||||
if (cmd->reqPermission != (permission & cmd->reqPermission)) {
|
if (cmd->reqPermission != (permission & cmd->reqPermission)) {
|
||||||
if (fd) {
|
if (client != NULL)
|
||||||
commandError(fd, ACK_ERROR_PERMISSION,
|
command_error(client, ACK_ERROR_PERMISSION,
|
||||||
"you don't have permission for \"%s\"",
|
"you don't have permission for \"%s\"",
|
||||||
cmd->cmd);
|
cmd->cmd);
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1404,29 +1403,26 @@ static int checkArgcAndPermission(CommandEntry * cmd, int fd,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (min == max && max != argc) {
|
if (min == max && max != argc) {
|
||||||
if (fd) {
|
if (client != NULL)
|
||||||
commandError(fd, ACK_ERROR_ARG,
|
command_error(client, ACK_ERROR_ARG,
|
||||||
"wrong number of arguments for \"%s\"",
|
"wrong number of arguments for \"%s\"",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (argc < min) {
|
} else if (argc < min) {
|
||||||
if (fd) {
|
if (client != NULL)
|
||||||
commandError(fd, ACK_ERROR_ARG,
|
command_error(client, ACK_ERROR_ARG,
|
||||||
"too few arguments for \"%s\"", argv[0]);
|
"too few arguments for \"%s\"", argv[0]);
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (argc > max && max /* != 0 */ ) {
|
} else if (argc > max && max /* != 0 */ ) {
|
||||||
if (fd) {
|
if (client != NULL)
|
||||||
commandError(fd, ACK_ERROR_ARG,
|
command_error(client, ACK_ERROR_ARG,
|
||||||
"too many arguments for \"%s\"", argv[0]);
|
"too many arguments for \"%s\"", argv[0]);
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
} else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CommandEntry *getCommandEntryAndCheckArgcAndPermission(int fd,
|
static CommandEntry *getCommandEntryAndCheckArgcAndPermission(struct client *client,
|
||||||
int *permission,
|
int *permission,
|
||||||
int argc,
|
int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -1440,16 +1436,15 @@ static CommandEntry *getCommandEntryAndCheckArgcAndPermission(int fd,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!findInList(commandList, argv[0], (void *)&cmd)) {
|
if (!findInList(commandList, argv[0], (void *)&cmd)) {
|
||||||
if (fd) {
|
if (client != NULL)
|
||||||
commandError(fd, ACK_ERROR_UNKNOWN,
|
command_error(client, ACK_ERROR_UNKNOWN,
|
||||||
"unknown command \"%s\"", argv[0]);
|
"unknown command \"%s\"", argv[0]);
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_command = cmd->cmd;
|
current_command = cmd->cmd;
|
||||||
|
|
||||||
if (checkArgcAndPermission(cmd, fd, *permission, argc, argv) < 0) {
|
if (checkArgcAndPermission(cmd, client, *permission, argc, argv) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1486,7 +1481,7 @@ static int processCommandInternal(struct client *client,
|
|||||||
if (argc == 0)
|
if (argc == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((cmd = getCommandEntryAndCheckArgcAndPermission(fd, permission,
|
if ((cmd = getCommandEntryAndCheckArgcAndPermission(client, permission,
|
||||||
argc, argv))) {
|
argc, argv))) {
|
||||||
if (!cmdnode || !cmd->listHandler) {
|
if (!cmdnode || !cmd->listHandler) {
|
||||||
ret = cmd->handler(fd, permission, argc, argv);
|
ret = cmd->handler(fd, permission, argc, argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user