src/irc_net.c
changeset 37 4fe4a3c4496e
parent 28 9c1050bc8709
child 38 0c2e0cb46c3a
equal deleted inserted replaced
36:791d7a5532e2 37:4fe4a3c4496e
    23 /**
    23 /**
    24  * Our irc_conn_callbacks list
    24  * Our irc_conn_callbacks list
    25  */
    25  */
    26 struct irc_conn_callbacks _conn_callbacks = {
    26 struct irc_conn_callbacks _conn_callbacks = {
    27     .on_registered  = &irc_net_conn_registered,
    27     .on_registered  = &irc_net_conn_registered,
       
    28 };
       
    29 
       
    30 /**
       
    31  * :nm JOIN <channel>
       
    32  */ 
       
    33 static void irc_net_on_JOIN (const struct irc_line *line, void *arg)
       
    34 {
       
    35     struct irc_net *net = arg;
       
    36     struct irc_chan *chan;
       
    37 
       
    38     // look up channel
       
    39     if ((chan = irc_net_get_chan(net, line->args[0])) == NULL) {
       
    40         log_warn("unkown channel: %s", line->args[0]);
       
    41         return;
       
    42     }
       
    43 
       
    44     // propagate
       
    45     irc_cmd_invoke(&chan->handlers, line);
       
    46 }
       
    47 
       
    48 /**
       
    49  * Our irc_cmd handler list
       
    50  */
       
    51 static struct irc_cmd_handler _cmd_handlers[] = {
       
    52     {   "JOIN",     &irc_net_on_JOIN        },
       
    53     {   NULL,       NULL                    }
    28 };
    54 };
    29 
    55 
    30 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err)
    56 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err)
    31 {
    57 {
    32     struct irc_net *net;
    58     struct irc_net *net;
    54 
    80 
    55     }
    81     }
    56 
    82 
    57     // create the irc connection state
    83     // create the irc connection state
    58     if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err))
    84     if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err))
       
    85         goto error;
       
    86 
       
    87     // add our command handlers
       
    88     if ((ERROR_CODE(err) = irc_conn_add_cmd_handlers (net->conn, _cmd_handlers, net)))
    59         goto error;
    89         goto error;
    60 
    90 
    61     // register
    91     // register
    62     log_info("connected, registering");
    92     log_info("connected, registering");
    63 
    93