summaryrefslogtreecommitdiff
path: root/limox.c
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-08-16 10:26:38 +0200
committerxengineering <me@xengineering.eu>2022-08-16 10:26:38 +0200
commit61be2e29d620006ee141ad88165de1819593ff35 (patch)
tree93f771a8357ae2fe3f6a5d1cd38379b6113fe554 /limox.c
parentba1c1dd3142ae48d547f839dabb3c1830740cef8 (diff)
downloadlimox-61be2e29d620006ee141ad88165de1819593ff35.tar
limox-61be2e29d620006ee141ad88165de1819593ff35.tar.zst
limox-61be2e29d620006ee141ad88165de1819593ff35.zip
Implement dummy receiving of XMPP chat messages
Diffstat (limited to 'limox.c')
-rw-r--r--limox.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/limox.c b/limox.c
index 911568b..b254336 100644
--- a/limox.c
+++ b/limox.c
@@ -9,6 +9,7 @@
#include <strophe.h>
+#include <gui.h>
#include <limox.h>
@@ -34,6 +35,27 @@ static long flags;
// this variable stays initialized while the connection is suspended
static xmpp_sm_state_t* sm_state;
+
+static int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza,
+ void *userdata) {
+
+ // local variables
+ xmpp_stanza_t* body;
+ const char* content;
+
+ body = xmpp_stanza_get_child_by_name(stanza, "body");
+ if (body == NULL) {
+ printf("DEBUG: Got message stanza of type char without body!\n");
+ return 1;
+ }
+
+ content = xmpp_stanza_get_text(body);
+
+ gui_add_message(xmpp_stanza_get_from(stanza), content);
+
+ return 1;
+}
+
static void conn_handler(xmpp_conn_t *conn, xmpp_conn_event_t status,int error,
xmpp_stream_error_t *stream_error, void *userdata) {
@@ -42,6 +64,10 @@ static void conn_handler(xmpp_conn_t *conn, xmpp_conn_event_t status,int error,
case XMPP_CONN_CONNECT:
printf("DEBUG: Got XMPP_CONN_CONNECT\n");
+ // add handler for <message> stanzas
+ xmpp_handler_add(conn, message_handler, NULL, "message", "chat",
+ NULL);
+
// send initial presence
xmpp_stanza_t* presence;
presence = xmpp_presence_new(ctx);