/*********************************************************************************************************************************** Compress data ***********************************************************************************************************************************/ static Buffer * testCompress(IoFilter *compress, Buffer *decompressed, size_t inputSize, size_t outputSize) { Buffer *compressed = bufNew(1024 * 1024); size_t inputTotal = 0; ioBufferSizeSet(outputSize); IoFilterGroup *filterGroup = ioFilterGroupNew(); ioFilterGroupAdd(filterGroup, compress); IoWrite *write = ioBufferWriteNew(compressed); ioWriteFilterGroupSet(write, filterGroup); ioWriteOpen(write); // Compress input data while (inputTotal < bufSize(decompressed)) { // Generate the input buffer based on input size. This breaks the data up into chunks as it would be in a real scenario. Buffer *input = bufNewC( bufPtr(decompressed) + inputTotal, inputSize > bufSize(decompressed) - inputTotal ? bufSize(decompressed) - inputTotal : inputSize); ioWrite(write, input); inputTotal += bufUsed(input); bufFree(input); } ioWriteClose(write); memContextFree(((GzipCompress *)ioFilterDriver(compress))->memContext); return compressed; }
/*********************************************************************************************************************************** Decompress data ***********************************************************************************************************************************/ static Buffer * testDecompress(IoFilter *decompress, Buffer *compressed, size_t inputSize, size_t outputSize) { Buffer *decompressed = bufNew(1024 * 1024); Buffer *output = bufNew(outputSize); ioBufferSizeSet(inputSize); IoFilterGroup *filterGroup = ioFilterGroupNew(); ioFilterGroupAdd(filterGroup, decompress); IoRead *read = ioBufferReadNew(compressed); ioReadFilterGroupSet(read, filterGroup); ioReadOpen(read); while (!ioReadEof(read)) { ioRead(read, output); bufCat(decompressed, output); bufUsedZero(output); } ioReadClose(read); bufFree(output); memContextFree(((GzipDecompress *)ioFilterDriver(decompress))->memContext); return decompressed; }
/* * Return a processed source line list for the next line of the file. * The source line list may have several entries if the line is an * includer directive or requires a continuation. */ SrcLineList includeLine(FileName fn, FILE *fin, int *plineno, InclIsContinuedFun iscont) { SrcLineList r; inclBuffer = bufNew(); localAssertList = globalAssertList; fileState.curDir = osCurDirName(); fileState.curFile = strCopy(fnameUnparseStatic(fn)); fileState.curFname = fn; fileState.infile = fin; fileState.fileCodes = 0; fileState.fileNames = 0; fileState.lineNumber= *plineno; ifState = NoIf; r = 0; inclLine(&r, iscont); r = listNReverse(SrcLine)(r); /* Leave the assert list and included files for the next call. */ globalAssertList = localAssertList; bufFree(inclBuffer); /* strFree(fileState.curFile); !!This is held on to by the srclines.*/ listFree(Hash) (fileState.fileCodes); listFree(String)(fileState.fileNames); *plineno = fileState.lineNumber; inclFileLineNo = fileState.lineNumber; return r; }
/* Map iana names to OpenSSL names so users can provide IANA names as well as OpenSSL cipher names */ static char *mapCipherNames(char *ciphers) { WebsBuf buf; CipherMap *cp; char *cipher, *next, *str; if (!ciphers || *ciphers == 0) { return 0; } bufCreate(&buf, 0, 0); ciphers = sclone(ciphers); for (next = ciphers; (cipher = stok(next, ":, \t", &next)) != 0; ) { for (cp = cipherMap; cp->name; cp++) { if (smatch(cp->name, cipher)) { bufPut(&buf, "%s:", cp->ossName); break; } } if (cp->name == 0) { bufPut(&buf, "%s:", cipher); } } wfree(ciphers); str = sclone(bufStart(&buf)); bufFree(&buf); return str; }
/* * Return a processed source line list of the file contents. */ SrcLineList includeFile(FileName fname) { String fnameString; SrcLineList r; inclSerialLineNo = 0; fnameString = strCopy(fnameUnparseStatic(fname)); inclBuffer = bufNew(); includedFileCodes = 0; localAssertList = listCopy(String)(globalAssertList); fileState.curDir = osCurDirName(); fileState.fileCodes = 0; fileState.fileNames = 0; r = listNReverse(SrcLine)( inclFile(fnameString, false, true, &inclFileLineNo)); strFree(fnameString); bufFree(inclBuffer); listFree(String)(localAssertList); listFree(Hash)(includedFileCodes); return r; }
void httpFree(HTTP *http) { if (http) { bufFree(http->in); free(http); } }
static int readClientRequest(int fd) { FD *f; Buf *buf; f = table[fd]; buf = readAvailableBytes(fd); send(f->writeFD, current(buf), inputLength(buf), 0); if (!logRequest(f, buf)) { bufFree(buf); } return 0; }
static int readProxyResponse(int fd) { FD *f; Buf *buf; f = table[fd]; buf = readStream(fd, (unsigned char *) "readProxyResponse"); send(f->writeFD, current(buf), inputLength(buf), 0); if (!logResponse(f, buf)) { bufFree(buf); } removeFD(f->writeFD); removeFD(fd); return 0; }
/* Evalute all lines in the edit box "id" b/ween "fromLine" and "toLine" */ local void wglEvalLines(int editBox, int fromLine, int toLine) { int i; LPSTR lineStr; Buffer evalBuf = bufNew(); for (i = fromLine; i < toLine; i++) { lineStr = pfcGetLine(editBox, i); if (lineStr[0] == NULL) continue; /* Skip blank lines */ bufPuts(evalBuf, lineStr); bufPutc(evalBuf, '\n'); } bufPutc(evalBuf, EOF); bufStart(evalBuf); osSetStdinBuffer(evalBuf); compGLoopEval(osStdin, osStdout, finfo); wglShowOutput(editBox); bufFree(evalBuf); }
static void httpGetObject(App *app, HTTP *http, int sock) { Buf *buf; HTTPNameValue *h; app->printHTML(app, "<h4>Request</h4>"); app->printHTML(app, "<pre>"); buf = bufAlloc(sock); bufMark(buf, 0); bufPutString(buf, (unsigned char *) "GET "); if (http->url->path) { bufPutString(buf, http->url->path); } if (http->url->params) { bufPutString(buf, http->url->params); } if (http->url->query) { bufPutString(buf, http->url->query); } bufPutChar(buf, ' '); bufPutString(buf, http->version); bufPutString(buf, (unsigned char *) "\r\n"); bufMark(buf, 0); app->httpRequest(app, buf); h = http->headers; if (h) { while (h->name) { httpPutHeader(app, buf, (char *) h->name, (char *) h->value); h++; } } httpPutHeader(app, buf, "Connection", "close"); httpPutHeader(app, buf, "Host", (char *) http->url->host); bufPutString(buf, (unsigned char *) "\r\n"); bufMark(buf, 0); app->httpRequest(app, buf); app->printHTML(app, "</pre>"); if (bufError(buf)) { return; } bufSend(buf); bufFree(buf); httpRead(app, http, sock); }
void httpParseStream(HTTP *http, App *app, unsigned char *url) { Buf *buf; unsigned short c; unsigned char *contentType; int chunked; int i; unsigned char *line; unsigned int size; chunked = 0; c = httpReadHeaders(http, app, http->in, url, &contentType, &chunked); if (chunked) { buf = bufAlloc(-1); while (1) { bufMark(http->in, 0); c = bufGetByte(http->in); c = readLine(http->in, c); bufMark(http->in, -1); line = bufCopy(http->in); size = 0; sscanf((char *) line, "%x", &size); free(line); if (!size) { break; } bufUnGetByte(http->in); for (i = 0; i < size; i++) { c = bufGetByte(http->in); if (c == 256) { break; } else { bufPutChar(buf, c); } } c = bufGetByte(http->in); if (c != '\r') { break; } c = bufGetByte(http->in); if (c != '\n') { break; } } bufSet(buf, 0); bufMark(buf, 0); } else { buf = http->in; } http->body = bufCurrent(buf); if (contentType) { if ( (contentType != emptyHTTPResponse) && (contentType != http09Response) && (contentType != locationURLWasAdded) ) { app->contentType(app, contentType); if (!strcasecmp((char *) contentType, "text/html")) { htmlRead(app, buf, url); } else { httpDefaultType(http, app); } free(contentType); } } else { httpDefaultType(http, app); } if (chunked) { bufFree(buf); } app->printHTML(app, "</pre>"); }