From ade38ae188238bdb62600283eb9f8b8374546a11 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 26 Aug 2008 04:44:19 +0000 Subject: [PATCH] Small patch to handler_fire_stanza() from Matthew Wild . prev was not advanced along with item. --- SConstruct | 4 ++-- src/handler.c | 2 ++ src/tls_dummy.c | 5 ----- src/tls_gnutls.c | 35 +++++++++++++++++++++++++++-------- src/tls_openssl.c | 5 ----- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/SConstruct b/SConstruct index 0e4250b..d5bfd81 100644 --- a/SConstruct +++ b/SConstruct @@ -48,7 +48,7 @@ Sources = Split(""" util.c thread.c snprintf.c - tls_dummy.c + tls_gnutls.c oocontext.cpp oostanza.cpp """) @@ -98,7 +98,7 @@ Default(strophe) exenv = env.Clone() exenv.Append(CPPPATH=['.']) -exenv.Append(LIBS=["strophe", "expat"]) +exenv.Append(LIBS=["strophe", "expat", "gnutls"]) exenv.Append(LIBPATH=["."]) if exenv["PLATFORM"] == "win32": exenv.Append(LIBS=["ws2_32", "winmm"]) diff --git a/src/handler.c b/src/handler.c index 55c7ad4..4a77f9c 100644 --- a/src/handler.c +++ b/src/handler.c @@ -89,12 +89,14 @@ void handler_fire_stanza(xmpp_conn_t * const conn, while (item) { /* skip newly added handlers */ if (!item->enabled) { + prev = item; item = item->next; continue; } /* don't call user handlers until authentication succeeds */ if (item->user_handler && !conn->authenticated) { + prev = item; item = item->next; continue; } diff --git a/src/tls_dummy.c b/src/tls_dummy.c index 13ccd69..8376823 100644 --- a/src/tls_dummy.c +++ b/src/tls_dummy.c @@ -78,11 +78,6 @@ int tls_write(tls_t *tls, const void * const buff, const size_t len) return -1; } -int tls_clear_pending_write(tls_t *tls) -{ - return -1; -} - int tls_is_recoverable(int error) { return 0; diff --git a/src/tls_gnutls.c b/src/tls_gnutls.c index 7fc13b5..044e34b 100644 --- a/src/tls_gnutls.c +++ b/src/tls_gnutls.c @@ -24,6 +24,7 @@ struct _tls { xmpp_ctx_t *ctx; /* do we need this? */ + int error; sock_t sock; gnutls_session_t session; gnutls_certificate_credentials_t cred; @@ -53,6 +54,7 @@ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock) if (tls) { tls->ctx = ctx; + tls->error = 0; tls->sock = sock; gnutls_init(&tls->session, GNUTLS_CLIENT); @@ -63,7 +65,7 @@ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock) /* fixme: this may require setting a callback on win32? */ gnutls_transport_set_ptr(tls->session, - (gnutls_transport_ptr_t)sock); + (gnutls_transport_ptr_t)sock); } return tls; @@ -93,7 +95,14 @@ int tls_set_credentials(tls_t *tls, const char *cafilename) int tls_start(tls_t *tls) { - return gnutls_handshake(tls->session); + int ret; + xmpp_debug(tls->ctx, "TLS", "tls starting"); + ret = gnutls_handshake(tls->session); + if (ret < 0) { + tls->error = ret; + return 0; + } + return 1; } int tls_stop(tls_t *tls) @@ -101,17 +110,13 @@ int tls_stop(tls_t *tls) return gnutls_bye(tls->session, GNUTLS_SHUT_RDWR); } -int tls_error(tls_t *tls) -{ - /* todo: some kind of error polling/dump */ - return 0; -} - int tls_read(tls_t *tls, void * const buff, const size_t len) { int ret; + xmpp_debug(tls->ctx, "TLS", "tls_read called"); ret = gnutls_record_recv(tls->session, buff, len); + xmpp_debug(tls->ctx, "TLS", "tls_read returned %d", ret); return ret; } @@ -125,3 +130,17 @@ int tls_write(tls_t *tls, const void * const buff, const size_t len) return ret; } +int tls_clear_pending_write(tls_t *tls) +{ + return 0; +} + +int tls_error(tls_t *tls) +{ + return tls->error; +} + +int tls_is_recoverable(int error) +{ + return sock_is_recoverable(error); +} diff --git a/src/tls_openssl.c b/src/tls_openssl.c index c567fe9..3806895 100644 --- a/src/tls_openssl.c +++ b/src/tls_openssl.c @@ -189,11 +189,6 @@ int tls_stop(tls_t *tls) return 1; } -int tls_error(tls_t *tls) -{ - return tls->lasterror; -} - int tls_is_recoverable(int error) { return (error == SSL_ERROR_NONE || error == SSL_ERROR_WANT_READ