Mercurial > pidgin.yaz
changeset 30277:d64a0d8ff36d
merge of '22ad9aecc804e89b1101cde696e58490a7efd603'
and '4c5c524129704ad1119bd51ae362bdb123bdaf75'
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 01 May 2010 20:10:21 +0000 |
parents | 4428b676c698 (current diff) 417a4e912738 (diff) |
children | 8b167aaf3457 |
files | |
diffstat | 4 files changed, 83 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/auth.c Sat May 01 19:57:00 2010 +0000 +++ b/libpurple/protocols/jabber/auth.c Sat May 01 20:10:21 2010 +0000 @@ -45,35 +45,6 @@ JabberIqType type, const char *id, xmlnode *packet, gpointer data); -gboolean -jabber_process_starttls(JabberStream *js, xmlnode *packet) -{ - PurpleAccount *account; - xmlnode *starttls; - - account = purple_connection_get_account(js->gc); - - if((starttls = xmlnode_get_child(packet, "starttls"))) { - if(purple_ssl_is_supported()) { - jabber_send_raw(js, - "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); - return TRUE; - } else if(xmlnode_get_child(starttls, "required")) { - purple_connection_error_reason(js->gc, - PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, - _("Server requires TLS/SSL, but no TLS/SSL support was found.")); - return TRUE; - } else if(purple_account_get_bool(account, "require_tls", JABBER_DEFAULT_REQUIRE_TLS)) { - purple_connection_error_reason(js->gc, - PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, - _("You require encryption, but no TLS/SSL support was found.")); - return TRUE; - } - } - - return FALSE; -} - static void finish_plaintext_authentication(JabberStream *js) { JabberIq *iq;
--- a/libpurple/protocols/jabber/auth.h Sat May 01 19:57:00 2010 +0000 +++ b/libpurple/protocols/jabber/auth.h Sat May 01 20:10:21 2010 +0000 @@ -45,7 +45,6 @@ void (*dispose)(JabberStream *js); }; -gboolean jabber_process_starttls(JabberStream *js, xmlnode *packet); void jabber_auth_start(JabberStream *js, xmlnode *packet); void jabber_auth_start_old(JabberStream *js); void jabber_auth_handle_challenge(JabberStream *js, xmlnode *packet);
--- a/libpurple/protocols/jabber/auth_plain.c Sat May 01 19:57:00 2010 +0000 +++ b/libpurple/protocols/jabber/auth_plain.c Sat May 01 20:10:21 2010 +0000 @@ -47,9 +47,9 @@ } response = g_string_new(""); - response = g_string_append_len(response, "\0", 1); + response = g_string_append_c(response, '\0'); response = g_string_append(response, js->user->node); - response = g_string_append_len(response, "\0", 1); + response = g_string_append_c(response, '\0'); response = g_string_append(response, purple_connection_get_password(js->gc));
--- a/libpurple/protocols/jabber/jabber.c Sat May 01 19:57:00 2010 +0000 +++ b/libpurple/protocols/jabber/jabber.c Sat May 01 20:10:21 2010 +0000 @@ -210,6 +210,35 @@ return purple_strreplace(input, "__HOSTNAME__", hostname); } +static gboolean +jabber_process_starttls(JabberStream *js, xmlnode *packet) +{ + PurpleAccount *account; + xmlnode *starttls; + + account = purple_connection_get_account(js->gc); + + if((starttls = xmlnode_get_child(packet, "starttls"))) { + if(purple_ssl_is_supported()) { + jabber_send_raw(js, + "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>", -1); + return TRUE; + } else if(xmlnode_get_child(starttls, "required")) { + purple_connection_error_reason(js->gc, + PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, + _("Server requires TLS/SSL, but no TLS/SSL support was found.")); + return TRUE; + } else if(purple_account_get_bool(account, "require_tls", JABBER_DEFAULT_REQUIRE_TLS)) { + purple_connection_error_reason(js->gc, + PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, + _("You require encryption, but no TLS/SSL support was found.")); + return TRUE; + } + } + + return FALSE; +} + void jabber_stream_features_parse(JabberStream *js, xmlnode *packet) { if(xmlnode_get_child(packet, "starttls")) { @@ -364,8 +393,7 @@ int ret; gboolean success = TRUE; - if (len == -1) - len = strlen(data); + g_return_val_if_fail(len > 0, FALSE); if (js->state == JABBER_STREAM_CONNECTED) jabber_stream_restart_inactivity_timer(js); @@ -409,6 +437,12 @@ void jabber_send_raw(JabberStream *js, const char *data, int len) { + PurpleConnection *gc; + PurpleAccount *account; + + gc = js->gc; + account = purple_connection_get_account(gc); + /* because printing a tab to debug every minute gets old */ if(strcmp(data, "\t")) { const char *username; @@ -436,9 +470,9 @@ *data_start = '\0'; } - username = purple_connection_get_display_name(js->gc); + username = purple_connection_get_display_name(gc); if (!username) - username = purple_account_get_username(purple_connection_get_account(js->gc)); + username = purple_account_get_username(account); purple_debug_misc("jabber", "Sending%s (%s): %s%s%s\n", jabber_stream_is_ssl(js) ? " (ssl)" : "", username, @@ -449,10 +483,13 @@ g_free(text); } - purple_signal_emit(purple_connection_get_prpl(js->gc), "jabber-sending-text", js->gc, &data); + purple_signal_emit(purple_connection_get_prpl(gc), "jabber-sending-text", gc, &data); if (data == NULL) return; + if (len == -1) + len = strlen(data); + /* If we've got a security layer, we need to encode the data, * splitting it on the maximum buffer length negotiated */ #ifdef HAVE_CYRUS_SASL @@ -460,21 +497,36 @@ int pos = 0; if (!js->gsc && js->fd<0) - return; - - if (len == -1) - len = strlen(data); + g_return_if_reached(); while (pos < len) { int towrite; const char *out; unsigned olen; + int rc; towrite = MIN((len - pos), js->sasl_maxbuf); - sasl_encode(js->sasl, &data[pos], towrite, &out, &olen); + rc = sasl_encode(js->sasl, &data[pos], towrite, + &out, &olen); + if (rc != SASL_OK) { + gchar *error = + g_strdup_printf(_("SASL error: %s"), + sasl_errdetail(js->sasl)); + purple_debug_error("jabber", + "sasl_encode error %d: %s\n", rc, + sasl_errdetail(js->sasl)); + purple_connection_error_reason(gc, + PURPLE_CONNECTION_ERROR_NETWORK_ERROR, + error); + g_free(error); + return; + } pos += towrite; + /* do_jabber_send_raw returns FALSE when it throws a + * connection error. + */ if (!do_jabber_send_raw(js, out, olen)) break; } @@ -482,9 +534,6 @@ } #endif - if (len == -1) - len = strlen(data); - if (js->bosh) jabber_bosh_connection_send_raw(js->bosh, data); else @@ -493,7 +542,7 @@ int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len) { - JabberStream *js = (JabberStream*)gc->proto_data; + JabberStream *js = purple_connection_get_protocol_data(gc); jabber_send_raw(js, buf, len); return len; } @@ -597,7 +646,7 @@ jabber_recv_cb(gpointer data, gint source, PurpleInputCondition condition) { PurpleConnection *gc = data; - JabberStream *js = gc->proto_data; + JabberStream *js = purple_connection_get_protocol_data(gc); int len; static char buf[4096]; @@ -607,14 +656,26 @@ if((len = read(js->fd, buf, sizeof(buf) - 1)) > 0) { gc->last_received = time(NULL); #ifdef HAVE_CYRUS_SASL - if (js->sasl_maxbuf>0) { + if (js->sasl_maxbuf > 0) { const char *out; unsigned int olen; - sasl_decode(js->sasl, buf, len, &out, &olen); - if (olen>0) { + int rc; + + rc = sasl_decode(js->sasl, buf, len, &out, &olen); + if (rc != SASL_OK) { + gchar *error = + g_strdup_printf(_("SASL error: %s"), + sasl_errdetail(js->sasl)); + purple_debug_error("jabber", + "sasl_decode_error %d: %s\n", rc, + sasl_errdetail(js->sasl)); + purple_connection_error_reason(gc, + PURPLE_CONNECTION_ERROR_NETWORK_ERROR, + error); + } else if (olen > 0) { purple_debug_info("jabber", "RecvSASL (%u): %s\n", olen, out); - jabber_parser_process(js,out,olen); - if(js->reinit) + jabber_parser_process(js, out, olen); + if (js->reinit) jabber_stream_init(js); } return;