Exemplo n.º 1
0
struct groupchat *jabber_chat_join(struct im_connection *ic, const char *room, const char *nick, const char *password)
{
	struct jabber_chat *jc;
	struct xt_node *node;
	struct groupchat *c;
	char *roomjid;

	roomjid = g_strdup_printf("%s/%s", room, nick);
	node = xt_new_node("x", NULL, NULL);
	xt_add_attr(node, "xmlns", XMLNS_MUC);
	if (password) {
		xt_add_child(node, xt_new_node("password", password, NULL));
	}
	node = jabber_make_packet("presence", NULL, roomjid, node);
	jabber_cache_add(ic, node, jabber_chat_join_failed);

	if (!jabber_write_packet(ic, node)) {
		g_free(roomjid);
		return NULL;
	}

	jc = g_new0(struct jabber_chat, 1);
	jc->name = jabber_normalize(room);

	if ((jc->me = jabber_buddy_add(ic, roomjid)) == NULL) {
		g_free(roomjid);
		g_free(jc->name);
		g_free(jc);
		return NULL;
	}

	/* roomjid isn't normalized yet, and we need an original version
	   of the nick to send a proper presence update. */
	jc->my_full_jid = roomjid;

	c = imcb_chat_new(ic, room);
	c->data = jc;

	return c;
}
Exemplo n.º 2
0
static void check_buddy_add(int l)
{
	struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud;
	
	budw1 = jabber_buddy_add( ic, "[email protected]/BitlBee" );
	budw1->last_msg = time( NULL ) - 100;
	budw2 = jabber_buddy_add( ic, "[email protected]/Telepathy" );
	budw2->priority = 2;
	budw2->last_msg = time( NULL );
	budw3 = jabber_buddy_add( ic, "[email protected]/bitlbee" );
	budw3->last_msg = time( NULL ) - 200;
	budw3->priority = 4;
	/* TODO(wilmer): Shouldn't this just return budw3? */
	fail_if( jabber_buddy_add( ic, "[email protected]/Telepathy" ) != NULL );
	
	budn = jabber_buddy_add( ic, "*****@*****.**" );
	/* Shouldn't be allowed if there's already a bare JID. */
	fail_if( jabber_buddy_add( ic, "[email protected]/Illegal" ) );
	
	/* Case sensitivity: Case only matters after the / */
	fail_if( jabber_buddy_by_jid( ic, "[email protected]/BitlBee", 0 ) ==
	         jabber_buddy_by_jid( ic, "[email protected]/bitlbee", 0 ) );
	fail_if( jabber_buddy_by_jid( ic, "[email protected]/telepathy", 0 ) );
	
	fail_unless( jabber_buddy_by_jid( ic, "[email protected]/BitlBee", 0 ) == budw1 );
	fail_unless( jabber_buddy_by_jid( ic, "[email protected]/BitlBee", GET_BUDDY_EXACT ) == budw1 );
	fail_unless( jabber_buddy_by_jid( ic, "[email protected]/BitlBee", GET_BUDDY_CREAT ) == budw1 );

	fail_if( jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_EXACT ) );
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", 0 ) == budw3 );

	/* Check O_FIRST and see if it's indeed the first item from the list. */
	fail_unless( ( bud = jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_FIRST ) ) == budw1 );
	fail_unless( bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL );
	
	/* Change the resource_select setting, now we should get a different resource. */
	set_setstr( &ic->acc->set, "resource_select", "activity" );
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", 0 ) == budw2 );
	
	/* Some testing of bare JID handling (which is horrible). */
	fail_if( jabber_buddy_by_jid( ic, "[email protected]/Illegal", 0 ) );
	fail_if( jabber_buddy_by_jid( ic, "[email protected]/Illegal", GET_BUDDY_CREAT ) );
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", 0 ) == budn );
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_EXACT ) == budn );
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_CREAT ) == budn );
	
	/* More case sensitivity testing, and see if remove works properly. */
	fail_if( jabber_buddy_remove( ic, "[email protected]/telepathy" ) );
	fail_if( jabber_buddy_by_jid( ic, "[email protected]/telepathy", GET_BUDDY_CREAT ) == budw2 );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/Telepathy" ) );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/telepathy" ) );
	
	/* Test activity_timeout and GET_BUDDY_BARE_OK. */
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_BARE_OK ) == budw1 );
	budw1->last_msg -= 50;
	fail_unless( ( bud = jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_BARE_OK ) ) != NULL );
	fail_unless( strcmp( bud->full_jid, "*****@*****.**" ) == 0 );
	
	fail_if( jabber_buddy_remove( ic, "*****@*****.**" ) );
	fail_unless( jabber_buddy_by_jid( ic, "*****@*****.**", 0 ) == budw1 );
	
	fail_if( jabber_buddy_remove( ic, "*****@*****.**" ) );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/bitlbee" ) );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/BitlBee" ) );
	fail_if( jabber_buddy_by_jid( ic, "*****@*****.**", GET_BUDDY_BARE_OK ) );
	
	/* Check if remove_bare() indeed gets rid of all. */
	/* disable this one for now.
	fail_unless( jabber_buddy_remove_bare( ic, "*****@*****.**" ) );
	fail_if( jabber_buddy_by_jid( ic, "*****@*****.**", 0 ) );
	*/

	fail_if( jabber_buddy_remove( ic, "[email protected]/Illegal" ) );
	fail_unless( jabber_buddy_remove( ic, "*****@*****.**" ) );
	fail_if( jabber_buddy_by_jid( ic, "*****@*****.**", 0 ) );
	
	/* Fixing a bug in this branch that caused information to get lost when
	   removing the first full JID from a list. */
	jabber_buddy_add( ic, "[email protected]/A" );
	jabber_buddy_add( ic, "[email protected]/B" );
	jabber_buddy_add( ic, "[email protected]/C" );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/A" ) );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/B" ) );
	fail_unless( jabber_buddy_remove( ic, "[email protected]/C" ) );
}