summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-08-16 11:10:50 +0200
committerxengineering <me@xengineering.eu>2022-08-16 11:10:50 +0200
commit94cca91f9c0036a5ceb95ff4099d2cdc3d9265af (patch)
tree7e7d66d85f41e01b021a5ef5a3cf44a7a9c7e691
parent61be2e29d620006ee141ad88165de1819593ff35 (diff)
downloadlimox-94cca91f9c0036a5ceb95ff4099d2cdc3d9265af.tar
limox-94cca91f9c0036a5ceb95ff4099d2cdc3d9265af.tar.zst
limox-94cca91f9c0036a5ceb95ff4099d2cdc3d9265af.zip
Add dummy roster request
-rw-r--r--gtk.c9
-rw-r--r--gui.h1
-rw-r--r--limox.c32
3 files changed, 42 insertions, 0 deletions
diff --git a/gtk.c b/gtk.c
index fd8ab8a..47caac0 100644
--- a/gtk.c
+++ b/gtk.c
@@ -268,3 +268,12 @@ void gui_add_message(const char* sender_jid, const char* content) {
printf("Received from %s:\n%s\n", sender_jid, content);
}
+
+void gui_add_roster_item(const char* jid, const char* sub, const char* name) {
+
+ if (name) {
+ printf("roster item: %s, %s, sub:%s\n", name, jid, sub);
+ } else {
+ printf("roster item: (no name), %s, sub:%s\n", jid, sub);
+ }
+}
diff --git a/gui.h b/gui.h
index 268cb19..ab59d3d 100644
--- a/gui.h
+++ b/gui.h
@@ -7,3 +7,4 @@ void gui_disconnected(void);
void gui_suspended(void);
void gui_resumed(void);
void gui_add_message(const char* sender_jid, const char* content);
+void gui_add_roster_item(const char* jid, const char* sub, const char* name);
diff --git a/limox.c b/limox.c
index b254336..123ca53 100644
--- a/limox.c
+++ b/limox.c
@@ -56,6 +56,24 @@ static int message_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza,
return 1;
}
+static int roster_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza,
+ void *userdata) {
+
+ printf("DEBUG: Received roster.\n");
+
+ // iterate over roster result
+ xmpp_stanza_t* query = xmpp_stanza_get_child_by_name(stanza, "query");
+ for (xmpp_stanza_t* item = xmpp_stanza_get_children(query); item;
+ item = xmpp_stanza_get_next(item)) {
+
+ gui_add_roster_item(xmpp_stanza_get_attribute(item, "jid"),
+ xmpp_stanza_get_attribute(item, "subscription"),
+ xmpp_stanza_get_attribute(item, "name"));
+ }
+
+ 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) {
@@ -68,12 +86,26 @@ static void conn_handler(xmpp_conn_t *conn, xmpp_conn_event_t status,int error,
xmpp_handler_add(conn, message_handler, NULL, "message", "chat",
NULL);
+ // add handler for roster response
+ xmpp_handler_add(conn, roster_handler, "jabber:iq:roster", "iq",
+ "result", NULL);
+
// send initial presence
xmpp_stanza_t* presence;
presence = xmpp_presence_new(ctx);
xmpp_send(conn, presence);
xmpp_stanza_release(presence);
+ // send roster request
+ xmpp_stanza_t* iq = xmpp_iq_new(ctx, "get", "initial_roster");
+ xmpp_stanza_t* query = xmpp_stanza_new(ctx);
+ xmpp_stanza_set_name(query, "query");
+ xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);
+ xmpp_stanza_add_child(iq, query);
+ xmpp_stanza_release(query);
+ xmpp_send(conn, iq);
+ xmpp_stanza_release(iq);
+
break;
case XMPP_CONN_RAW_CONNECT: