From 61be2e29d620006ee141ad88165de1819593ff35 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 16 Aug 2022 10:26:38 +0200 Subject: Implement dummy receiving of XMPP chat messages --- gtk.c | 5 +++++ gui.h | 1 + limox.c | 26 ++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/gtk.c b/gtk.c index 3139cbb..fd8ab8a 100644 --- a/gtk.c +++ b/gtk.c @@ -263,3 +263,8 @@ void gui_run(void) { g_object_unref(app); } + +void gui_add_message(const char* sender_jid, const char* content) { + + printf("Received from %s:\n%s\n", sender_jid, content); +} diff --git a/gui.h b/gui.h index 057e0b1..268cb19 100644 --- a/gui.h +++ b/gui.h @@ -6,3 +6,4 @@ void gui_connected(char* jid, char* password); void gui_disconnected(void); void gui_suspended(void); void gui_resumed(void); +void gui_add_message(const char* sender_jid, const char* content); diff --git a/limox.c b/limox.c index 911568b..b254336 100644 --- a/limox.c +++ b/limox.c @@ -9,6 +9,7 @@ #include +#include #include @@ -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 stanzas + xmpp_handler_add(conn, message_handler, NULL, "message", "chat", + NULL); + // send initial presence xmpp_stanza_t* presence; presence = xmpp_presence_new(ctx); -- cgit v1.2.3-70-g09d2