Commit | Line | Data |
---|---|---|
5b62e993 MW |
1 | #include "strerr.h" |
2 | #include "subscribe.h" | |
f8beb284 MW |
3 | #include "sgetopt.h" |
4 | #include "substdio.h" | |
5 | #include "readwrite.h" | |
6 | #include "getln.h" | |
7 | #include "scan.h" | |
8 | #include "errtxt.h" | |
9 | #include "idx.h" | |
5b62e993 MW |
10 | |
11 | #define FATAL "ezmlm-unsub: fatal: " | |
f8beb284 MW |
12 | |
13 | void *psql = (void *) 0; | |
14 | ||
15 | char inbuf[512]; | |
16 | substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf)); | |
17 | ||
18 | stralloc line = {0}; | |
19 | ||
20 | void die_usage() | |
21 | { | |
22 | strerr_die1x(100, | |
23 | "ezmlm-unsub: usage: ezmlm-unsub [-h hash] [-HmMnNvV] dir box@domain ..."); | |
24 | } | |
5b62e993 MW |
25 | |
26 | void main(argc,argv) | |
27 | int argc; | |
28 | char **argv; | |
29 | { | |
30 | char *dir; | |
31 | char *addr; | |
f8beb284 MW |
32 | char *cp; |
33 | char ch; | |
34 | int match; | |
35 | int flagmysql = 1; /* if there is mysql support, use it! */ | |
36 | int forcehash = -1; | |
37 | int flagname = 0; | |
38 | unsigned int u; | |
39 | int opt; | |
5b62e993 | 40 | |
f8beb284 MW |
41 | (void) umask(022); |
42 | ||
43 | while ((opt = getopt(argc,argv,"h:HmMnNvV")) != opteof) | |
44 | switch(opt) { | |
45 | case 'h': (void) scan_ulong(optarg,&u); forcehash = 0; break; | |
46 | case 'H': forcehash = -1; break; | |
47 | case 'm': flagmysql = 1; break; | |
48 | case 'M': flagmysql = 0; break; | |
49 | case 'n': flagname = 1; break; | |
50 | case 'N': flagname = 0; break; | |
51 | case 'v': | |
52 | case 'V': strerr_die2x(0, | |
53 | "ezmlm-unsub version: ezmlm-0.53+",EZIDX_VERSION); | |
54 | default: | |
55 | die_usage(); | |
5b62e993 MW |
56 | } |
57 | ||
f8beb284 MW |
58 | dir = argv[optind++]; |
59 | if (!dir) die_usage(); | |
60 | ||
61 | if (dir[0] != '/') | |
62 | strerr_die2x(100,FATAL,ERR_SLASH); | |
63 | ||
64 | if (chdir(dir) == -1) | |
65 | strerr_die4sys(111,FATAL,ERR_SWITCH,dir,": "); | |
66 | ||
67 | if (forcehash == 0) forcehash = (int) u; | |
68 | ||
69 | if (argv[optind]) { | |
70 | while ((addr = argv[optind++])) | |
71 | (void) subscribe(dir,addr,0,"","-manual",flagmysql, | |
72 | forcehash,(char *) 0,FATAL); | |
73 | } else { | |
74 | for (;;) { | |
75 | if (getln(&ssin,&line,&match,'\n') == -1) | |
76 | strerr_die2sys(111,FATAL,ERR_READ_INPUT); | |
77 | if (!match) break; | |
78 | if (line.len == 1 || *line.s == '#') continue; | |
79 | line.s[line.len - 1] = '\0'; | |
80 | if (flagname) { | |
81 | cp = line.s; | |
82 | while ((ch = *cp)) { | |
83 | if (ch == '\\') { | |
84 | if (!*(++cp)) break; | |
85 | } else if (ch == ' ' || ch == '\t' || ch == ',') break; | |
86 | cp++; | |
87 | } | |
88 | if (ch) | |
89 | *cp = '\0'; | |
90 | } | |
91 | (void) subscribe(dir,line.s,0,"","+manual",flagmysql, | |
92 | forcehash,(char *) 0,FATAL); | |
93 | } | |
94 | } | |
95 | closesql(); | |
5b62e993 MW |
96 | _exit(0); |
97 | } |