Example #1
0
static void _start_element(void *userdata,
                           const XML_Char *nsname,
                           const XML_Char **attrs)
{
    parser_t *parser = (parser_t *)userdata;
    xmpp_stanza_t *child;
    char *ns, *name;

    ns = _xml_namespace(parser->ctx, nsname);
    name = _xml_name(parser->ctx, nsname);

    if (parser->depth == 0) {
        /* notify the owner */
        if (parser->startcb)
            parser->startcb((char *)name, (char **)attrs, 
                            parser->userdata);
    } else {
	/* build stanzas at depth 1 */
	if (!parser->stanza && parser->depth != 1) {
	    /* something terrible happened */
	    /* FIXME: shutdown disconnect */
	    xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?");
	} else if (!parser->stanza) {
	    /* starting a new toplevel stanza */
	    parser->stanza = xmpp_stanza_new(parser->ctx);
	    if (!parser->stanza) {
		/* FIXME: can't allocate, disconnect */
	    }
	    xmpp_stanza_set_name(parser->stanza, name);
	    _set_attributes(parser->stanza, attrs);
	    if (ns)
		xmpp_stanza_set_ns(parser->stanza, ns);
	} else {
	    /* starting a child of parser->stanza */
	    child = xmpp_stanza_new(parser->ctx);
	    if (!child) {
		/* FIXME: can't allocate, disconnect */
	    }
	    xmpp_stanza_set_name(child, name);
	    _set_attributes(child, attrs);
	    if (ns)
		xmpp_stanza_set_ns(child, ns);

	    /* add child to parent */
	    xmpp_stanza_add_child(parser->stanza, child);
	    
	    /* the child is owned by the toplevel stanza now */
	    xmpp_stanza_release(child);

	    /* make child the current stanza */
	    parser->stanza = child;
	}
    }

    if (ns) xmpp_free(parser->ctx, ns);
    if (name) xmpp_free(parser->ctx, name);

    parser->depth++;
}
static void _start_element(void *userdata, 
                           const xmlChar *name, const xmlChar *prefix,
                           const xmlChar *uri, int nnamespaces,
                           const xmlChar **namespaces, int nattrs,
                           int ndefaulted, const xmlChar **attrs)
{
    parser_t *parser = (parser_t *)userdata;
    xmpp_stanza_t *child;
    char **cbattrs;

    if (parser->depth == 0) {
        /* notify the owner */
        if (parser->startcb)
            cbattrs = _convert_attrs(parser, nattrs, attrs);
            parser->startcb((char *)name, cbattrs, 
                            parser->userdata);
            _free_cbattrs(parser, cbattrs);
    } else {
	/* build stanzas at depth 1 */
	if (!parser->stanza && parser->depth != 1) {
	    /* something terrible happened */
	    /* FIXME: we should probably trigger a disconnect */
	    xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?");
	} else if (!parser->stanza) {
	    /* starting a new toplevel stanza */
	    parser->stanza = xmpp_stanza_new(parser->ctx);
	    if (!parser->stanza) {
		/* FIXME: can't allocate, disconnect */
	    }
	    xmpp_stanza_set_name(parser->stanza, (char *)name);
	    _set_attributes(parser->stanza, nattrs, attrs);
	    if (uri)
		xmpp_stanza_set_ns(parser->stanza, (char *)uri);
	} else {
	    /* starting a child of conn->stanza */
	    child = xmpp_stanza_new(parser->ctx);
	    if (!child) {
		/* FIXME: can't allocate, disconnect */
	    }
	    xmpp_stanza_set_name(child, (char *)name);
	    _set_attributes(child, nattrs, attrs);
	    if (uri)
		xmpp_stanza_set_ns(child, (char *)uri);

	    /* add child to parent */
	    xmpp_stanza_add_child(parser->stanza, child);
	    
	    /* the child is owned by the toplevel stanza now */
	    xmpp_stanza_release(child);

	    /* make child the current stanza */
	    parser->stanza = child;
	}
    }

    parser->depth++;
}
Example #3
0
void
mood_publish(mood_callback_t callback, const char * const usermood,
    const char * const usertext)
{
	xmpp_stanza_t *iq, *pubsub, *publish, *item, *mood, *stanza, *text;

	iq = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_id(iq, "mood1");	/* FIXME */

	pubsub = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(pubsub, "pubsub");
	xmpp_stanza_set_ns(pubsub, NS_PUBSUB);
	xmpp_stanza_add_child(iq, pubsub);
	xmpp_stanza_release(pubsub);

	publish = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(publish, "publish");
	xmpp_stanza_set_attribute(publish, "node", NS_MOOD);
	xmpp_stanza_add_child(pubsub, publish);
	xmpp_stanza_release(publish);

	item = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(item, "item");
	xmpp_stanza_add_child(publish, item);
	xmpp_stanza_release(item);

	mood = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(mood, "mood");
	xmpp_stanza_set_ns(mood, NS_MOOD);
	xmpp_stanza_add_child(item, mood);
	xmpp_stanza_release(mood);

	if (usermood != NULL) {
		stanza = xmpp_stanza_new(ctx);
		xmpp_stanza_set_name(stanza, usermood);
		xmpp_stanza_add_child(mood, stanza);
		xmpp_stanza_release(stanza);
	}

	if (usertext != NULL) {
		text = xmpp_stanza_new(ctx);
		xmpp_stanza_set_name(text, "text");
		xmpp_stanza_set_text(text, usertext);
		xmpp_stanza_add_child(mood, text);
		xmpp_stanza_release(text);
	}

	xmpp_id_handler_add(conn, mood_result_handler,
	    xmpp_stanza_get_id(iq), callback);

	xmpp_send(conn, iq);
	xmpp_stanza_release(iq);
}
Example #4
0
xmpp_stanza_t *
stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
    const char * const type, const char * const message,
    const char * const state)
{
    char *encoded_xml = encode_xml(message);

    xmpp_stanza_t *msg, *body, *text;

    msg = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
    xmpp_stanza_set_type(msg, type);
    xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient);

    body = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(body, STANZA_NAME_BODY);

    text = xmpp_stanza_new(ctx);
    xmpp_stanza_set_text(text, encoded_xml);
    xmpp_stanza_add_child(body, text);
    xmpp_stanza_add_child(msg, body);

    if (state != NULL) {
        xmpp_stanza_t *chat_state = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(chat_state, state);
        xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
        xmpp_stanza_add_child(msg, chat_state);
    }

    g_free(encoded_xml);

    return msg;
}
Example #5
0
static void _respond_iq_with_error(xmpp_conn_t *conn, xmpp_stanza_t *stanza, const char *type, const char* condition)
{
	char *id = xmpp_stanza_get_attribute(stanza, "id");
	if (!id)
		return;
	xmpp_stanza_t *response = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(response, "iq");
	xmpp_stanza_set_attribute(response, "type", "error");
	xmpp_stanza_set_attribute(response, "id", id);

	char *req_from = xmpp_stanza_get_attribute(stanza, "from");
	//当req_from为NULL时, to属性应该设为服务器, 不设应该默认是服务器;
	if (req_from)
		xmpp_stanza_set_attribute(response, "to", req_from);

	xmpp_stanza_t *stanza_error = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_error, "error");
	xmpp_stanza_set_attribute(stanza_error, "type", type);

	xmpp_stanza_t *stanza_condition = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_condition, condition);
	xmpp_stanza_set_ns(stanza_condition, XMPP_NS_STANZA);

	xmpp_stanza_add_child(stanza_error, stanza_condition);
	xmpp_stanza_add_child(response, stanza_error);

	xmpp_stanza_release(stanza_condition);
	xmpp_stanza_release(stanza_error);

	xmpp_send(conn, response);
	xmpp_stanza_release(response);
}
Example #6
0
static void _zkmuc_destroy_room(char *room_jid, xmpp_ua_t *ua)
{
	xmpp_stanza_t *iq = xmpp_stanza_new(_xmpp_ctx);
	
	char id[128];
	xmpp_ua_get_unique_string(ua, id);

	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_id(iq, id);
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_attribute(iq, "to", room_jid);
	xmpp_stanza_t *query = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(query, "query");
	xmpp_stanza_set_ns(query, XMPP_NS_MUC_OWNER);

	xmpp_stanza_t *destroy = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(destroy, "destroy");
	xmpp_stanza_set_attribute(destroy, "jid", room_jid);

	xmpp_stanza_add_child(query, destroy);
	xmpp_stanza_release(destroy);
	xmpp_stanza_add_child(iq, query);
	xmpp_stanza_release(query);
	xmpp_ua_id_handler_add(ua, zkmuc_destroy_room_result, id, NULL);
	xmpp_ua_send(ua, iq);
	xmpp_stanza_release(iq);
}
Example #7
0
static int
_disco_items_get_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
    void * const userdata)
{
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
    const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);

    if (id != NULL) {
        log_debug("IQ disco items get handler fired, id: %s.", id);
    } else {
        log_debug("IQ disco items get handler fired.");
    }

    if (from != NULL) {
        xmpp_stanza_t *response = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(response, STANZA_NAME_IQ);
        xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza));
        xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from);
        xmpp_stanza_set_type(response, STANZA_TYPE_RESULT);
        xmpp_stanza_t *query = xmpp_stanza_new(ctx);
        xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
        xmpp_stanza_set_ns(query, XMPP_NS_DISCO_ITEMS);
        xmpp_stanza_add_child(response, query);
        xmpp_send(conn, response);

        xmpp_stanza_release(response);
    }

    return 1;
}
Example #8
0
/* handle the rspauth phase of digest auth */
static int _handle_digestmd5_rspauth(xmpp_conn_t * const conn,
			      xmpp_stanza_t * const stanza,
			      void * const userdata)
{
    xmpp_stanza_t *auth;
    char *name;

    name = xmpp_stanza_get_name(stanza);
    xmpp_debug(conn->ctx, "xmpp",
	"handle digest-md5 (rspauth) called for %s", name);


    if (strcmp(name, "challenge") == 0) {
	/* assume it's an rspauth response */
	auth = xmpp_stanza_new(conn->ctx);
	if (!auth) {
	    disconnect_mem_error(conn);
	    return 0;
	}
	xmpp_stanza_set_name(auth, "response");
	xmpp_stanza_set_ns(auth, XMPP_NS_SASL);
	xmpp_send(conn, auth);
	xmpp_stanza_release(auth);
    } else {
	return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
    }

    return 1;
}
Example #9
0
int zkmuc_get_room_description(zkmuc_ctx_t *ctx, const char *room_id, on_get_room_description cb, void *user_data)
{
	char iq_id[128];
	xmpp_ua_get_unique_string(ctx->ua, iq_id);
	xmpp_stanza_t *stanza_iq = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_iq, "iq");
	xmpp_stanza_set_attribute(stanza_iq, "to", room_id);
	xmpp_stanza_set_attribute(stanza_iq, "id", iq_id);
	xmpp_stanza_set_type(stanza_iq, "get");

	xmpp_stanza_t *stanza_query = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_query, "query");
	xmpp_stanza_set_ns(stanza_query, XMPP_NS_MUC_ROOM_INFO);
	xmpp_stanza_add_child(stanza_iq, stanza_query);
	xmpp_stanza_release(stanza_query);

	room_info_data *info_data = (room_info_data *)malloc(sizeof(room_info_data));
	info_data->cb = cb;
	info_data->ctx = ctx;
	info_data->user_data = user_data;
	xmpp_ua_id_handler_add(ctx->ua, _on_room_info, iq_id, info_data);
	xmpp_ua_send(ctx->ua, stanza_iq);
	xmpp_stanza_release(stanza_iq);
	return 0;
}
Example #10
0
int zkmuc_enter_room(zkmuc_ctx_t *ctx, const char *room_id, const char *nick, zkmuc_room_cbs *cbs, void *user_data)
{
	char room_jid[256];
	ctx->room_id = strdup(room_id);
	sprintf(room_jid, "%s/%s", room_id, nick);
	ctx->room_jid = strdup(room_jid);
	ctx->room_cbs = *cbs;///////
	ctx->room_data = user_data;///////

	xmpp_ua_presence_handler_add(ctx->ua, zkmuc_room_presence_handler, ctx);
	xmpp_ua_msg_handler_add(ctx->ua, zkmuc_group_msg_handler, ctx);
	xmpp_ua_msg_handler_add(ctx->ua, _zkmuc_source_query, ctx);
	xmpp_stanza_t *prensece = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(prensece, "presence");
	xmpp_stanza_set_attribute(prensece, "to", ctx->room_jid);

	xmpp_stanza_t *x = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(x, "x");
	xmpp_stanza_set_ns(x, XMPP_NS_MUC);
	xmpp_stanza_add_child(prensece, x);
	xmpp_stanza_release(x);

	xmpp_ua_send(ctx->ua, prensece);
	xmpp_stanza_release(prensece);

	return 0;
}
Example #11
0
static void zkmuc_unlock_room(zkmuc_ctx_t *ctx)
{
	xmpp_stanza_t *iq = xmpp_stanza_new(_xmpp_ctx);
	char id[128];
	xmpp_ua_get_unique_string(ctx->ua, id);

	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_id(iq, id);
	xmpp_stanza_set_type(iq, "set");
	xmpp_stanza_set_attribute(iq, "to", ctx->room_id);

	xmpp_stanza_t *query = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(query, "query");
	xmpp_stanza_set_ns(query, XMPP_NS_MUC_OWNER);

	xmpp_stanza_t *x = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(x, "x");
	xmpp_stanza_set_ns(x, XMPP_NS_X);
	xmpp_stanza_set_type(x, "submit");

	xmpp_stanza_t *field = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(field, "field");
	xmpp_stanza_set_attribute(field, "var", "muc#roomconfig_roomname");

	xmpp_stanza_t *stanza_value = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_value, "value");

	xmpp_stanza_t *stanza_text = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_text(stanza_text, ctx->room_desc);
	xmpp_stanza_add_child(stanza_value, stanza_text);
	xmpp_stanza_release(stanza_text);

	xmpp_stanza_add_child(field, stanza_value);
	xmpp_stanza_release(stanza_value);

	xmpp_stanza_add_child(x, field);
	xmpp_stanza_release(field);

	xmpp_stanza_add_child(query, x);
	xmpp_stanza_release(x);
	xmpp_stanza_add_child(iq, query);
	xmpp_stanza_release(query);

	xmpp_ua_id_handler_add(ctx->ua, zkmuc_unlock_room_result, id, ctx);
	xmpp_ua_send(ctx->ua, iq);
	xmpp_stanza_release(iq);
}
Example #12
0
int register_user(mio_conn_t *conn, char *user, char *pass)
{
	int err;
	mio_response_t *response = mio_response_new();
    xmpp_stanza_t *iq = NULL, *query = NULL, *username = NULL, *username_tag = NULL, *password = NULL, *password_tag = NULL;
    mio_stanza_t *stanza = mio_stanza_new(conn);
    // Check if connection is active
	if (!conn->xmpp_conn->authenticated) {
		return MIO_ERROR_DISCONNECTED;
	}

    // Create a new user stanza
	iq = xmpp_stanza_new(conn->xmpp_conn->ctx);
	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_attribute(iq, "id", "reg2");
	xmpp_stanza_set_type(iq, "set");

    // Creqte query stanza
    query = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    xmpp_stanza_set_name(query,"query");
    xmpp_stanza_set_ns(query,"jabber:iq:register");
    
    // create username stanza 
    username = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    username_tag = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    xmpp_stanza_set_name(username,"username");
    xmpp_stanza_set_text(username_tag, user);



    // create password stanza
    password = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    password_tag = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    xmpp_stanza_set_name(password, "password");
    xmpp_stanza_set_text(password_tag,pass);

    // create password stanza
    password = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    password_tag = xmpp_stanza_new(conn -> xmpp_conn -> ctx);
    xmpp_stanza_set_name(password, "password");
    xmpp_stanza_set_text(password_tag,pass);
    // Build xmpp message
	xmpp_stanza_add_child(password, password_tag);
	xmpp_stanza_add_child(username, username_tag);
	xmpp_stanza_add_child(query, username);
	xmpp_stanza_add_child(query, password);
	xmpp_stanza_add_child(iq, query);
    stanza -> xmpp_stanza = iq;
    
    // Send out the stanza
	err = _mio_send_nonblocking(conn, stanza);
    
    // Release the stanzas
	mio_stanza_free(stanza);
    
	mio_response_free(response);
	return 0;
}
Example #13
0
char*
message_send_chat_pgp(const char *const barejid, const char *const msg)
{
    xmpp_conn_t * const conn = connection_get_conn();
    xmpp_ctx_t * const ctx = connection_get_ctx();

    char *state = _session_state(barejid);
    char *jid = _session_jid(barejid);
    char *id = create_unique_id("msg");

    xmpp_stanza_t *message = NULL;
#ifdef HAVE_LIBGPGME
    char *account_name = jabber_get_account_name();
    ProfAccount *account = accounts_get_account(account_name);
    if (account->pgp_keyid) {
        Jid *jidp = jid_create(jid);
        char *encrypted = p_gpg_encrypt(jidp->barejid, msg);
        if (encrypted) {
            message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, "This message is encrypted.");
            xmpp_stanza_t *x = xmpp_stanza_new(ctx);
            xmpp_stanza_set_name(x, STANZA_NAME_X);
            xmpp_stanza_set_ns(x, STANZA_NS_ENCRYPTED);
            xmpp_stanza_t *enc_st = xmpp_stanza_new(ctx);
            xmpp_stanza_set_text(enc_st, encrypted);
            xmpp_stanza_add_child(x, enc_st);
            xmpp_stanza_release(enc_st);
            xmpp_stanza_add_child(message, x);
            xmpp_stanza_release(x);
            free(encrypted);
        } else {
            message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
        }
        jid_destroy(jidp);
    } else {
        message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
    }
    account_free(account);
#else
    message = stanza_create_message(ctx, id, jid, STANZA_TYPE_CHAT, msg);
#endif
    free(jid);

    if (state) {
        stanza_attach_state(ctx, message, state);
    }

    stanza_attach_carbons_private(ctx, message);

    if (prefs_get_boolean(PREF_RECEIPTS_REQUEST)) {
        stanza_attach_receipt_request(ctx, message);
    }

    xmpp_send(conn, message);
    xmpp_stanza_release(message);

    return id;
}
Example #14
0
/* handle the challenge phase of digest auth */
static int _handle_digestmd5_challenge(xmpp_conn_t * const conn,
			      xmpp_stanza_t * const stanza,
			      void * const userdata)
{
    char *text;
    char *response;
    xmpp_stanza_t *auth, *authdata;
    char *name;

    name = xmpp_stanza_get_name(stanza);
    xmpp_debug(conn->ctx, "xmpp",\
	"handle digest-md5 (challenge) called for %s", name);

    if (strcmp(name, "challenge") == 0) {
	text = xmpp_stanza_get_text(stanza);
	response = sasl_digest_md5(conn->ctx, text, conn->jid, conn->pass);
	if (!response) {
	    disconnect_mem_error(conn);
	    return 0;
	}
	xmpp_free(conn->ctx, text);

	auth = xmpp_stanza_new(conn->ctx);
	if (!auth) {
	    disconnect_mem_error(conn);
	    return 0;
	}
	xmpp_stanza_set_name(auth, "response");
	xmpp_stanza_set_ns(auth, XMPP_NS_SASL);

	authdata = xmpp_stanza_new(conn->ctx);
	if (!authdata) {
	    disconnect_mem_error(conn);
	    return 0;
	}

	xmpp_stanza_set_text(authdata, response);
	xmpp_free(conn->ctx, response);

	xmpp_stanza_add_child(auth, authdata);
	xmpp_stanza_release(authdata);

	handler_add(conn, _handle_digestmd5_rspauth,
		    XMPP_NS_SASL, NULL, NULL, NULL);

	xmpp_send(conn, auth);
	xmpp_stanza_release(auth);

    } else {
	return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
    }

    /* remove ourselves */
    return 0;
}
Example #15
0
void XMPP_IBB_SendPayload(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, 
void * const userdata, char* resp )
{

    static int seq = 0;
    int data_seq = 0;
    char Data_Seq_Buf[32];
    char ID_Buf[32];
    char* encoded_data;
    xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
    xmpp_stanza_t *iq, *data,  *text;

    iq  = xmpp_stanza_new(ctx);
    data = xmpp_stanza_new(ctx);
    text = xmpp_stanza_new(ctx);

    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "set");

    sprintf(ID_Buf, "ID-seq-%d", seq);
    seq++;
    xmpp_stanza_set_id(iq, ID_Buf);
    xmpp_stanza_set_attribute(iq, "to", xmpp_stanza_get_attribute(stanza, "from"));
    xmpp_stanza_set_attribute(iq, "from", xmpp_stanza_get_attribute(stanza, "to"));

    xmpp_stanza_set_name(data, "data");

    xmpp_stanza_set_ns(data, XMLNS_IBB);

    xmpp_stanza_set_attribute(data, "sid",   \
    xmpp_stanza_get_attribute(xmpp_stanza_get_child_by_name(stanza, "data"), "sid"));
  
    sprintf(Data_Seq_Buf , "%d", data_seq);
    xmpp_stanza_set_attribute(data, "seq", Data_Seq_Buf);
       
    printf("\n[Response =%s]\n", resp);
    encoded_data = base64_encode(ctx, (unsigned char*)resp, strlen(resp));

    xmpp_stanza_set_text_with_size(text, encoded_data, strlen(encoded_data));
    xmpp_stanza_add_child(data, text);
    xmpp_stanza_add_child(iq, data);
    xmpp_send(conn, iq);
    seq++;

    free(resp);
    xmpp_free(ctx, encoded_data);

    xmpp_stanza_release(data);
    xmpp_stanza_release(iq);
    xmpp_stanza_release(text);

    xmpp_stanza_release(stanza);  //copied by IBB IQ receiver handler

}
Example #16
0
static int _zkmuc_source_query(xmpp_ua_t *ua, xmpp_stanza_t *stanza, void *userdata)
{
	zkmuc_ctx_t *ctx = (zkmuc_ctx_t *)userdata;
	char *from = xmpp_stanza_get_attribute(stanza, "from");
	char *id = xmpp_stanza_get_id(stanza);
	if (id == NULL)
	{
		return 0;
	}
	xmpp_stanza_t *x = xmpp_stanza_get_child_by_name(stanza, "x");
	if(x && xmpp_stanza_get_ns(x) && !strcmp(XMPP_NS_SOURCE, xmpp_stanza_get_ns(x)))
	{
		char *action = xmpp_stanza_get_attribute(x, "action");
		if (!strcmp("query", action))	
		{
			xmpp_stanza_t *message = xmpp_stanza_new(_xmpp_ctx);
			xmpp_stanza_set_name(message, "message");
			xmpp_stanza_set_attribute(message, "to", from);
			xmpp_stanza_set_id(message, id);

			xmpp_stanza_t *result_x = xmpp_stanza_new(_xmpp_ctx);
			xmpp_stanza_set_name(result_x, "x");
			xmpp_stanza_set_ns(result_x, XMPP_NS_SOURCE);
			xmpp_stanza_set_attribute(result_x, "action", "result");

			WaitForSingleObject(ctx->_mutex_4_source, INFINITE);
			zkmuc_source_t *item = ctx->head;
			while (item)
			{
				xmpp_stanza_t *stanza_item = xmpp_stanza_new(_xmpp_ctx);
				xmpp_stanza_set_name(stanza_item, "item");
				char buf[32];
				xmpp_stanza_set_attribute(stanza_item, "cid", itoa(item->cid, buf, 10));
				xmpp_stanza_set_attribute(stanza_item, "sid", itoa(item->sid, buf, 10));
				xmpp_stanza_set_attribute(stanza_item, "desc", item->description);
				xmpp_stanza_set_attribute(stanza_item, "mcu", item->mcu);
				xmpp_stanza_add_child(result_x, stanza_item);
				xmpp_stanza_release(stanza_item);

				item = item->next;
			}
			ReleaseMutex(ctx->_mutex_4_source);
			xmpp_stanza_add_child(message, result_x);
			xmpp_stanza_release(result_x);
			xmpp_ua_send(ctx->ua, message);
			xmpp_stanza_release(message);

			return 1;
		}
	}
	return 0;
}
Example #17
0
static xmpp_stanza_t *_make_starttls(xmpp_conn_t * const conn)
{
    xmpp_stanza_t *starttls;

    /* build start stanza */
    starttls = xmpp_stanza_new(conn->ctx);
    if (starttls) {
	xmpp_stanza_set_name(starttls, "starttls");
	xmpp_stanza_set_ns(starttls, XMPP_NS_TLS);
    }

    return starttls;
}
Example #18
0
static xmpp_stanza_t *_make_sasl_auth(xmpp_conn_t * const conn,
				 const char * const mechanism)
{
    xmpp_stanza_t *auth;

    /* build auth stanza */
    auth = xmpp_stanza_new(conn->ctx);
    if (auth) {
	xmpp_stanza_set_name(auth, "auth");
	xmpp_stanza_set_ns(auth, XMPP_NS_SASL);
	xmpp_stanza_set_attribute(auth, "mechanism", mechanism);
    }

    return auth;
}
Example #19
0
xmpp_stanza_t *
stanza_create_room_join_presence(xmpp_ctx_t *ctx,
    const char * const full_room_jid)
{
    xmpp_stanza_t *presence = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(presence, STANZA_NAME_PRESENCE);
    xmpp_stanza_set_attribute(presence, STANZA_ATTR_TO, full_room_jid);

    xmpp_stanza_t *x = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(x, STANZA_NAME_X);
    xmpp_stanza_set_ns(x, STANZA_NS_MUC);

    xmpp_stanza_add_child(presence, x);

    return presence;
}
Example #20
0
xmpp_ibb_session_t *xmpp_ibb_open(xmpp_conn_t * const conn, char * const peer, char * const sid)
{
    xmpp_ibb_session_t *sess;
    xmpp_stanza_t *iq, *open;
    xmpp_ctx_t *ctx;
    const char *jid = xmpp_conn_get_bound_jid(conn);
    char sizetemp[6] = "";
    int size;

    if (peer == NULL || strlen(peer) == 0) {
        return NULL;
    }
    sess = _ibb_session_init(conn, peer, sid);
    if (sess == NULL) {
        return NULL;
    }
    size = snprintf(sizetemp, sizeof(sizetemp), "%d", sess->block_size);
    if (size < sizeof(sizetemp)) {
        sizetemp[size] = '\0';
    }
    nmtoken_generate(sess->id, 8);

    ctx = xmpp_conn_get_context(conn);
    iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "set");
    xmpp_stanza_set_id(iq, sess->id);
    xmpp_stanza_set_attribute(iq, "from", jid);
    xmpp_stanza_set_attribute(iq, "to", sess->peer);

    open = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(open, "open");
    xmpp_stanza_set_ns(open, XMLNS_IBB);
    xmpp_stanza_set_attribute(open, "block-size", sizetemp);
    xmpp_stanza_set_attribute(open, "sid", sess->sid);
    xmpp_stanza_set_attribute(open, "stanza", "iq");

    xmpp_stanza_add_child(iq, open);
    xmpp_send(conn, iq);
    xmpp_stanza_release(open);
    xmpp_stanza_release(iq);

    ilist_add(g_list, sess);

    return sess;
}
Example #21
0
xmpp_stanza_t *
stanza_create_roster_iq(xmpp_ctx_t *ctx)
{
    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
    xmpp_stanza_set_id(iq, "roster");

    xmpp_stanza_t *query = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
    xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);

    xmpp_stanza_add_child(iq, query);
    xmpp_stanza_release(query);

    return iq;
}
Example #22
0
int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{
    xmpp_stanza_t *reply, *query, *name, *version, *text;
    const char *ns;
    xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;

    printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));

    reply = xmpp_stanza_reply(stanza);
    xmpp_stanza_set_type(reply, "result");

    query = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(query, "query");
    ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza));
    if (ns) {
        xmpp_stanza_set_ns(query, ns);
    }

    name = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(name, "name");
    xmpp_stanza_add_child(query, name);
    xmpp_stanza_release(name);

    text = xmpp_stanza_new(ctx);
    xmpp_stanza_set_text(text, "libstrophe example bot");
    xmpp_stanza_add_child(name, text);
    xmpp_stanza_release(text);

    version = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(version, "version");
    xmpp_stanza_add_child(query, version);
    xmpp_stanza_release(version);

    text = xmpp_stanza_new(ctx);
    xmpp_stanza_set_text(text, "1.0");
    xmpp_stanza_add_child(version, text);
    xmpp_stanza_release(text);

    xmpp_stanza_add_child(reply, query);
    xmpp_stanza_release(query);

    xmpp_send(conn, reply);
    xmpp_stanza_release(reply);
    return 1;
}
Example #23
0
xmpp_stanza_t *
stanza_create_ping_iq(xmpp_ctx_t *ctx)
{
    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
    xmpp_stanza_set_type(iq, STANZA_TYPE_GET);
    xmpp_stanza_set_id(iq, "c2s1");

    xmpp_stanza_t *ping = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(ping, STANZA_NAME_PING);

    xmpp_stanza_set_ns(ping, STANZA_NS_PING);

    xmpp_stanza_add_child(iq, ping);
    xmpp_stanza_release(ping);

    return iq;
}
Example #24
0
xmpp_stanza_t *
stanza_create_chat_state(xmpp_ctx_t *ctx, const char * const recipient,
    const char * const state)
{
    xmpp_stanza_t *msg, *chat_state;

    msg = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(msg, STANZA_NAME_MESSAGE);
    xmpp_stanza_set_type(msg, STANZA_TYPE_CHAT);
    xmpp_stanza_set_attribute(msg, STANZA_ATTR_TO, recipient);

    chat_state = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(chat_state, state);
    xmpp_stanza_set_ns(chat_state, STANZA_NS_CHATSTATES);
    xmpp_stanza_add_child(msg, chat_state);

    return msg;
}
Example #25
0
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_attribute(iq, "to", "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);
    }
}
Example #26
0
int xmpp_ibb_close(xmpp_ibb_session_t *sess)
{
    xmpp_stanza_t *iq, *close;
    xmpp_ctx_t *ctx;
    const char *jid;

    if (sess == NULL) { return -1; }

    if (!ilist_foundinlist(g_list, sess)) {
        fprintf(stderr, "session is not in handle, may be closed.\n");
        return -1;
    }

    jid = xmpp_conn_get_bound_jid(sess->conn);
    ctx = xmpp_conn_get_context(sess->conn);

    iq = xmpp_stanza_new(ctx);
    close = xmpp_stanza_new(ctx);
    nmtoken_generate(sess->id, 8);

    xmpp_stanza_set_name(iq, "iq");
    xmpp_stanza_set_type(iq, "set");
    xmpp_stanza_set_id(iq, sess->id);
    xmpp_stanza_set_attribute(iq, "to", sess->peer);
    xmpp_stanza_set_attribute(iq, "from", jid);

    xmpp_stanza_set_name(close, "close");
    xmpp_stanza_set_ns(close, XMLNS_IBB);
    xmpp_stanza_set_attribute(close, "sid", sess->sid);

    xmpp_stanza_add_child(iq, close);
    xmpp_send(sess->conn, iq);
    xmpp_stanza_release(close);
    xmpp_stanza_release(iq);

    sess->state = STATE_CLOSING;

    return 0;
}
Example #27
0
static int _SendRosterRequest(xmpp_conn_t * const conn, xmpp_ctx_t *ctx) {
	xmpp_stanza_t *roaster, *roaster_qry;
	char packetId[PACKET_ID_LENGTH_INC_TERM];
	_GeneratePacketId(packetId, PACKET_ID_LENGTH_INC_TERM);
	roaster = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(roaster, "iq");
	xmpp_stanza_set_type(roaster, "get");
	xmpp_stanza_set_id(roaster, packetId);
	roaster_qry = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(roaster_qry, "query");
	xmpp_stanza_set_ns(roaster_qry, XMPP_NS_ROSTER);
	xmpp_stanza_add_child(roaster, roaster_qry);
// we can release the stanza since it belongs to sr_iq now
	xmpp_stanza_release(roaster_qry);
// set up reply handler
	xmpp_handler_add(conn, _HandleRosterReply, "jabber:iq:roster", NULL, NULL,
			ctx);
	xmpp_send(conn, roaster);
	xmpp_stanza_release(roaster);

	return 0;
}
Example #28
0
int zkmuc_invite(zkmuc_ctx_t *ctx, const char *remote_id)
{
	xmpp_stanza_t *stanza_msg = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_msg, "message");
	xmpp_stanza_set_attribute(stanza_msg, "to", remote_id);
	xmpp_stanza_set_ns(stanza_msg, XMPP_NS_CONFERECE);

	xmpp_stanza_t *stanza_body = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_name(stanza_body, "body");

	xmpp_stanza_t *stanza_txt = xmpp_stanza_new(_xmpp_ctx);
	xmpp_stanza_set_text(stanza_txt, ctx->room_id);

	xmpp_stanza_add_child(stanza_body,stanza_txt);
	xmpp_stanza_release(stanza_txt);
	xmpp_stanza_add_child(stanza_msg, stanza_body);
	xmpp_stanza_release(stanza_body);

	xmpp_ua_send(ctx->ua, stanza_msg);
	xmpp_stanza_release(stanza_msg);
	return 0;
}
Example #29
0
static void sdvpSendPing( xmpp_conn_t * const conn, xmpp_ctx_t * const ctx) {

	xmpp_stanza_t *iq,*ping;
	
	iq = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(iq, "iq");
	xmpp_stanza_set_type(iq, "get");
	xmpp_stanza_set_id(iq, "ping");

	ping = xmpp_stanza_new(ctx);
	xmpp_stanza_set_name(ping, "ping");
	xmpp_stanza_set_ns(ping, "urn:xmpp:ping");
	xmpp_stanza_add_child(iq,ping);
	xmpp_stanza_release(ping);

	xmpp_send(conn,iq);
	xmpp_stanza_release(iq);

	sdvpIdleCounter = 0;
	sdvpPingsSent++;

}
Example #30
0
gboolean
blocked_remove(char *jid)
{
    GList *found = g_list_find_custom(blocked, jid, (GCompareFunc)g_strcmp0);
    if (!found) {
        return FALSE;
    }

    xmpp_ctx_t *ctx = connection_get_ctx();

    xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
    xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
    char *id = create_unique_id("unblock");
    xmpp_stanza_set_id(iq, id);

    xmpp_stanza_t *block = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(block, STANZA_NAME_UNBLOCK);
    xmpp_stanza_set_ns(block, STANZA_NS_BLOCKING);

    xmpp_stanza_t *item = xmpp_stanza_new(ctx);
    xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
    xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);

    xmpp_stanza_add_child(block, item);
    xmpp_stanza_release(item);

    xmpp_stanza_add_child(iq, block);
    xmpp_stanza_release(block);

    iq_id_handler_add(id, _block_remove_result_handler, free, strdup(jid));

    iq_send_stanza(iq);
    xmpp_stanza_release(iq);
    free(id);

    return TRUE;
}