11 #include "subscribe.h"
15 static char inbuf[512];
16 char strnum[FMT_ULONG];
17 static stralloc line = {0};
18 static stralloc domains = {0};
19 static stralloc quoted = {0};
20 static stralloc fn = {0};
22 static void die_nomem(fatal)
25 strerr_die2x(111,fatal,ERR_NOMEM);
28 static void die_write(fatal)
31 strerr_die3x(111,fatal,ERR_WRITE,"stdout");
34 unsigned long putsubs(dbname,hash_lo,hash_hi,
35 subwrite,flagsql,fatal)
36 /* Outputs all userhostesses in 'dbname' to stdout. If userhost is not null */
37 /* that userhost is excluded. 'dbname' is the base directory name. */
38 /* subwrite must be a*/
39 /* function returning >=0 on success, -1 on error, and taking arguments */
40 /* (char* string, unsigned int length). It will be called once per address */
41 /* and should take care of newline or whatever needed for the output form. */
43 char *dbname; /* database base dir */
44 unsigned long hash_lo;
45 unsigned long hash_hi;
46 int subwrite(); /* write function. */
48 char *fatal; /* fatal error string */
54 unsigned long no = 0L;
58 if (!stralloc_copys(&fn,dbname)) die_nomem(fatal);
59 if (!stralloc_catb(&fn,"/subscribers/?",15)) die_nomem(fatal);
60 /* NOTE: Also copies terminal '\0' */
62 if (hash_lo > 52) hash_lo = 52;
63 if (hash_hi > 52) hash_hi = 52;
64 if (hash_hi < hash_lo) hash_hi = hash_lo;
66 for (i = hash_lo;i <= hash_hi;++i) {
67 fn.s[hashpos] = 64 + i; /* hash range 0-52 */
70 if (errno != error_noent)
71 strerr_die4sys(111,fatal,ERR_READ,fn.s,": ");
73 substdio_fdbuf(&ssin,read,fd,inbuf,sizeof(inbuf));
75 if (getln(&ssin,&line,&match,'\0') == -1)
76 strerr_die4sys(111,fatal,ERR_READ,fn.s,": ");
79 if (subwrite(line.s + 1,line.len - 2) == -1) die_write(fatal);