# HG changeset patch # User Sean Egan # Date 1189719295 0 # Node ID 6e93a79b2ae569bedb2654a61d97526649034ddd # Parent c9f994a88f5f4cf1179f603a81ff0337bb1d3b0a Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration diff -r c9f994a88f5f -r 6e93a79b2ae5 autogen.sh --- 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; diff -r c9f994a88f5f -r 6e93a79b2ae5 libpurple/protocols/simple/simple.c --- 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) diff -r c9f994a88f5f -r 6e93a79b2ae5 libpurple/protocols/simple/simple.h --- 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;