/**
 * Free the entire message queue for a profile.
 */
void
twc_message_queue_free_profile(struct t_twc_profile *profile)
{
    weechat_hashtable_map(profile->message_queues,
                          twc_message_queue_free_map_callback, NULL);
    weechat_hashtable_free(profile->message_queues);
}
void
relay_weechat_msg_add_hashtable (struct t_relay_weechat_msg *msg,
                                 struct t_hashtable *hashtable)
{
    char *types[2] = { "type_keys", "type_values" };
    const char *type;
    int i, count;

    for (i = 0; i < 2; i++)
    {
        type = weechat_hashtable_get_string (hashtable, types[i]);
        if (strcmp (type, WEECHAT_HASHTABLE_INTEGER) == 0)
            relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
        else if (strcmp (type, WEECHAT_HASHTABLE_STRING) == 0)
            relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
        else if (strcmp (type, WEECHAT_HASHTABLE_POINTER) == 0)
            relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
        else if (strcmp (type, WEECHAT_HASHTABLE_BUFFER) == 0)
            relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
        else if (strcmp (type, WEECHAT_HASHTABLE_TIME) == 0)
            relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
    }

    /* number of items */
    count = weechat_hashtable_get_integer (hashtable, "items_count");
    relay_weechat_msg_add_int (msg, count);

    /* add all items */
    weechat_hashtable_map (hashtable,
                           &relay_weechat_msg_hashtable_map_cb, msg);
}
void
weechat_aspell_speller_remove_unused ()
{
    struct t_hashtable *used_spellers;
    struct t_infolist *infolist;

    if (weechat_aspell_plugin->debug)
    {
        weechat_printf (NULL,
                        "%s: removing unused spellers",
                        ASPELL_PLUGIN_NAME);
    }

    /* create a hashtable that will contain all used spellers */
    used_spellers = weechat_hashtable_new (32,
                                           WEECHAT_HASHTABLE_STRING,
                                           WEECHAT_HASHTABLE_STRING,
                                           NULL,
                                           NULL);
    if (!used_spellers)
        return;

    /* collect used spellers and store them in hashtable "used_spellers" */
    weechat_aspell_speller_add_dicts_to_hash (used_spellers,
                                              weechat_config_string (weechat_aspell_config_check_default_dict));
    infolist = weechat_infolist_get ("option", NULL, "aspell.dict.*");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            weechat_aspell_speller_add_dicts_to_hash (used_spellers,
                                                      weechat_infolist_string (infolist, "value"));
        }
        weechat_infolist_free (infolist);
    }

    /*
     * look at current spellers, and remove spellers that are not in hashtable
     * "used_spellers"
     */
    weechat_hashtable_map (weechat_aspell_spellers,
                           &weechat_aspell_speller_remove_unused_cb,
                           used_spellers);

    weechat_hashtable_free (used_spellers);
}
int
relay_weechat_protocol_timer_nicklist_cb (void *data, int remaining_calls)
{
    struct t_relay_client *ptr_client;

    /* make C compiler happy */
    (void) remaining_calls;

    ptr_client = (struct t_relay_client *)data;
    if (!ptr_client || !relay_client_valid (ptr_client))
        return WEECHAT_RC_OK;

    weechat_hashtable_map (RELAY_WEECHAT_DATA(ptr_client, buffers_nicklist),
                           &relay_weechat_protocol_nicklist_map_cb,
                           ptr_client);

    weechat_hashtable_remove_all (RELAY_WEECHAT_DATA(ptr_client, buffers_nicklist));

    RELAY_WEECHAT_DATA(ptr_client, hook_timer_nicklist) = NULL;

    return WEECHAT_RC_OK;
}