s/qmail
4.3.21
Next generation secure email transport
Loading...
Searching...
No Matches
4.3
sqmail-4.3.21
src
printforward.c
Go to the documentation of this file.
1
#include <unistd.h>
2
#include "buffer.h"
3
#include "logmsg.h"
4
#include "stralloc.h"
5
#include "cdbread.h"
6
7
#define WHO "printmaillist"
8
9
static
void
badformat
()
10
{
11
logmsg(
WHO
,100,FATAL,
"bad database format"
);
12
}
13
static
void
nomem
()
14
{
15
logmsg(
WHO
,111,FATAL,
"out of memory"
);
16
}
17
18
static
void
getch(
char
*ch)
19
{
20
int
r;
21
r = buffer_get(buffer_0small,ch,1);
22
if
(r == -1)
23
logmsg(
WHO
,111,FATAL,
"unable to read input"
);
24
if
(r == 0)
25
badformat
();
26
}
27
28
static
void
out
(
char
*ch)
29
{
30
if
(buffer_put(buffer_1small,ch,1) == -1)
31
logmsg(
WHO
,111,FATAL,
"unable to write output"
);
32
}
33
34
static
void
printbuf(
char
*
buf
)
35
{
36
while
(*
buf
)
37
out
(
buf
++);
38
}
39
40
static
void
printsafe(
char
*
buf
,
int
len)
41
{
42
char
ch;
43
44
while
(len) {
45
ch = *
buf
;
46
if
((ch <= 32) || (ch ==
','
) || (ch ==
':'
) || (ch ==
';'
) || (ch ==
'\\'
) || (ch ==
'#'
))
47
out
(
"\\"
);
48
out
(&ch);
49
++
buf
;
50
--len;
51
}
52
}
53
54
stralloc
key
= {0};
55
stralloc
data
= {0};
56
57
int
main
()
58
{
59
uint32 eod;
60
uint32 pos;
61
uint32 klen;
62
uint32
dlen
;
63
char
buf
[8];
64
char
ch;
65
int
i;
66
int
j
;
67
68
for
(i = 0; i < 4; ++i)
69
getch(
buf
+ i);
70
eod = cdb_unpack(
buf
);
71
72
for
(i = 4; i < 2048; ++i)
73
getch(&ch);
74
75
pos = 2048;
76
while
(pos < eod) {
77
if
(eod - pos < 8)
badformat
();
78
pos += 8;
79
for
(i = 0; i < 8; ++i) getch(
buf
+ i);
80
klen = cdb_unpack(
buf
);
81
dlen
= cdb_unpack(
buf
+ 4);
82
83
if
(!
stralloc_copys
(&
key
,
""
))
nomem
();
84
if
(eod - pos < klen)
badformat
();
85
pos += klen;
86
while
(klen) {
87
--klen;
88
getch(&ch);
89
if
(!stralloc_append(&
key
,&ch))
nomem
();
90
}
91
92
if
(eod - pos <
dlen
)
badformat
();
93
pos +=
dlen
;
94
if
(!
stralloc_copys
(&
data
,
""
))
nomem
();
95
while
(
dlen
) {
96
--
dlen
;
97
getch(&ch);
98
if
(!stralloc_append(&
data
,&ch))
nomem
();
99
}
100
101
if
(!
key
.len)
badformat
();
102
if
(
key
.s[0] ==
'?'
) {
103
printsafe(
key
.s + 1,
key
.len - 1);
104
printbuf(
": ?"
);
105
printsafe(
data
.s,
data
.len);
106
printbuf(
";\n"
);
107
}
108
else
if
(
key
.s[0] ==
':'
) {
109
printsafe(
key
.s + 1,
key
.len - 1);
110
printbuf(
":\n"
);
111
112
i = 0;
113
for
(
j
= 0;
j
<
data
.len; ++
j
)
114
if
(!
data
.s[
j
]) {
115
if
((
data
.s[i] ==
'.'
) || (
data
.s[i] ==
'/'
)) {
116
printbuf(
", "
);
117
printsafe(
data
.s + i,
j
- i);
118
printbuf(
"\n"
);
119
}
120
else
if
((
data
.s[i] ==
'|'
) || (
data
.s[i] ==
'!'
)) {
121
printbuf(
", "
);
122
printsafe(
data
.s + i,
j
- i);
123
printbuf(
"\n"
);
124
}
125
else
if
((
data
.s[i] ==
'&'
) && (
j
- i < 900)) {
126
printbuf(
", "
);
127
printsafe(
data
.s + i,
j
- i);
128
printbuf(
"\n"
);
129
}
130
else
badformat
();
131
i =
j
+ 1;
132
}
133
if
(i !=
j
)
badformat
();
134
printbuf(
";\n"
);
135
}
136
else
badformat
();
137
}
138
139
if
(buffer_flush(buffer_1small) == -1)
140
logmsg(
WHO
,111,FATAL,
"unable to write output"
);
141
_exit
(0);
142
}
WHO
#define WHO
Definition
bouncesaying.c:8
nomem
void nomem()
Definition
columnt.c:15
stralloc_copys
int stralloc_copys(stralloc *, char const *)
out
stralloc out
Definition
dnscname.c:12
_exit
void _exit(int)
key
stralloc key
Definition
fastforward.c:116
data
stralloc data
Definition
fastforward.c:118
dlen
uint32 dlen
Definition
fastforward.c:117
buf
char buf[100+FMT_ULONG]
Definition
hier.c:11
main
int main()
Definition
printforward.c:57
badformat
void badformat()
Definition
printmaillist.c:10
j
int j
Definition
qmail-send.c:926
Generated on
for s/qmail by
1.14.0