From f95fae8eba793751547db6b203f417b6fe7a35f7 Mon Sep 17 00:00:00 2001 From: John Denker Date: Fri, 23 Nov 2012 12:58:49 -0800 Subject: we have passable code for reading envelope data --- tools/envelope.dat | Bin 0 -> 29 bytes tools/pipette.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++- tools/test-qq | 12 +++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tools/envelope.dat create mode 100755 tools/test-qq (limited to 'tools') diff --git a/tools/envelope.dat b/tools/envelope.dat new file mode 100644 index 0000000..f103b22 Binary files /dev/null and b/tools/envelope.dat differ diff --git a/tools/pipette.c b/tools/pipette.c index 1eda2d0..c76b9e5 100644 --- a/tools/pipette.c +++ b/tools/pipette.c @@ -26,6 +26,7 @@ using namespace std; #include #include #include +#include /* for strlen() */ #include /* for fstat */ #include /* .. */ @@ -438,11 +439,84 @@ void play() { dumpstat(tube[rEnd]); dumpstat(tube[wEnd]); sleep(1.5); + int plus = dup(tube[wEnd]); close(tube[rEnd]); dumpstat(tube[rEnd]); dumpstat(tube[wEnd]); + dumpstat(plus); } +void test_read(){ +// test with: +// cat envelope.dat | 1<&0 ./pipette + char buf[1024]; + list rslt; + int didsome(0); + for (;;){ // loop over all read buffers + int nr = read(1, buf, sizeof(buf)); + if (nr == 0) break; + if (nr < 0) { + cerr << "read failed " << strError() << endl; + exit(1); + } + for (;;){ // loop over all strings + for (int ii = 0; ii < nr; ii++) { + char ch = buf[ii]; + if (ch == 0) { + if (!didsome) goto done; + didsome = 0; + continue; + } + if (!didsome) { + rslt.push_back(""); + } + rslt.back() += ch; + didsome++; + } + } + } +done:;;;; + for (list::const_iterator ptr = rslt.begin(); + ptr != rslt.end(); ptr++) { + cerr << *ptr << endl; + } +} + +#if 0 +void old_test_read(){ +// test with: +// echo asfd | 1<&0 ./pipette +// cat pipette.c | 1<&0 ./pipette + char buf[1024]; + for (;;){ + int nr = read(1, buf, sizeof(buf)); + if (nr == 0) break; + if (nr < 0) { + cerr << "read failed " << strError() << endl; + exit(1); + } +// unit 1 fails: bad file descriptor: +// int nw = write(1, buf, nr); + for (int ii = 0; ii < nr; ii++) { + char* foo; + char out[2] = {0, 0}; + char ch = buf[ii]; + if (ch) { + foo = out; + *foo = ch; + } else { + foo = "␀\n"; + } + int nw = write(2, foo, strlen(foo)); + if (nw < 0) { + cerr << "write failed " << strError() << endl; + exit(1); + } + } + } +} +#endif + int main(int argc, char** argv) { { progname = *argv; @@ -452,7 +526,9 @@ int main(int argc, char** argv) { progid = binder.str(); } - play(); +// play(); + test_read(); + cerr << "" << endl; exit(0); #define foo(name, num) codemap[num] = #name ; diff --git a/tools/test-qq b/tools/test-qq new file mode 100755 index 0000000..b747bc8 --- /dev/null +++ b/tools/test-qq @@ -0,0 +1,12 @@ +#! /bin/bash + +host=0 +port=1288 + +flags_not_used=" -u21165 -g21164 " + +PATH=/var/qmail/bin:$PATH # so we can find qmail-smtpd and friends + +QMAILQUEUE=/usr/src/netqmail-1.06/tools/pipette \ + /usr/local/bin/tcpserver -R -x/etc/tcpserver/smtp.cdb \ + $host $port qmail-smtpd -- cgit v1.2.3