]> code.citadel.org Git - citadel.git/blobdiff - webcit/tcp_sockets.c
Use strbuf in template token handler
[citadel.git] / webcit / tcp_sockets.c
index 19fb7a258a464f81a0e1b5f4d863e43fca500f85..2f969242ec6df4e98ebc971e61fb0fafd6fa89d7 100644 (file)
@@ -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))
        {