aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:21:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:33:34 +0300
commitde3fbe3e8d4dd2a89f7755906d76055784c437cc (patch)
tree65356dd7b5a9010499550c468e960c93515a7e15 /src
parentf569a6f2628b9ddef4dfb4424aff2dad644a8f19 (diff)
downloadwydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.gz
wydawca-de3fbe3e8d4dd2a89f7755906d76055784c437cc.tar.bz2
Drop gnulib.
* bootstrap: Rewrite. * bootstrap.conf: Remove. * configure.ac: Remove gl_EARLY/gl_INIT * src/backup.c: New file. * src/txtacc.c (txtacc_finish): Make sure a new entry is appended only once to the list. * (all sources): Use grecs memory allocation functions. * src/wydawca.h" Include fnmatch.h and regex.h (backup_type): New enum. (simple_backup_suffix): New extern. (find_backup_file_name): New proto. * tests/bkupname.c: New file. * tests/backup00.at: New file. * tests/backup01.at: New file. * tests/backup02.at: New file. * tests/backup03.at: New file. * tests/Makefile.am: Add new tests. * tests/testsuite.at: Add new tests. * grecs: Update.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am5
-rw-r--r--src/backup.c165
-rw-r--r--src/builtin.c10
-rw-r--r--src/config.c26
-rw-r--r--src/dictionary.c11
-rw-r--r--src/directive.c8
-rw-r--r--src/diskio.c6
-rw-r--r--src/exec.c2
-rw-r--r--src/gpg.c7
-rw-r--r--src/job.c2
-rw-r--r--src/lock.c12
-rw-r--r--src/mail.c14
-rw-r--r--src/net.c4
-rw-r--r--src/process.c4
-rw-r--r--src/sql.c4
-rw-r--r--src/timer.c5
-rw-r--r--src/triplet.c17
-rw-r--r--src/txtacc.c16
-rw-r--r--src/verify.c4
-rw-r--r--src/wydawca.c8
-rw-r--r--src/wydawca.h20
21 files changed, 268 insertions, 82 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8139849..3b524ba 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,71 +1,72 @@
# This file is part of Wydawca
# Copyright (C) 2007, 2009, 2010 Sergey Poznyakoff
#
# Wydawca is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# Wydawca is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Wydawca. If not, see <http://www.gnu.org/licenses/>.
sbin_PROGRAMS=wydawca
wydawca_SOURCES=\
+ backup.c\
builtin.c\
builtin.h\
cmdline.h\
config.c\
dictionary.c\
directive.c\
diskio.c\
exec.c\
gpg.c\
interval.c\
job.c\
lock.c\
meta.c\
net.c\
pidfile.c\
process.c\
pushd.c\
sql.c\
sql.h\
tcpwrap.c\
triplet.c\
userprivs.c\
verify.c\
wydawca.c\
wydawca.h\
mail.h\
mail.c\
vtab.c\
null.c\
timer.c\
txtacc.c\
report.c
BUILT_SOURCES=cmdline.h
EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk
SUFFIXES=.opt .c .h
.opt.h:
$(AM_V_GEN)m4 -s $(top_srcdir)/@GRECS_SUBDIR@/build-aux/getopt.m4 $< > $@
incdir=$(pkgdatadir)/$(VERSION)/include
inc_DATA = $(PP_SETUP_FILE)
-LDADD=../grecs/src/libgrecs.a ../gnu/libgnu.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@
-INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/gnu -I../gnu @MAILUTILS_INCLUDES@
+LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@
+INCLUDES = -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@
AM_CPPFLAGS= \
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DLOCALSTATEDIR=\"$(localstatedir)\"\
-DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
-DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
-DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)"
diff --git a/src/backup.c b/src/backup.c
new file mode 100644
index 0000000..312375d
--- /dev/null
+++ b/src/backup.c
@@ -0,0 +1,165 @@
+/* wydawca - automatic release submission daemon
+ Copyright (C) 2011 Sergey Poznyakoff
+
+ Wydawca is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ Wydawca is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with wydawca. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "wydawca.h"
+
+char const *simple_backup_suffix = "~";
+
+static const char *
+split_filename (char const *file, char **pdir)
+{
+ const char *p = strrchr (file, '/');
+
+ if (!p)
+ {
+ *pdir = grecs_strdup (".");
+ p = file;
+ }
+ else
+ {
+ size_t len = p - file;
+ char *dir = grecs_malloc (len + 1);
+ memcpy (dir, file, len);
+ dir[len] = 0;
+ *pdir = dir;
+ p++;
+ }
+ return p;
+}
+
+#define MINSUFSIZE 8
+#define ISDIGIT(c) ('0' <= (c) && (c) <= '9')
+
+static char *
+get_backup_suffix (char const *file, enum backup_type type)
+{
+ char *dirname;
+ const char *basename;
+ size_t baselen;
+ DIR *dir;
+ struct dirent *ent;
+ char *lastsuf = NULL;
+ size_t lastsuflen = 0;
+ size_t lastsufsize = 0;
+ int carry;
+ char *newsuf;
+ char *q;
+
+ if (type == simple_backups)
+ return grecs_strdup (simple_backup_suffix);
+
+ basename = split_filename (file, &dirname);
+ baselen = strlen (basename);
+ dir = opendir (dirname);
+ if (!dir)
+ {
+ int ec = errno;
+ free (dirname);
+ errno = ec;
+ return NULL;
+ }
+
+ while ((ent = readdir (dir)))
+ {
+ size_t len = strlen (ent->d_name);
+ const char *p;
+ size_t suflen;
+
+ if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen))
+ continue;
+ p = ent->d_name + baselen;
+ suflen = len - baselen;
+ if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' &&
+ (suflen > lastsuflen
+ || (suflen == lastsuflen &&
+ memcmp (p, lastsuf, lastsuflen) > 0)))
+ {
+ carry = 1;
+ for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--)
+ if (*q != '9')
+ carry = 0;
+ q++;
+ if (!ISDIGIT (*q))
+ continue;
+
+ if (suflen > lastsufsize)
+ {
+ lastsufsize = suflen;
+ if (!lastsuf)
+ {
+ if (lastsufsize < MINSUFSIZE)
+ lastsufsize = MINSUFSIZE;
+ lastsuf = grecs_malloc (lastsufsize);
+ }
+ else
+ lastsuf = grecs_realloc (lastsuf, lastsufsize);
+ }
+ memcpy (lastsuf, p, suflen);
+ lastsuflen = suflen;
+ }
+ }
+ closedir (dir);
+ free (dirname);
+
+ if (lastsuf)
+ {
+ size_t newsuflen;
+
+ newsuflen = lastsuflen + carry;
+ newsuf = grecs_malloc (newsuflen + 1);
+ newsuf[0] = '.';
+ newsuf[1] = '~';
+ newsuf[2] = '0';
+ memcpy (newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3);
+ newsuf[newsuflen-1] = '~';
+ newsuf[newsuflen] = 0;
+
+ for (q = newsuf + newsuflen - 2; *q == '9'; q--)
+ *q = '0';
+ ++*q;
+ free (lastsuf);
+ }
+ else if (type == numbered_existing_backups)
+ newsuf = grecs_strdup (simple_backup_suffix);
+ else
+ newsuf = grecs_strdup (".~1~");
+ return newsuf;
+}
+
+char *
+find_backup_file_name (char const *file, enum backup_type type)
+{
+ size_t flen;
+ char *suffix;
+ char *newname;
+
+ if (type == no_backups)
+ {
+ errno = 0;
+ return NULL;
+ }
+
+ suffix = get_backup_suffix (file, type);
+ if (!suffix)
+ return NULL;
+ flen = strlen (file);
+ newname = grecs_malloc (flen + strlen (suffix) + 1);
+ memcpy (newname, file, flen);
+ strcpy (newname + flen, suffix);
+ free (suffix);
+ /* FIXME: Check newname length */
+ return newname;
+}
diff --git a/src/builtin.c b/src/builtin.c
index 9d1063c..8a07eab 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -1,44 +1,46 @@
/* wydawca - automatic release submission daemon
Copyright (C) 2009, 2010 Sergey Poznyakoff
Wydawca is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
Wydawca is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
#include "wydawca.h"
#include "builtin.h"
-#include "fnmatch.h"
-#include "regex.h"
+
+#ifndef FNM_CASEFOLD
+# define FNM_CASEFOLD 0
+#endif
int
builtin_init (struct dictionary *dict)
{
return 0;
}
int
builtin_done (struct dictionary *dict)
{
return 0;
}
void *
builtin_open (struct dictionary *dict)
{
return dict;
}
#define CMP_EXACT 0
#define CMP_FNMATCH 1
#define CMP_REGEX 2
#define RF_ICASE 0x1
@@ -199,51 +201,51 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
{
char *val = dict->parmv[i + j];
txtacc_grow (acc, val, strlen (val) + 1);
}
count++;
}
i += ncol;
}
dict->nrow = count;
dict->ncol = ncol;
if (count == 0)
{
txtacc_free (acc);
bds = NULL;
rc = 1;
}
else
{
size_t i;
char *p;
- bds = xmalloc (sizeof (*bds));
+ bds = grecs_malloc (sizeof (*bds));
count *= ncol;
- bds->wp = xcalloc (count, sizeof (bds->wp[0]));
+ bds->wp = grecs_calloc (count, sizeof (bds->wp[0]));
bds->acc = acc;
p = txtacc_finish (acc, 0);
for (i = 0; i < count; i++)
{
bds->wp[i] = p;
p += strlen (p) + 1;
}
rc = 0;
}
dict->storage = bds;
return rc;
}
int
builtin_free_result (struct dictionary *dict, void *handle)
{
if (dict->storage)
{
struct builtin_data_storage *bds = dict->storage;
txtacc_free (bds->acc);
free (bds->wp);
diff --git a/src/config.c b/src/config.c
index df9816e..8250749 100644
--- a/src/config.c
+++ b/src/config.c
@@ -125,49 +125,49 @@ safe_file_name (char *file_name)
/* Copy stuff */
p = q;
while ((*q++ = *s++))
;
continue;
}
}
p++;
}
if (file_name[0] == 0)
{
file_name[0] = '/';
file_name[1] = 0;
}
return file_name;
}
/* Same as safe_file_name, but returns an allocated copy. */
char *
safe_file_name_alloc (const char *file_name)
{
- char *s = xstrdup (file_name);
+ char *s = grecs_strdup (file_name);
char *ns = safe_file_name (s);
if (!ns)
free (s);
return ns;
}
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 }
};
const char *
notification_event_str (enum notification_event evt)
{
const char *ret;
if (tok_to_keyword (evt, event_tab, &ret))
{
grecs_error (NULL, 0,
_("INTERNAL ERROR: unknown notification event number: %d"),
@@ -528,94 +528,94 @@ cb_statistics (enum grecs_callback_command cmd,
return parse_statmask (locus, value, varptr);
}
static int
cb_sql_host (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
struct sqlconn *pconn = varptr;
char *p;
if (assert_string_arg (locus, cmd, value))
return 1;
p = strchr (value->v.string, ':');
if (p)
{
/* FIXME: Modifies constant string */
*p++ = 0;
if (p[0] == '/')
{
- pconn->socket = xstrdup (p);
- pconn->host = xstrdup ("localhost");
+ pconn->socket = grecs_strdup (p);
+ pconn->host = grecs_strdup ("localhost");
}
else
{
char *end;
unsigned long n = strtoul (p, &end, 10);
if (*end)
{
grecs_error (locus, 0, _("invalid port number (near %s)"), end);
return 0;
}
if (n == 0 || n > USHRT_MAX)
{
grecs_error (locus, 0, _("port number out of range 1..%d"),
USHRT_MAX);
return 0;
}
pconn->port = n;
/* Save host name */
- pconn->host = xstrdup (value->v.string);
+ pconn->host = grecs_strdup (value->v.string);
}
}
else
- pconn->host = xstrdup (value->v.string);
+ pconn->host = grecs_strdup (value->v.string);
return 0;
}
static int
cb_sql (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
struct sqlconn *pconn;
void **pdata = cb_data;
switch (cmd) {
case grecs_callback_section_begin:
if (!value || value->type != GRECS_TYPE_STRING)
{
grecs_error(locus, 0, _("tag must be a string"));
return 0;
}
- pconn = xzalloc (sizeof (*pconn));
+ pconn = grecs_zalloc (sizeof (*pconn));
pconn->ident = strdup (value->v.string);
*pdata = pconn;
break;
case grecs_callback_section_end:
pconn = *pdata;
sql_register_conn (pconn);
free (pconn);
*pdata = NULL;
break;
case grecs_callback_set_value:
grecs_error (locus, 0, _("invalid use of block statement"));
}
return 0;
}
static struct grecs_keyword sql_kw[] = {
{ "config-file", N_("file"), N_("Read MySQL configuration from <file>"),
grecs_type_string, NULL, offsetof(struct sqlconn, config_file) },
{ "config-group", N_("name"),
N_("Read the named group from the SQL configuration file"),
grecs_type_string, NULL, offsetof(struct sqlconn, config_group) },
{ "host", N_("host"), N_("Set SQL server hostname or IP address"),
@@ -875,49 +875,49 @@ static struct grecs_keyword notify_event_kw[] = {
{ "recipient", N_("who"), N_("Notify this recipient"),
grecs_type_string, NULL, offsetof(struct notification, tgt),
cb_recipient },
{ "message", N_("text-or-id"),
N_("Text of the notification or identifier of a defined message template"),
grecs_type_string, NULL, offsetof(struct notification, msg) },
{ "gpg-sign", N_("key"),
N_("Sign message with this key"),
grecs_type_string, NULL, offsetof(struct notification, sign_keys) },
{ NULL }
};
static int
cb_notify_event (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
struct notification *ntf;
void **pdata = cb_data;
switch (cmd) {
case grecs_callback_section_begin:
- ntf = xzalloc (sizeof (*ntf));
+ ntf = grecs_zalloc (sizeof (*ntf));
*pdata = ntf;
break;
case grecs_callback_section_end:
ntf = *pdata;
if (!ntf->msg)
grecs_error (locus, 0, _("missing message definition"));
else
{
struct notification **p = (struct notification **) varptr;
ntf->next = *p;
*p = ntf;
/* FIXME: check ev and tgt? */
}
break;
case grecs_callback_set_value:
grecs_error (locus, 0, _("invalid use of block statement"));
}
return 0;
}
@@ -963,58 +963,58 @@ cb_dictionary_params (enum grecs_callback_command cmd,
if (cmd != grecs_callback_set_value)
{
grecs_error (locus, 0, _("Unexpected block statement"));
return 1;
}
if (!value || value->type != GRECS_TYPE_LIST)
{
grecs_error (locus, 0, _("expected list value"));
return 1;
}
size = grecs_list_size (value->v.list);
if (size == 0)
{
meth->parmc = 0;
meth->parmv = NULL;
}
else
{
int i;
struct grecs_list_entry *ep;
meth->parmc = size;
- meth->parmv = xcalloc (size + 1, sizeof (meth->parmv[0]));
+ meth->parmv = grecs_calloc (size + 1, sizeof (meth->parmv[0]));
for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++)
{
const grecs_value_t *vp = ep->data;
if (assert_string_arg (locus, cmd, vp))
break;
- meth->parmv[i] = xstrdup (vp->v.string);
+ meth->parmv[i] = grecs_strdup (vp->v.string);
}
meth->parmv[i] = NULL;
}
return 0;
}
static struct grecs_keyword dictionary_kw[] = {
{ "type", N_("type"), N_("Dictionary type"),
grecs_type_string, NULL, offsetof(struct dictionary, type),
cb_dictionary_type },
{ "query", N_("string"), N_("Query template"),
grecs_type_string, NULL, offsetof(struct dictionary, query) },
{ "params", N_("arg"), N_("Set dictionary parameters"),
grecs_type_string|GRECS_LIST, NULL, 0,
cb_dictionary_params },
{ NULL }
};
int
string_to_dictionary_id (grecs_locus_t *locus,
const char *str, enum dictionary_id *idp)
{
static struct keyword id_tab[] = {
{ "project-uploader", project_uploader_dict },
@@ -1138,50 +1138,50 @@ static struct grecs_keyword spool_kw[] = {
grecs_type_string, NULL, offsetof(struct spool, check_script) },
{ NULL }
};
static int
cb_spool (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
struct spool *spool;
void **pdata = cb_data;
int rc, ec, i;
switch (cmd)
{
case grecs_callback_section_begin:
if (!value || value->type != GRECS_TYPE_STRING)
{
grecs_error (locus, 0, _("tag must be a string"));
return 1;
}
- spool = xzalloc (sizeof (*spool));
- spool->tag = xstrdup (value->v.string);
+ spool = grecs_zalloc (sizeof (*spool));
+ spool->tag = grecs_strdup (value->v.string);
spool->file_sweep_time = file_sweep_time;
for (i = 0; i < NITEMS (spool->dictionary); i++)
spool->dictionary[i] = default_dictionary[i];
spool->archive = default_archive_descr;
*pdata = spool;
break;
case grecs_callback_section_end:
rc = 0;
spool = *pdata;
if (!spool->source_dir)
{
grecs_error (locus, 0, _("source is not given"));
rc = 1;
}
else if (test_dir (spool->source_dir, &ec))
{
if (ec)
grecs_error (locus, ec, _("cannot access %s"), spool->source_dir);
else
grecs_error (locus, 0, _("%s is not a directory"),
spool->source_dir);
rc = 1;
}
@@ -1256,50 +1256,50 @@ cb_supp_groups (enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
grecs_value_t *value,
void *cb_data)
{
if (cmd != grecs_callback_set_value)
{
grecs_error (locus, 0, _("Unexpected block statement"));
return 1;
}
if (!value || value->type != GRECS_TYPE_LIST)
{
grecs_error (locus, 0, _("expected list value"));
return 1;
}
wydawca_supp_groupc = grecs_list_size (value->v.list);
if (wydawca_supp_groupc == 0)
wydawca_supp_groups = NULL;
else
{
int i;
struct grecs_list_entry *ep;
- wydawca_supp_groups = xcalloc (wydawca_supp_groupc,
- sizeof (wydawca_supp_groups[0]));
+ wydawca_supp_groups = grecs_calloc (wydawca_supp_groupc,
+ sizeof (wydawca_supp_groups[0]));
for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++)
{
const grecs_value_t *vp = ep->data;
struct group *grp;
if (assert_string_arg (locus, cmd, vp))
break;
grp = getgrnam (vp->v.string);
if (!grp)
{
grecs_error (locus, 0, _("no such group: %s"), value->v.string);
break;
}
wydawca_supp_groups[i] = grp->gr_gid;
}
}
return 0;
}
static struct grecs_keyword locking_kw[] = {
{ "enable", NULL, N_("Enable or disable locking"),
grecs_type_bool, &enable_locking },
diff --git a/src/dictionary.c b/src/dictionary.c
index b7baf05..2b995d4 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -27,92 +27,93 @@ struct dictionary_descr
int (*free) (struct dictionary *, void *);
void *(*open) (struct dictionary *);
int (*close) (struct dictionary *, void *);
int (*get) (struct dictionary *, void *, unsigned, unsigned);
int (*lookup) (struct dictionary *, void *, const char *);
int (*quote) (struct dictionary *, void *, const char *, char **, size_t *);
};
static struct dictionary_descr dictionary_tab[] = {
{ "none", NULL, NULL, NULL, NULL, NULL, NULL, NULL },
{ "sql", sql_init_dictionary, sql_done_dictionary, sql_free_result,
sql_open, NULL, sql_get_dictionary, sql_lookup_dictionary, sql_quote },
{ "builtin", builtin_init, builtin_done, builtin_free_result,
builtin_open, NULL,
builtin_get,
builtin_lookup },
{ "external", NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
struct dictionary *
dictionary_new (enum dictionary_id id, enum dictionary_type type)
{
- struct dictionary *mp = xmalloc (sizeof mp[0]);
- memset (mp, 0, sizeof mp[0]);
+ struct dictionary *mp = grecs_zalloc (sizeof mp[0]);
mp->id = id;
mp->type = type;
return mp;
}
int
dictionary_init (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
int rc = 0;
if (dict->init_passed++)
return 0;
if (debug_level > 1)
{
int i;
logmsg (LOG_DEBUG, _("initializing dictionary: %s \"%s\""),
mp->name, SP (dict->query));
for (i = 0; i < dict->parmc; i++)
logmsg (LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]);
}
if (mp->init)
rc = mp->init (dict);
if (rc == 0)
dict->init_passed = 1;
return rc;
}
void *
dictionary_open (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
if (!mp->open)
return NULL;
return mp->open (dict);
}
int
dictionary_close (struct dictionary *dict, void *handle)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
+ if (mp->free)
+ mp->free (dict, handle);
if (!mp->close)
return 0;
return mp->close (dict, handle);
}
int
dictionary_done (struct dictionary *dict)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
int rc = 0;
if (dict->init_passed == 0)
return 0;
if (--dict->init_passed)
return 0;
if (debug_level > 1)
{
int i;
logmsg (LOG_DEBUG, _("closing dictionary: %s \"%s\""),
mp->name, SP (dict->query));
for (i = 0; i < dict->parmc; i++)
logmsg (LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]);
}
if (mp->done)
@@ -165,64 +166,64 @@ dictionary_num_rows (struct dictionary *dict)
unsigned
dictionary_num_cols (struct dictionary *dict)
{
return dict->ncol;
}
const char *
dictionary_result (struct dictionary *dict, void *handle,
unsigned nrow, unsigned ncol)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
if (nrow >= dict->nrow || ncol >= dict->ncol
|| mp->get (dict, handle, nrow, ncol))
return NULL;
return dict->result;
}
void
dictionary_copy_result (struct dictionary *dict, const char *res, size_t size)
{
if (dict->result_size < size + 1)
{
dict->result_size = size + 1;
- dict->result = x2realloc (dict->result, &dict->result_size);
+ dict->result = grecs_realloc (dict->result, dict->result_size);
}
memcpy (dict->result, res, size);
dict->result[size] = 0;
}
/* Quote non-printable characters in INPUT. Point *OUTPUT to the malloc'ed
quoted string. Return its length. */
int
dictionary_quote_string (struct dictionary *dict, void *handle,
const char *input,
char **poutput, size_t *psize)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
size_t size;
int quote;
char *output;
if (!input)
{
- *poutput = xmalloc (1);
+ *poutput = grecs_malloc (1);
(*poutput)[0] = 0;
*psize = 1;
return 0;
}
if (mp->quote)
return mp->quote (dict, handle, input, poutput, psize);
size = wordsplit_c_quoted_length (input, 0, &quote);
- output = xmalloc (size + 1);
+ output = grecs_malloc (size + 1);
wordsplit_c_quote_copy (output, input, 0);
output[size] = 0;
*poutput = output;
if (psize)
*psize = size;
return 0;
}
diff --git a/src/directive.c b/src/directive.c
index 08a14df..fadaedf 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -13,49 +13,49 @@
You should have received a copy of the GNU General Public License along
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
#include "wydawca.h"
/* Directive file support */
/* Parse directives from TRP->blurb. Fill TRP->directive */
int
directive_parse (struct file_triplet *trp)
{
size_t dcount, i, j;
char *p;
if (debug_level > 2)
logmsg (LOG_DEBUG, _("%s: parsing directive blurb: %s"),
trp->file[file_directive].name, trp->blurb);
dcount = 0;
for (p = trp->blurb; *p; p++)
if (*p == '\n')
dcount++;
- trp->directive = xcalloc (dcount + 1, sizeof trp->directive[0]);
+ trp->directive = grecs_calloc (dcount + 1, sizeof trp->directive[0]);
p = trp->blurb;
for (i = j = 0; i < dcount; i++)
{
trp->directive[j] = p;
p = strchr (p, '\n');
if (p)
*p++ = 0;
if (trim (trp->directive[j]) == 0) /* ignore empty lines */
continue;
if (strchr (trp->directive[j], ':') == NULL)
{
logmsg (LOG_ERR, _("%s: invalid line: %s"),
trp->file[file_directive].name, trp->directive[j]);
free (trp->directive);
trp->directive = NULL;
return 1;
}
j++;
if (!p)
break;
}
trp->directive[j] = NULL;
return 0;
}
@@ -90,49 +90,49 @@ directive_get_value (struct file_triplet *trp, const char *key,
Arguments:
N - Index of the current directive,
TRP - Triplet,
PKEY, PVAL - Return addresses.
The function points PKEY and PVAL to the keyword and value of the Nth
directive, and returns N + 1.
If N points past all the directive, the function returns 0. */
static int
_directive_seq_get (int n, struct file_triplet *trp,
const char **pkey, const char **pval)
{
char *p;
size_t len;
if (trp->directive[n] == NULL)
return 0;
p = strchr (trp->directive[n], ':');
len = p - trp->directive[n];
if (len + 1 > trp->tmpsize)
{
trp->tmpsize = len + 1;
- trp->tmp = x2realloc (trp->tmp, &trp->tmpsize);
+ trp->tmp = grecs_realloc (trp->tmp, trp->tmpsize);
}
memcpy (trp->tmp, trp->directive[n], len);
trp->tmp[len] = 0;
*pkey = trp->tmp;
for (p++; *p && isspace (*p); p++)
;
if (pval)
*pval = p;
return ++n;
}
/* Get the first directive from TRP. Point *PKEY to its keyword and
*PVAL to its value. Return 1 on success, 0 on failure. */
int
directive_first (struct file_triplet *trp,
const char **pkey, const char **pval)
{
int n = 0;
return _directive_seq_get (n, trp, pkey, pval);
}
/* Get the first directive from TRP. Point *PKEY to its keyword and
*PVAL to its value. Return 1 on success, 0 on failure.
Return non-0 on success, 0 on failure */
@@ -359,49 +359,49 @@ stderr_redirector (const char *tag)
if (pipe (p))
{
logmsg (LOG_CRIT, "redirector pipe: %s", strerror (errno));
return -1;
}
pid = fork ();
if (pid == -1)
{
logmsg (LOG_CRIT, "redirector fork: %s", strerror (errno));
return -1;
}
if (pid == 0)
{
FILE *fp;
size_t size = 0;
char *buf = NULL;
close (p[1]);
fp = fdopen (p[0], "r");
if (!fp)
_exit (127);
- while (getline (&buf, &size, fp) >= 0)
+ while (grecs_getline (&buf, &size, fp) >= 0)
{