From 3b14333a9457d671bf3293a7d357c5af47956244 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 16 Sep 2016 17:20:59 +1000 Subject: [PATCH] * move enum with command types --- src/cmsg.h | 23 +++-------------------- src/commands.c | 2 +- src/commands.h | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/cmsg.h b/src/cmsg.h index 69935ab..c57cd00 100644 --- a/src/cmsg.h +++ b/src/cmsg.h @@ -3,29 +3,12 @@ #include +#include "commands.h" + #define DATA_LEN_MAX 1476 /* 1500 - (16 bytes of cmsg header + 8 bytes of udp) */ #define DATA_ARGS_MAX 6 /* number of args in data */ #define F2B_PROTO_VER 1 -enum f2b_cmsg_type { - CMD_NONE = 0, - CMD_RESP, - CMD_HELP, - CMD_PING = 8, - CMD_STATUS, - CMD_ROTATE, - CMD_RELOAD, - CMD_SHUTDOWN, - CMD_JAIL_STATUS = 16, - CMD_JAIL_SET, - CMD_JAIL_IP_SHOW, - CMD_JAIL_IP_BAN, - CMD_JAIL_IP_RELEASE, - CMD_JAIL_REGEX_STATS, - CMD_JAIL_REGEX_ADD, - CMD_MAX_NUMBER, -}; - #define CMSG_FLAG_NEED_REPLY 0x01 #define CMSG_FLAG_AUTH_PASS 0x02 @@ -38,7 +21,7 @@ typedef struct f2b_cmsg_t { char magic[3]; /**< magic string "F2B" */ uint8_t version; /**< protocol version */ /* 4 bytes */ - uint8_t type; /**< command type, cast from enum f2b_cmsg_type */ + uint8_t type; /**< command type, cast from enum f2b_cmd_type */ uint8_t flags; /**< CMSG_FLAG_* */ uint16_t size; /**< payload length */ /* 8 bytes */ diff --git a/src/commands.c b/src/commands.c index ab9fc44..3cd1ab2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -116,7 +116,7 @@ f2b_cmd_help() { * @param buflen Size of buffer above * @return Type of parsed command or CMD_NONE if no matches */ -enum f2b_cmsg_type +enum f2b_cmd_type f2b_cmd_parse(const char *src, char *buf, size_t buflen) { size_t tokenc = 0; /* tokens count */ char *tokens[CMD_TOKENS_MAX] = { NULL }; diff --git a/src/commands.h b/src/commands.h index 366c874..19bd0da 100644 --- a/src/commands.h +++ b/src/commands.h @@ -11,8 +11,27 @@ #define INPUT_LINE_MAX 256 #define CMD_TOKENS_MAX 6 +enum f2b_cmd_type { + CMD_NONE = 0, + CMD_RESP, + CMD_HELP, + CMD_PING = 8, + CMD_STATUS, + CMD_ROTATE, + CMD_RELOAD, + CMD_SHUTDOWN, + CMD_JAIL_STATUS = 16, + CMD_JAIL_SET, + CMD_JAIL_IP_SHOW, + CMD_JAIL_IP_BAN, + CMD_JAIL_IP_RELEASE, + CMD_JAIL_REGEX_STATS, + CMD_JAIL_REGEX_ADD, + CMD_MAX_NUMBER, +}; + void f2b_cmd_help(); -enum f2b_cmsg_type +enum f2b_cmd_type f2b_cmd_parse(const char *src, char *buf, size_t buflen); #endif /* F2B_COMMANDS_H_ */