Mercurial > pidgin.yaz
changeset 23378:e12600d6b902
Cleanup some duplication and simplify this.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 18 Jun 2008 03:14:47 +0000 |
parents | b175f6441bba |
children | 6c728443b426 |
files | libpurple/protocols/jabber/jabber.c |
diffstat | 1 files changed, 52 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c Wed Jun 18 00:24:44 2008 +0000 +++ b/libpurple/protocols/jabber/jabber.c Wed Jun 18 03:14:47 2008 +0000 @@ -273,70 +273,10 @@ purple_circ_buffer_mark_read(js->write_buffer, ret); } -void jabber_send_raw(JabberStream *js, const char *data, int len) +static gboolean do_jabber_send_raw(JabberStream *js, const char *data, int len) { int ret; - - /* because printing a tab to debug every minute gets old */ - if(strcmp(data, "\t")) - purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s\n", - js->gsc ? " (ssl)" : "", data); - - /* If we've got a security layer, we need to encode the data, - * splitting it on the maximum buffer length negotiated */ - - purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data); - if (data == NULL) - return; - -#ifdef HAVE_CYRUS_SASL - if (js->sasl_maxbuf>0) { - int pos; - - if (!js->gsc && js->fd<0) - return; - pos = 0; - if (len == -1) - len = strlen(data); - while (pos < len) { - int towrite; - const char *out; - unsigned olen; - - if ((len - pos) < js->sasl_maxbuf) - towrite = len - pos; - else - towrite = js->sasl_maxbuf; - - sasl_encode(js->sasl, &data[pos], towrite, &out, &olen); - pos += towrite; - - if (js->writeh == 0) - ret = jabber_do_send(js, out, olen); - else { - ret = -1; - errno = EAGAIN; - } - - if (ret < 0 && errno != EAGAIN) - purple_connection_error_reason (js->gc, - PURPLE_CONNECTION_ERROR_NETWORK_ERROR, - _("Write error")); - else if (ret < olen) { - if (ret < 0) - ret = 0; - if (js->writeh == 0) - js->writeh = purple_input_add( - js->gsc ? js->gsc->fd : js->fd, - PURPLE_INPUT_WRITE, - jabber_send_cb, js); - purple_circ_buffer_append(js->write_buffer, - out + ret, olen - ret); - } - } - return; - } -#endif + gboolean success = TRUE; if (len == -1) len = strlen(data); @@ -348,11 +288,12 @@ errno = EAGAIN; } - if (ret < 0 && errno != EAGAIN) + if (ret < 0 && errno != EAGAIN) { purple_connection_error_reason (js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Write error")); - else if (ret < len) { + success = FALSE; + } else if (ret < len) { if (ret < 0) ret = 0; if (js->writeh == 0) @@ -362,7 +303,53 @@ purple_circ_buffer_append(js->write_buffer, data + ret, len - ret); } - return; + + return success; +} + +void jabber_send_raw(JabberStream *js, const char *data, int len) +{ + + /* because printing a tab to debug every minute gets old */ + if(strcmp(data, "\t")) + purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s\n", + js->gsc ? " (ssl)" : "", data); + + /* If we've got a security layer, we need to encode the data, + * splitting it on the maximum buffer length negotiated */ + + purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data); + if (data == NULL) + return; + +#ifdef HAVE_CYRUS_SASL + if (js->sasl_maxbuf>0) { + int pos = 0; + + if (!js->gsc && js->fd<0) + return; + + if (len == -1) + len = strlen(data); + + while (pos < len) { + int towrite; + const char *out; + unsigned olen; + + towrite = MIN((len - pos), js->sasl_maxbuf); + + sasl_encode(js->sasl, &data[pos], towrite, &out, &olen); + pos += towrite; + + if (!do_jabber_send_raw(js, out, olen)) + break; + } + return; + } +#endif + + do_jabber_send_raw(js, data, len); } int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len)