From 0b740bb3557d0c2fc4cc205926b7fe8bd12d1f81 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 3 Feb 2013 18:28:54 +0000 Subject: [PATCH] Added debugging to presence and iq handlers --- src/xmpp/iq.c | 6 +++++- src/xmpp/presence.c | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index e4bcecb4..fc3ef780 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -269,9 +269,11 @@ static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { + log_debug("Recieved diso#info response"); const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); if ((id != NULL) && (g_str_has_prefix(id, "disco"))) { + log_debug("Response to query: %s", id); xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); char *node = xmpp_stanza_get_attribute(query, STANZA_ATTR_NODE); if (node == NULL) { @@ -290,7 +292,9 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan char *generated_sha1 = caps_create_sha1_str(query); if (g_strcmp0(given_sha1, generated_sha1) != 0) { - log_info("Invalid SHA1 recieved for caps."); + log_info("Generated sha-1 does not match given:"); + log_info("Generated : %s", generated_sha1); + log_info("Given : %s", given_sha1); FREE_SET_NULL(generated_sha1); g_strfreev(split); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 7fd58df6..0d50a080 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -273,6 +273,7 @@ _presence_handler(xmpp_conn_t * const conn, // handle regular presence } else { + log_debug("Regular presence received from %s", from); char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE); char *show_str, *status_str; int idle_seconds = stanza_get_idle_time(stanza); @@ -338,38 +339,54 @@ _handle_presence_caps(xmpp_stanza_t * const stanza) char *node = NULL; char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (stanza_contains_caps(stanza)) { + log_debug("Presence contains capabilities."); char *hash_type = stanza_caps_get_hash(stanza); // xep-0115 if (hash_type != NULL) { + log_debug("Hash type: %s", hash_type); // supported hash if (strcmp(hash_type, "sha-1") == 0) { + log_debug("Hash type supported."); node = stanza_get_caps_str(stanza); caps_key = node; - + if (node != NULL) { + log_debug("Node string: %s.", node); if (!caps_contains(caps_key)) { + log_debug("Capabilities not cached for '%s', sending discovery IQ.", caps_key); xmpp_stanza_t *iq = stanza_create_disco_iq(ctx, "disco", from, node); xmpp_send(conn, iq); xmpp_stanza_release(iq); + } else { + log_debug("Capabilities already cached, for %s", caps_key); } + } else { + log_debug("No node string, not sending discovery IQ."); } // unsupported hash } else { + log_debug("Hash type unsupported."); node = stanza_get_caps_str(stanza); caps_key = from; if (node != NULL) { + log_debug("Node string: %s.", node); if (!caps_contains(caps_key)) { + log_debug("Capabilities not cached for '%s', sending discovery IQ.", caps_key); GString *id = g_string_new("disco_"); g_string_append(id, from); xmpp_stanza_t *iq = stanza_create_disco_iq(ctx, id->str, from, node); xmpp_send(conn, iq); xmpp_stanza_release(iq); g_string_free(id, TRUE); + } else { + log_debug("Capabilities already cached, for %s", caps_key); } + } else { + log_debug("No node string, not sending discovery IQ."); } } @@ -377,18 +394,25 @@ _handle_presence_caps(xmpp_stanza_t * const stanza) //ignore or handle legacy caps } else { + log_debug("No hash type, using legacy capabilities."); node = stanza_get_caps_str(stanza); caps_key = from; if (node != NULL) { + log_debug("Node string: %s.", node); if (!caps_contains(caps_key)) { + log_debug("Capabilities not cached for '%s', sending discovery IQ.", caps_key); GString *id = g_string_new("disco_"); g_string_append(id, from); xmpp_stanza_t *iq = stanza_create_disco_iq(ctx, id->str, from, node); xmpp_send(conn, iq); xmpp_stanza_release(iq); g_string_free(id, TRUE); + } else { + log_debug("Capabilities already cached, for %s", caps_key); } + } else { + log_debug("No node string, not sending discovery IQ."); } return caps_key; @@ -439,6 +463,8 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza) char *show_str, *status_str; char *caps_key = _handle_presence_caps(stanza); + log_debug("Room presence received from %s", jid); + xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_STATUS); if (status != NULL) { status_str = xmpp_stanza_get_text(status);