terom@25: #include "irc_net.h" terom@25: #include "log.h" terom@25: terom@25: #include terom@25: terom@25: err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err) terom@25: { terom@25: struct irc_net *net; terom@25: struct sock_stream *sock; terom@25: terom@25: // allocate terom@25: if ((net = calloc(1, sizeof(*net))) == NULL) terom@25: return SET_ERROR(err, ERR_CALLOC); terom@25: terom@25: // XXX: over-simplified blocking connect terom@25: if (info->use_ssl) { terom@25: log_info("connecting to [%s]:%s using SSL", info->hostname, info->service); terom@25: terom@25: if (sock_ssl_connect(&sock, info->hostname, info->service, err)) terom@25: goto error; terom@25: terom@25: } else { terom@25: log_info("connecting to [%s]:%s", info->hostname, info->service); terom@25: terom@25: if (sock_tcp_connect(&sock, info->hostname, info->service, err)) terom@25: goto error; terom@25: terom@25: } terom@25: terom@25: log_info("connected, registering"); terom@25: terom@25: // create the irc connection state terom@25: if (irc_conn_create(&net->conn, sock, &info->register_info, err)) terom@25: goto error; terom@25: terom@25: // ok terom@25: *net_ptr = net; terom@25: terom@25: return SUCCESS; terom@25: terom@25: error: terom@25: // XXX: cleanup terom@25: terom@25: return ERROR_CODE(err); terom@25: } terom@25: