Index: res/res_jabber.c
===================================================================
--- res/res_jabber.c (revision 337971)
+++ res/res_jabber.c (working copy)
@@ -1431,8 +1431,10 @@
case IKS_NOMEM:
ast_log(LOG_WARNING, "Parsing failure: Out of memory.\n");
break;
- case IKS_BADXML:
- ast_log(LOG_WARNING, "Parsing failure: Invalid XML.\n");
+ case IKS_BADXML: /* Empty element is valid when connecting as component to XMPP, so absorb this*/
+ if (!(client->component && client->state == AJI_CONNECTING)) {
+ ast_log(LOG_WARNING, "Parsing failure: Invalid XML.\n");
+ }
break;
case IKS_HOOK:
ast_log(LOG_WARNING, "Parsing failure: Hook returned an error.\n");
@@ -1767,6 +1769,8 @@
case IKS_NODE_START:
if (client->state == AJI_DISCONNECTED) {
char secret[160], shasum[320], *handshake;
+
+ client->state = AJI_CONNECTING;
sprintf(secret, "%s%s", pak->id, client->password);
ast_sha1_hash(shasum, secret);
@@ -1776,12 +1780,16 @@
ast_free(handshake);
handshake = NULL;
}
- client->state = AJI_CONNECTING;
- if (aji_recv(client, 1) == 2) /*XXX proper result for iksemel library on iks_recv of XXX*/
+
+ /* Upon successful authentication, the server will send empty handshake element, "",
+ which is proper, but iksemel returns IKS_BADXML; so check for this return code and
+ indicate we are connected; this probably should be improved upon */
+ if (aji_recv(client, 1) == IKS_BADXML) {
client->state = AJI_CONNECTED;
- else
+ } else {
ast_log(LOG_WARNING, "Jabber didn't seem to handshake, failed to authenticate.\n");
- break;
+ client->state = AJI_DISCONNECTED;
+ }
}
break;
@@ -2818,9 +2826,11 @@
} else if (res == IKS_NET_TLSFAIL) {
ast_log(LOG_ERROR, "JABBER: Failure in TLS.\n");
} else if (client->timeout == 0 && client->state == AJI_CONNECTED) {
+ client->state = AJI_CONNECTING;
res = client->keepalive ? aji_send_raw(client, " ") : IKS_OK;
if (res == IKS_OK) {
client->timeout = 50;
+ client->state = AJI_CONNECTED;
} else {
ast_log(LOG_WARNING, "JABBER: Network Timeout\n");
}