Mercurial > dovecot > original-hg > dovecot-1.2
comparison src/lib-storage/mail-storage.c @ 903:fd8888f6f037 HEAD
Naming style changes, finally got tired of most of the typedefs. Also the
previous enum -> macro change reverted so that we don't use the highest bit
anymore, that's incompatible with old indexes so they will be rebuilt.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 05 Jan 2003 15:09:51 +0200 |
parents | 39e0b536e708 |
children | 340dea0150bf |
comparison
equal
deleted
inserted
replaced
902:5043e48c022f | 903:fd8888f6f037 |
---|---|
8 #include <ctype.h> | 8 #include <ctype.h> |
9 | 9 |
10 /* Message to show to users when critical error occurs */ | 10 /* Message to show to users when critical error occurs */ |
11 #define CRITICAL_MSG "Internal error [%Y-%m-%d %H:%M:%S]" | 11 #define CRITICAL_MSG "Internal error [%Y-%m-%d %H:%M:%S]" |
12 | 12 |
13 typedef struct _MailStorageList MailStorageList; | 13 struct mail_storage_list { |
14 | 14 struct mail_storage_list *next; |
15 struct _MailStorageList { | 15 struct mail_storage *storage; |
16 MailStorageList *next; | |
17 MailStorage *storage; | |
18 }; | 16 }; |
19 | 17 |
20 static MailStorageList *storages = NULL; | 18 static struct mail_storage_list *storages = NULL; |
21 | 19 |
22 void mail_storage_class_register(MailStorage *storage_class) | 20 void mail_storage_class_register(struct mail_storage *storage_class) |
23 { | 21 { |
24 MailStorageList *list, **pos; | 22 struct mail_storage_list *list, **pos; |
25 | 23 |
26 list = i_new(MailStorageList, 1); | 24 list = i_new(struct mail_storage_list, 1); |
27 list->storage = storage_class; | 25 list->storage = storage_class; |
28 | 26 |
29 /* append it after the list, so the autodetection order is correct */ | 27 /* append it after the list, so the autodetection order is correct */ |
30 pos = &storages; | 28 pos = &storages; |
31 while (*pos != NULL) | 29 while (*pos != NULL) |
32 pos = &(*pos)->next; | 30 pos = &(*pos)->next; |
33 *pos = list; | 31 *pos = list; |
34 } | 32 } |
35 | 33 |
36 void mail_storage_class_unregister(MailStorage *storage_class) | 34 void mail_storage_class_unregister(struct mail_storage *storage_class) |
37 { | 35 { |
38 MailStorageList **list, *next; | 36 struct mail_storage_list **list, *next; |
39 | 37 |
40 for (list = &storages; *list != NULL; list = &(*list)->next) { | 38 for (list = &storages; *list != NULL; list = &(*list)->next) { |
41 if ((*list)->storage == storage_class) { | 39 if ((*list)->storage == storage_class) { |
42 next = (*list)->next; | 40 next = (*list)->next; |
43 | 41 |
47 *list = next; | 45 *list = next; |
48 } | 46 } |
49 } | 47 } |
50 } | 48 } |
51 | 49 |
52 MailStorage *mail_storage_create(const char *name, const char *data, | 50 struct mail_storage *mail_storage_create(const char *name, const char *data, |
53 const char *user) | 51 const char *user) |
54 { | 52 { |
55 MailStorageList *list; | 53 struct mail_storage_list *list; |
56 | 54 |
57 i_assert(name != NULL); | 55 i_assert(name != NULL); |
58 | 56 |
59 for (list = storages; list != NULL; list = list->next) { | 57 for (list = storages; list != NULL; list = list->next) { |
60 if (strcasecmp(list->storage->name, name) == 0) | 58 if (strcasecmp(list->storage->name, name) == 0) |
62 } | 60 } |
63 | 61 |
64 return NULL; | 62 return NULL; |
65 } | 63 } |
66 | 64 |
67 MailStorage *mail_storage_create_default(const char *user) | 65 struct mail_storage *mail_storage_create_default(const char *user) |
68 { | 66 { |
69 MailStorageList *list; | 67 struct mail_storage_list *list; |
70 MailStorage *storage; | 68 struct mail_storage *storage; |
71 | 69 |
72 for (list = storages; list != NULL; list = list->next) { | 70 for (list = storages; list != NULL; list = list->next) { |
73 storage = list->storage->create(NULL, user); | 71 storage = list->storage->create(NULL, user); |
74 if (storage != NULL) | 72 if (storage != NULL) |
75 return storage; | 73 return storage; |
76 } | 74 } |
77 | 75 |
78 return NULL; | 76 return NULL; |
79 } | 77 } |
80 | 78 |
81 static MailStorage *mail_storage_autodetect(const char *data) | 79 static struct mail_storage *mail_storage_autodetect(const char *data) |
82 { | 80 { |
83 MailStorageList *list; | 81 struct mail_storage_list *list; |
84 | 82 |
85 for (list = storages; list != NULL; list = list->next) { | 83 for (list = storages; list != NULL; list = list->next) { |
86 if (list->storage->autodetect(data)) | 84 if (list->storage->autodetect(data)) |
87 return list->storage; | 85 return list->storage; |
88 } | 86 } |
89 | 87 |
90 return NULL; | 88 return NULL; |
91 } | 89 } |
92 | 90 |
93 MailStorage *mail_storage_create_with_data(const char *data, const char *user) | 91 struct mail_storage *mail_storage_create_with_data(const char *data, |
94 { | 92 const char *user) |
95 MailStorage *storage; | 93 { |
94 struct mail_storage *storage; | |
96 const char *p, *name; | 95 const char *p, *name; |
97 | 96 |
98 if (data == NULL || *data == '\0') | 97 if (data == NULL || *data == '\0') |
99 return mail_storage_create_default(user); | 98 return mail_storage_create_default(user); |
100 | 99 |
113 } | 112 } |
114 | 113 |
115 return storage; | 114 return storage; |
116 } | 115 } |
117 | 116 |
118 void mail_storage_destroy(MailStorage *storage) | 117 void mail_storage_destroy(struct mail_storage *storage) |
119 { | 118 { |
120 i_assert(storage != NULL); | 119 i_assert(storage != NULL); |
121 | 120 |
122 i_free(storage->dir); | 121 i_free(storage->dir); |
123 i_free(storage); | 122 i_free(storage); |
124 } | 123 } |
125 | 124 |
126 void mail_storage_clear_error(MailStorage *storage) | 125 void mail_storage_clear_error(struct mail_storage *storage) |
127 { | 126 { |
128 i_free(storage->error); | 127 i_free(storage->error); |
129 storage->error = NULL; | 128 storage->error = NULL; |
130 | 129 |
131 storage->syntax_error = FALSE; | 130 storage->syntax_error = FALSE; |
132 } | 131 } |
133 | 132 |
134 void mail_storage_set_error(MailStorage *storage, const char *fmt, ...) | 133 void mail_storage_set_error(struct mail_storage *storage, const char *fmt, ...) |
135 { | 134 { |
136 va_list va; | 135 va_list va; |
137 | 136 |
138 i_free(storage->error); | 137 i_free(storage->error); |
139 | 138 |
145 storage->syntax_error = FALSE; | 144 storage->syntax_error = FALSE; |
146 va_end(va); | 145 va_end(va); |
147 } | 146 } |
148 } | 147 } |
149 | 148 |
150 void mail_storage_set_syntax_error(MailStorage *storage, const char *fmt, ...) | 149 void mail_storage_set_syntax_error(struct mail_storage *storage, |
150 const char *fmt, ...) | |
151 { | 151 { |
152 va_list va; | 152 va_list va; |
153 | 153 |
154 i_free(storage->error); | 154 i_free(storage->error); |
155 | 155 |
161 storage->syntax_error = TRUE; | 161 storage->syntax_error = TRUE; |
162 va_end(va); | 162 va_end(va); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 void mail_storage_set_internal_error(MailStorage *storage) | 166 void mail_storage_set_internal_error(struct mail_storage *storage) |
167 { | 167 { |
168 struct tm *tm; | 168 struct tm *tm; |
169 char str[256]; | 169 char str[256]; |
170 | 170 |
171 tm = localtime(&ioloop_time); | 171 tm = localtime(&ioloop_time); |
173 storage->error = strftime(str, sizeof(str), CRITICAL_MSG, tm) > 0 ? | 173 storage->error = strftime(str, sizeof(str), CRITICAL_MSG, tm) > 0 ? |
174 i_strdup(str) : i_strdup("Internal error"); | 174 i_strdup(str) : i_strdup("Internal error"); |
175 storage->syntax_error = FALSE; | 175 storage->syntax_error = FALSE; |
176 } | 176 } |
177 | 177 |
178 void mail_storage_set_critical(MailStorage *storage, const char *fmt, ...) | 178 void mail_storage_set_critical(struct mail_storage *storage, |
179 const char *fmt, ...) | |
179 { | 180 { |
180 va_list va; | 181 va_list va; |
181 | 182 |
182 i_free(storage->error); | 183 i_free(storage->error); |
183 if (fmt == NULL) | 184 if (fmt == NULL) |
192 easier to look from log files the actual error message. */ | 193 easier to look from log files the actual error message. */ |
193 mail_storage_set_internal_error(storage); | 194 mail_storage_set_internal_error(storage); |
194 } | 195 } |
195 } | 196 } |
196 | 197 |
197 const char *mail_storage_get_last_error(MailStorage *storage, int *syntax) | 198 const char *mail_storage_get_last_error(struct mail_storage *storage, |
199 int *syntax) | |
198 { | 200 { |
199 if (syntax != NULL) | 201 if (syntax != NULL) |
200 *syntax = storage->syntax_error; | 202 *syntax = storage->syntax_error; |
201 return storage->error; | 203 return storage->error; |
202 } | 204 } |
203 | 205 |
204 int mail_storage_is_inconsistency_error(Mailbox *box) | 206 int mail_storage_is_inconsistency_error(struct mailbox *box) |
205 { | 207 { |
206 return box->inconsistent; | 208 return box->inconsistent; |
207 } | 209 } |