diff options
author | xengineering <me@xengineering.eu> | 2022-08-16 10:26:38 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-08-16 10:26:38 +0200 |
commit | 61be2e29d620006ee141ad88165de1819593ff35 (patch) | |
tree | 93f771a8357ae2fe3f6a5d1cd38379b6113fe554 | |
parent | ba1c1dd3142ae48d547f839dabb3c1830740cef8 (diff) | |
download | limox-61be2e29d620006ee141ad88165de1819593ff35.tar limox-61be2e29d620006ee141ad88165de1819593ff35.tar.zst limox-61be2e29d620006ee141ad88165de1819593ff35.zip |
Implement dummy receiving of XMPP chat messages
-rw-r--r-- | gtk.c | 5 | ||||
-rw-r--r-- | gui.h | 1 | ||||
-rw-r--r-- | limox.c | 26 |
3 files changed, 32 insertions, 0 deletions
@@ -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); +} @@ -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); @@ -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); |