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.c288
-rw-r--r--src/lock.c43
4 files changed, 166 insertions, 168 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.
Please send Wydawca bug reports to <bug-wydawca@gnu.org.ua>.
+Version 2.1.90 (Git)
+
Version 2.1 "KMB", 2010-01-06
* 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
mkdtemp
save-cwd
backupfile
-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 @@
#include "wydawca.h"
#include "sql.h"
-#include "argmatch.h"
#include <mail.h>
+struct keyword
+{
+ char *name;
+ int tok;
+};
+
+static int
+keyword_to_tok (const char *str, struct keyword *kw, int *pres)
+{
+ for (; kw->name; kw++)
+ if (strcmp (kw->name, str) == 0)
+ {
+ *pres = kw->tok;
+ return 0;
+ }
+ return 1;
+}
+
+static int
+tok_to_keyword (int tok, struct keyword *kw, const char **pres)
+{
+ for (; kw->name; kw++)
+ if (kw->tok == tok)
+ {
+ *pres = kw->name;
+ return 0;
+ }
+ return 1;
+}
+
+
static struct archive_descr default_archive_descr = {
archive_none,
NULL,
@@ -123,102 +153,82 @@ safe_file_name_alloc (const char *file_name)
return ns;
}
-int
-string_to (const char *what, const char *str,
- const char **args, int *vals,
- int *pret,
- grecs_locus_t *locus)
-{
- ptrdiff_t x = ARGMATCH (str, args, vals);
- if (x == (ptrdiff_t)-1)
- {
- grecs_error (locus, 0, _("unknown %s: %s"), what, str);
- return 1;
- }
- else if (x == (ptrdiff_t)-2)
- {
- grecs_error (locus, 0, _("ambiguous %s: %s"), what, str);
- return 1;
- }
- *pret = vals[x];
- return 0;
-}
-
-static const char *event_args[] = {
- "success",
- "bad-ownership",
- "bad-directive-signature",
- "bad-detached-signature",
- "check-failure",
- NULL
-};
-
-static int event_types[] = {
- ev_success,
- ev_bad_ownership,
- ev_bad_directive_signature,
- ev_bad_detached_signature,
- ev_check_fail
+static struct keyword event_tab[] = {
+ { "success", ev_success },
+ { "bad-ownership", ev_bad_ownership },
+ { "bad-directive-signature", ev_bad_directive_signature },
+ { "bad-detached-signature", ev_bad_detached_signature },
+ { "check-failure", ev_check_fail },
+ { NULL }
};
-ARGMATCH_VERIFY (event_args, event_types);
-
const char *
notification_event_str (enum notification_event evt)
{
- return ARGMATCH_TO_ARGUMENT ((char*)&evt, event_args, event_types);
+ const char *ret;
+ if (tok_to_keyword (evt, event_tab, &ret))
+ {
+ grecs_error (NULL, 0,
+ _("INTERNAL ERROR: unknown notification event number: %d"),
+ evt);
+ return NULL;
+ }
+ return ret;
}
int
string_to_notification_event (grecs_locus_t *locus, const char *val,
enum notification_event *pret)
{
- int rc, res;
- rc = string_to ("notification event", val,
- event_args, event_types,
- &res,
- locus);
+ int res;
+ if (keyword_to_tok (val, event_tab, &res))
+ {
+ grecs_error (locus, 0, _("unknown notification event: %s"), val);
+ return 1;
+ }
*pret = res;
- return rc;
+ return 0;
}
-static const char *target_args[] = {
- "read",
- "message",
- "admin",
- "owner",
- "user",
- NULL
-};
-
-static int target_types[] = {
- notify_read, /* Read recipients from the message headers */
- notify_read,
- notify_admin, /* System administrator */
- notify_owner, /* Project admin */
- notify_user /* User (uploader) */
+static struct keyword target_tab[] = {
+ { "read", notify_read }, /* Read recipients from the message headers */
+ { "message", notify_read },
+ { "admin", notify_admin}, /* System administrator */
+ { "owner", notify_owner }, /* Project admin */
+ { "user", notify_user }, /* User (uploader) */
+ { NULL }
};
-ARGMATCH_VERIFY (target_args, target_types);
const char *
notification_target_str (enum notification_target tgt)
{
- return ARGMATCH_TO_ARGUMENT ((char*)&tgt, target_args, target_types);
+ const char *ret;
+ if (tok_to_keyword (tgt, target_tab, &ret))
+ {
+ grecs_error (NULL, 0,
+ _("INTERNAL ERROR: unknown notification target number: %d"),
+ tgt);
+ return NULL;
+ }
+ return ret;
}
int
string_to_notification_target (grecs_locus_t *locus, const char *val,
enum notification_target *pret)
{
- int rc, res;
- rc = string_to ("notification target", val,
- target_args, target_types,
- &res,
- locus);
+ int res;
+ if (keyword_to_tok (val, target_tab, &res))
+ {
+ grecs_error (locus, 0,
+ _("unknown notification target: %s"),
+ val);
+ return 1;
+ }
*pret = res;
- return rc;
+ return 0;
}
@@ -400,47 +410,29 @@ cb_set_umask (enum grecs_callback_command cmd,
}
-static const char *stat_args[] = {
- "errors",
- "warnings",
- "bad-signatures",
- "access-violations",
- "complete-triplets",
- "incomplete-triplets",
- "bad-triplets",
- "expired-triplets",
- "triplet-success",
- "uploads",
- "archives",
- "symlinks",
- "rmsymlinks",
- NULL
-};
-
-static unsigned long stat_types[] = {
- STAT_ERRORS,
- STAT_WARNINGS,
- STAT_BAD_SIGNATURE,
- STAT_ACCESS_VIOLATIONS,
- STAT_COMPLETE_TRIPLETS,
- STAT_INCOMPLETE_TRIPLETS,
- STAT_BAD_TRIPLETS,
- STAT_EXPIRED_TRIPLETS,
- STAT_TRIPLET_SUCCESS,
- STAT_UPLOADS,
- STAT_ARCHIVES,
- STAT_SYMLINKS,
- STAT_RMSYMLINKS
+static struct keyword stat_tab[] = {
+ { "errors", STAT_ERRORS },
+ { "warnings", STAT_WARNINGS },
+ { "bad-signatures", STAT_BAD_SIGNATURE },
+ { "access-violations", STAT_ACCESS_VIOLATIONS },
+ { "complete-triplets", STAT_COMPLETE_TRIPLETS },
+ { "incomplete-triplets", STAT_INCOMPLETE_TRIPLETS },
+ { "bad-triplets", STAT_BAD_TRIPLETS },
+ { "expired-triplets", STAT_EXPIRED_TRIPLETS },
+ { "triplet-success", STAT_TRIPLET_SUCCESS },
+ { "uploads", STAT_UPLOADS },
+ { "archives", STAT_ARCHIVES },
+ { "symlinks", STAT_SYMLINKS },
+ { "rmsymlinks", STAT_RMSYMLINKS },
+ { NULL },
};
-ARGMATCH_VERIFY (stat_args, stat_types);
-
static int
parse_single_statmask (grecs_locus_t *locus, const grecs_value_t *val,
unsigned long *pmask, int *invert)
{
const char *arg;
- ptrdiff_t x;
+ int x;
if (val->type != GRECS_TYPE_STRING)
{
@@ -463,19 +455,12 @@ parse_single_statmask (grecs_locus_t *locus, const grecs_value_t *val,
return 0;
}
- x = ARGMATCH (arg, stat_args, stat_types);
-
- if (x == (ptrdiff_t)-1)
+ if (keyword_to_tok (arg, stat_tab, &x))
{
grecs_error (locus, 0, _("unknown statistics type: %s"), arg);
return 1;
}
- else if (x == (ptrdiff_t)-2)
- {
- grecs_error (locus, 0, _("ambiguous statistics type: %s"), arg);
- return 1;
- }
- *pmask = STAT_MASK (stat_types[x]);
+ *pmask = STAT_MASK (x);
return 0;
}
@@ -718,39 +703,27 @@ static struct grecs_keyword syslog_kw[] = {
};
-static char const * const backup_args[] =
-{
- /* In a series of synonyms, present the most meaningful first, so
- that argmatch_valid be more readable. */
- "none", "off",
- "simple", "never",
- "existing", "nil",
- "numbered", "t",
- NULL
-};
-
-static const enum backup_type backup_types[] =
+static struct keyword backup_tab[] =
{
- no_backups, no_backups,
- simple_backups, simple_backups,
- numbered_existing_backups, numbered_existing_backups,
- numbered_backups, numbered_backups
+ { "none", no_backups },
+ { "off", no_backups },
+ { "simple", simple_backups },
+ { "never", simple_backups },
+ { "existing", numbered_existing_backups },
+ { "nil", numbered_existing_backups },
+ { "numbered", numbered_backups },
+ { "t", numbered_backups },
+ { NULL }
};
-/* Ensure that these two vectors have the same number of elements,
- not counting the final NULL in the first one. */
-ARGMATCH_VERIFY (backup_args, backup_types);
-
static enum backup_type
-get_backup_version (grecs_locus_t *locus, const char *ctx,
- const char *version)
+get_backup_version (grecs_locus_t *locus, const char *ctx, const char *version)
{
+ int d;
+
if (version == 0 || *version == 0)
return numbered_existing_backups;
- else
- {
- ptrdiff_t d = ARGMATCH (version, backup_args, backup_types);
- if (d == -2)
+ else if (keyword_to_tok (version, backup_tab, &d))
{
if (ctx)
grecs_error (locus, 0, _("%s: ambiguous backup type `%s'"),
@@ -759,17 +732,7 @@ get_backup_version (grecs_locus_t *locus, const char *ctx,
grecs_error (locus, 0, _("ambiguous backup type `%s'"), version);
return no_backups;
}
- else if (d == -1)
- {
- if (ctx)
- grecs_error (locus, 0, _("%s: invalid backup type `%s'"),
- ctx, version);
- else
- grecs_error (locus, 0, _("invalid backup type `%s'"), version);
- return no_backups;
- }
- return backup_types[d];
- }
+ return d;
}
static int
@@ -1053,24 +1016,20 @@ int
string_to_dictionary_id (grecs_locus_t *locus,
const char *str, enum dictionary_id *idp)
{
- static const char *id_str[] = {
- "project-uploader",
- "project-owner",
- NULL
- };
- static int id_num[] = {
- project_uploader_dict,
- project_owner_dict
+ static struct keyword id_tab[] = {
+ { "project-uploader", project_uploader_dict },
+ { "project-owner", project_owner_dict },
+ { NULL }
};
- ARGMATCH_VERIFY (id_str, id_num);
+ int res;
- int rc, res;
- rc = string_to ("dictionary", str,
- id_str, id_num,
- &res,
- locus);
+ if (keyword_to_tok (str, id_tab, &res))
+ {
+ grecs_error (locus, 0, _("unknown dictionary ID: %s"), str);
+ return 1;
+ }
*idp = res;
- return rc;
+ return 0;
}
static int
@@ -1503,4 +1462,3 @@ config_finish (struct grecs_node *tree)
if (grecs_tree_process (tree, wydawca_kw))
exit (EX_CONFIG);
}
-
diff --git a/src/lock.c b/src/lock.c
index 24d0205..9e73463 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -15,7 +15,6 @@
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
#include "wydawca.h"
-#include "xgethostname.h"
int enable_locking = 1;
char *lockdir;
@@ -173,6 +172,46 @@ expire_stale_lock (const char *file)
unlink (file);
}
+static char *
+host_name ()
+{
+ static char *hostbuf = NULL;
+ size_t size;
+ int rc;
+
+ if (hostbuf)
+ return hostbuf;
+
+ do
+ {
+ if (!hostbuf)
+ {
+ size = 256;
+ hostbuf = xmalloc (size);
+ }
+ else
+ {
+ size_t ns = size * 2;
+ if (size < ns)
+ xalloc_die ();
+ size = ns;
+ hostbuf = xrealloc (hostbuf, size);
+ }
+ }
+ while ((rc = gethostname (hostbuf, size )) == -1 &&
+ (errno == EINVAL
+#ifdef ENAMETOOLONG
+ || errno == ENAMETOOLONG
+#endif
+ ));
+ if (rc)
+ {
+ logmsg (LOG_ERR, _("cannot get hostname: %s"), strerror (rc));
+ exit (EX_SOFTWARE);
+ }
+ return hostbuf;
+}
+
int
wydawca_lock (const char *lockname)
{
@@ -188,7 +227,7 @@ wydawca_lock (const char *lockname)
grecs_asprintf (&tempname, &size, "%s.%lu.%lu.%s",
lockname,
(unsigned long) getpid (),
- (unsigned long) time (NULL), xgethostname ());
+ (unsigned long) time (NULL), host_name ());
if (!tempname)
return LOCK_FAILURE;
if (lock_timeout)

Return to:

Send suggestions and report system problems to the System administrator.