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
13 /* If ffs() is missing on, for instance, Solaris, make sure that config.h or fetchmail.h
14 * contains #define __EXTENSIONS__ - autoconf should set it in config.h. */
21 struct uid_db_record {
26 num - message number assigned by server
27 status - message status (eg seen, deleted, ...)
28 pos - position in record list
30 unsigned num, status, pos;
32 struct uid_db_record *next;
37 Used to find uid records by message number.
39 pos_0_value - highest message number
40 end_value - lowest known message number
42 Grows downwards because the fastuidl-code may record
43 message numbers in non-ascending order but the
44 lookup array should ideally only be large enough to
45 store pointers to interesting ('new') messages.
47 struct uid_db_record **records;
48 unsigned pos_0_value, end_value;
53 struct pat_node *pat_root;
55 struct uid_db_record **records;
56 unsigned records_max, records_next;
58 struct num_ndx num_ndx;
61 typedef int uid_db_traversal_routine(struct uid_db_record *, void *);
64 /** initialization/ finalization */
65 void init_uid_db(struct uid_db *db);
67 void free_uid_db(struct uid_db *db);
69 static inline void clear_uid_db(struct uid_db *db)
75 /** message number index handling */
76 static inline unsigned uid_db_num_ofs(struct num_ndx const *num_ndx, unsigned num)
78 return num_ndx->pos_0_value - num;
81 void set_uid_db_num(struct uid_db *db, struct uid_db_record *rec,
84 static inline void set_uid_db_num_pos_0(struct uid_db *db, unsigned num)
86 db->num_ndx.pos_0_value = num;
87 db->num_ndx.end_value = num + 1;
90 void reset_uid_db_nums(struct uid_db *db);
92 /** various uidl db manipulatiors */
93 struct uid_db_record *uid_db_insert(struct uid_db *db,
94 char const *id, unsigned status);
96 void swap_uid_db_data(struct uid_db *db_0, struct uid_db *db_1);
98 /** search routines */
99 struct uid_db_record *find_uid_by_id(struct uid_db *db, char const *id);
101 static inline struct uid_db_record *
102 find_uid_by_num(struct uid_db *db, unsigned num)
104 struct num_ndx *num_ndx;
106 num_ndx = &db->num_ndx;
107 return num >= num_ndx->end_value ?
108 num_ndx->records[uid_db_num_ofs(num_ndx, num)] : NULL;
111 static inline struct uid_db_record *
112 find_uid_by_pos(struct uid_db *db, unsigned pos)
114 return pos < db->records_next ? db->records[pos] : NULL;
117 static inline struct uid_db_record *
118 first_uid_in_db(struct uid_db *db, char const *id)
120 return find_uid_by_id(db, id);
123 struct uid_db_record *last_uid_in_db(struct uid_db *db, char const *id);
125 /** various accessors */
126 static inline unsigned uid_db_n_records(struct uid_db const *db)
128 return db->records_next;
132 Traverses the struct uid_db records array in insert order,
133 invoking the subroutine pointed to by r with a pointer to
134 each record and the arg pointer as arguments. If the return
135 value of that is non-zero, traverse_uid_db immediately returns
136 with this value. Otherwise, zero is returned after the last
139 The uid_db_traversal_routine must not modify the uid_db during
142 int traverse_uid_db(struct uid_db *db,
143 uid_db_traversal_routine *r, void *arg);