diff options
author | James Booth <boothj5@gmail.com> | 2016-08-18 22:51:06 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-08-18 22:53:23 +0100 |
commit | a978bb12bf0235be9e57e0e08b6328acc88add8b (patch) | |
tree | f5245c813a82bcbcf5d403ceed2c9ec189abc3e0 /src/xmpp | |
parent | 71dcb2e427ec3e7e15f2131f18d64b84fc6230f8 (diff) | |
download | profani-tty-a978bb12bf0235be9e57e0e08b6328acc88add8b.tar.gz |
Send receipt request only when receiver supports feature
issue #829
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/capabilities.c | 18 | ||||
-rw-r--r-- | src/xmpp/chat_session.c | 35 | ||||
-rw-r--r-- | src/xmpp/chat_session.h | 2 | ||||
-rw-r--r-- | src/xmpp/jid.c | 18 | ||||
-rw-r--r-- | src/xmpp/message.c | 59 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 8 |
6 files changed, 83 insertions, 57 deletions
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 6ca3a29e..ca09e703 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -307,6 +307,24 @@ caps_lookup(const char *const jid) return NULL; } +gboolean +caps_jid_has_feature(const char *const jid, const char *const feature) +{ + char *ver = g_hash_table_lookup(jid_to_ver, jid); + EntityCapabilities *caps = ver ? _caps_by_ver(ver) : _caps_by_jid(jid); + + if (caps == NULL) { + return FALSE; + } + + GSList *found = g_slist_find_custom(caps->features, feature, (GCompareFunc)g_strcmp0); + gboolean result = found != NULL; + + caps_destroy(caps); + + return result; +} + char* caps_get_my_sha1(xmpp_ctx_t *const ctx) { diff --git a/src/xmpp/chat_session.c b/src/xmpp/chat_session.c index 61d7018c..d08ba340 100644 --- a/src/xmpp/chat_session.c +++ b/src/xmpp/chat_session.c @@ -41,6 +41,7 @@ #include "log.h" #include "config/preferences.h" #include "xmpp/xmpp.h" +#include "xmpp/stanza.h" #include "xmpp/chat_session.h" static GHashTable *sessions; @@ -100,6 +101,40 @@ chat_session_get(const char *const barejid) return g_hash_table_lookup(sessions, barejid); } +char* +chat_session_get_jid(const char *const barejid) +{ + ChatSession *session = chat_session_get(barejid); + char *jid = NULL; + if (session) { + Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); + jid = strdup(jidp->fulljid); + jid_destroy(jidp); + } else { + jid = strdup(barejid); + } + + return jid; +} + +char* +chat_session_get_state(const char *const barejid) +{ + ChatSession *session = chat_session_get(barejid); + char *state = NULL; + if (session) { + if (prefs_get_boolean(PREF_STATES) && session->send_states) { + state = STANZA_NAME_ACTIVE; + } + } else { + if (prefs_get_boolean(PREF_STATES)) { + state = STANZA_NAME_ACTIVE; + } + } + + return state; +} + void chat_session_recipient_gone(const char *const barejid, const char *const resource) { diff --git a/src/xmpp/chat_session.h b/src/xmpp/chat_session.h index 705799a1..46edb494 100644 --- a/src/xmpp/chat_session.h +++ b/src/xmpp/chat_session.h @@ -56,6 +56,8 @@ void chat_session_recipient_typing(const char *const barejid, const char *const void chat_session_recipient_paused(const char *const barejid, const char *const resource); void chat_session_recipient_gone(const char *const barejid, const char *const resource); void chat_session_recipient_inactive(const char *const barejid, const char *const resource); +char* chat_session_get_jid(const char *const barejid); +char* chat_session_get_state(const char *const barejid); void chat_session_remove(const char *const barejid); diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index fb4361d7..7289ca4c 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -119,15 +119,17 @@ jid_create_from_bare_and_resource(const char *const room, const char *const nick void jid_destroy(Jid *jid) { - if (jid) { - g_free(jid->str); - g_free(jid->localpart); - g_free(jid->domainpart); - g_free(jid->resourcepart); - g_free(jid->barejid); - g_free(jid->fulljid); - free(jid); + if (jid == NULL) { + return; } + + g_free(jid->str); + g_free(jid->localpart); + g_free(jid->domainpart); + g_free(jid->resourcepart); + g_free(jid->barejid); + g_free(jid->fulljid); + free(jid); } gboolean diff --git a/src/xmpp/message.c b/src/xmpp/message.c index fc314e30..60c63178 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -131,47 +131,14 @@ message_handlers_init(void) xmpp_handler_add(conn, _message_handler, NULL, STANZA_NAME_MESSAGE, NULL, ctx); } -static char* -_session_jid(const char *const barejid) -{ - ChatSession *session = chat_session_get(barejid); - char *jid = NULL; - if (session) { - Jid *jidp = jid_create_from_bare_and_resource(session->barejid, session->resource); - jid = strdup(jidp->fulljid); - jid_destroy(jidp); - } else { - jid = strdup(barejid); - } - - return jid; -} - -static char* -_session_state(const char *const barejid) -{ - ChatSession *session = chat_session_get(barejid); - char *state = NULL; - if (session) { - if (prefs_get_boolean(PREF_STATES) && session->send_states) { - state = STANZA_NAME_ACTIVE; - } - } else { - if (prefs_get_boolean(PREF_STATES)) { - state = STANZA_NAME_ACTIVE; - } - } - - return state; -} - char* -message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url) +message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, + gboolean request_receipt) { xmpp_ctx_t * const ctx = connection_get_ctx(); - char *state = _session_state(barejid); - char *jid = _session_jid(barejid); + char *state = chat_session_get_state(barejid); + char *jid = chat_session_get_jid(barejid); char *id = create_unique_id("msg"); xmpp_stanza_t *message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg); @@ -185,7 +152,7 @@ message_send_chat(const char *const barejid, const char *const msg, const char * stanza_attach_x_oob_url(ctx, message, oob_url); } - if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { + if (request_receipt) { stanza_attach_receipt_request(ctx, message); } @@ -196,12 +163,12 @@ message_send_chat(const char *const barejid, const char *const msg, const char * } char* -message_send_chat_pgp(const char *const barejid, const char *const msg) +message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean request_receipt) { xmpp_ctx_t * const ctx = connection_get_ctx(); - char *state = _session_state(barejid); - char *jid = _session_jid(barejid); + char *state = chat_session_get_state(barejid); + char *jid = chat_session_get_jid(barejid); char *id = create_unique_id("msg"); xmpp_stanza_t *message = NULL; @@ -240,7 +207,7 @@ message_send_chat_pgp(const char *const barejid, const char *const msg) stanza_attach_state(ctx, message, state); } - if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { + if (request_receipt) { stanza_attach_receipt_request(ctx, message); } @@ -251,12 +218,12 @@ message_send_chat_pgp(const char *const barejid, const char *const msg) } char* -message_send_chat_otr(const char *const barejid, const char *const msg) +message_send_chat_otr(const char *const barejid, const char *const msg, gboolean request_receipt) { xmpp_ctx_t * const ctx = connection_get_ctx(); - char *state = _session_state(barejid); - char *jid = _session_jid(barejid); + char *state = chat_session_get_state(barejid); + char *jid = chat_session_get_jid(barejid); char *id = create_unique_id("msg"); xmpp_stanza_t *message = stanza_create_message(ctx, id, barejid, STANZA_TYPE_CHAT, msg); @@ -270,7 +237,7 @@ message_send_chat_otr(const char *const barejid, const char *const msg) stanza_attach_hints_no_copy(ctx, message); stanza_attach_hints_no_store(ctx, message); - if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) { + if (request_receipt) { stanza_attach_receipt_request(ctx, message); } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 80245b2d..9c0690a2 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -130,9 +130,10 @@ gboolean connection_send_stanza(const char *const stanza); GList* connection_get_available_resources(void); gboolean connection_supports(const char *const feature); -char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url); -char* message_send_chat_otr(const char *const barejid, const char *const msg); -char* message_send_chat_pgp(const char *const barejid, const char *const msg); +char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, + gboolean request_receipt); +char* message_send_chat_otr(const char *const barejid, const char *const msg, gboolean request_receipt); +char* message_send_chat_pgp(const char *const barejid, const char *const msg, gboolean request_receipt); void message_send_private(const char *const fulljid, const char *const msg, const char *const oob_url); void message_send_groupchat(const char *const roomjid, const char *const msg, const char *const oob_url); void message_send_groupchat_subject(const char *const roomjid, const char *const subject); @@ -183,6 +184,7 @@ void caps_destroy(EntityCapabilities *caps); void caps_reset_ver(void); void caps_add_feature(char *feature); void caps_remove_feature(char *feature); +gboolean caps_jid_has_feature(const char *const jid, const char *const feature); gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str); gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str); |