ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
putsubs.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "getln.h"
3#include "error.h"
4#include "logmsg.h"
5#include "readwrite.h"
6#include "str.h"
7#include "fmt.h"
8#include "stralloc.h"
9#include "open.h"
10#include "buffer.h"
11#include "case.h"
12#include "errtxt.h"
13#include "subscribe.h"
14#include "qmail.h"
15#include "idx.h"
16
17#define WHO "putsubs"
18
24
25static buffer bi;
26static char inbuf[512];
27char strnum[FMT_ULONG];
28static stralloc line = {0};
29static stralloc fn = {0};
30
31static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
32static void die_write(void) { logmsg(WHO,111,FATAL,B(ERR_WRITE,"stdout")); }
33
48
49unsigned long putsubs(const char *dbname,unsigned long hash_lo,unsigned long hash_hi,int subwrite(),int flagsql)
50{
51
52 unsigned int i;
53 int fd;
54 unsigned long no = 0L;
55 int match;
56 unsigned int hashpos;
57
58 if (!stralloc_copys(&fn,dbname)) die_nomem();
59 if (!stralloc_catb(&fn,"/subscribers/?",15)) die_nomem(); /* NOTE: Also copies terminal '\0' */
60 hashpos = fn.len - 2;
61 if (hash_lo > 52) hash_lo = 52;
62 if (hash_hi > 52) hash_hi = 52;
64
65 for (i = hash_lo; i <= hash_hi; ++i) {
66 fn.s[hashpos] = 64 + i; /* hash range 0-52 */
67 fd = open_read(fn.s);
68 if (fd == -1) {
69 if (errno != error_noent)
70 logmsg(WHO,111,FATAL,B(ERR_READ,fn.s));
71 } else {
72 buffer_init(&bi,buffer_unixread,fd,inbuf,sizeof(inbuf));
73
74 for (;;) {
75 if (getln(&bi,&line,&match,'\0') == -1)
76 logmsg(WHO,111,FATAL,B(ERR_READ,fn.s));
77 if (!match)
78 break;
79 if (subwrite(line.s + 1,line.len - 2) == -1) die_write();
80 no++;
81 }
82 close(fd);
83 }
84 }
85
86 return no;
87}
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
Definition errtxt.h:18
#define ERR_WRITE
Definition errtxt.h:17
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
stralloc fn
char inbuf[1024]
buffer bi
unsigned long putsubs(const char *dbname, unsigned long hash_lo, unsigned long hash_hi, int subwrite(), int flagsql)
Definition putsubs.c:49
unsigned long hash_lo
Definition ezmlm-send.c:87
unsigned long hash_hi
Definition ezmlm-send.c:88
int fd
Definition ezmlm-cgi.c:141
int match
Definition ezmlm-cgi.c:140
int subwrite(char *s, unsigned int l)
Definition ezmlm-list.c:29
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32
void die_write(void)
Definition subscribe.c:41