s/qmail 4.2.29a
Next generation secure email transport
Loading...
Searching...
No Matches
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
10{
11 logmsg(WHO,100,FATAL,"bad database format");
12}
13void nomem()
14{
15 logmsg(WHO,111,FATAL,"out of memory");
16}
17
18void 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
28void out(char *ch)
29{
30 if (buffer_put(buffer_1small,ch,1) == -1)
31 logmsg(WHO,111,FATAL,"unable to write output");
32}
33
34void printbuf(char *buf)
35{
36 while (*buf)
37 out(buf++);
38}
39
40void 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
54stralloc key = {0};
55stralloc data = {0};
56
57int 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}
int stralloc_copys(stralloc *, char const *)
stralloc out
Definition: dnscname.c:12
void _exit()
uint32 dlen
Definition: fastforward.c:117
char buf[100+FMT_ULONG]
Definition: hier.c:10
stralloc key
Definition: printforward.c:54
void badformat()
Definition: printforward.c:9
void printsafe(char *buf, int len)
Definition: printforward.c:40
void getch(char *ch)
Definition: printforward.c:18
stralloc data
Definition: printforward.c:55
void nomem()
Definition: printforward.c:13
#define WHO
Definition: printforward.c:7
int main()
Definition: printforward.c:57
void printbuf(char *buf)
Definition: printforward.c:34
int j
Definition: qmail-send.c:920