From 4ca00dc38c72f67dc714fbb45b3006afec097c9c Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Sat, 19 Oct 2019 13:26:56 +0000
Subject: [PATCH] Compression except of trisurf header is done. Preparing for decompression

---
 src/b64zlib_compression.c |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/b64zlib_compression.c b/src/b64zlib_compression.c
index 09ed942..5f51a97 100644
--- a/src/b64zlib_compression.c
+++ b/src/b64zlib_compression.c
@@ -78,7 +78,6 @@
 	free(compr);
 
 	ts_uint header[4]={1, data_len, data_len, number_of_compressed_bytes};
-	fprintf(stderr,"Header before encoding: %d, %d, %d, %d\n", header[0],header[1],header[2], header[3]);
 	char *encoded_header=(char *)base64_encode((unsigned char *)header, 4*sizeof(ts_uint), &nbase2);
 	char *return_value=malloc((nbase1+nbase2+1)*sizeof(char));
 	strncpy(return_value,encoded_header,nbase2);
@@ -89,9 +88,13 @@
 	free(encoded_header);
 
 	//test decoding and decompression
-	char *test_data = ts_decompress((unsigned char *)return_value, nbase1+nbase2, data_len);
-	free(test_data);
-	fprintf(stderr,"WAS HERE!\n");
+	//char *test_data = ts_decompress((unsigned char *)return_value, nbase1+nbase2, data_len);
+	//for(int i=0;i<data_len;i++){
+	//	if(data[i]!=test_data[i]){
+	//		fprintf(stderr,"(DE)COMPRESSION ERROR!\n");
+	//	}
+	//}
+	//free(test_data);
 	return return_value;
 }
 
@@ -101,8 +104,9 @@
 	size_t nbase1=0,nbase2=0;
 	header=(ts_uint *)base64_decode((const char *)compressed_data, encoded_header_len, &nbase2);
 	if(header==NULL) fprintf(stderr, "Error decoding header\n");
-	fprintf(stderr,"Header=%d, %d, %d, %d\n", header[0],header[1], header[2], header[3]);
+	//fprintf(stderr,"Header=%d, %d, %d, %d\n", header[0],header[1], header[2], header[3]);
 	unsigned char *decoded_data=base64_decode((const char *)&compressed_data[encoded_header_len], data_len-encoded_header_len, &nbase1);
+	if(decoded_data==NULL) fprintf(stderr, "Error decoding compressed data\n");
 	unsigned char *return_value=(unsigned char *)malloc(result_len*sizeof(char));
 	uncompress(return_value, (unsigned long *)&result_len, decoded_data, header[3]);
 	free(decoded_data);
@@ -123,7 +127,6 @@
                                 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
                                 'w', 'x', 'y', 'z', '0', '1', '2', '3',
                                 '4', '5', '6', '7', '8', '9', '+', '/'};
-static char *decoding_table = NULL;
 static int mod_table[] = {0, 2, 1};
 
 
@@ -155,7 +158,7 @@
 
 unsigned char *base64_decode(const char *data, size_t input_length, size_t *output_length) {
 	int i,j;
-	if (decoding_table == NULL) build_decoding_table();
+	char *decoding_table = build_decoding_table();
 
 	if (input_length % 4 != 0) return NULL;
 
@@ -181,23 +184,20 @@
        	if (j < *output_length) decoded_data[j++] = (triple >> 1 * 8) & 0xFF;
        	if (j < *output_length) decoded_data[j++] = (triple >> 0 * 8) & 0xFF;
     }
-	if(decoding_table !=NULL) free(decoding_table);
+	free(decoding_table);
     return decoded_data;
 }
 
 
-void build_decoding_table() {
-
-    decoding_table = malloc(256);
+char *build_decoding_table() {
+    char *decoding_table = malloc(256);
 	int i;
     for (i = 0; i < 64; i++)
 		decoding_table[(unsigned char) encoding_table[i]] = i;
+	return decoding_table;
 }
 
 
-void base64_cleanup() {
-    free(decoding_table);
-}
 
 
 

--
Gitblit v1.9.3