change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
#include "irc_log.h"
#include "log.h"
// XXX: fix this err_t crap
#define LIB_ERR_H
#include <evsql.h>
/**
* The core irc_log state
*/
static struct irc_log_ctx {
/** The database connection */
struct evsql *db;
} _ctx;
static void on_PRIVMSG (const struct irc_line *line, void *arg)
{
struct irc_log_ctx *ctx = arg;
(void) ctx;
// log it! :P
log_debug("%s: %s: %s", line->prefix, line->args[0], line->args[1]);
}
static struct irc_cmd_handler _cmd_handlers[] = {
{ "PRIVMSG", &on_PRIVMSG },
{ NULL, NULL }
};
err_t irc_log_init (struct event_base *ev_base, const struct irc_log_info *info)
{
struct irc_log_ctx *ctx = &_ctx;
err_t err;
// open the database connection
if (info->db_info) {
log_info("connect to database: %s", info->db_info);
if ((ctx->db = evsql_new_pq(ev_base, info->db_info, NULL, NULL)) == NULL)
return ERR_EVSQL_NEW_PQ;
}
if (info->channel) {
log_info("log channel: %s", irc_chan_name(info->channel));
}
// register for events
// XXX: need irc_chan API for this
if ((err = irc_conn_add_cmd_handlers(info->channel->net->conn, _cmd_handlers, ctx)))
return err;
// ok
return SUCCESS;
}