--- a/src/irc_net.c Thu Mar 12 18:11:44 2009 +0200
+++ b/src/irc_net.c Thu Mar 12 18:35:05 2009 +0200
@@ -28,16 +28,15 @@
};
/**
- * :nm JOIN <channel>
- */
-static void irc_net_on_JOIN (const struct irc_line *line, void *arg)
+ * Propagate the command to the appropriate irc_chan based on the given name
+ */
+static void irc_net_propagate_chan (struct irc_net *net, const struct irc_line *line, const char *channel)
{
- struct irc_net *net = arg;
struct irc_chan *chan;
// look up channel
- if ((chan = irc_net_get_chan(net, line->args[0])) == NULL) {
- log_warn("unkown channel: %s", line->args[0]);
+ if ((chan = irc_net_get_chan(net, channel)) == NULL) {
+ log_warn("unknown channel: %s", channel);
return;
}
@@ -46,10 +45,41 @@
}
/**
+ * Propagate line to irc_chan based on args[0]
+ */
+static void irc_net_on_chan0 (const struct irc_line *line, void *arg)
+{
+ struct irc_net *net = arg;
+
+ irc_net_propagate_chan(net, line, line->args[0]);
+}
+
+/**
+ * :nm PRIVMSG <target> <message>
+ *
+ * Either propagate to channel if found, otherwise handle as a privmsg
+ */
+static void irc_net_on_PRIVMSG (const struct irc_line *line, void *arg)
+{
+ struct irc_net *net = arg;
+
+ // XXX: does two lookups
+ if (irc_net_get_chan(net, line->args[0])) {
+ // short-circuit to on_chan0
+ irc_net_on_chan0(line, arg);
+
+ } else {
+ // XXX: callbacks for privmsgs
+
+ }
+}
+
+/**
* Our irc_cmd handler list
*/
static struct irc_cmd_handler _cmd_handlers[] = {
- { "JOIN", &irc_net_on_JOIN },
+ { "JOIN", &irc_net_on_chan0 },
+ { "PRIVMSG", &irc_net_on_PRIVMSG },
{ NULL, NULL }
};