ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
ezmlm-sub.c
Go to the documentation of this file.
1#include <sys/types.h>
2#include <sys/stat.h>
3#include <unistd.h>
4#include "subscribe.h"
5#include "getoptb.h"
6#include "stralloc.h"
7#include "buffer.h"
8#include "readwrite.h"
9#include "getln.h"
10#include "scan.h"
11#include "errtxt.h"
12#include "idx.h"
13#include "auto_version.h"
14#include "logmsg.h"
15
16#define WHO "ezmlm-subunsub"
17
23
24stralloc line = {0};
25
26static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
27static void die_usage(void) { logmsg(WHO,100,USAGE,"ezmlm-sub [-mMvV] [-h hash] [-n] dir [box@domain [name]] ..."); };
28
29int main (int argc,char **argv)
30{
31 char *dir;
32 char *addr;
33 char *comment;
34 char *cp;
35 char ch;
36 int match;
37 int flagmysql = 1; /* use mysql if supported */
38 int forcehash = -1;
39 int flagname = 0;
40 int submode = 1; // subscribe
41 unsigned long u;
42 int opt;
43 char manual[8] = "+manual";
44
45 manual[0] = submode ? '+' : '-';
46
47 umask(022);
48 while ((opt = getoptb(argc,argv,"h:HmMnNvV")) != opteof)
49 switch(opt) {
50 case 'h': scan_ulong(optarg,&u); forcehash = 0; break;
51 case 'H': forcehash = -1; break;
52 case 'm': flagmysql = 1; break;
53 case 'M': flagmysql = 0; break;
54 case 'n': flagname = 1; break;
55 case 'N': flagname = 0; break;
56 case 'v':
57 case 'V': logmsg(WHO,0,VERSION,auto_version);
58 default: die_usage();
59 }
60
61 dir = argv[optind++];
62 if (!dir) die_usage();
63
64 if (dir[0] != '/')
65 logmsg(WHO,100,FATAL,B(ERR_SLASH,dir));
66
67 if (chdir(dir) == -1)
68 logmsg(WHO,111,FATAL,B(ERR_SWITCH,dir));
69
70 if (forcehash == 0) forcehash = (int) u;
71
72 if (argv[optind]) {
73 if (flagname) {
74 /* allow repeats and last addr doesn't need comment */
75 while ((addr = argv[optind++])) {
76 subscribe(dir,addr,submode,argv[optind],manual,flagmysql,forcehash,(char *) 0);
77 if (!argv[optind++]) break;
78 }
79 } else {
80 while ((addr = argv[optind++]))
81 subscribe(dir,addr,submode,"",manual,flagmysql,forcehash,(char *) 0);
82 }
83 } else { /* stdin */
84 for (;;) {
85 if (getln(buffer_0,&line,&match,'\n') == -1)
86 logmsg(WHO,111,FATAL,ERR_READ_INPUT);
87 if (!match) break;
88 if (line.len == 1 || *line.s == '#') continue;
89 line.s[line.len - 1] = '\0';
90 comment = (char *) 0;
91 if (flagname) {
92 cp = line.s;
93 while ((ch = *cp)) {
94 if (ch == '\\') {
95 if (!*(++cp)) break;
96 } else
97 if (ch == ' ' || ch == '\t' || ch == ',') break;
98 cp++;
99 }
100 if (ch) {
101 *cp = '\0';
102 comment = cp + 1;
103 }
104 }
105 subscribe(dir,line.s,submode,comment,manual,flagmysql,forcehash,(char *) 0);
106 }
107 }
108 closesql();
109 _exit(0);
110}
const char auto_version[]
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
#define ERR_READ_INPUT
Definition errtxt.h:26
#define ERR_SWITCH
Definition errtxt.h:42
#define ERR_SLASH
Definition errtxt.h:118
void closesql(void)
close connection to SQL server, if open
Definition opensql.c:21
int subscribe(const char *dir, const char *username, int flagadd, const char *from, const char *event, int flagmysql, int forcehash, const char *table_override)
Definition subscribe.c:76
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
char * dir
int main()
Definition ezmlm-weed.c:69
int opt
Definition ezmlm-cron.c:53
const char * cp
Definition ezmlm-cron.c:76
stralloc addr
Definition ezmlm-cron.c:45
int match
Definition ezmlm-cgi.c:140
stralloc comment
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32