28 }; |
28 }; |
29 |
29 |
30 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) |
31 { |
31 { |
32 struct irc_net *net; |
32 struct irc_net *net; |
33 struct sock_stream *sock; |
33 struct sock_stream *sock = NULL; |
34 |
34 |
35 // allocate |
35 // allocate |
36 if ((net = calloc(1, sizeof(*net))) == NULL) |
36 if ((net = calloc(1, sizeof(*net))) == NULL) |
37 return SET_ERROR(err, ERR_CALLOC); |
37 return SET_ERROR(err, ERR_CALLOC); |
38 |
38 |
52 if (sock_tcp_connect(&sock, info->hostname, info->service, err)) |
52 if (sock_tcp_connect(&sock, info->hostname, info->service, err)) |
53 goto error; |
53 goto error; |
54 |
54 |
55 } |
55 } |
56 |
56 |
57 log_info("connected, registering"); |
|
58 |
|
59 // create the irc connection state |
57 // create the irc connection state |
60 if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err)) |
58 if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err)) |
61 goto error; |
59 goto error; |
62 |
60 |
63 // register |
61 // register |
|
62 log_info("connected, registering"); |
|
63 |
64 if ((ERROR_CODE(err) = irc_conn_register(net->conn, &info->register_info))) |
64 if ((ERROR_CODE(err) = irc_conn_register(net->conn, &info->register_info))) |
65 goto error; |
65 goto error; |
66 |
66 |
67 // ok |
67 // ok |
68 *net_ptr = net; |
68 *net_ptr = net; |
69 |
69 |
70 return SUCCESS; |
70 return SUCCESS; |
71 |
71 |
72 error: |
72 error: |
73 // XXX: cleanup |
73 // cleanup |
|
74 if (net->conn) |
|
75 // irc_conn takes care of the socket as well |
|
76 irc_conn_destroy(net->conn); |
|
77 |
|
78 else if (sock) |
|
79 // we need to clean up the socket ourself |
|
80 sock_stream_release(sock); |
|
81 |
|
82 // release our state |
|
83 free(net); |
74 |
84 |
75 return ERROR_CODE(err); |
85 return ERROR_CODE(err); |
76 } |
86 } |
77 |
87 |
78 struct irc_chan* irc_net_add_chan (struct irc_net *net, const struct irc_chan_info *info) |
88 struct irc_chan* irc_net_add_chan (struct irc_net *net, const struct irc_chan_info *info) |