Beispiel #1
0
gboolean
bookmark_join(const char *jid)
{
    Bookmark *item = malloc(sizeof(*item));
    item->jid = strdup(jid);
    item->nick = NULL;
    item->password = NULL;
    item->autojoin = FALSE;

    GList *found = g_list_find_custom(bookmark_list, item, _match_bookmark_by_jid);
    _bookmark_item_destroy(item);
    if (found == NULL) {
        return FALSE;
    } else {
        char *account_name = jabber_get_account_name();
        ProfAccount *account = accounts_get_account(account_name);
        Bookmark *item = found->data;
        if (!muc_active(item->jid)) {
            char *nick = item->nick;
            if (nick == NULL) {
                nick = account->muc_nick;
            }
            presence_join_room(item->jid, nick, item->password);
            muc_join(item->jid, nick, item->password, FALSE);
            account_free(account);
        } else if (muc_roster_complete(item->jid)) {
            ui_room_join(item->jid, TRUE);
        }
        return TRUE;
    }
}
Beispiel #2
0
gboolean
bookmark_join(const char *jid)
{
    assert(jid != NULL);

    Bookmark *bookmark = g_hash_table_lookup(bookmarks, jid);
    if (!bookmark) {
        return FALSE;
    }

    char *account_name = session_get_account_name();
    ProfAccount *account = accounts_get_account(account_name);
    if (!muc_active(bookmark->barejid)) {
        char *nick = bookmark->nick;
        if (!nick) {
            nick = account->muc_nick;
        }
        presence_join_room(bookmark->barejid, nick, bookmark->password);
        muc_join(bookmark->barejid, nick, bookmark->password, FALSE);
        account_free(account);
    } else if (muc_roster_complete(bookmark->barejid)) {
        ui_room_join(bookmark->barejid, TRUE);
        account_free(account);
    }

    return TRUE;
}
Beispiel #3
0
static void
channels_join_func(SERVER_REC *server, const char *data, int automatic)
{
	/* ignore automatic joins from irssi */
	if (automatic)
		return;
	muc_join(XMPP_SERVER(server), data, FALSE);
}
Beispiel #4
0
static void
restore_channels(XMPP_SERVER_REC *server)
{
	GSList *tmp;

	if (server->connrec->channels_list != NULL)
		return;
	for (tmp = server->connrec->channels_list; tmp != NULL;
	    tmp = tmp->next) {
	    	muc_join(server, tmp->data, TRUE);
		g_free(tmp->data);
	}
	g_slist_free(server->connrec->channels_list);
	server->connrec->channels_list = NULL;
}
Beispiel #5
0
static void
sig_connected(SERVER_REC *server)
{
	GSList *tmp;
	CHANNEL_SETUP_REC *channel_setup;

	if (!IS_XMPP_SERVER(server))
		return;
	server->channel_find_func = channel_find_func;
	server->channels_join = channels_join_func;
	server->ischannel = ischannel_func;
	/* autojoin channels */
	if (!server->connrec->no_autojoin_channels) {
		for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
			channel_setup = tmp->data;
			if (IS_MUC_SETUP(channel_setup)
			    && channel_setup->autojoin
			    && strcmp(channel_setup->chatnet,
			    server->connrec->chatnet) == 0)
				 muc_join(XMPP_SERVER(server),
				     channel_setup->name, TRUE);
		}
	}
}
Beispiel #6
0
static int
_bookmark_handle_result(xmpp_conn_t *const conn,
    xmpp_stanza_t *const stanza, void *const userdata)
{
    xmpp_ctx_t *ctx = connection_get_ctx();
    char *id = (char *)userdata;
    xmpp_stanza_t *ptr;
    xmpp_stanza_t *nick;
    xmpp_stanza_t *password_st;
    char *name;
    char *jid;
    char *autojoin;
    char *password;
    gboolean autojoin_val;
    Jid *my_jid;
    Bookmark *item;

    xmpp_timed_handler_delete(conn, _bookmark_handle_delete);
    g_free(id);

    name = xmpp_stanza_get_name(stanza);
    if (!name || strcmp(name, STANZA_NAME_IQ) != 0) {
        return 0;
    }

    ptr = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
    if (!ptr) {
        return 0;
    }
    ptr = xmpp_stanza_get_child_by_name(ptr, STANZA_NAME_STORAGE);
    if (!ptr) {
        return 0;
    }

    if (bookmark_ac == NULL) {
        bookmark_ac = autocomplete_new();
    }
    my_jid = jid_create(jabber_get_fulljid());

    ptr = xmpp_stanza_get_children(ptr);
    while (ptr) {
        name = xmpp_stanza_get_name(ptr);
        if (!name || strcmp(name, STANZA_NAME_CONFERENCE) != 0) {
            ptr = xmpp_stanza_get_next(ptr);
            continue;
        }
        jid = xmpp_stanza_get_attribute(ptr, STANZA_ATTR_JID);
        if (!jid) {
            ptr = xmpp_stanza_get_next(ptr);
            continue;
        }

        log_debug("Handle bookmark for %s", jid);

        name = NULL;
        nick = xmpp_stanza_get_child_by_name(ptr, "nick");
        if (nick) {
            char *tmp;
            tmp = xmpp_stanza_get_text(nick);
            if (tmp) {
                name = strdup(tmp);
                xmpp_free(ctx, tmp);
            }
        }

        password = NULL;
        password_st = xmpp_stanza_get_child_by_name(ptr, "password");
        if (password_st) {
            char *tmp;
            tmp = xmpp_stanza_get_text(password_st);
            if (tmp) {
                password = strdup(tmp);
                xmpp_free(ctx, tmp);
            }
        }

        autojoin = xmpp_stanza_get_attribute(ptr, "autojoin");
        if (autojoin && (strcmp(autojoin, "1") == 0 || strcmp(autojoin, "true") == 0)) {
            autojoin_val = TRUE;
        } else {
            autojoin_val = FALSE;
        }

        autocomplete_add(bookmark_ac, jid);
        item = malloc(sizeof(*item));
        item->jid = strdup(jid);
        item->nick = name;
        item->password = password;
        item->autojoin = autojoin_val;
        bookmark_list = g_list_append(bookmark_list, item);

        if (autojoin_val) {
            Jid *room_jid;

            char *account_name = jabber_get_account_name();
            ProfAccount *account = accounts_get_account(account_name);
            if (name == NULL) {
                name = account->muc_nick;
            }

            log_debug("Autojoin %s with nick=%s", jid, name);
            room_jid = jid_create_from_bare_and_resource(jid, name);
            if (!muc_active(room_jid->barejid)) {
                presence_join_room(jid, name, password);
                muc_join(jid, name, password, TRUE);
            }
            jid_destroy(room_jid);
            account_free(account);
        }

        ptr = xmpp_stanza_get_next(ptr);
    }

    jid_destroy(my_jid);

    return 0;
}