src/irc_log.c
changeset 38 0c2e0cb46c3a
parent 37 4fe4a3c4496e
child 45 71e65564afd2
equal deleted inserted replaced
37:4fe4a3c4496e 38:0c2e0cb46c3a
    12     /** The database connection */
    12     /** The database connection */
    13     struct evsql *db;
    13     struct evsql *db;
    14 
    14 
    15 } _ctx;
    15 } _ctx;
    16 
    16 
    17 static void on_PRIVMSG (const struct irc_line *line, void *arg)
    17 static void on_chan_msg (struct irc_chan *chan, const char *prefix, const char *message, void *arg)
    18 {
    18 {
    19     struct irc_log_ctx *ctx = arg;
    19     struct irc_log_ctx *ctx = arg;
    20 
    20 
    21     (void) ctx;
    21     (void) ctx;
    22 
    22 
    23     // log it! :P
    23     // log it! :P
    24     log_debug("%s: %s: %s", line->prefix, line->args[0], line->args[1]);
    24     log_debug("%s: %s: %s", prefix, irc_chan_name(chan), message);
    25 }
    25 }
    26 
    26 
    27 static struct irc_cmd_handler _cmd_handlers[] = {
    27 static struct irc_chan_callbacks _chan_callbacks = {
    28     {   "PRIVMSG",  &on_PRIVMSG     },
    28     .on_msg         = on_chan_msg,
    29     {   NULL,       NULL            }
       
    30 };
    29 };
    31 
    30 
    32 err_t irc_log_init (struct event_base *ev_base, const struct irc_log_info *info)
    31 err_t irc_log_init (struct event_base *ev_base, const struct irc_log_info *info)
    33 {
    32 {
    34     struct irc_log_ctx *ctx = &_ctx;
    33     struct irc_log_ctx *ctx = &_ctx;
    44     
    43     
    45     if (info->channel) {
    44     if (info->channel) {
    46         log_info("log channel: %s", irc_chan_name(info->channel));
    45         log_info("log channel: %s", irc_chan_name(info->channel));
    47     }
    46     }
    48 
    47 
    49     // register for events
    48     // add channel callbacks
    50     // XXX: need irc_chan API for this
    49     if ((err = irc_chan_add_callbacks(info->channel, &_chan_callbacks, ctx)))
    51     if ((err = irc_conn_add_cmd_handlers(info->channel->net->conn, _cmd_handlers, ctx)))
    50         goto error;
    52         return err;
       
    53 
    51 
    54     // ok
    52     // ok
    55     return SUCCESS;
    53     return SUCCESS;
       
    54 
       
    55 error:
       
    56     // XXX: cleanup
       
    57     
       
    58     return err;
    56 }
    59 }
    57 
    60