extern int DisableGzip;
/*
- * register the timeout
- * signum signalhandler number
- * \return signals
+ * register the timeout
*/
RETSIGTYPE timeout(int signum)
{
if (rc < 0)
{
lprintf(1, "Server connection broken: %s\n",
- ErrStr);
+ (ErrStr)?ErrStr:"");
wc_backtrace();
WCC->serv_sock = (-1);
WCC->connected = 0;
int StrBuf_ServGetBLOBBuffered(StrBuf *buf, long BlobSize)
{
wcsession *WCC = WC;
- const char *Err;
+ const char *ErrStr;
int rc;
rc = StrBufReadBLOBBuffered(buf,
1,
BlobSize,
NNN_TERM,
- &Err);
+ &ErrStr);
if (rc < 0)
{
lprintf(1, "Server connection broken: %s\n",
- Err);
+ (ErrStr)?ErrStr:"");
wc_backtrace();
WCC->serv_sock = (-1);
WCC->connected = 0;
int StrBuf_ServGetBLOB(StrBuf *buf, long BlobSize)
{
wcsession *WCC = WC;
- const char *Err;
+ const char *ErrStr;
int rc;
WCC->ReadPos = NULL;
- rc = StrBufReadBLOB(buf, &WCC->serv_sock, 1, BlobSize, &Err);
+ rc = StrBufReadBLOB(buf, &WCC->serv_sock, 1, BlobSize, &ErrStr);
if (rc < 0)
{
lprintf(1, "Server connection broken: %s\n",
- Err);
+ (ErrStr)?ErrStr:"");
wc_backtrace();
WCC->serv_sock = (-1);
WCC->connected = 0;
retval = write(WCC->serv_sock, &buf[bytes_written],
nbytes - bytes_written);
if (retval < 1) {
+ const char *ErrStr = strerror(errno);
lprintf(1, "Server connection broken: %s\n",
- strerror(errno));
+ (ErrStr)?ErrStr:"");
close(WCC->serv_sock);
WCC->serv_sock = (-1);
WCC->connected = 0;
*/
int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
{
+ struct protoent *p;
struct sockaddr_in sin;
int s, i;
}
sin.sin_port = htons((u_short) port_number);
- s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
+ p = getprotobyname("tcp");
+
+ s = socket(PF_INET, SOCK_STREAM, (p->p_proto));
if (s < 0) {
lprintf(1, "Can't create a socket: %s\n", strerror(errno));
exit(WC_EXIT_BIND);
#ifdef HAVE_OPENSSL
if (is_https) {
- long bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf));
+ long bufremain;
+
+ if (Hdr->Pos == NULL)
+ Hdr->Pos = ChrPtr(Hdr->ReadBuf);
+ bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf));
+
+ if (bytes < bufremain)
+ bufremain = bytes;
StrBufAppendBufPlain(Target, Hdr->Pos, bufremain, 0);
- Hdr->Pos = NULL;
- FlushStrBuf(Hdr->ReadBuf);
-
- while ((StrLength(Hdr->ReadBuf) + StrLength(Target) < bytes) &&
- (retval >= 0))
- retval = client_read_sslbuffer(Hdr->ReadBuf, timeout);
- if (retval >= 0) {
- StrBufAppendBuf(Target, Hdr->ReadBuf, 0); /* todo: Buf > bytes? */
+ StrBufCutLeft(Hdr->ReadBuf, bufremain);
+
+ if (bytes > bufremain)
+ {
+ while ((StrLength(Hdr->ReadBuf) + StrLength(Target) < bytes) &&
+ (retval >= 0))
+ retval = client_read_sslbuffer(Hdr->ReadBuf, timeout);
+ if (retval >= 0) {
+ StrBufAppendBuf(Target, Hdr->ReadBuf, 0); /* todo: Buf > bytes? */
#ifdef HTTP_TRACING
- write(2, "\033[32m", 5);
- write(2, buf, bytes);
- write(2, "\033[30m", 5);
+ write(2, "\033[32m", 5);
+ write(2, buf, bytes);
+ write(2, "\033[30m", 5);
#endif
- return 1;
- }
- else {
- lprintf(2, "client_read_ssl() failed\n");
- return -1;
+ return 1;
+ }
+ else {
+ lprintf(2, "client_read_ssl() failed\n");
+ return -1;
+ }
}
+ else
+ return 1;
}
#endif
wcsession *WCC = WC;
const char *ptr, *eptr;
long count;
- ssize_t res;
+ ssize_t res = 0;
fd_set wset;
int fdflags;
- if (!DisableGzip && (WCC->Hdr->HR.gzip_ok) && CompressBuffer(WCC->WBuf))
+ if (!DisableGzip && (WCC->Hdr->HR.gzip_ok))
{
- hprintf("Content-encoding: gzip\r\n");
+ if (CompressBuffer(WCC->WBuf) > 0)
+ hprintf("Content-encoding: gzip\r\n");
+ else {
+ lprintf(CTDL_ALERT, "Compression failed: %d [%s] sending uncompressed\n", errno, strerror(errno));
+ wc_backtrace();
+ }
}
+ if (WCC->Hdr->HR.prohibit_caching)
+ hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
hprintf("Content-length: %d\r\n\r\n", StrLength(WCC->WBuf));
ptr = ChrPtr(WCC->HBuf);
write(2, ptr, StrLength(WCC->WBuf));
write(2, "\033[30m", 5);
#endif
+ if (WCC->Hdr->http_sock == -1)
+ return -1;
fdflags = fcntl(WC->Hdr->http_sock, F_GETFL);
- while (ptr < eptr) {
+ while ((ptr < eptr) && (WCC->Hdr->http_sock != -1)){
if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
FD_ZERO(&wset);
FD_SET(WCC->Hdr->http_sock, &wset);
}
}
- if ((res = write(WCC->Hdr->http_sock,
+ if ((WCC->Hdr->http_sock == -1) ||
+ (res = write(WCC->Hdr->http_sock,
ptr,
count)) == -1) {
lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
write(2, "\033[30m", 5);
#endif
- while (ptr < eptr) {
+ while ((ptr < eptr) && (WCC->Hdr->http_sock != -1)) {
if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
FD_ZERO(&wset);
FD_SET(WCC->Hdr->http_sock, &wset);
}
}
- if ((res = write(WCC->Hdr->http_sock,
+ if ((WCC->Hdr->http_sock == -1) ||
+ (res = write(WCC->Hdr->http_sock,
ptr,
count)) == -1) {
lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
struct timeval tv, start;
gettimeofday(&start, NULL);
+ if (fd == -1)
+ return -1;
shutdown(fd, 1);
do {
do {
(ParsedHttpHdrs *httpreq)
{
- httpreq->ReadBuf = NewStrBuf();
+ httpreq->ReadBuf = NewStrBufPlain(NULL, SIZ * 4);
}
void