From aada6d5cd6871847a79ccc932499aaf098f4e0fe Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 17:18:30 +0000 Subject: [PATCH 1/8] Don't show error for initial bookmarks request --- src/xmpp/bookmark.c | 5 +---- src/xmpp/connection.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 4516454f..726772a2 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -37,10 +37,7 @@ bookmark_request(void) xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_stanza_t *iq; - id = get_unique_id(); - if (!id) { - return; - } + id = strdup("bookmark_init_request"); autojoin_count = 0; if (bookmark_ac != NULL) { diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 2bf5a304..075321f7 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -345,8 +345,17 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, gchar *err_msg = NULL; gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); - xmpp_stanza_t *text_stanza = - xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT); + xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT); + + // handle specific errors by ID + char *id = xmpp_stanza_get_id(stanza); + if (id != NULL) { + + // ignore if server doesn't support bookmarks + if (strcmp("bookmark_init_request", id) == 0) { + return 1; + } + } if (error_stanza == NULL) { log_debug("error message without received"); From 78e8232b6130374f1123f6e5317d78c3a5f3c923 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 20:47:32 +0000 Subject: [PATCH 2/8] Renamed namespace variables --- src/xmpp/message.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 09e1fdc2..21e7073a 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -184,9 +184,9 @@ _conference_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); - xmpp_stanza_t *x_muc = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - xmpp_stanza_t *x_groupchat = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); - xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA); + xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); + xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); + xmpp_stanza_t *xns_captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *room = NULL; char *invitor = NULL; @@ -198,10 +198,10 @@ _conference_message_handler(xmpp_conn_t * const conn, } // XEP-0045 - if (x_muc != NULL) { + if (xns_muc_user != NULL) { room = from; - xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(x_muc, STANZA_NAME_INVITE); + xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE); if (invite == NULL) { return 1; } @@ -230,8 +230,8 @@ _conference_message_handler(xmpp_conn_t * const conn, } // XEP-0429 - } else if (x_groupchat != NULL) { - room = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_JID); + } else if (xns_conference != NULL) { + room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); if (room == NULL) { return 1; } @@ -242,14 +242,14 @@ _conference_message_handler(xmpp_conn_t * const conn, } invitor = jidp->barejid; - reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON); + reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); handle_room_invite(INVITE_DIRECT, invitor, room, reason); jid_destroy(jidp); // XEP-0158 - } else if (captcha != NULL) { + } else if (xns_captcha != NULL) { xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); if (body != NULL) { char *message = xmpp_stanza_get_text(body); From d8a92f933b0356375030f06a903a53b7e3a0aba7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 21:20:56 +0000 Subject: [PATCH 3/8] Split xmpp message handlers by namespace --- src/xmpp/message.c | 117 ++++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 44 deletions(-) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 21e7073a..f93d0acf 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -40,11 +40,15 @@ #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_MESSAGE, type, ctx) -static int _groupchat_message_handler(xmpp_conn_t * const conn, +static int _groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _chat_message_handler(xmpp_conn_t * const conn, +static int _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _conference_message_handler(xmpp_conn_t * const conn, +static int _muc_user_handler(xmpp_conn_t * const conn, + xmpp_stanza_t * const stanza, void * const userdata); +static int _conference_handler(xmpp_conn_t * const conn, + xmpp_stanza_t * const stanza, void * const userdata); +static int _captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); void @@ -53,9 +57,11 @@ message_add_handlers(void) xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_message_handler); - HANDLE(NULL, STANZA_TYPE_CHAT, _chat_message_handler); - HANDLE(NULL, NULL, _conference_message_handler); + HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_handler); + HANDLE(NULL, STANZA_TYPE_CHAT, _chat_handler); + HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler); + HANDLE(STANZA_NS_CONFERENCE, NULL, _conference_handler); + HANDLE(STANZA_NS_CAPTCHA, NULL, _captcha_handler); } static void @@ -180,32 +186,23 @@ _message_send_gone(const char * const recipient) } static int -_conference_message_handler(xmpp_conn_t * const conn, - xmpp_stanza_t * const stanza, void * const userdata) +_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, + void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER); - xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); - xmpp_stanza_t *xns_captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA); - char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); - char *room = NULL; + char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); char *invitor = NULL; char *reason = NULL; - if (from == NULL) { + if (room == NULL) { log_warning("Message received with no from attribute, ignoring"); return 1; } // XEP-0045 - if (xns_muc_user != NULL) { - room = from; - - xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE); - if (invite == NULL) { - return 1; - } - + xmpp_stanza_t *invite = xmpp_stanza_get_child_by_name(xns_muc_user, STANZA_NAME_INVITE); + if (invite != NULL) { char *invitor_jid = xmpp_stanza_get_attribute(invite, STANZA_ATTR_FROM); if (invitor_jid == NULL) { log_warning("Chat room invite received with no from attribute"); @@ -228,35 +225,67 @@ _conference_message_handler(xmpp_conn_t * const conn, if (reason != NULL) { xmpp_free(ctx, reason); } + } + + return 1; +} + +static int +_conference_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, + void * const userdata) +{ + xmpp_stanza_t *xns_conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE); + char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + char *room = NULL; + char *invitor = NULL; + char *reason = NULL; + + if (from == NULL) { + log_warning("Message received with no from attribute, ignoring"); + return 1; + } // XEP-0429 - } else if (xns_conference != NULL) { - room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); - if (room == NULL) { - return 1; - } + room = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_JID); + if (room == NULL) { + return 1; + } - Jid *jidp = jid_create(from); - if (jidp == NULL) { - return 1; - } - invitor = jidp->barejid; + Jid *jidp = jid_create(from); + if (jidp == NULL) { + return 1; + } + invitor = jidp->barejid; - reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); + reason = xmpp_stanza_get_attribute(xns_conference, STANZA_ATTR_REASON); - handle_room_invite(INVITE_DIRECT, invitor, room, reason); + handle_room_invite(INVITE_DIRECT, invitor, room, reason); - jid_destroy(jidp); + jid_destroy(jidp); + + + return 1; +} + +static int +_captcha_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, + void * const userdata) +{ + xmpp_ctx_t *ctx = connection_get_ctx(); + char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + + if (from == NULL) { + log_warning("Message received with no from attribute, ignoring"); + return 1; + } // XEP-0158 - } else if (xns_captcha != NULL) { - xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); - if (body != NULL) { - char *message = xmpp_stanza_get_text(body); - if (message != NULL) { - handle_room_broadcast(from, message); - xmpp_free(ctx, message); - } + xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); + if (body != NULL) { + char *message = xmpp_stanza_get_text(body); + if (message != NULL) { + handle_room_broadcast(from, message); + xmpp_free(ctx, message); } } @@ -264,7 +293,7 @@ _conference_message_handler(xmpp_conn_t * const conn, } static int -_groupchat_message_handler(xmpp_conn_t * const conn, +_groupchat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); @@ -341,7 +370,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn, } static int -_chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = connection_get_ctx(); From 6a15a09ed7322c70021b827f1d40cbab4f98c89e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 21:25:35 +0000 Subject: [PATCH 4/8] Renamed xmpp roster handlers --- src/xmpp/roster.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index a70436e7..68e34e63 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -47,9 +47,9 @@ typedef struct _group_data { } GroupData; // event handlers -static int _roster_handle_push(xmpp_conn_t * const conn, +static int _roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _roster_handle_result(xmpp_conn_t * const conn, +static int _roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); // id handlers @@ -68,8 +68,8 @@ roster_add_handlers(void) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - HANDLE(STANZA_TYPE_SET, _roster_handle_push); - HANDLE(STANZA_TYPE_RESULT, _roster_handle_result); + HANDLE(STANZA_TYPE_SET, _roster_set_handler); + HANDLE(STANZA_TYPE_RESULT, _roster_result_handler); } void @@ -206,7 +206,7 @@ _group_remove_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_roster_set_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_stanza_t *query = @@ -270,7 +270,7 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_roster_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); From 8600efa55b49dbeb276b42072cbb419686e94909 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 21:29:17 +0000 Subject: [PATCH 5/8] Renamed _room_presence_handler -> _muc_user_handler --- src/xmpp/presence.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 164e309e..2126d8a5 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -53,8 +53,7 @@ static int _unsubscribed_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static int _available_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); - -static int _room_presence_handler(xmpp_conn_t * const conn, +static int _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); static char* _get_caps_key(xmpp_stanza_t * const stanza); @@ -73,7 +72,7 @@ presence_add_handlers(void) xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - HANDLE(STANZA_NS_MUC_USER, NULL, _room_presence_handler); + HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler); HANDLE(NULL, STANZA_TYPE_UNAVAILABLE, _unavailable_handler); HANDLE(NULL, STANZA_TYPE_SUBSCRIBE, _subscribe_handler); HANDLE(NULL, STANZA_TYPE_SUBSCRIBED, _subscribed_handler); @@ -588,7 +587,7 @@ _get_caps_key(xmpp_stanza_t * const stanza) } static int -_room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { // handler still fires if error From 9b825518099f5569742b2a9ad495bc6ec2d7af4d Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 21:41:17 +0000 Subject: [PATCH 6/8] Renamed iq handlers --- src/xmpp/iq.c | 53 ++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 3e598c10..ff5e47ec 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -44,21 +44,21 @@ #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, STANZA_NAME_IQ, type, ctx) -static int _iq_handle_error(xmpp_conn_t * const conn, +static int _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_ping_get(xmpp_conn_t * const conn, +static int _ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_version_get(xmpp_conn_t * const conn, +static int _version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_discoinfo_get(xmpp_conn_t * const conn, +static int _disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_discoinfo_result(xmpp_conn_t * const conn, +static int _disco_info_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_version_result(xmpp_conn_t * const conn, +static int _version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_discoitems_result(xmpp_conn_t * const conn, +static int _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); -static int _iq_handle_discoitems_get(xmpp_conn_t * const conn, +static int _disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata); void @@ -66,14 +66,19 @@ iq_add_handlers(void) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); - HANDLE(NULL, STANZA_TYPE_ERROR, _iq_handle_error); - HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _iq_handle_discoinfo_get); - HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_RESULT, _iq_handle_discoinfo_result); - HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _iq_handle_discoitems_result); - HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _iq_handle_discoitems_get); - HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _iq_handle_version_get); - HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _iq_handle_version_result); - HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _iq_handle_ping_get); + + HANDLE(NULL, STANZA_TYPE_ERROR, _error_handler); + + HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_GET, _disco_info_get_handler); + HANDLE(XMPP_NS_DISCO_INFO, STANZA_TYPE_RESULT, _disco_info_result_handler); + + HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_GET, _disco_items_get_handler); + HANDLE(XMPP_NS_DISCO_ITEMS, STANZA_TYPE_RESULT, _disco_items_result_handler); + + HANDLE(STANZA_NS_VERSION, STANZA_TYPE_GET, _version_get_handler); + HANDLE(STANZA_NS_VERSION, STANZA_TYPE_RESULT, _version_result_handler); + + HANDLE(STANZA_NS_PING, STANZA_TYPE_GET, _ping_get_handler); } static void @@ -117,7 +122,7 @@ _iq_send_software_version(const char * const fulljid) } static int -_iq_handle_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID); @@ -132,7 +137,7 @@ _iq_handle_error(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_iq_handle_version_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_version_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { const char *jid = xmpp_stanza_get_attribute(stanza, "from"); @@ -182,7 +187,7 @@ _iq_handle_version_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza } static int -_iq_handle_ping_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_ping_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; @@ -211,7 +216,7 @@ _iq_handle_ping_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_version_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; @@ -273,7 +278,7 @@ _iq_handle_version_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, } static int -_iq_handle_discoitems_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; @@ -299,7 +304,7 @@ _iq_handle_discoitems_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza static int -_iq_handle_discoinfo_get(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_disco_info_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; @@ -350,7 +355,7 @@ _item_destroy(DiscoItem *item) } static int -_iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_disco_info_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { log_debug("Recieved diso#info response"); @@ -518,7 +523,7 @@ _iq_handle_discoinfo_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stan } static int -_iq_handle_discoitems_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, +_disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { From e1aca3b1f6ff9cd6196bef280b29abe2dc8ef639 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 22:57:53 +0000 Subject: [PATCH 7/8] Add message and presence error handlers seperately --- src/xmpp/connection.c | 11 ----------- src/xmpp/message.c | 1 + src/xmpp/presence.c | 1 + src/xmpp/roster.c | 1 + 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 075321f7..8566a8d6 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -347,16 +347,6 @@ connection_error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, xmpp_stanza_t *error_stanza = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT); - // handle specific errors by ID - char *id = xmpp_stanza_get_id(stanza); - if (id != NULL) { - - // ignore if server doesn't support bookmarks - if (strcmp("bookmark_init_request", id) == 0) { - return 1; - } - } - if (error_stanza == NULL) { log_debug("error message without received"); } else { @@ -499,7 +489,6 @@ _connection_handler(xmpp_conn_t * const conn, chat_sessions_init(); - xmpp_handler_add(conn, connection_error_handler, NULL, NULL, STANZA_TYPE_ERROR, ctx); roster_add_handlers(); message_add_handlers(); presence_add_handlers(); diff --git a/src/xmpp/message.c b/src/xmpp/message.c index f93d0acf..89ea5b7d 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -57,6 +57,7 @@ message_add_handlers(void) xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); + HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler); HANDLE(NULL, STANZA_TYPE_GROUPCHAT, _groupchat_handler); HANDLE(NULL, STANZA_TYPE_CHAT, _chat_handler); HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 2126d8a5..9b11c898 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -72,6 +72,7 @@ presence_add_handlers(void) xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); + HANDLE(NULL, STANZA_TYPE_ERROR, connection_error_handler); HANDLE(STANZA_NS_MUC_USER, NULL, _muc_user_handler); HANDLE(NULL, STANZA_TYPE_UNAVAILABLE, _unavailable_handler); HANDLE(NULL, STANZA_TYPE_SUBSCRIBE, _subscribe_handler); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 68e34e63..542da2d0 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -68,6 +68,7 @@ roster_add_handlers(void) { xmpp_conn_t * const conn = connection_get_conn(); xmpp_ctx_t * const ctx = connection_get_ctx(); + HANDLE(STANZA_TYPE_SET, _roster_set_handler); HANDLE(STANZA_TYPE_RESULT, _roster_result_handler); } From fbdecdad0cf27187c46c8c930a3cfd02be47f7ff Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 25 Jan 2014 23:18:10 +0000 Subject: [PATCH 8/8] generate_unique_id allows prefix --- src/common.c | 8 ++++++-- src/common.h | 2 +- src/xmpp/roster.c | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common.c b/src/common.c index c8367592..5cce121a 100644 --- a/src/common.c +++ b/src/common.c @@ -372,14 +372,18 @@ xdg_get_data_home(void) } char * -get_unique_id(void) +generate_unique_id(char *prefix) { static unsigned long unique_id; char *result = NULL; GString *result_str = g_string_new(""); unique_id++; - g_string_printf(result_str, "prof%lu", unique_id); + if (prefix != NULL) { + g_string_printf(result_str, "prof_%s_%lu", prefix, unique_id); + } else { + g_string_printf(result_str, "prof_%lu", unique_id); + } result = result_str->str; g_string_free(result_str, FALSE); diff --git a/src/common.h b/src/common.h index ad98aa2c..1559c12a 100644 --- a/src/common.h +++ b/src/common.h @@ -88,7 +88,7 @@ const char * string_from_resource_presence(resource_presence_t presence); resource_presence_t resource_presence_from_string(const char * const str); contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence); -char * get_unique_id(void); +char * generate_unique_id(char *prefix); int cmp_win_num(gconstpointer a, gconstpointer b); int get_next_available_win_num(GList *used); diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c index 542da2d0..cf42acac 100644 --- a/src/xmpp/roster.c +++ b/src/xmpp/roster.c @@ -126,7 +126,7 @@ _roster_send_add_to_group(const char * const group, PContact contact) new_groups = g_slist_append(new_groups, strdup(group)); // add an id handler to handle the response - char *unique_id = get_unique_id(); + char *unique_id = generate_unique_id(NULL); GroupData *data = malloc(sizeof(GroupData)); data->group = strdup(group); if (p_contact_name(contact) != NULL) { @@ -175,7 +175,7 @@ _roster_send_remove_from_group(const char * const group, PContact contact) xmpp_ctx_t * const ctx = connection_get_ctx(); // add an id handler to handle the response - char *unique_id = get_unique_id(); + char *unique_id = generate_unique_id(NULL); GroupData *data = malloc(sizeof(GroupData)); data->group = strdup(group); if (p_contact_name(contact) != NULL) {