Exemplo n.º 1
0
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 */
Exemplo n.º 2
0
void jabber_fetch_roster(gpointer user_data)
{
	LmMessage *m = NULL;
	LmMessageNode *node = NULL;

	print_debug("jabber_fetch_roster a");
	print_debug("jabber: Fetching roster. %s", lm_connection_get_server(jabber_data.connection));

	m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET);
	node = lm_message_node_add_child(m->node, "query", NULL);
	lm_message_node_set_attribute(m->node, "id", "fetch_roster");
	lm_message_node_set_attribute(node, "xmlns", "jabber:iq:roster");

	if (!lm_connection_send(jabber_data.connection, m, NULL))
		print_debug("jabber: Can't fetch roster (lm_connection_send() failed).\n");
	else
		action_queue_add("fetch_roster", "result", action_roster_fetch_result, user_data, FALSE);

	print_debug("jabber_fetch_roster b");
	lm_message_unref(m);
	print_debug("jabber_fetch_roster c");
}
Exemplo n.º 3
0
gboolean
_lm_proxy_connect_cb (GIOChannel *source, GIOCondition condition, gpointer data)
{
    LmConnection  *connection;
    LmConnectData *connect_data;
    LmProxy       *proxy;
    int            error;
    socklen_t      len;

    connect_data = (LmConnectData *) data;
    connection = connect_data->connection;
    proxy = lm_connection_get_proxy (connection);

    g_return_val_if_fail (proxy != NULL, FALSE);

    if (condition == G_IO_ERR) {
        len = sizeof (error);
        _lm_sock_get_error (connect_data->fd, &error, &len);
        _lm_old_socket_failed_with_error (connect_data, error);
        return FALSE;
    } else if (condition == G_IO_OUT) {
        if (!proxy_negotiate (lm_connection_get_proxy (connection), connect_data->fd, lm_connection_get_server (connection), lm_connection_get_port (connection))) {
            _lm_old_socket_failed (connect_data);
            return FALSE;
        }

        proxy->io_watch = g_io_add_watch (connect_data->io_channel,
                                          G_IO_IN|G_IO_ERR,
                                          (GIOFunc) proxy_read_cb,
                                          connect_data);
    } else {
        g_assert_not_reached ();
    }

    return FALSE;
}