Added basic subscriptions

This commit is contained in:
James Booth
2012-10-28 18:51:13 +00:00
parent cd56134ebb
commit 15cdc69f31
3 changed files with 64 additions and 0 deletions

View File

@@ -184,6 +184,19 @@ jabber_roster_request(void)
xmpp_stanza_release(iq);
}
void
jabber_subscribe(const char * const recipient)
{
xmpp_stanza_t *presence;
presence = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(presence, "presence");
xmpp_stanza_set_type(presence, "subscribe");
xmpp_stanza_set_attribute(presence, "to", recipient);
xmpp_send(jabber_conn.conn, presence);
xmpp_stanza_release(presence);
}
void
jabber_update_presence(jabber_presence_t status, const char * const msg)
{
@@ -435,6 +448,20 @@ _presence_handler(xmpp_conn_t * const conn,
char *short_from = strtok(from, "/");
char *type = xmpp_stanza_get_attribute(stanza, "type");
if (type != NULL) {
if (strcmp(type, "subscribe") == 0) {
xmpp_stanza_t *presence;
presence = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(presence, "presence");
xmpp_stanza_set_type(presence, "subscribed");
xmpp_stanza_set_attribute(presence, "to", short_from);
xmpp_send(jabber_conn.conn, presence);
xmpp_stanza_release(presence);
return 1;
}
}
char *show_str, *status_str;
xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, "show");