From: michael Date: Sun, 14 Jun 2015 12:06:57 +0000 (+0000) Subject: - opercmd.c: reformatting X-Git-Tag: 1.1.0beta1~33 X-Git-Url: http://git.serene-ircd.net/?a=commitdiff_plain;h=c91cd7aecdd9cf437f58ba8c9b2b23cfd04d6b3a;p=hopm.git - opercmd.c: reformatting git-svn-id: svn://svn.ircd-hybrid.org/svnroot/hopm/trunk@6138 82007160-df01-0410-b94d-b575c5fd34c7 --- diff --git a/src/opercmd.c b/src/opercmd.c index 55ce88b..a63c87f 100644 --- a/src/opercmd.c +++ b/src/opercmd.c @@ -37,29 +37,69 @@ #include "stats.h" -static list_t *COMMANDS = NULL; /* List of active commands */ +static list_t *COMMANDS; /* List of active commands */ -static struct Command *command_create(const struct OperCommandHash *, char *param, char *irc_nick, const struct ChannelConf *target); -static void command_free(struct Command *); +/* cmd_check + * + * Start a manual scan on given IP address/hostname. + * + * Parameters: + * param: Parameters of the command + * target: channel command was sent to + * + */ +static void +cmd_check(char *param, const struct ChannelConf *target) +{ + scan_manual(param, target); +} -static void cmd_check(char *, const struct ChannelConf *); -static void cmd_stat(char *, const struct ChannelConf *); -static void cmd_fdstat(char *, const struct ChannelConf *); -static void cmd_protocols(char *, const struct ChannelConf *); +/* cmd_stat + * + * Send output of stats to channel. + * + * Parameters: + * param: Parameters of the command + * target: channel command was sent to + */ +static void +cmd_stat(char *param, const struct ChannelConf *target) +{ + stats_output(target->name); +} -static const struct OperCommandHash COMMAND_TABLE[] = +/* cmd_fdstat + * + * Send output of stats to channel. + * + * Parameters: + * param: Parameters of the command + * target: channel command was sent to + */ +static void +cmd_fdstat(char *param, const struct ChannelConf *target) { - { "CHECK", cmd_check }, - { "SCAN", cmd_check }, - { "STAT", cmd_stat }, - { "STATS", cmd_stat }, - { "STATUS", cmd_stat }, - { "FDSTAT", cmd_fdstat }, - { "PROTOCOLS", cmd_protocols }, - { NULL, NULL } -}; + fdstats_output(target->name); +} + +static void +cmd_protocols(char *param, const struct ChannelConf *target) +{ + node_t *node, *node2; + LIST_FOREACH(node, ScannerItemList->head) + { + const struct ScannerConf *sc = node->data; + irc_send("PRIVMSG %s :Scanner: '%s'", target->name, sc->name); + + LIST_FOREACH(node2, sc->protocols->head) + { + const struct ProtocolConf *proto = node2->data; + irc_send("PRIVMSG %s : %s:%d", target->name, scan_gettype(proto->type), proto->port); + } + } +} /* command_init * @@ -76,45 +116,68 @@ command_init(void) COMMANDS = list_create(); } -/* command_timer - * - * Perform ~1 second actions. +/* command_create * - * Parameters: NONE + * Create a Command struct. * - * Return: NONE + * Parameters: + * type: Index in COMMAND_TABLE + * param: Parameters to the command (NULL if there are not any) + * irc_nick: Nickname of user that initiated the command + * target: Target channel (target is ALWAYS a channel) * + * Return: + * Pointer to new Command */ -void -command_timer(void) +static struct Command * +command_create(const struct OperCommandHash *tab, char *param, char *irc_nick, + const struct ChannelConf *target) { - static unsigned int interval; - node_t *node, *node_next; - time_t present; + struct Command *const ret = xcalloc(sizeof *ret); - /* Only perform command removal every COMMANDINTERVAL seconds */ - if (interval++ < COMMANDINTERVAL) - return; - else - interval = 0; + if (param) + ret->param = xstrdup(param); - time(&present); + ret->tab = tab; + ret->irc_nick = xstrdup(irc_nick); + ret->target = target; - LIST_FOREACH_SAFE(node, node_next, COMMANDS->head) - { - struct Command *cs = node->data; + time(&ret->added); - if ((present - cs->added) > COMMANDTIMEOUT) - { - command_free(cs); - list_remove(COMMANDS, node); - node_free(node); - } - else /* Since the queue is in order, it's also ordered by time, no nodes after this will be timed out */ - return; - } + return ret; +} + +/* command_free + * + * Free a command struct + * + * Parameters: + * command: Command struct to free + * + * Return: NONE + */ +static void +command_free(struct Command *command) +{ + if (command->param) + xfree(command->param); + + xfree(command->irc_nick); + xfree(command); } +static const struct OperCommandHash COMMAND_TABLE[] = +{ + { "CHECK", cmd_check }, + { "SCAN", cmd_check }, + { "STAT", cmd_stat }, + { "STATS", cmd_stat }, + { "STATUS", cmd_stat }, + { "FDSTAT", cmd_fdstat }, + { "PROTOCOLS", cmd_protocols }, + { NULL, NULL } +}; + /* command_parse * * Parse a command to hopm (sent to a channel hopm is on). The command is parsed @@ -188,54 +251,43 @@ command_parse(char *command, const struct ChannelConf *target, irc_send("USERHOST %s", source_p->irc_nick); } -/* command_create +/* command_timer * - * Create a Command struct. + * Perform ~1 second actions. * - * Parameters: - * type: Index in COMMAND_TABLE - * param: Parameters to the command (NULL if there are not any) - * irc_nick: Nickname of user that initiated the command - * target: Target channel (target is ALWAYS a channel) + * Parameters: NONE + * + * Return: NONE * - * Return: - * Pointer to new Command */ -static struct Command * -command_create(const struct OperCommandHash *tab, char *param, char *irc_nick, - const struct ChannelConf *target) +void +command_timer(void) { - struct Command *const ret = xcalloc(sizeof *ret); - - if (param) - ret->param = xstrdup(param); - - ret->tab = tab; - ret->irc_nick = xstrdup(irc_nick); - ret->target = target; + static unsigned int interval; + node_t *node, *node_next; + time_t present; - time(&ret->added); + /* Only perform command removal every COMMANDINTERVAL seconds */ + if (interval++ < COMMANDINTERVAL) + return; + else + interval = 0; - return ret; -} + time(&present); -/* command_free - * - * Free a command struct - * - * Parameters: - * command: Command struct to free - * - * Return: NONE - */ -static void -command_free(struct Command *command) -{ - if (command->param) - xfree(command->param); + LIST_FOREACH_SAFE(node, node_next, COMMANDS->head) + { + struct Command *cs = node->data; - xfree(command->irc_nick); - xfree(command); + if ((present - cs->added) > COMMANDTIMEOUT) + { + command_free(cs); + list_remove(COMMANDS, node); + node_free(node); + } + else /* Since the queue is in order, it's also ordered by time, no nodes after this will be timed out */ + return; + } } /* command_userhost @@ -290,64 +342,3 @@ command_userhost(const char *reply) } } } - -/* cmd_check - * - * Start a manual scan on given IP address/hostname. - * - * Parameters: - * param: Parameters of the command - * target: channel command was sent to - * - */ -static void -cmd_check(char *param, const struct ChannelConf *target) -{ - scan_manual(param, target); -} - -/* cmd_stat - * - * Send output of stats to channel. - * - * Parameters: - * param: Parameters of the command - * target: channel command was sent to - */ -static void -cmd_stat(char *param, const struct ChannelConf *target) -{ - stats_output(target->name); -} - -/* cmd_fdstat - * - * Send output of stats to channel. - * - * Parameters: - * param: Parameters of the command - * target: channel command was sent to - */ -static void -cmd_fdstat(char *param, const struct ChannelConf *target) -{ - fdstats_output(target->name); -} - -static void -cmd_protocols(char *param, const struct ChannelConf *target) -{ - node_t *node, *node2; - - LIST_FOREACH(node, ScannerItemList->head) - { - const struct ScannerConf *sc = node->data; - irc_send("PRIVMSG %s :Scanner: '%s'", target->name, sc->name); - - LIST_FOREACH(node2, sc->protocols->head) - { - const struct ProtocolConf *proto = node2->data; - irc_send("PRIVMSG %s : %s:%d", target->name, scan_gettype(proto->type), proto->port); - } - } -}