diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-10 21:46:51 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-10 22:18:02 +0300 |
commit | 84db86f0151385a8f05483bf691fde86b4e4e153 (patch) | |
tree | f4b3e184c30f2bbc462a2b67cb52f869881afd47 | |
parent | 18cf87abfc95f85d184c3f6b328c4a8228609f68 (diff) | |
download | wydawca-84db86f0151385a8f05483bf691fde86b4e4e153.tar.gz wydawca-84db86f0151385a8f05483bf691fde86b4e4e153.tar.bz2 |
Drop dependencies on argmatch and xgethostname.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | gnulib.modules | 1 | ||||
-rw-r--r-- | src/config.c | 332 | ||||
-rw-r--r-- | src/lock.c | 43 |
4 files changed, 188 insertions, 190 deletions
@@ -5,6 +5,8 @@ See the end of file for copying conditions. | |||
5 | Please send Wydawca bug reports to <bug-wydawca@gnu.org.ua>. | 5 | Please send Wydawca bug reports to <bug-wydawca@gnu.org.ua>. |
6 | 6 | ||
7 | 7 | ||
8 | Version 2.1.90 (Git) | ||
9 | |||
8 | Version 2.1 "KMB", 2010-01-06 | 10 | Version 2.1 "KMB", 2010-01-06 |
9 | 11 | ||
10 | * Incompatible changes | 12 | * Incompatible changes |
diff --git a/gnulib.modules b/gnulib.modules index 61618ad..3d3f7f9 100644 --- a/gnulib.modules +++ b/gnulib.modules | |||
@@ -4,4 +4,3 @@ getline | |||
4 | mkdtemp | 4 | mkdtemp |
5 | save-cwd | 5 | save-cwd |
6 | backupfile | 6 | backupfile |
7 | xgethostname | ||
diff --git a/src/config.c b/src/config.c index 7353f29..df9816e 100644 --- a/src/config.c +++ b/src/config.c | |||
@@ -16,10 +16,40 @@ | |||
16 | 16 | ||
17 | #include "wydawca.h" | 17 | #include "wydawca.h" |
18 | #include "sql.h" | 18 | #include "sql.h" |
19 | #include "argmatch.h" | ||
20 | #include <mail.h> | 19 | #include <mail.h> |
21 | 20 | ||
22 | 21 | ||
22 | struct keyword | ||
23 | { | ||
24 | char *name; | ||
25 | int tok; | ||
26 | }; | ||
27 | |||
28 | static int | ||
29 | keyword_to_tok (const char *str, struct keyword *kw, int *pres) | ||
30 | { | ||
31 | for (; kw->name; kw++) | ||
32 | if (strcmp (kw->name, str) == 0) | ||
33 | { | ||
34 | *pres = kw->tok; | ||
35 | return 0; | ||
36 | } | ||
37 | return 1; | ||
38 | } | ||
39 | |||
40 | static int | ||
41 | tok_to_keyword (int tok, struct keyword *kw, const char **pres) | ||
42 | { | ||
43 | for (; kw->name; kw++) | ||
44 | if (kw->tok == tok) | ||
45 | { | ||
46 | *pres = kw->name; | ||
47 | return 0; | ||
48 | } | ||
49 | return 1; | ||
50 | } | ||
51 | |||
52 | |||
23 | static struct archive_descr default_archive_descr = { | 53 | static struct archive_descr default_archive_descr = { |
24 | archive_none, | 54 | archive_none, |
25 | NULL, | 55 | NULL, |
@@ -35,7 +65,7 @@ static struct notification *default_notification = NULL; | |||
35 | Strip trailing delimiter if present, unless it is the only character | 65 | Strip trailing delimiter if present, unless it is the only character |
36 | left. E.g.: | 66 | left. E.g.: |
37 | 67 | ||
38 | /home/user/../smith --> /home/smith | 68 | /home/user/../smith --> /home/smith |
39 | /home/user/../.. --> / | 69 | /home/user/../.. --> / |
40 | ../file --> NULL | 70 | ../file --> NULL |
41 | */ | 71 | */ |
@@ -123,102 +153,82 @@ safe_file_name_alloc (const char *file_name) | |||
123 | return ns; | 153 | return ns; |
124 | } | 154 | } |
125 | 155 | ||
126 | int | ||
127 | string_to (const char *what, const char *str, | ||
128 | const char **args, int *vals, | ||
129 | int *pret, | ||
130 | grecs_locus_t *locus) | ||
131 | { | ||
132 | ptrdiff_t x = ARGMATCH (str, args, vals); | ||
133 | |||
134 | if (x == (ptrdiff_t)-1) | ||
135 | { | ||
136 | grecs_error (locus, 0, _("unknown %s: %s"), what, str); | ||
137 | return 1; | ||
138 | } | ||
139 | else if (x == (ptrdiff_t)-2) | ||
140 | { | ||
141 | grecs_error (locus, 0, _("ambiguous %s: %s"), what, str); | ||
142 | return 1; | ||
143 | } | ||
144 | *pret = vals[x]; | ||
145 | return 0; | ||
146 | } | ||
147 | 156 | ||
148 | static const char *event_args[] = { | 157 | static struct keyword event_tab[] = { |
149 | "success", | 158 | { "success", ev_success }, |
150 | "bad-ownership", | 159 | { "bad-ownership", ev_bad_ownership }, |
151 | "bad-directive-signature", | 160 | { "bad-directive-signature", ev_bad_directive_signature }, |
152 | "bad-detached-signature", | 161 | { "bad-detached-signature", ev_bad_detached_signature }, |
153 | "check-failure", | 162 | { "check-failure", ev_check_fail }, |
154 | NULL | 163 | { NULL } |
155 | }; | ||
156 | |||
157 | static int event_types[] = { | ||
158 | ev_success, | ||
159 | ev_bad_ownership, | ||
160 | ev_bad_directive_signature, | ||
161 | ev_bad_detached_signature, | ||
162 | ev_check_fail | ||
163 | }; | 164 | }; |
164 | 165 | ||
165 | ARGMATCH_VERIFY (event_args, event_types); | ||
166 | |||
167 | const char * | 166 | const char * |
168 | notification_event_str (enum notification_event evt) | 167 | notification_event_str (enum notification_event evt) |
169 | { | 168 | { |
170 | return ARGMATCH_TO_ARGUMENT ((char*)&evt, event_args, event_types); | 169 | const char *ret; |
170 | if (tok_to_keyword (evt, event_tab, &ret)) | ||
171 | { | ||
172 | grecs_error (NULL, 0, | ||
173 | _("INTERNAL ERROR: unknown notification event number: %d"), | ||
174 | evt); | ||
175 | return NULL; | ||
176 | } | ||
177 | return ret; | ||
171 | } | 178 | } |
172 | 179 | ||
173 | int | 180 | int |
174 | string_to_notification_event (grecs_locus_t *locus, const char *val, | 181 | string_to_notification_event (grecs_locus_t *locus, const char *val, |
175 | enum notification_event *pret) | 182 | enum notification_event *pret) |
176 | { | 183 | { |
177 | int rc, res; | 184 | int res; |
178 | rc = string_to ("notification event", val, | 185 | if (keyword_to_tok (val, event_tab, &res)) |
179 | event_args, event_types, | 186 | { |
180 | &res, | 187 | grecs_error (locus, 0, _("unknown notification event: %s"), val); |
181 | locus); | 188 | return 1; |
189 | } | ||
182 | *pret = res; | 190 | *pret = res; |
183 | return rc; | 191 | return 0; |
184 | } | 192 | } |
185 | 193 | ||
186 | static const char *target_args[] = { | 194 | static struct keyword target_tab[] = { |
187 | "read", | 195 | { "read", notify_read }, /* Read recipients from the message headers */ |
188 | "message", | 196 | { "message", notify_read }, |
189 | "admin", | 197 | { "admin", notify_admin}, /* System administrator */ |
190 | "owner", | 198 | { "owner", notify_owner }, /* Project admin */ |
191 | "user", | 199 | { "user", notify_user }, /* User (uploader) */ |
192 | NULL | 200 | { NULL } |
193 | }; | ||
194 | |||
195 | static int target_types[] = { | ||
196 | notify_read, /* Read recipients from the message headers */ | ||
197 | notify_read, | ||
198 | notify_admin, /* System administrator */ | ||
199 | notify_owner, /* Project admin */ | ||
200 | notify_user /* User (uploader) */ | ||
201 | }; | 201 | }; |
202 | 202 | ||
203 | ARGMATCH_VERIFY (target_args, target_types); | ||
204 | 203 | ||
205 | const char * | 204 | const char * |
206 | notification_target_str (enum notification_target tgt) | 205 | notification_target_str (enum notification_target tgt) |
207 | { | 206 | { |
208 | return ARGMATCH_TO_ARGUMENT ((char*)&tgt, target_args, target_types); | 207 | const char *ret; |
208 | if (tok_to_keyword (tgt, target_tab, &ret)) | ||
209 | { | ||
210 | grecs_error (NULL, 0, | ||
211 | _("INTERNAL ERROR: unknown notification target number: %d"), | ||
212 | tgt); | ||
213 | return NULL; | ||
214 | } | ||
215 | return ret; | ||
209 | } | 216 | } |
210 | 217 | ||
211 | int | 218 | int |
212 | string_to_notification_target (grecs_locus_t *locus, const char *val, | 219 | string_to_notification_target (grecs_locus_t *locus, const char *val, |
213 | enum notification_target *pret) | 220 | enum notification_target *pret) |
214 | { | 221 | { |
215 | int rc, res; | 222 | int res; |
216 | rc = string_to ("notification target", val, | 223 | if (keyword_to_tok (val, target_tab, &res)) |
217 | target_args, target_types, | 224 | { |
218 | &res, | 225 | grecs_error (locus, 0, |
219 | locus); | 226 | _("unknown notification target: %s"), |
227 | val); | ||
228 | return 1; | ||
229 | } | ||
220 | *pret = res; | 230 | *pret = res; |
221 | return rc; | 231 | return 0; |
222 | } | 232 | } |
223 | 233 | ||
224 | 234 | ||
@@ -328,7 +338,7 @@ cb_email_address (enum grecs_callback_command cmd, | |||
328 | grecs_error (locus, 0, _("too many arguments")); | 338 | grecs_error (locus, 0, _("too many arguments")); |
329 | return 1; | 339 | return 1; |
330 | } | 340 | } |
331 | 341 | ||
332 | *(mu_address_t*) varptr = addr; | 342 | *(mu_address_t*) varptr = addr; |
333 | return rc; | 343 | return rc; |
334 | } | 344 | } |
@@ -400,47 +410,29 @@ cb_set_umask (enum grecs_callback_command cmd, | |||
400 | } | 410 | } |
401 |