void xmpp_connect() { GError *err = NULL; const gchar *conf_server; LmSSL *ssl; int use_ssl, use_tls, port; const gchar *jid; wantconnection = 1; if (connection && lm_connection_is_open(connection)) { ui_print("connect: connection alredy opened, aborting\n"); return; } if (connection == NULL) connection = lm_connection_new(NULL); use_ssl = get_settings_int(USE_SSL); use_tls = get_settings_int(USE_TLS); jid = get_settings_str(JID); port = get_settings_int(PORT); if (use_ssl || use_tls) { if (!lm_ssl_is_supported()) { ui_print("Error: SSL not available\n"); } else if (use_ssl && use_tls) { ui_print("Error: You can't use ssl and tls at the same time"); } else { ssl = lm_ssl_new(NULL, ssl_cb, NULL, NULL); lm_ssl_use_starttls(ssl, !use_ssl, use_tls); lm_connection_set_ssl(connection, ssl); lm_ssl_unref(ssl); } } if (!port) { port = (use_ssl) ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT; } lm_connection_set_port(connection, port); lm_connection_set_jid(connection, jid); lm_connection_set_keep_alive_rate(connection, 30); lm_connection_set_disconnect_function(connection, connection_disconnect_cb, NULL, NULL); conf_server = get_settings_str(SERVER); if (!conf_server) { ui_print("ERROR: Insufficient configuration, " "connecting aborted (server not set)\n"); return; } else { if(!lm_connection_get_server(connection)) lm_connection_set_server(connection, conf_server); } ui_print("Opening connection to %s\n", conf_server); if(!lm_connection_open(connection, (LmResultFunction)connection_open_cb, NULL, NULL, &err)) { ui_print("Error opening connection: %s\n", err->message); g_error_free(err); } } /* xmpp_connect */
SERVER_REC * xmpp_server_init_connect(SERVER_CONNECT_REC *connrec) { XMPP_SERVER_REC *server; XMPP_SERVER_CONNECT_REC *conn = (XMPP_SERVER_CONNECT_REC *)connrec; char *recoded; if (conn->address == NULL || conn->address[0] == '\0') return NULL; if (conn->nick == NULL || conn->nick[0] == '\0') return NULL; g_return_val_if_fail(IS_XMPP_SERVER_CONNECT(conn), NULL); server = g_new0(XMPP_SERVER_REC, 1); server->chat_type = XMPP_PROTOCOL; server->user = xmpp_extract_user(conn->nick); server->domain = xmpp_have_domain(conn->nick) ? xmpp_extract_domain(conn->nick) : g_strdup(conn->address); server->jid = xmpp_have_domain(conn->nick) ? xmpp_strip_resource(conn->nick) : g_strconcat(server->user, "@", server->domain, (void *)NULL); server->resource = xmpp_extract_resource(conn->nick); if (server->resource == NULL) server->resource = g_strdup("irssi-xmpp"); server->priority = settings_get_int("xmpp_priority"); if (xmpp_priority_out_of_bound(server->priority)) server->priority = 0; server->ping_id = NULL; server->server_features = NULL; server->my_resources = NULL; server->roster = NULL; server->msg_handlers = NULL; server->channels_join = channels_join; server->isnickflag = isnickflag_func; server->ischannel = ischannel_func; server->get_nick_flags = get_nick_flags; server->send_message = send_message; server->connrec = (XMPP_SERVER_CONNECT_REC *)conn; server_connect_ref(connrec); /* don't use irssi's sockets */ server->connrec->no_connect = TRUE; server->connect_pid = -1; if (server->connrec->port <= 0) server->connrec->port = (server->connrec->use_ssl) ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT; if (conn->real_jid == NULL) conn->real_jid = conn->nick; else g_free(conn->nick); conn->nick = g_strdup(settings_get_bool("xmpp_set_nick_as_username") ? server->user : server->jid); /* init loudmouth connection structure */ server->lmconn = lm_connection_new(NULL); lm_connection_set_server(server->lmconn, server->connrec->address); lm_connection_set_port(server->lmconn, server->connrec->port); recoded = xmpp_recode_out(server->jid); lm_connection_set_jid(server->lmconn, recoded); g_free(recoded); lm_connection_set_keep_alive_rate(server->lmconn, 30); server->timeout_tag = 0; server_connect_init((SERVER_REC *)server); server->connect_tag = 1; return (SERVER_REC *)server; }