diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/backup.c | 165 | ||||
-rw-r--r-- | src/builtin.c | 10 | ||||
-rw-r--r-- | src/config.c | 24 | ||||
-rw-r--r-- | src/dictionary.c | 11 | ||||
-rw-r--r-- | src/directive.c | 8 | ||||
-rw-r--r-- | src/diskio.c | 6 | ||||
-rw-r--r-- | src/exec.c | 2 | ||||
-rw-r--r-- | src/gpg.c | 5 | ||||
-rw-r--r-- | src/job.c | 2 | ||||
-rw-r--r-- | src/lock.c | 12 | ||||
-rw-r--r-- | src/mail.c | 14 | ||||
-rw-r--r-- | src/net.c | 4 | ||||
-rw-r--r-- | src/process.c | 4 | ||||
-rw-r--r-- | src/sql.c | 4 | ||||
-rw-r--r-- | src/timer.c | 5 | ||||
-rw-r--r-- | src/triplet.c | 17 | ||||
-rw-r--r-- | src/txtacc.c | 12 | ||||
-rw-r--r-- | src/verify.c | 4 | ||||
-rw-r--r-- | src/wydawca.c | 8 | ||||
-rw-r--r-- | src/wydawca.h | 20 |
21 files changed, 264 insertions, 78 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8139849..3b524ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | sbin_PROGRAMS=wydawca | 17 | sbin_PROGRAMS=wydawca |
18 | wydawca_SOURCES=\ | 18 | wydawca_SOURCES=\ |
19 | backup.c\ | ||
19 | builtin.c\ | 20 | builtin.c\ |
20 | builtin.h\ | 21 | builtin.h\ |
21 | cmdline.h\ | 22 | cmdline.h\ |
@@ -60,8 +61,8 @@ SUFFIXES=.opt .c .h | |||
60 | incdir=$(pkgdatadir)/$(VERSION)/include | 61 | incdir=$(pkgdatadir)/$(VERSION)/include |
61 | inc_DATA = $(PP_SETUP_FILE) | 62 | inc_DATA = $(PP_SETUP_FILE) |
62 | 63 | ||
63 | LDADD=../grecs/src/libgrecs.a ../gnu/libgnu.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@ | 64 | LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @MAILUTILS_LIBS@ |
64 | INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/gnu -I../gnu @MAILUTILS_INCLUDES@ | 65 | INCLUDES = -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@ |
65 | AM_CPPFLAGS= \ | 66 | AM_CPPFLAGS= \ |
66 | -DSYSCONFDIR=\"$(sysconfdir)\"\ | 67 | -DSYSCONFDIR=\"$(sysconfdir)\"\ |
67 | -DLOCALSTATEDIR=\"$(localstatedir)\"\ | 68 | -DLOCALSTATEDIR=\"$(localstatedir)\"\ |
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 @@ | |||
1 | /* wydawca - automatic release submission daemon | ||
2 | Copyright (C) 2011 Sergey Poznyakoff | ||
3 | |||
4 | Wydawca is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU General Public License as published by the | ||
6 | Free Software Foundation; either version 3 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | Wydawca is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License along | ||
15 | with wydawca. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "wydawca.h" | ||
18 | |||
19 | char const *simple_backup_suffix = "~"; | ||
20 | |||
21 | static const char * | ||
22 | split_filename (char const *file, char **pdir) | ||
23 | { | ||
24 | const char *p = strrchr (file, '/'); | ||
25 | |||
26 | if (!p) | ||
27 | { | ||
28 | *pdir = grecs_strdup ("."); | ||
29 | p = file; | ||
30 | } | ||
31 | else | ||
32 | { | ||
33 | size_t len = p - file; | ||
34 | char *dir = grecs_malloc (len + 1); | ||
35 | memcpy (dir, file, len); | ||
36 | dir[len] = 0; | ||
37 | *pdir = dir; | ||
38 | p++; | ||
39 | } | ||
40 | return p; | ||
41 | } | ||
42 | |||
43 | #define MINSUFSIZE 8 | ||
44 | #define ISDIGIT(c) ('0' <= (c) && (c) <= '9') | ||
45 | |||
46 | static char * | ||
47 | get_backup_suffix (char const *file, enum backup_type type) | ||
48 | { | ||
49 | char *dirname; | ||
50 | const char *basename; | ||
51 | size_t baselen; | ||
52 | DIR *dir; | ||
53 | struct dirent *ent; | ||
54 | char *lastsuf = NULL; | ||
55 | size_t lastsuflen = 0; | ||
56 | size_t lastsufsize = 0; | ||
57 | int carry; | ||
58 | char *newsuf; | ||
59 | char *q; | ||
60 | |||
61 | if (type == simple_backups) | ||
62 | return grecs_strdup (simple_backup_suffix); | ||
63 | |||
64 | basename = split_filename (file, &dirname); | ||
65 | baselen = strlen (basename); | ||
66 | dir = opendir (dirname); | ||
67 | if (!dir) | ||
68 | { | ||
69 | int ec = errno; | ||
70 | free (dirname); | ||
71 | errno = ec; | ||
72 | return NULL; | ||
73 | } | ||
74 | |||
75 | while ((ent = readdir (dir))) | ||
76 | { | ||
77 | size_t len = strlen (ent->d_name); | ||
78 | const char *p; | ||
79 | size_t suflen; | ||
80 | |||
81 | if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen)) | ||
82 | continue; | ||
83 | p = ent->d_name + baselen; | ||
84 | suflen = len - baselen; | ||
85 | if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' && | ||
86 | (suflen > lastsuflen | ||
87 | || (suflen == lastsuflen && | ||
88 | memcmp (p, lastsuf, lastsuflen) > 0))) | ||
89 | { | ||
90 | carry = 1; | ||
91 | for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--) | ||
92 | if (*q != '9') | ||
93 | carry = 0; | ||
94 | q++; | ||
95 | if (!ISDIGIT (*q)) | ||
96 | continue; | ||
97 | |||
98 | if (suflen > lastsufsize) | ||
99 | { | ||
100 | lastsufsize = suflen; | ||
101 | if (!lastsuf) | ||
102 | { | ||
103 | if (lastsufsize < MINSUFSIZE) | ||
104 | lastsufsize = MINSUFSIZE; | ||
105 | lastsuf = grecs_malloc (lastsufsize); | ||
106 | } | ||
107 | else | ||
108 | lastsuf = grecs_realloc (lastsuf, lastsufsize); | ||
109 | } | ||
110 | memcpy (lastsuf, p, suflen); | ||
111 | lastsuflen = suflen; | ||
112 | } | ||
113 | } | ||
114 | closedir (dir); | ||
115 | free (dirname); | ||
116 | |||
117 | if (lastsuf) | ||
118 | { | ||
119 | size_t newsuflen; | ||
120 | |||
121 | newsuflen = lastsuflen + carry; | ||
122 | newsuf = grecs_malloc (newsuflen + 1); | ||
123 | newsuf[0] = '.'; | ||
124 | newsuf[1] = '~'; | ||
125 | newsuf[2] = '0'; | ||
126 | memcpy (newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3); | ||
127 | newsuf[newsuflen-1] = '~'; | ||
128 | newsuf[newsuflen] = 0; | ||
129 | |||
130 | for (q = newsuf + newsuflen - 2; *q == '9'; q--) | ||
131 | *q = '0'; | ||
132 | ++*q; | ||
133 | free (lastsuf); | ||
134 | } | ||
135 | else if (type == numbered_existing_backups) | ||
136 | newsuf = grecs_strdup (simple_backup_suffix); | ||
137 | else | ||
138 | newsuf = grecs_strdup (".~1~"); | ||
139 | return newsuf; | ||
140 | } | ||
141 | |||
142 | char * | ||
143 | find_backup_file_name (char const *file, enum backup_type type) | ||
144 | { | ||
145 | size_t flen; | ||
146 | char *suffix; | ||
147 | char *newname; | ||
148 | |||
149 | if (type == no_backups) | ||
150 | { | ||
151 | errno = 0; | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | suffix = get_backup_suffix (file, type); | ||
156 | if (!suffix) | ||
157 | return NULL; | ||
158 | flen = strlen (file); | ||
159 | newname = grecs_malloc (flen + strlen (suffix) + 1); | ||
160 | memcpy (newname, file, flen); | ||
161 | strcpy (newname + flen, suffix); | ||
162 | free (suffix); | ||
163 | /* FIXME: Check newname length */ | ||
164 | return newname; | ||
165 | } | ||
diff --git a/src/builtin.c b/src/builtin.c index 9d1063c..8a07eab 100644 --- a/src/builtin.c +++ b/src/builtin.c | |||
@@ -16,8 +16,10 @@ | |||
16 | 16 | ||
17 | #include "wydawca.h" | 17 | #include "wydawca.h" |
18 | #include "builtin.h" | 18 | #include "builtin.h" |
19 | #include "fnmatch.h" | 19 | |
20 | #include "regex.h" | 20 | #ifndef FNM_CASEFOLD |
21 | # define FNM_CASEFOLD 0 | ||
22 | #endif | ||
21 | 23 | ||
22 | int | 24 | int |
23 | builtin_init (struct dictionary *dict) | 25 | builtin_init (struct dictionary *dict) |
@@ -220,9 +222,9 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req) | |||
220 | size_t i; | 222 | size_t i; |
221 | char *p; | 223 | char *p; |
222 | 224 | ||
223 | bds = xmalloc (sizeof (*bds)); | 225 | bds = grecs_malloc (sizeof (*bds)); |
224 | count *= ncol; | 226 | count *= ncol; |
225 | bds->wp = xcalloc (count, sizeof (bds->wp[0])); | 227 | bds->wp = grecs_calloc (count, sizeof (bds->wp[0])); |
226 | bds->acc = acc; | 228 | bds->acc = acc; |
227 | p = txtacc_finish (acc, 0); | 229 | p = txtacc_finish (acc, 0); |
228 |