aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-10 21:46:51 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-10 22:18:02 +0300
commit84db86f0151385a8f05483bf691fde86b4e4e153 (patch)
treef4b3e184c30f2bbc462a2b67cb52f869881afd47
parent18cf87abfc95f85d184c3f6b328c4a8228609f68 (diff)
downloadwydawca-84db86f0151385a8f05483bf691fde86b4e4e153.tar.gz
wydawca-84db86f0151385a8f05483bf691fde86b4e4e153.tar.bz2
Drop dependencies on argmatch and xgethostname.
-rw-r--r--NEWS2
-rw-r--r--gnulib.modules1
-rw-r--r--src/config.c332
-rw-r--r--src/lock.c43
4 files changed, 188 insertions, 190 deletions
diff --git a/NEWS b/NEWS
index 5a806d5..4bd6735 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ See the end of file for copying conditions.
5Please send Wydawca bug reports to <bug-wydawca@gnu.org.ua>. 5Please send Wydawca bug reports to <bug-wydawca@gnu.org.ua>.
6 6
7 7
8Version 2.1.90 (Git)
9
8Version 2.1 "KMB", 2010-01-06 10Version 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
4mkdtemp 4mkdtemp
5save-cwd 5save-cwd
6backupfile 6backupfile
7xgethostname
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
22struct keyword
23{
24 char *name;
25 int tok;
26};
27
28static int
29keyword_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
40static int
41tok_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
23static struct archive_descr default_archive_descr = { 53static 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
126int
127string_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
148static const char *event_args[] = { 157static 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
157static 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
165ARGMATCH_VERIFY (event_args, event_types);
166
167const char * 166const char *
168notification_event_str (enum notification_event evt) 167notification_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
173int 180int
174string_to_notification_event (grecs_locus_t *locus, const char *val, 181string_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
186static const char *target_args[] = { 194static 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
195static 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
203ARGMATCH_VERIFY (target_args, target_types);
204 203
205const char * 204const char *
206notification_target_str (enum notification_target tgt) 205notification_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
211int 218int
212string_to_notification_target (grecs_locus_t *locus, const char *val, 219string_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