#include "config.h"
#include "extern.h"
+static void checkoper(const char *nick, const char *param,
+ const char *target, unsigned int cmd_type);
+static void delete_command(unsigned int index);
+
+struct command cmd_stack[MAXCMD];
+time_t LAST_REAP_TIME;
+
void do_oper_cmd(const char *nick, const char *cmd, const char *param,
- const char *target)
+ const char *target)
{
- if(strncasecmp(cmd, "CHECK", 5) == 0)
- {
- if(!param)
- {
- irc_send("PRIVMSG %s :*ring* Hello, cluephone for %s, you need to "
- "specify a host or IP address if you want me to do any "
- "checking, yo.", target, nick);
- return;
- }
- checkoper(nick, param, target, CMD_CHECK);
- }
- else
- {
- irc_send("PRIVMSG %s :Sorry, I don't know how to %s, %s.", target,
- cmd, nick);
- }
- return;
+ if (strncasecmp(cmd, "CHECK", 5) == 0) {
+ if (!param) {
+ irc_send("PRIVMSG %s :*ring* Hello, cluephone for "
+ "%s, you need to specify a host or IP address "
+ "if you want me to do any checking, yo.",
+ target, nick);
+ return;
+ }
+ checkoper(nick, param, target, CMD_CHECK);
+ } else {
+ irc_send("PRIVMSG %s :Sorry, I don't know how to %s, %s.",
+ target, cmd, nick);
+ }
+ return;
}
-void checkoper(const char *nick, const char *param, const char *target,
- unsigned int cmd_type)
+static void checkoper(const char *nick, const char *param,
+ const char *target, unsigned int cmd_type)
{
- int i;
-
- for(i = 0; i < MAXCMD; i++)
- {
- if(cmd_stack[i].type == CMD_NONE)
- {
- cmd_stack[i].type = cmd_type;
- cmd_stack[i].param = strdup(param);
- cmd_stack[i].target = strdup(target);
- strncpy(cmd_stack[i].nick, nick, NICKMAX);
- break;
- }
- }
-
- if(i == MAXCMD)
- irc_send("PRIVMSG %s :Too many queued commands, try later.", target);
- else
- irc_send("USERHOST %s", nick);
+ unsigned int i;
+
+ for (i = 0; i < MAXCMD; i++) {
+ if (cmd_stack[i].type == CMD_NONE) {
+ cmd_stack[i].type = cmd_type;
+ cmd_stack[i].param = strdup(param);
+ cmd_stack[i].target = strdup(target);
+ strncpy(cmd_stack[i].nick, nick, NICKMAX);
+ break;
+ }
+ }
+
+ if (i == MAXCMD) {
+ irc_send("PRIVMSG %s :Too many queued commands, try later.",
+ target);
+ } else {
+ irc_send("USERHOST %s", nick);
+ }
}
+/*
+ * Check a userhost to see if it is from an oper, we're looking for the
+ * asterisk (*) between the nick and the ident as below:
+ * :grifferz*=+goats@pc-62-30-219-54-pb.blueyonder.co.uk
+ */
void check_userhost(const char *userhost)
{
- /* check a userhost to see if it is from an oper, we're looking for
- * the asterisk (*) between the nick and the ident as below:
- * :grifferz*=+goats@pc-62-30-219-54-pb.blueyonder.co.uk */
- char *tmp;
- int c, oper = 0;
+ int c, oper;
+ char *tmp;
+
+ oper = 0;
- tmp = strchr(userhost, '=');
-
- if(!tmp)
- {
- /* looks like they quit, oh well, just ignore it */
- return;
- }
-
- if(*(tmp - 1) == '*')
- {
- oper = 1;
- tmp--;
- }
-
- /* null terminate userhost so we have a nickname there now */
- *tmp = '\0';
-
- /* go through the command list looking for commands by this person */
- for(c = 0; c < MAXCMD; c++)
- {
- if(!strcasecmp(userhost + 1, cmd_stack[c].nick))
- {
- if(oper)
- {
- /* do the command */
- if(cmd_stack[c].type == CMD_CHECK)
- {
- do_manual_check(&cmd_stack[c]);
- }
- }
- else
- {
- irc_send("PRIVMSG %s :You are not an IRC Operator. Go away.",
- cmd_stack[c].target);
- }
-
- delete_command(c);
- }
- }
+ tmp = strchr(userhost, '=');
+
+ if (!tmp) {
+ /* Looks like they quit, oh well, just ignore it. */
+ return;
+ }
+
+ if (*(tmp - 1) == '*') {
+ oper = 1;
+ tmp--;
+ }
+
+ /* Null terminate userhost so we have a nickname there now. */
+ *tmp = '\0';
+
+ /* Go through the command list looking for commands by this person */
+ for (c = 0; c < MAXCMD; c++) {
+ if (!strcasecmp(userhost + 1, cmd_stack[c].nick)) {
+ if (oper) {
+ /* Do the command. */
+ if (cmd_stack[c].type == CMD_CHECK) {
+ do_manual_check(&cmd_stack[c]);
+ }
+ } else {
+ irc_send("PRIVMSG %s :You are not an IRC "
+ "Operator. Go away.",
+ cmd_stack[c].target);
+ }
+
+ delete_command(c);
+ }
+ }
}
-/* set a command to CMD_NONE and free all resources it used, so that it
- * can be reused later */
-void delete_command(unsigned int index)
+/*
+ * Set a command to CMD_NONE and free all resources it used, so that it
+ * can be reused later.
+ */
+static void delete_command(unsigned int index)
{
- if(cmd_stack[index].type == CMD_NONE)
- return;
+ if (cmd_stack[index].type == CMD_NONE)
+ return;
- cmd_stack[index].type = CMD_NONE;
- cmd_stack[index].added = 0;
- free(cmd_stack[index].param);
- free(cmd_stack[index].target);
+ cmd_stack[index].type = CMD_NONE;
+ cmd_stack[index].added = 0;
+ free(cmd_stack[index].param);
+ free(cmd_stack[index].target);
}
-/* delete any commands which are more than 2 minutes old, they are almost certainly
- * no longer relevant. */
+/*
+ * Delete any commands which are more than 2 minutes old, they are almost certainly
+ * no longer relevant.
+ */
void reap_commands(time_t present)
{
- int c;
-
- for(c = 0; c < MAXCMD; c++)
- {
- if(cmd_stack[c].type != CMD_NONE &&
- (present - cmd_stack[c].added >= 120))
- {
- irc_send("PRIVMSG %s :Reaping dead command from %s of type %u "
- "with param '%s', added %s ago.", cmd_stack[c].nick,
- cmd_stack[c].type, cmd_stack[c].param,
- dissect_time(present - cmd_stack[c].added));
- delete_command(c);
- }
- }
+ int c;
+
+ for (c = 0; c < MAXCMD; c++) {
+ if (cmd_stack[c].type != CMD_NONE &&
+ (present - cmd_stack[c].added >= 120)) {
+ irc_send("PRIVMSG %s :Reaping dead command from "
+ "%s of type %u with param '%s', added %s ago.",
+ cmd_stack[c].nick, cmd_stack[c].type,
+ cmd_stack[c].param,
+ dissect_time(present - cmd_stack[c].added));
+ delete_command(c);
+ }
+ }
}
#ifndef OPERCMD_H
#define OPERCMD_H
- struct command {
- /* types defined below */
- /* THIS MUST BE CMD_NONE FOR AN EMPTY COMMAND! */
- unsigned int type;
-
- /* command parameter
- * <erik> but i cant think of any commands bopm will ever
- * have that is multiple parameters
- */
- char *param;
+struct command {
+ /* Types defined below. */
+ /* THIS MUST BE CMD_NONE FOR AN EMPTY COMMAND! */
+ unsigned int type;
+
+ /* Command parameter.
+ * <erik> but i cant think of any commands bopm will ever have that is
+ * multiple parameters
+ */
+ char *param;
- /* who ordered it */
- char nick[NICKMAX];
+ /* Who ordered it. */
+ char nick[NICKMAX];
- /* where the reply is to be sent */
- char *target;
+ /* Where the reply is to be sent. */
+ char *target;
- /* when it was added, because we might need to remove
- * it if it does not get executed */
- time_t added;
- };
+ /*
+ * When it was added, because we might need to remove it if it does
+ * not get executed.
+ */
+ time_t added;
+};
- /* allow 5 outstanding commands */
- #define MAXCMD 5
+/* Allow 5 outstanding commands. */
+#define MAXCMD 5
- struct command cmd_stack[MAXCMD];
+/* One for each oper command we support. */
+#define CMD_NONE 0
+#define CMD_CHECK 1
- /* one for each oper command we support */
- #define CMD_NONE 0
- #define CMD_CHECK 1
+extern void do_oper_cmd(const char *nick, const char *cmd,
+ const char *param, const char *target);
+extern void check_userhost(const char *userhost);
+extern void reap_commands(time_t present);
- time_t LAST_REAP_TIME;
-
- void do_oper_cmd(const char *nick, const char *cmd,
- const char *param, const char *target);
- void checkoper(const char *nick, const char *param,
- const char *target, unsigned int cmd_type);
- void check_userhost(const char *userhost);
- void delete_command(unsigned int index);
- void reap_commands(time_t present);
#endif