about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2021-06-10 13:50:18 +0200
committerGitHub <noreply@github.com>2021-06-10 13:50:18 +0200
commitc83f246a90d750a34be58dac077608e2c89b538e (patch)
tree210162d39ec30b06f5f849ee806f590f6497f430
parent642fbf4118f38c46ac53d734426a17ac8b16f7e9 (diff)
parent46cd09cce42491c4a77cfd6e8e71c65d68897138 (diff)
downloadprofani-tty-c83f246a90d750a34be58dac077608e2c89b538e.tar.gz
Merge pull request #1560 from profanity-im/feature/1525-jingle
XEP-0353: Display a notice when receiving a call
-rw-r--r--src/xmpp/message.c23
-rw-r--r--src/xmpp/stanza.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index fc841ae2..e14ae07d 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -93,6 +93,7 @@ static void _send_message_stanza(xmpp_stanza_t* const stanza);
 static gboolean _handle_mam(xmpp_stanza_t* const stanza);
 static void _handle_pubsub(xmpp_stanza_t* const stanza, xmpp_stanza_t* const event);
 static gboolean _handle_form(xmpp_stanza_t* const stanza);
+static gboolean _handle_jingle_message(xmpp_stanza_t* const stanza);
 
 #ifdef HAVE_LIBGPGME
 static xmpp_stanza_t* _openpgp_signcrypt(xmpp_ctx_t* ctx, const char* const to, const char* const text);
@@ -170,6 +171,11 @@ _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* con
     } else if (type == NULL || g_strcmp0(type, STANZA_TYPE_CHAT) == 0 || g_strcmp0(type, STANZA_TYPE_NORMAL) == 0) {
         // type: chat, normal (==NULL)
 
+        // XEP-0353: Jingle Message Initiation
+        if (_handle_jingle_message(stanza)) {
+            return 1;
+        }
+
         // XEP-0045: Multi-User Chat 8.6 Voice Requests
         if (_handle_form(stanza)) {
             return 1;
@@ -1664,3 +1670,20 @@ message_request_voice(const char* const roomjid)
     _send_message_stanza(stanza);
     xmpp_stanza_release(stanza);
 }
+
+static gboolean
+_handle_jingle_message(xmpp_stanza_t* const stanza)
+{
+    xmpp_stanza_t* propose = xmpp_stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_PROPOSE, STANZA_NS_JINGLE_MESSAGE);
+
+    if (propose) {
+        xmpp_stanza_t* description = xmpp_stanza_get_child_by_ns(propose, STANZA_NS_JINGLE_RTP);
+        if (description) {
+            const char* const from = xmpp_stanza_get_from(stanza);
+            cons_show("Ring ring: %s is trying to call you", from);
+            cons_alert(NULL);
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index 06b2815a..5effaf3e 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -121,6 +121,7 @@
 #define STANZA_NAME_LAST             "last"
 #define STANZA_NAME_AFTER            "after"
 #define STANZA_NAME_USERNAME         "username"
+#define STANZA_NAME_PROPOSE          "propose"
 
 // error conditions
 #define STANZA_NAME_BAD_REQUEST             "bad-request"
@@ -238,6 +239,8 @@
 #define STANZA_NS_RSM                     "http://jabber.org/protocol/rsm"
 #define STANZA_NS_REGISTER                "jabber:iq:register"
 #define STANZA_NS_VOICEREQUEST            "http://jabber.org/protocol/muc#request"
+#define STANZA_NS_JINGLE_MESSAGE          "urn:xmpp:jingle-message:0"
+#define STANZA_NS_JINGLE_RTP              "urn:xmpp:jingle:apps:rtp:1"
 
 #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"