Mercurial > pidgin.yaz
changeset 19997:6e93a79b2ae5
Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 13 Sep 2007 21:34:55 +0000 |
parents | c9f994a88f5f |
children | 7baa2bc64226 |
files | autogen.sh libpurple/protocols/simple/simple.c libpurple/protocols/simple/simple.h |
diffstat | 3 files changed, 66 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/autogen.sh Thu Sep 13 04:32:19 2007 +0000 +++ b/autogen.sh Thu Sep 13 21:34:55 2007 +0000 @@ -58,7 +58,7 @@ done libtoolize -c -f --automake -glib-gettextize --force --copy +glib-gettextize --force --copy --previous intltoolize --force --copy aclocal $ACLOCAL_FLAGS || exit; autoheader || exit;
--- a/libpurple/protocols/simple/simple.c Thu Sep 13 04:32:19 2007 +0000 +++ b/libpurple/protocols/simple/simple.c Thu Sep 13 21:34:55 2007 +0000 @@ -693,19 +693,24 @@ } static void do_register_exp(struct simple_account_data *sip, int expire) { - char *uri = g_strdup_printf("sip:%s", sip->servername); - char *to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); - char *contact = get_contact(sip); - char *hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire); + char *uri, *to, *contact, *hdr; + + /* Set our default expiration to 900, + * as done in the initialization of the simple_account_data + * structure. + */ + if (!expire) + expire = 900; + + sip->reregister = time(NULL) + expire - 50; + + uri = g_strdup_printf("sip:%s", sip->servername); + to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); + contact = get_contact(sip); + hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire); g_free(contact); - sip->registerstatus = 1; - - if(expire) { - sip->reregister = time(NULL) + expire - 50; - } else { - sip->reregister = time(NULL) + 600; - } + sip->registerstatus = SIMPLE_REGISTER_SENT; send_sip_request(sip->gc, "REGISTER", uri, to, hdr, "", NULL, process_register_response); @@ -1013,12 +1018,12 @@ purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); switch (msg->response) { case 200: - if(sip->registerstatus < 3) { /* registered */ + if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */ if(purple_account_get_bool(sip->account, "dopublish", TRUE)) { send_publish(sip); } } - sip->registerstatus = 3; + sip->registerstatus = SIMPLE_REGISTER_COMPLETE; purple_connection_set_state(sip->gc, PURPLE_CONNECTED); /* get buddies from blist */ @@ -1032,16 +1037,29 @@ break; case 401: - if(sip->registerstatus != 2) { + if(sip->registerstatus != SIMPLE_REGISTER_RETRY) { purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries); - if(sip->registrar.retries > 3) { + if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { + purple_debug_info("simple", "Setting wants_to_die to true.\n"); sip->gc->wants_to_die = TRUE; purple_connection_error(sip->gc, _("Incorrect password.")); return TRUE; } tmp = sipmsg_find_header(msg, "WWW-Authenticate"); fill_auth(sip, tmp, &sip->registrar); - sip->registerstatus = 2; + sip->registerstatus = SIMPLE_REGISTER_RETRY; + do_register(sip); + } + break; + default: + if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { + purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); + if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { + sip->gc->wants_to_die = TRUE; + purple_connection_error(sip->gc, _("Unknown server response.")); + return TRUE; + } + sip->registerstatus = SIMPLE_REGISTER_RETRY; do_register(sip); } break; @@ -1327,13 +1345,29 @@ } else { sip->proxy.retries = 0; if(!strcmp(trans->msg->method, "REGISTER")) { - if(msg->response == 401) sip->registrar.retries++; - else sip->registrar.retries = 0; + + /* This is encountered when a REGISTER request was ... + */ + if(msg->response == 401) { + /* denied until further authentication was provided. */ + sip->registrar.retries++; + } + else if (msg->response != 200) { + /* denied for some other reason! */ + sip->registrar.retries++; + } + else { + /* accepted! */ + sip->registrar.retries = 0; + } } else { if(msg->response == 401) { + /* This is encountered when a generic (MESSAGE, NOTIFY, etc) + * was denied until further authorization is provided. + */ gchar *resend, *auth, *ptmp; - if(sip->registrar.retries > 4) return; + if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) return; sip->registrar.retries++; ptmp = sipmsg_find_header(msg, "WWW-Authenticate"); @@ -1347,6 +1381,11 @@ /* resend request */ sendout_pkt(sip->gc, resend); g_free(resend); + } else { + /* Reset any count of retries that may have + * accumulated in the above branch. + */ + sip->registrar.retries = 0; } } if(trans->callback) { @@ -1696,7 +1735,8 @@ if(sip) { /* unregister */ - do_register_exp(sip, 0); + if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE) + do_register_exp(sip, 0); connection_free_all(sip); if (sip->query_data != NULL)
--- a/libpurple/protocols/simple/simple.h Thu Sep 13 04:32:19 2007 +0000 +++ b/libpurple/protocols/simple/simple.h Thu Sep 13 21:34:55 2007 +0000 @@ -37,6 +37,11 @@ #include "sipmsg.h" #define SIMPLE_BUF_INC 1024 +#define SIMPLE_REGISTER_RETRY_MAX 2 + +#define SIMPLE_REGISTER_SENT 1 +#define SIMPLE_REGISTER_RETRY 2 +#define SIMPLE_REGISTER_COMPLETE 3 struct sip_dialog { gchar *ourtag;