irc: Expose more IRC functionality

Now exposing the connection event and raw incoming commands.
This commit is contained in:
Christian Decker 2016-09-27 18:26:35 +02:00
parent 356bb73fe9
commit c97c47da47
2 changed files with 14 additions and 4 deletions

10
irc.c
View file

@ -3,6 +3,8 @@
#include "daemon/log.h" #include "daemon/log.h"
void (*irc_privmsg_cb)(struct ircstate *, const struct privmsg *) = NULL; void (*irc_privmsg_cb)(struct ircstate *, const struct privmsg *) = NULL;
void (*irc_command_cb)(struct ircstate *, const struct irccommand *) = NULL;
void (*irc_connect_cb)(struct ircstate *) = NULL;
void (*irc_disconnect_cb)(struct ircstate *) = NULL; void (*irc_disconnect_cb)(struct ircstate *) = NULL;
static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_state *dstate, struct ircstate *state); static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_state *dstate, struct ircstate *state);
@ -94,6 +96,10 @@ static void handle_irc_command(struct ircstate *state, const char *line)
pm->msg = tal_strjoin(m, splits + 2, " ", STR_NO_TRAIL); pm->msg = tal_strjoin(m, splits + 2, " ", STR_NO_TRAIL);
irc_privmsg_cb(state, pm); irc_privmsg_cb(state, pm);
} }
if (irc_command_cb != NULL)
irc_command_cb(state, m);
tal_free(m); tal_free(m);
} }
@ -168,7 +174,9 @@ static struct io_plan *irc_connected(struct io_conn *conn, struct lightningd_sta
state->connected = true; state->connected = true;
irc_send(state, "USER", "%s 0 * :A lightning node", state->nick); irc_send(state, "USER", "%s 0 * :A lightning node", state->nick);
irc_send(state, "NICK", "%s", state->nick); irc_send(state, "NICK", "%s", state->nick);
irc_send(state, "JOIN", "#lightning-nodes");
if (irc_connect_cb != NULL)
irc_connect_cb(state);
return io_duplex(conn, return io_duplex(conn,
io_read_partial(conn, io_read_partial(conn,

4
irc.h
View file

@ -53,8 +53,10 @@ struct ircstate {
struct timerel reconnect_timeout; struct timerel reconnect_timeout;
}; };
/* Callback to register for incoming messages */ /* Callbacks to register for incoming messages, events and raw commands */
extern void (*irc_privmsg_cb)(struct ircstate *, const struct privmsg *); extern void (*irc_privmsg_cb)(struct ircstate *, const struct privmsg *);
extern void (*irc_command_cb)(struct ircstate *, const struct irccommand *);
extern void (*irc_connect_cb)(struct ircstate *);
extern void (*irc_disconnect_cb)(struct ircstate *); extern void (*irc_disconnect_cb)(struct ircstate *);
/* Send messages to IRC */ /* Send messages to IRC */