Browse Source

* more doxygen comments

master
Alex 'AdUser' Z 8 years ago
parent
commit
d9260454c0
  1. 70
      src/commands.h
  2. 25
      src/common.h

70
src/commands.h

@ -7,36 +7,70 @@
#ifndef F2B_COMMANDS_H_
#define F2B_COMMANDS_H_
/* yes, i know about LINE_MAX */
/**
* @file
* This header contains definition of control commands and routines
* for work with data buffer of control message
*/
/**
* Maximum length of input line in client
* @note yes, i know about LINE_MAX
*/
#define INPUT_LINE_MAX 256
/** Maximum count of data pieces in control message data buf */
#define CMD_TOKENS_MAX 6
/** control command type */
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_STATUS,
CMD_JAIL_IP_BAN,
CMD_JAIL_IP_RELEASE,
CMD_JAIL_FILTER_STATS,
CMD_JAIL_FILTER_RELOAD,
CMD_MAX_NUMBER,
CMD_NONE = 0, /**< unset */
CMD_RESP, /**< response of command */
CMD_HELP, /**< show help for commands (used internally by client) */
CMD_PING = 8, /**< check connection */
CMD_STATUS, /**< show general status of f2b daemon */
CMD_ROTATE, /**< reopen logfile. works only if set `logdest = file` */
CMD_RELOAD, /**< reload all jails */
CMD_SHUTDOWN, /**< gracefull shutdown */
/* jail commands */
CMD_JAIL_STATUS = 16, /**< show status of given jail */
CMD_JAIL_SET, /**< set parameter of given jail */
CMD_JAIL_IP_STATUS, /**< show status of given ip */
CMD_JAIL_IP_BAN, /**< force ban given ip */
CMD_JAIL_IP_RELEASE, /**< force unban given ip */
CMD_JAIL_FILTER_STATS, /**< show stats of fileter matches */
CMD_JAIL_FILTER_RELOAD, /**< reload filter patterns from file */
CMD_MAX_NUMBER, /**< placeholder */
};
/**
* @brief Print to stdout help for defined commands
*/
void f2b_cmd_help();
/**
* @brief Try to parse user input
* @param buf Buffer of control message for storing parsed args
* @param bufsize Size of buffer size above
* @param src Line with user input
* @returns @a CMD_NONE if parsing fails, or cmd type less than @a CMD_MAX_NUMBER on success
*/
enum f2b_cmd_type
f2b_cmd_parse(char *buf, size_t bufsize, const char *src);
/**
* @brief Append data piece to data buffer of control message
* @param buf Buffer of control message for storing parsed args
* @param bufsize Size of buffer size above
* @param arg Piece to append
*/
void
f2b_cmd_append_arg(char *buf, size_t bufsize, const char *arg);
/**
* @brief Checks is args count match given command type
* @param type Command type
* @param argc Args count
* @returns true if matches, false if not
*/
bool
f2b_cmd_check_argc(enum f2b_cmd_type type, int argc);

25
src/common.h

@ -26,19 +26,42 @@
#include <time.h>
#include <unistd.h>
/**
* @file
* This header contains common includes, usefull macro defs and default paths
*/
#include "strlcpy.h"
/**
* @def DEFAULT_PIDFILE_PATH
* Self-descriptive
*/
#define DEFAULT_PIDFILE_PATH "/var/run/f2b.pid"
/**
* Default path of unix control socket (server endpoint)
*/
#define DEFAULT_CSOCKET_PATH "/var/run/f2b.sock"
/**
* Template for making path for client side of connection to control socket
*/
#define DEFAULT_CSOCKET_CPATH "/tmp/f2bc-sock-XXXXXX"
/**
* @def UNUSED
* Supresses compiler warning about unused variable
*/
#define UNUSED(x) (void)(x)
/**
* @def SA_REGISTER
* Register signal handler
*/
#define SA_REGISTER(SIGNUM, HANDLER) \
memset(&act, 0x0, sizeof(act)); \
act.sa_handler = HANDLER; \
if (sigaction(SIGNUM, &act, NULL) != 0) { \
f2b_log_msg(log_error, "can't register handler for " #SIGNUM); \
f2b_log_msg(log_fatal, "can't register handler for " #SIGNUM); \
return EXIT_FAILURE; \
}

Loading…
Cancel
Save