/** Create a stanza object in reply to another. * This function makes a copy of a stanza object with the attribute “to” set * its original “from”. * The stanza will have a reference count of one, so the caller does not * need to clone it. * * @param stanza a Strophe stanza object * * @return a new Strophe stanza object * * @ingroup Stanza */ xmpp_stanza_t *xmpp_stanza_reply(xmpp_stanza_t * const stanza) { xmpp_stanza_t *copy = NULL; const char *from; int rc; from = xmpp_stanza_get_from(stanza); if (!from) goto copy_error; copy = xmpp_stanza_new(stanza->ctx); if (!copy) goto copy_error; copy->type = stanza->type; if (stanza->data) { copy->data = xmpp_strdup(stanza->ctx, stanza->data); if (!copy->data) goto copy_error; } if (stanza->attributes) { if (_stanza_copy_attributes(copy, stanza) < 0) goto copy_error; } xmpp_stanza_del_attribute(copy, "to"); xmpp_stanza_del_attribute(copy, "from"); rc = xmpp_stanza_set_to(copy, from); if (rc != XMPP_EOK) goto copy_error; return copy; copy_error: if (copy) xmpp_stanza_release(copy); return NULL; }
/** Create a stanza object in reply to another. * This function makes a copy of a stanza object with the attribute “to” set * its original “from”. * The stanza will have a reference count of one, so the caller does not * need to clone it. * * @param stanza a Strophe stanza object * * @return a new Strophe stanza object * * @ingroup Stanza */ xmpp_stanza_t *xmpp_stanza_reply(xmpp_stanza_t * const stanza) { xmpp_stanza_t *copy; copy = xmpp_stanza_new(stanza->ctx); if (!copy) goto copy_error; copy->type = stanza->type; if (stanza->data) { copy->data = xmpp_strdup(stanza->ctx, stanza->data); if (!copy->data) goto copy_error; } if (stanza->attributes) { if (_stanza_copy_attributes(copy, stanza) == -1) goto copy_error; } xmpp_stanza_set_to(copy, xmpp_stanza_get_from(stanza)); xmpp_stanza_del_attribute(copy, "from"); return copy; copy_error: if (copy) xmpp_stanza_release(copy); return NULL; }
void presence_subscription(const char *const jid, const jabber_subscr_t action) { assert(jid != NULL); Jid *jidp = jid_create(jid); autocomplete_remove(sub_requests_ac, jidp->barejid); const char *type = NULL; switch (action) { case PRESENCE_SUBSCRIBE: log_debug("Sending presence subscribe: %s", jid); type = STANZA_TYPE_SUBSCRIBE; break; case PRESENCE_SUBSCRIBED: log_debug("Sending presence subscribed: %s", jid); type = STANZA_TYPE_SUBSCRIBED; break; case PRESENCE_UNSUBSCRIBED: log_debug("Sending presence usubscribed: %s", jid); type = STANZA_TYPE_UNSUBSCRIBED; break; default: break; } if (!type) { log_error("Attempt to send unknown subscription action: %s", jid); return; } xmpp_ctx_t * const ctx = connection_get_ctx(); xmpp_stanza_t *presence = xmpp_presence_new(ctx); char *id = create_unique_id("sub"); xmpp_stanza_set_id(presence, id); free(id); xmpp_stanza_set_type(presence, type); xmpp_stanza_set_to(presence, jidp->barejid); jid_destroy(jidp); _send_presence_stanza(presence); xmpp_stanza_release(presence); }
void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, const int error, xmpp_stream_error_t * const stream_error, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; xmpp_stanza_t *iq, *query; if (status == XMPP_CONN_CONNECT) { fprintf(stderr, "DEBUG: connected\n"); /* create iq stanza for request */ iq = xmpp_stanza_new(ctx); xmpp_stanza_set_name(iq, "iq"); xmpp_stanza_set_type(iq, "get"); xmpp_stanza_set_id(iq, "active1"); xmpp_stanza_set_to(iq, "xxxxxxxxx.com"); query = xmpp_stanza_new(ctx); xmpp_stanza_set_name(query, "query"); xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS); xmpp_stanza_set_attribute(query, "node", "sessions"); xmpp_stanza_add_child(iq, query); /* we can release the stanza since it belongs to iq now */ xmpp_stanza_release(query); /* set up reply handler */ xmpp_id_handler_add(conn, handle_reply, "active1", ctx); /* send out the stanza */ xmpp_send(conn, iq); /* release the stanza */ xmpp_stanza_release(iq); } else { fprintf(stderr, "DEBUG: disconnected\n"); xmpp_stop(ctx); } }
static void _send_room_presence(xmpp_stanza_t *presence) { GList *rooms = muc_rooms(); GList *curr = rooms; while (curr) { const char *room = curr->data; const char *nick = muc_nick(room); if (nick) { char *full_room_jid = create_fulljid(room, nick); xmpp_stanza_set_to(presence, full_room_jid); log_debug("Sending presence to room: %s", full_room_jid); free(full_room_jid); _send_presence_stanza(presence); } curr = g_list_next(curr); } g_list_free(rooms); }
static xmpp_stanza_t * _stanza_new_with_attrs(xmpp_ctx_t *ctx, const char * const name, const char * const type, const char * const id, const char * const to) { xmpp_stanza_t *stanza = xmpp_stanza_new(ctx); int ret; if (stanza) { ret = xmpp_stanza_set_name(stanza, name); if (ret == XMPP_EOK && type) ret = xmpp_stanza_set_type(stanza, type); if (ret == XMPP_EOK && id) ret = xmpp_stanza_set_id(stanza, id); if (ret == XMPP_EOK && to) ret = xmpp_stanza_set_to(stanza, to); if (ret != XMPP_EOK) { xmpp_stanza_release(stanza); stanza = NULL; } } return stanza; }