* 0 Request timed out.
* -1 Connection is broken, or other error.
*/
-int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, int bytes, int timeout)
+int client_read_to(int *sock, StrBuf *Target, StrBuf *Buf, const char **Pos, int bytes, int timeout)
{
const char *Error;
int retval = 0;
#ifdef HAVE_OPENSSL
if (is_https) {
+ long bufremain = StrLength(Buf) - (*Pos - ChrPtr(Buf));
+ StrBufAppendBufPlain(Target, *Pos, bufremain, 0);
+ *Pos = NULL;
+ FlushStrBuf(Buf);
+
while ((StrLength(Buf) + StrLength(Target) < bytes) &&
(retval >= 0))
retval = client_read_sslbuffer(Buf, timeout);
}
#endif
- if (StrLength(Buf) > 0) {/*/// todo: what if Buf > bytes?*/
- StrBufAppendBuf(Target, Buf, 0);
- }
- retval = StrBufReadBLOB(Target,
- sock,
- (StrLength(Target) > 0),
- bytes - StrLength(Target),
- &Error);
+ retval = StrBufReadBLOBBuffered(Target,
+ Buf, Pos,
+ sock,
+ 1,
+ bytes,
+ O_TERM,
+ &Error);
if (retval < 0) {
lprintf(2, "client_read() failed: %s\n",
Error);
fd_set wset;
int fdflags;
- //#ifdef HAVE_ZLIB
- /* Perform gzip compression, if enabled and supported by client */
if (!DisableGzip && (WCC->gzip_ok) && CompressBuffer(WCC->WBuf))
{
hprintf("Content-encoding: gzip\r\n");
}
- //#endif /* HAVE_ZLIB */
hprintf("Content-length: %d\r\n\r\n", StrLength(WCC->WBuf));
}
-
-/*
- * Read data from the client socket with default timeout.
- * (This is implemented in terms of client_read_to() and could be
- * justifiably moved out of sysdep.c)
- *
- * sock the socket fd to read from
- * buf the buffer to write to
- * bytes Number of bytes to read
- */
-int client_read(int *sock, StrBuf *Target, StrBuf *buf, int bytes)
-{
- return (client_read_to(sock, Target, buf, bytes, SLEEPING));
-}
-
-
-
/*
* Shut us down the regular way.
* signum is the signal we want to forward
const char *Error, *pch, *pchs;
int rlen, len, retval = 0;
+#ifdef HAVE_OPENSSL
if (is_https) {
int ntries = 0;
if (StrLength(CLineBuf) > 0) {
return -1;
}
else
+#endif
return StrBufTCP_read_buffered_line_fast(Target,
CLineBuf,
Pos,