summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk.c5
-rw-r--r--gui.h1
-rw-r--r--limox.c26
3 files changed, 32 insertions, 0 deletions
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 <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);