--- a/loudmouth/lm-connection.c Wed Feb 06 00:29:05 2008 +0100
+++ b/loudmouth/lm-connection.c Wed Feb 13 01:15:21 2008 +0100
@@ -73,7 +73,7 @@
GSList *handlers[LM_MESSAGE_TYPE_UNKNOWN];
/* XMPP1.0 stuff (SASL, resource binding, StartTLS) */
- gboolean use_xmpp;
+ gboolean use_sasl;
LmSASL *sasl;
gchar *resource;
LmMessageHandler *features_cb;
@@ -727,7 +727,7 @@
lm_verbose ("XMPP 1.0 stream received: %s\n",
connection->stream_id);
- connection->use_xmpp = TRUE;
+ connection->use_sasl = TRUE;
/* stream is started multiple times, but we only want
* one sasl mechanism */
@@ -1029,6 +1029,7 @@
{
LmMessageNode *bind_node;
LmMessageNode *starttls_node;
+ LmMessageNode *old_auth;
starttls_node = lm_message_node_find_child (message->node, "starttls");
if (connection->ssl && lm_ssl_get_use_starttls (connection->ssl)) {
@@ -1097,6 +1098,33 @@
}
}
+ old_auth = lm_message_node_find_child (message->node, "auth");
+ if (connection->use_sasl && old_auth) {
+ g_debug ("Server uses XEP-0078 (jabber iq auth) instead of SASL");
+ /* So the server is XMPP1.0, but doesn't support SASL and uses
+ * obsolete XEP-0078 instead. Let's cope. */
+
+ connection->use_sasl = FALSE;
+
+ if (connection->sasl) {
+ const gchar *user, *pass;
+
+ lm_sasl_get_auth_params (connection->sasl, &user, &pass);
+ if (user && pass) {
+ GError *error = NULL;
+ _lm_connection_old_auth (connection, user, pass,
+ connection->resource, &error);
+
+ if (error)
+ g_error_free (error);
+
+ }
+
+ lm_sasl_free (connection->sasl);
+ connection->sasl = NULL;
+ }
+ }
+
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
}
@@ -1142,7 +1170,7 @@
connection->keep_alive_source = NULL;
connection->keep_alive_rate = 0;
connection->socket = NULL;
- connection->use_xmpp = FALSE;
+ connection->use_sasl = FALSE;
connection->tls_started = FALSE;
connection->id_handlers = g_hash_table_new_full (g_str_hash,
@@ -1374,11 +1402,6 @@
GDestroyNotify notify,
GError **error)
{
- LmMessage *m;
- LmMessageHandler *handler;
- gboolean result;
- AuthReqData *data;
-
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (username != NULL, FALSE);
g_return_val_if_fail (password != NULL, FALSE);
@@ -1402,7 +1425,7 @@
connection->effective_jid = g_strdup_printf ("%s/%s",
connection->jid, connection->resource);
- if (connection->use_xmpp) {
+ if (connection->use_sasl) {
lm_sasl_authenticate (connection->sasl,
username, password,
connection->server,
@@ -1419,6 +1442,20 @@
return TRUE;
}
+ return _lm_connection_old_auth (connection, username, password,
+ resource, error);
+}
+
+gboolean
+_lm_connection_old_auth (LmConnection *connection, const gchar *username,
+ const gchar *password, const gchar *resource, GError **error)
+{
+ LmMessage *m;
+ AuthReqData *data;
+ LmMessageHandler *handler;
+ gboolean result;
+
+
m = connection_create_auth_req_msg (username);
data = g_new0 (AuthReqData, 1);