X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftcp_sockets.c;h=1ac55143eed9409980df370bbca9112a3d768a8c;hb=d337527fdb58a5496428babc0d68736ada0d4c0e;hp=19fb7a258a464f81a0e1b5f4d863e43fca500f85;hpb=e1578346eec8f68c75a930ae4efc52e70e859adc;p=citadel.git diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index 19fb7a258..1ac55143e 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1987-2012 by the citadel.org team + * Copyright (c) 1987-2017 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 3. @@ -293,12 +293,12 @@ void FlushReadBuf (void) pche = pch + len; if (WCC->ReadPos != pche) { - syslog(LOG_EMERG, + syslog(LOG_ERR, "ERROR: somebody didn't eat his soup! Remaing Chars: %ld [%s]\n", (long)(pche - WCC->ReadPos), pche ); - syslog(LOG_EMERG, + syslog(LOG_ERR, "--------------------------------------------------------------------------------\n" "Whole buf: [%s]\n" "--------------------------------------------------------------------------------\n", @@ -556,11 +556,11 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, int client_con_state = 0; int chunked = 0; int is_gzip = 0; - int is_gzip_header = 1; + const char *Err = NULL; StrBuf *BufHeader = NULL; StrBuf *Buf; StrBuf *pBuf = NULL; - void *SC = NULL; + vStreamT *SC = NULL; IOBuffer ReadBuffer; IOBuffer WriteBuffer; @@ -614,7 +614,12 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, if (chunked && !DisableGzip && WCC->Hdr->HR.gzip_ok) { is_gzip = 1; - SC = StrBufNewStreamContext (eZLibEncode); + SC = StrBufNewStreamContext (eZLibEncode, &Err); + if (SC == NULL) { + syslog(LOG_ERR, "Error while initializing stream context: %s", Err); + FreeStrBuf(&Buf); + return; + } memset(&ReadBuffer, 0, sizeof(IOBuffer)); ReadBuffer.Buf = WCC->WBuf; @@ -624,7 +629,6 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, } else { - is_gzip_header = 0; pBuf = WCC->WBuf; } @@ -637,7 +641,9 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, FreeStrBuf(&Buf); FreeStrBuf(&WriteBuffer.Buf); FreeStrBuf(&BufHeader); - StrBufDestroyStreamContext(eZLibEncode, SC); + if (StrBufDestroyStreamContext(eZLibEncode, &SC, &Err) && Err) { + syslog(LOG_ERR, "Error while destroying stream context: %s", Err); + } return; } } @@ -652,7 +658,10 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, FreeStrBuf(&Buf); FreeStrBuf(&WriteBuffer.Buf); FreeStrBuf(&BufHeader); - StrBufDestroyStreamContext(eZLibEncode, SC); + StrBufDestroyStreamContext(eZLibEncode, &SC, &Err); + if (StrBufDestroyStreamContext(eZLibEncode, &SC, &Err) && Err) { + syslog(LOG_ERR, "Error while destroying stream context: %s", Err); + } return; } @@ -686,14 +695,9 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, int rc; do { - rc = StrBufStreamTranscode(eZLibEncode, &WriteBuffer, &ReadBuffer, NULL, -1, SC, done); + rc = StrBufStreamTranscode(eZLibEncode, &WriteBuffer, &ReadBuffer, NULL, -1, SC, done, &Err); if (StrLength (pBuf) > 0) { - if (!done && is_gzip_header && (StrLength(pBuf) == 10)) { - /* we don't want to send the gzip header as single package... */ - break; - } - is_gzip_header = 0; StrBufPrintf(BufHeader, "%s%x\r\n", (first)?"":"\r\n", StrLength (pBuf)); @@ -725,7 +729,9 @@ void serv_read_binary_to_http(StrBuf *MimeType, size_t total_len, int is_static, } } - StrBufDestroyStreamContext(eZLibEncode, &SC); + if (SC && StrBufDestroyStreamContext(eZLibEncode, &SC, &Err) && Err) { + syslog(LOG_ERR, "Error while destroying stream context: %s", Err); + } FreeStrBuf(&WriteBuffer.Buf); if ((chunked) && (client_con_state == 0)) { @@ -895,13 +901,13 @@ retry: } if (b < 0) { - syslog(LOG_EMERG, "Can't bind: %s\n", strerror(errno)); + syslog(LOG_ERR, "Can't bind: %s\n", strerror(errno)); close(s); return (-WC_EXIT_BIND); } if (listen(s, queue_len) < 0) { - syslog(LOG_EMERG, "Can't listen: %s\n", strerror(errno)); + syslog(LOG_ERR, "Can't listen: %s\n", strerror(errno)); close(s); return (-WC_EXIT_BIND); } @@ -914,8 +920,7 @@ retry: * sockpath - file name of the unix domain socket * queue_len - Number of incoming connections to allow in the queue */ -int webcit_uds_server(char *sockpath, int queue_len) -{ +int webcit_uds_server(char *sockpath, int queue_len) { struct sockaddr_un addr; int s; int i; @@ -958,8 +963,6 @@ int webcit_uds_server(char *sockpath, int queue_len) } - - /* * Read data from the client socket. * @@ -973,8 +976,7 @@ int webcit_uds_server(char *sockpath, int queue_len) * 0 Request timed out. * -1 Connection is broken, or other error. */ -int client_read_to(ParsedHttpHdrs *Hdr, StrBuf *Target, int bytes, int timeout) -{ +int client_read_to(ParsedHttpHdrs *Hdr, StrBuf *Target, int bytes, int timeout) { const char *Error; int retval = 0; @@ -985,11 +987,11 @@ int client_read_to(ParsedHttpHdrs *Hdr, StrBuf *Target, int bytes, int timeout) baselen = StrLength(Target); - if (Hdr->Pos == NULL) + if (Hdr->Pos == NULL) { Hdr->Pos = ChrPtr(Hdr->ReadBuf); + } - if (StrLength(Hdr->ReadBuf) > 0) - { + if (StrLength(Hdr->ReadBuf) > 0) { bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf)); if (bytes < bufremain) @@ -998,8 +1000,7 @@ int client_read_to(ParsedHttpHdrs *Hdr, StrBuf *Target, int bytes, int timeout) StrBufCutLeft(Hdr->ReadBuf, bufremain); } - if (bytes > bufremain) - { + if (bytes > bufremain) { while ((StrLength(Hdr->ReadBuf) + StrLength(Target) < bytes + baselen) && (retval >= 0)) retval = client_read_sslbuffer(Hdr->ReadBuf, timeout); @@ -1026,8 +1027,7 @@ int client_read_to(ParsedHttpHdrs *Hdr, StrBuf *Target, int bytes, int timeout) O_TERM, &Error); if (retval < 0) { - syslog(LOG_INFO, "client_read() failed: %s\n", - Error); + syslog(LOG_INFO, "client_read() failed: %s\n", Error); wc_backtrace(LOG_DEBUG); return retval; } @@ -1090,11 +1090,12 @@ long end_burst(void) } #endif - if (WCC->Hdr->http_sock == -1) + if (WCC->Hdr->http_sock == -1) { return -1; + } fdflags = fcntl(WC->Hdr->http_sock, F_GETFL); - while ((ptr < eptr) && (WCC->Hdr->http_sock != -1)){ + while ((ptr < eptr) && (WCC->Hdr->http_sock != -1)) { if ((fdflags & O_NONBLOCK) == O_NONBLOCK) { FD_ZERO(&wset); FD_SET(WCC->Hdr->http_sock, &wset);