Browse Source

* chg params order for f2b_cmd_parse()

master
Alex 'AdUser' Z 8 years ago
parent
commit
036bd4c6c6
  1. 2
      src/client.c
  2. 18
      src/commands.c
  3. 2
      src/commands.h

2
src/client.c

@ -42,7 +42,7 @@ handle_cmd(const char *line) {
memset(&addr, 0x0, sizeof(addr)); memset(&addr, 0x0, sizeof(addr));
memset(&cmsg, 0x0, sizeof(cmsg)); memset(&cmsg, 0x0, sizeof(cmsg));
cmsg.type = f2b_cmd_parse(line, &cmsg.data[0], sizeof(cmsg.data)); cmsg.type = f2b_cmd_parse(&cmsg.data[0], sizeof(cmsg.data), line);
if (cmsg.type == CMD_HELP) { if (cmsg.type == CMD_HELP) {
f2b_cmd_help(); f2b_cmd_help();
return EXIT_SUCCESS; return EXIT_SUCCESS;

18
src/commands.c

@ -118,13 +118,13 @@ f2b_cmd_append_arg(char *buf, size_t bufsize, const char *arg) {
/** /**
* @brief Parse command from line * @brief Parse command from line
* @param src Line taken from user input
* @param buf Buffer for command parameters * @param buf Buffer for command parameters
* @param buflen Size of buffer above * @param bufsize SSize of buffer above
* @param src Line taken from user input
* @return Type of parsed command or CMD_NONE if no matches * @return Type of parsed command or CMD_NONE if no matches
*/ */
enum f2b_cmd_type enum f2b_cmd_type
f2b_cmd_parse(const char *src, char *buf, size_t buflen) { f2b_cmd_parse(char *buf, size_t bufsize, const char *src) {
size_t tokenc = 0; /* tokens count */ size_t tokenc = 0; /* tokens count */
char *tokens[CMD_TOKENS_MAX] = { NULL }; char *tokens[CMD_TOKENS_MAX] = { NULL };
char line[INPUT_LINE_MAX]; char line[INPUT_LINE_MAX];
@ -163,25 +163,25 @@ f2b_cmd_parse(const char *src, char *buf, size_t buflen) {
buf[0] = '\0'; buf[0] = '\0';
if (strcmp(line, "jail") == 0 && tokenc > 1) { if (strcmp(line, "jail") == 0 && tokenc > 1) {
/* commands for jail */ /* commands for jail */
f2b_cmd_append_arg(buf, buflen, tokens[1]); f2b_cmd_append_arg(buf, bufsize, tokens[1]);
if (tokenc == 3 && strcmp(tokens[2], "status") == 0) { if (tokenc == 3 && strcmp(tokens[2], "status") == 0) {
return CMD_JAIL_STATUS; return CMD_JAIL_STATUS;
} }
if (tokenc == 5 && strcmp(tokens[2], "set") == 0) { if (tokenc == 5 && strcmp(tokens[2], "set") == 0) {
f2b_cmd_append_arg(buf, buflen, tokens[3]); f2b_cmd_append_arg(buf, bufsize, tokens[3]);
f2b_cmd_append_arg(buf, buflen, tokens[4]); f2b_cmd_append_arg(buf, bufsize, tokens[4]);
return CMD_JAIL_SET; return CMD_JAIL_SET;
} }
if (tokenc == 5 && strcmp(tokens[2], "ip") == 0 && strcmp(tokens[3], "status") == 0) { if (tokenc == 5 && strcmp(tokens[2], "ip") == 0 && strcmp(tokens[3], "status") == 0) {
f2b_cmd_append_arg(buf, buflen, tokens[4]); f2b_cmd_append_arg(buf, bufsize, tokens[4]);
return CMD_JAIL_IP_STATUS; return CMD_JAIL_IP_STATUS;
} }
if (tokenc == 5 && strcmp(tokens[2], "ip") == 0 && strcmp(tokens[3], "ban") == 0) { if (tokenc == 5 && strcmp(tokens[2], "ip") == 0 && strcmp(tokens[3], "ban") == 0) {
f2b_cmd_append_arg(buf, buflen, tokens[4]); f2b_cmd_append_arg(buf, bufsize, tokens[4]);
return CMD_JAIL_IP_BAN; return CMD_JAIL_IP_BAN;
} }
if (tokenc == 5 && strcmp(tokens[2], "ip") == 0 && strcmp(tokens[3], "release") == 0) { if (tokenc == 5 && strcmp(tokens[2], "ip") == 0 && strcmp(tokens[3], "release") == 0) {
f2b_cmd_append_arg(buf, buflen, tokens[4]); f2b_cmd_append_arg(buf, bufsize, tokens[4]);
return CMD_JAIL_IP_RELEASE; return CMD_JAIL_IP_RELEASE;
} }
if (tokenc == 4 && strcmp(tokens[2], "filter") == 0 && strcmp(tokens[3], "stats") == 0) { if (tokenc == 4 && strcmp(tokens[2], "filter") == 0 && strcmp(tokens[3], "stats") == 0) {

2
src/commands.h

@ -32,7 +32,7 @@ enum f2b_cmd_type {
void f2b_cmd_help(); void f2b_cmd_help();
enum f2b_cmd_type enum f2b_cmd_type
f2b_cmd_parse(const char *src, char *buf, size_t buflen); f2b_cmd_parse (char *buf, size_t bufsize, const char *src);
void void
f2b_cmd_append_arg(char *buf, size_t bufsize, const char *arg); f2b_cmd_append_arg(char *buf, size_t bufsize, const char *arg);

Loading…
Cancel
Save