~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/lib-storage/mailbox-guid-cache.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/{control,rules}: enable PIE hardening.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "hash.h"
 
5
#include "mail-storage.h"
 
6
#include "mailbox-list-private.h"
 
7
#include "mailbox-guid-cache.h"
 
8
 
 
9
struct mailbox_guid_cache_rec {
 
10
        guid_128_t guid;
 
11
        const char *vname;
 
12
};
 
13
 
 
14
int mailbox_guid_cache_find(struct mailbox_list *list,
 
15
                            const guid_128_t guid, const char **vname_r)
 
16
{
 
17
        const struct mailbox_guid_cache_rec *rec;
 
18
 
 
19
        if (list->guid_cache == NULL) {
 
20
                mailbox_guid_cache_refresh(list);
 
21
                rec = hash_table_lookup(list->guid_cache, guid);
 
22
        } else {
 
23
                rec = hash_table_lookup(list->guid_cache, guid);
 
24
                if (rec == NULL) {
 
25
                        mailbox_guid_cache_refresh(list);
 
26
                        rec = hash_table_lookup(list->guid_cache, guid);
 
27
                }
 
28
        }
 
29
        if (rec == NULL) {
 
30
                *vname_r = NULL;
 
31
                return list->guid_cache_errors ? -1 : 0;
 
32
        }
 
33
        *vname_r = rec->vname;
 
34
        return 0;
 
35
}
 
36
 
 
37
void mailbox_guid_cache_refresh(struct mailbox_list *list)
 
38
{
 
39
        struct mailbox_list_iterate_context *ctx;
 
40
        const struct mailbox_info *info;
 
41
        struct mailbox *box;
 
42
        struct mailbox_metadata metadata;
 
43
        struct mailbox_guid_cache_rec *rec;
 
44
 
 
45
        if (list->guid_cache == NULL) {
 
46
                list->guid_cache_pool =
 
47
                        pool_alloconly_create("guid cache", 1024*16);
 
48
                list->guid_cache = hash_table_create(default_pool,
 
49
                                                     list->guid_cache_pool, 0,
 
50
                                                     guid_128_hash,
 
51
                                                     guid_128_cmp);
 
52
        } else {
 
53
                hash_table_clear(list->guid_cache, TRUE);
 
54
                p_clear(list->guid_cache_pool);
 
55
        }
 
56
        list->guid_cache_errors = FALSE;
 
57
 
 
58
        ctx = mailbox_list_iter_init(list, "*",
 
59
                                     MAILBOX_LIST_ITER_NO_AUTO_BOXES);
 
60
        while ((info = mailbox_list_iter_next(ctx)) != NULL) {
 
61
                if ((info->flags &
 
62
                     (MAILBOX_NOSELECT | MAILBOX_NONEXISTENT)) != 0)
 
63
                        continue;
 
64
 
 
65
                box = mailbox_alloc(list, info->name, 0);
 
66
                if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
 
67
                                         &metadata) < 0) {
 
68
                        i_error("Couldn't get mailbox %s GUID: %s",
 
69
                                info->name, mailbox_get_last_error(box, NULL));
 
70
                        list->guid_cache_errors = TRUE;
 
71
                } else {
 
72
                        rec = p_new(list->guid_cache_pool,
 
73
                                    struct mailbox_guid_cache_rec, 1);
 
74
                        memcpy(rec->guid, metadata.guid, sizeof(rec->guid));
 
75
                        rec->vname = p_strdup(list->guid_cache_pool, info->name);
 
76
                        hash_table_insert(list->guid_cache, rec->guid, rec);
 
77
                }
 
78
                mailbox_free(&box);
 
79
        }
 
80
        if (mailbox_list_iter_deinit(&ctx) < 0)
 
81
                list->guid_cache_errors = TRUE;
 
82
}