X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=libcitadel%2Ftests%2Fstringbuf_stream.c;fp=libcitadel%2Ftests%2Fstringbuf_stream.c;h=6ea03a7b19dd8c809cdab0e04e52624ea0f0934e;hp=0000000000000000000000000000000000000000;hb=e50541a93234d675ea8e0055326f335daa1ced76;hpb=dda7d0d3dfaa0a7fede33155e2795f4379d492e7 diff --git a/libcitadel/tests/stringbuf_stream.c b/libcitadel/tests/stringbuf_stream.c new file mode 100644 index 000000000..6ea03a7b1 --- /dev/null +++ b/libcitadel/tests/stringbuf_stream.c @@ -0,0 +1,163 @@ +/* + * CUnit - A Unit testing framework library for C. + * Copyright (C) 2001 Anil Kumar + * + * This library is open source software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +typedef void testfunc(int Sock); + +#include + +#include "../lib/libcitadel.h" + + +int DeZip = -1; +int DeBase64 = -1; + +int msock; /* master listening socket */ +int BindPort; +int time_to_die=0; +int n_Lines_to_read = 0; +int blobsize = 0; +int timeout = 5; +int selres = 1; +char ip_addr[256]="0.0.0.0"; + + + +static void StreamEncode(void) +{ + IOBuffer ReadBuffer; + IOBuffer WriteBuffer; + int err; + int done = 0; + void *vStream; + + memset(&ReadBuffer, 0, sizeof(IOBuffer)); + memset(&WriteBuffer, 0, sizeof(IOBuffer)); + ReadBuffer.fd = fileno(stdin); + WriteBuffer.fd = fileno(stdout); + ReadBuffer.Buf = NewStrBufPlain(NULL, SIZ*2); + WriteBuffer.Buf = NewStrBufPlain(NULL, SIZ*2); + + int fdin = fileno(stdin); + int fdout = fileno(stdout); + eStreamType ST; + + + if (DeZip == 0) + ST = eZLibEncode; + else if (DeZip == 1) + ST = eZLibDecode; + else if (DeBase64 == 0) + ST = eBase64Encode; + else if (DeBase64 == 1) + ST = eBase64Decode; + else + ST = eEmtyCodec; + vStream = StrBufNewStreamContext(ST); + + while (!done && (fdin >= 0) && (fdout >= 0) && (!feof(stdin))) + { + + done = StrBuf_read_one_chunk_callback(fdin, + 0, + &ReadBuffer) < SIZ * 4; + if (IOBufferStrLength(&ReadBuffer) == 0) + { + done = 1; + } + do + { + StrBufStreamTranscode(ST, &WriteBuffer, &ReadBuffer, NULL, -1, vStream, done); + + while (IOBufferStrLength(&WriteBuffer) > 0) + { + err = StrBuf_write_one_chunk_callback(fdout, + 0, + &WriteBuffer); + } + } while (IOBufferStrLength(&ReadBuffer) > 0); + } + + + StrBufDestroyStreamContext(ST, &vStream); + + FreeStrBuf(&ReadBuffer.Buf); + FreeStrBuf(&WriteBuffer.Buf); + time_to_die = 1; +} + + + + +int main(int argc, char* argv[]) +{ + char a; + setvbuf(stdout, NULL, _IONBF, 0); + + + while ((a = getopt(argc, argv, "z:b")) != EOF) + { + switch (a) { + + case 'z': + // zip... + DeZip = *optarg == 'x'; + break; + case 'b': + // base64 + DeBase64 = *optarg == 'x'; + + } + } + + + StartLibCitadel(8); + + StreamEncode(); + return 0; +} + + +/// run -z 1 < ~/testfile1.txt > /tmp/blarg.z