src/irc_net.c
changeset 27 e6639132bead
parent 26 aec062af155d
child 28 9c1050bc8709
equal deleted inserted replaced
26:aec062af155d 27:e6639132bead
     1 #include "irc_net.h"
     1 #include "irc_net.h"
     2 #include "log.h"
     2 #include "log.h"
     3 
     3 
     4 #include <stdlib.h>
     4 #include <stdlib.h>
     5 #include <string.h>
     5 #include <string.h>
       
     6 
       
     7 static void irc_net_conn_registered (struct irc_conn *conn, void *arg)
       
     8 {
       
     9     struct irc_net *net = arg;
       
    10     struct irc_chan *chan = NULL;
       
    11     err_t err;
       
    12 
       
    13     (void) conn;
       
    14 
       
    15     // join our channels
       
    16     TAILQ_FOREACH(chan, &net->channels, node) {
       
    17         if ((err = irc_chan_join(chan)))
       
    18             // XXX: fuck...
       
    19             FATAL_ERR(err, "irc_chan_join failed");
       
    20     }
       
    21 }
       
    22 
       
    23 /**
       
    24  * Our irc_conn_callbacks list
       
    25  */
       
    26 struct irc_conn_callbacks _conn_callbacks = {
       
    27     .on_registered  = &irc_net_conn_registered,
       
    28 };
     6 
    29 
     7 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err)
    30 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err)
     8 {
    31 {
     9     struct irc_net *net;
    32     struct irc_net *net;
    10     struct sock_stream *sock;
    33     struct sock_stream *sock;
    32     }
    55     }
    33 
    56 
    34     log_info("connected, registering");
    57     log_info("connected, registering");
    35 
    58 
    36     // create the irc connection state
    59     // create the irc connection state
    37     if (irc_conn_create(&net->conn, sock, &info->register_info, err))
    60     if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err))
       
    61         goto error;
       
    62 
       
    63     // register
       
    64     if ((ERROR_CODE(err) = irc_conn_register(net->conn, &info->register_info)))
    38         goto error;
    65         goto error;
    39     
    66     
    40     // ok
    67     // ok
    41     *net_ptr = net;
    68     *net_ptr = net;
    42 
    69 
    58         // XXX: we lose error info
    85         // XXX: we lose error info
    59         return NULL;
    86         return NULL;
    60     
    87     
    61     // add to network list
    88     // add to network list
    62     TAILQ_INSERT_TAIL(&net->channels, chan, node);
    89     TAILQ_INSERT_TAIL(&net->channels, chan, node);
    63 
    90     
    64     // then join
    91     // currently connected?
    65     if ((ERROR_CODE(&err) = irc_chan_join(chan)))
    92     if (net->conn && net->conn->registered) {
    66         // XXX
    93         // then join
    67         return NULL;
    94         if ((ERROR_CODE(&err) = irc_chan_join(chan)))
       
    95             // XXX
       
    96             return NULL;
       
    97     }
    68 
    98 
    69     // ok, return
    99     // ok, return
    70     return chan;
   100     return chan;
    71 }
   101 }
    72 
   102