Index: include/asterisk/jabber.h =================================================================== --- include/asterisk/jabber.h (revision 345544) +++ include/asterisk/jabber.h (working copy) @@ -179,6 +179,8 @@ int timeout; int message_timeout; int authorized; + int authorization_failed; + int run; int distribute_events; int send_to_dialplan; struct ast_flags flags; Index: res/res_jabber.c =================================================================== --- res/res_jabber.c (revision 345544) +++ res/res_jabber.c (working copy) @@ -1737,7 +1737,8 @@ } } } else if (!strcmp("failure", iks_name(node))) { - ast_log(LOG_ERROR, "JABBER: encryption failure. possible bad password.\n"); + ast_log(LOG_ERROR, "JABBER: encryption failure. possible bad password. shutting down this client.\n"); + client->authorization_failed = 1; } else if (!strcmp("success", iks_name(node))) { client->authorized = 1; aji_send_header(client, client->jid->server); @@ -2784,6 +2785,8 @@ sleep(4); } + client->run = 1; + do { if (res == IKS_NET_RWERR || client->timeout == 0) { while (res != IKS_OK) { @@ -2794,10 +2797,15 @@ } res = aji_recv(client, 1); + + if (client->authorization_failed) { + ast_debug(2, "Ending our Jabber client's thread due to authorization failure\n"); + client->run = 0; + } if (client->state == AJI_DISCONNECTING) { ast_debug(2, "Ending our Jabber client's thread due to a disconnect\n"); - pthread_exit(NULL); + client->run = 0; } /* Decrease timeout if no data received, and delete @@ -2820,8 +2828,9 @@ } else if (res == IKS_NET_RWERR) { ast_log(LOG_WARNING, "JABBER: socket read error\n"); } - } while (client); + } while (client->run); ASTOBJ_UNREF(client, aji_client_destroy); + pthread_exit(NULL); return 0; }