4 Copyright (c) 2010 MAD Partners, Ltd. (rweikusat@mssgmbh.com)
6 This file is being published in accordance with the GPLv2 terms
7 contained in the COPYING file being part of the fetchmail
8 6.3.17 release, including the OpenSSL exemption.
10 #ifndef fetchmail_uid_db_h
11 #define fetchmail_uid_db_h
17 struct uid_db_record {
22 num - message number assigned by server
23 status - message status (eg seen, deleted, ...)
24 pos - position in record list
26 unsigned num, status, pos;
28 struct uid_db_record *next;
33 Used to find uid records by message number.
35 pos_0_value - highest message number
36 end_value - lowest known message number
38 Grows downwards because the fastuidl-code may record
39 message numbers in non-ascending order but the
40 lookup array should ideally only be large enough to
41 store pointers to interesting ('new') messages.
43 struct uid_db_record **records;
44 unsigned pos_0_value, end_value;
49 struct pat_node *pat_root;
51 struct uid_db_record **records;
52 unsigned records_max, records_next;
54 struct num_ndx num_ndx;
57 typedef int uid_db_traversal_routine(struct uid_db_record *, void *);
60 /** initialization/ finalization */
61 void init_uid_db(struct uid_db *db);
63 void free_uid_db(struct uid_db *db);
65 static inline void clear_uid_db(struct uid_db *db)
71 /** message number index handling */
72 static inline unsigned uid_db_num_ofs(struct num_ndx const *num_ndx, unsigned num)
74 return num_ndx->pos_0_value - num;
77 void set_uid_db_num(struct uid_db *db, struct uid_db_record *rec,
80 static inline void set_uid_db_num_pos_0(struct uid_db *db, unsigned num)
82 db->num_ndx.pos_0_value = num;
83 db->num_ndx.end_value = num + 1;
86 void reset_uid_db_nums(struct uid_db *db);
88 /** various uidl db manipulatiors */
89 struct uid_db_record *uid_db_insert(struct uid_db *db,
90 char const *id, unsigned status);
92 void swap_uid_db_data(struct uid_db *db_0, struct uid_db *db_1);
94 /** search routines */
95 struct uid_db_record *find_uid_by_id(struct uid_db *db, char const *id);
97 static inline struct uid_db_record *
98 find_uid_by_num(struct uid_db *db, unsigned num)
100 struct num_ndx *num_ndx;
102 num_ndx = &db->num_ndx;
103 return num >= num_ndx->end_value ?
104 num_ndx->records[uid_db_num_ofs(num_ndx, num)] : NULL;
107 static inline struct uid_db_record *
108 find_uid_by_pos(struct uid_db *db, unsigned pos)
110 return pos < db->records_next ? db->records[pos] : NULL;
113 static inline struct uid_db_record *
114 first_uid_in_db(struct uid_db *db, char const *id)
116 return find_uid_by_id(db, id);
119 struct uid_db_record *last_uid_in_db(struct uid_db *db, char const *id);
121 /** various accessors */
122 static inline unsigned uid_db_n_records(struct uid_db const *db)
124 return db->records_next;
128 Traverses the struct uid_db records array in insert order,
129 invoking the subroutine pointed to by r with a pointer to
130 each record and the arg pointer as arguments. If the return
131 value of that is non-zero, traverse_uid_db immediately returns
132 with this value. Otherwise, zero is returned after the last
135 The uid_db_traversal_routine must not modify the uid_db during
138 int traverse_uid_db(struct uid_db *db,
139 uid_db_traversal_routine *r, void *arg);